Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Screencap] Rudimentary Profiles #208

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 39 additions & 4 deletions src/Core_Screencap/Core.ScreenshotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Illusion.Game;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -72,6 +73,14 @@ public partial class ScreenshotManager
public static ConfigEntry<CameraGuideLinesMode> GuideLinesModes { get; private set; }
public static ConfigEntry<int> UIShotUpscale { get; private set; }

// screenshot setting presets

public static ConfigEntry<int> presetCount { get; private set; }
public static List<ConfigEntry<KeyboardShortcut>> presetKeys { get; private set; } = new List<ConfigEntry<KeyboardShortcut>>();
public static List<ConfigEntry<int>> presetResX { get; private set; } = new List<ConfigEntry<int>>();
public static List<ConfigEntry<int>> presetResY { get; private set; } = new List<ConfigEntry<int>>();
public static List<ConfigEntry<int>> presetDownscaling { get; private set; } = new List<ConfigEntry<int>>();
Comment on lines +79 to +82
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather make a struct to hold all these config entries in a single list.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understandable, I can fix that 😄


private void InitializeSettings()
{
KeyCapture = Config.Bind(
Expand Down Expand Up @@ -194,6 +203,21 @@ private void InitializeSettings()
"UI Screenshots", "Screenshot resolution multiplier",
1,
new ConfigDescription("Multiplies the UI screenshot resolution from the current game resolution by this amount.\nWarning: Some elements will still be rendered at the original resolution (most notably the interface).", new AcceptableValueRange<int>(1, 8), "Advanced"));

// config presets
presetCount = Config.Bind(
"Presets", "Preset Count",
1,
new ConfigDescription("Amount of additional screenshot presets. Requires Restart to apply.", new AcceptableValueRange<int>(0, 10), "Advanced"));


for(int i = 0; i < presetCount.Value; i++)
{
presetKeys.Add(Config.Bind("Presets", $"~{i + 1} - Shortcut", KeyboardShortcut.Empty, new ConfigDescription($"Keyboard Shortcut for Preset #{i + 1}.", null, "Advanced")));
presetResX.Add(Config.Bind("Presets", $"~{i + 1} - Res Horizontal", Screen.width, new ConfigDescription($"Horizontal size (width) of rendered screenshots in pixels of Preset #{i + 1}.", new AcceptableValueRange<int>(ScreenshotSizeMin, ScreenshotSizeMax), "Advanced")));
presetResY.Add(Config.Bind("Presets", $"~{i + 1} - Res Vertical", Screen.height, new ConfigDescription($"Vertical size (height) of rendered screenshots in pixels of Preset #{i + 1}.", new AcceptableValueRange<int>(ScreenshotSizeMin, ScreenshotSizeMax), "Advanced")));
presetDownscaling.Add(Config.Bind("Presets", $"~{i + 1} - Upsampling Ratio", 2, new ConfigDescription($"Capture screenshots in a higher resolution and then downscale them to desired size for Preset #{i + 1}. Prevents aliasing, perserves small details and gives a smoother result, but takes longer to create.", new AcceptableValueRange<int>(1, 4), "Advanced")));
Comment on lines +216 to +219
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to include number of the preset in the category name? e.g. [Custom Hotkey 1]

Here's how I implemented something similar, a bit less user friendly though.

}
}

#endregion
Expand Down Expand Up @@ -280,6 +304,13 @@ protected void Update()
else if (KeyCapture360.Value.IsDown()) StartCoroutine(Take360Screenshot(false));
else if (KeyCaptureAlphaIn3D.Value.IsDown()) StartCoroutine(TakeCharScreenshot(true));
else if (KeyCapture360in3D.Value.IsDown()) StartCoroutine(Take360Screenshot(true));
else
{
for (int i = 0; i < presetCount.Value && i < presetKeys.Count; i++)
{
if (presetKeys[i].Value.IsDown()) StartCoroutine(TakeCharScreenshot(false, presetResX[i].Value, presetResY[i].Value, presetDownscaling[i].Value));
}
}
}

/// <summary>
Expand Down Expand Up @@ -326,14 +357,18 @@ private IEnumerator TakeScreenshotLog(string filename)
Logger.Log(ScreenshotMessage.Value ? LogLevel.Message : LogLevel.Info, $"UI screenshot saved to {filename}");
}

private IEnumerator TakeCharScreenshot(bool in3D)
private IEnumerator TakeCharScreenshot(bool in3D, int resX = -1, int resY = -1, int downscaling = -1)
{
if (currentAlphaShot == null)
{
Logger.Log(LogLevel.Message, "Can't render a screenshot here, try UI screenshot instead");
yield break;
}

if (resX <= 0) resX = ResolutionX.Value;
if (resY <= 0) resY = ResolutionY.Value;
if (downscaling <= 0) downscaling = DownscalingRate.Value;

try { OnPreCapture?.Invoke(); }
catch (Exception ex) { Logger.LogError(ex); }

Expand All @@ -350,7 +385,7 @@ private IEnumerator TakeCharScreenshot(bool in3D)
if (!in3D)
{
yield return new WaitForEndOfFrame();
var capture = currentAlphaShot.CaptureTex(ResolutionX.Value, ResolutionY.Value, DownscalingRate.Value, CaptureAlphaMode.Value);
var capture = currentAlphaShot.CaptureTex(resX, resY, downscaling, CaptureAlphaMode.Value);

var filename = GetUniqueFilename("Render");
File.WriteAllBytes(filename, EncodeToFile(capture));
Expand All @@ -369,11 +404,11 @@ private IEnumerator TakeCharScreenshot(bool in3D)
targetTr.position += targetTr.right * EyeSeparation.Value / 2;
// Let the game render at the new position
yield return new WaitForEndOfFrame();
var capture = currentAlphaShot.CaptureTex(ResolutionX.Value, ResolutionY.Value, DownscalingRate.Value, CaptureAlphaMode.Value);
var capture = currentAlphaShot.CaptureTex(resX, resY, downscaling, CaptureAlphaMode.Value);

targetTr.position -= targetTr.right * EyeSeparation.Value;
yield return new WaitForEndOfFrame();
var capture2 = currentAlphaShot.CaptureTex(ResolutionX.Value, ResolutionY.Value, DownscalingRate.Value, CaptureAlphaMode.Value);
var capture2 = currentAlphaShot.CaptureTex(resX, resY, downscaling, CaptureAlphaMode.Value);

targetTr.position += targetTr.right * EyeSeparation.Value / 2;

Expand Down