diff --git a/Assets.Scripts.Core/GameSystem.cs b/Assets.Scripts.Core/GameSystem.cs index 959b9d56..2fa40b31 100644 --- a/Assets.Scripts.Core/GameSystem.cs +++ b/Assets.Scripts.Core/GameSystem.cs @@ -1059,7 +1059,7 @@ public T ChooseJapaneseEnglish(T japanese, T english) } } - public Resolution GetFullscreenResolution() + public Resolution GetFullscreenResolution(bool useOverride = true, bool doLogging = true) { Resolution resolution = new Resolution(); string source = ""; @@ -1119,17 +1119,24 @@ public Resolution GetFullscreenResolution() PlayerPrefs.SetInt("fullscreen_height_override", 0); } - if (PlayerPrefs.GetInt("fullscreen_width_override") > 0) + if(useOverride) { - resolution.width = PlayerPrefs.GetInt("fullscreen_width_override"); - source += " + Width Override"; + if (PlayerPrefs.GetInt("fullscreen_width_override") > 0) + { + resolution.width = PlayerPrefs.GetInt("fullscreen_width_override"); + source += " + Width Override"; + } + if (PlayerPrefs.GetInt("fullscreen_height_override") > 0) + { + resolution.height = PlayerPrefs.GetInt("fullscreen_height_override"); + source += " + Height Override"; + } } - if (PlayerPrefs.GetInt("fullscreen_height_override") > 0) + + if(doLogging) { - resolution.height = PlayerPrefs.GetInt("fullscreen_height_override"); - source += " + Height Override"; + Debug.Log("Using resolution " + resolution.width + "x" + resolution.height + " as the fullscreen resolution based on " + source + "."); } - Debug.Log("Using resolution " + resolution.width + "x" + resolution.height + " as the fullscreen resolution based on " + source + "."); return resolution; } diff --git a/MOD.Scripts.UI/MODMenuCommon.cs b/MOD.Scripts.UI/MODMenuCommon.cs index 67f4a1e2..34c0f27b 100644 --- a/MOD.Scripts.UI/MODMenuCommon.cs +++ b/MOD.Scripts.UI/MODMenuCommon.cs @@ -14,6 +14,11 @@ public static void Label(string label, params GUILayoutOption[] options) GUILayout.Label(label, MODStyleManager.OnGUIInstance.Group.label, options); } + public static void LabelRightAlign(string label, params GUILayoutOption[] options) + { + GUILayout.Label(label, MODStyleManager.OnGUIInstance.Group.labelRightAlign, options); + } + public static void Label(GUIContent content, params GUILayoutOption[] options) { GUILayout.Label(content, MODStyleManager.OnGUIInstance.Group.label, options); diff --git a/MOD.Scripts.UI/MODMenuResolution.cs b/MOD.Scripts.UI/MODMenuResolution.cs index 5d906939..b0aba6af 100644 --- a/MOD.Scripts.UI/MODMenuResolution.cs +++ b/MOD.Scripts.UI/MODMenuResolution.cs @@ -9,7 +9,16 @@ namespace MOD.Scripts.UI { class MODMenuResolution { + private string overrideFullScreenResolutionDescription = + "Set a custom fullscreen resolution\n\n" + + "Use this option only if the fullscreen resolution is detected incorrectly (such as on some Linux systems)\n" + + "You can manually type in a resolution to use below.\n\n" + + "Click 'Clear Override' to let the game automatically determine the fullscreen resolution"; + private string screenHeightString; + private string fullscreenWidthOverrideString; + private string fullscreenHeightOverrideString; + private int overrideFullResCountdown; public MODMenuResolution() { @@ -19,55 +28,142 @@ public MODMenuResolution() public void OnBeforeMenuVisible() { screenHeightString = $"{Screen.height}"; + + if (PlayerPrefs.HasKey("fullscreen_width_override")) + { + fullscreenWidthOverrideString = $"{PlayerPrefs.GetInt("fullscreen_width_override")}"; + } + + if (PlayerPrefs.HasKey("fullscreen_height_override")) + { + fullscreenHeightOverrideString = $"{PlayerPrefs.GetInt("fullscreen_height_override")}"; + } + + overrideFullResCountdown = 3; } public void OnGUI() { - Label("Resolution Settings"); + Label("Windowed Resolution Settings"); { GUILayout.BeginHorizontal(); - if (Button(new GUIContent("480p", "Set resolution to 853 x 480"))) { SetAndSaveResolution(480); } - if (Button(new GUIContent("720p", "Set resolution to 1280 x 720"))) { SetAndSaveResolution(720); } - if (Button(new GUIContent("1080p", "Set resolution to 1920 x 1080"))) { SetAndSaveResolution(1080); } - if (Button(new GUIContent("1440p", "Set resolution to 2560 x 1440"))) { SetAndSaveResolution(1440); } + + if (!GameSystem.Instance.IsFullscreen) + { + if (Button(new GUIContent("480p", "Set resolution to 853 x 480"))) { SetAndSaveResolution(480); } + if (Button(new GUIContent("720p", "Set resolution to 1280 x 720"))) { SetAndSaveResolution(720); } + if (Button(new GUIContent("1080p", "Set resolution to 1920 x 1080"))) { SetAndSaveResolution(1080); } + if (Button(new GUIContent("1440p", "Set resolution to 2560 x 1440"))) { SetAndSaveResolution(1440); } + + screenHeightString = GUILayout.TextField(screenHeightString); + if (Button(new GUIContent("Set", "Sets a custom resolution - mainly for windowed mode.\n\n" + + "Height set automatically to maintain 16:9 aspect ratio."))) + { + if (int.TryParse(screenHeightString, out int new_height)) + { + if (new_height < 480) + { + MODToaster.Show("Height too small - must be at least 480 pixels"); + new_height = 480; + } + else if (new_height > 15360) + { + MODToaster.Show("Height too big - must be less than 15360 pixels"); + new_height = 15360; + } + screenHeightString = $"{new_height}"; + int new_width = Mathf.RoundToInt(new_height * GameSystem.Instance.AspectRatio); + GameSystem.Instance.SetResolution(new_width, new_height, Screen.fullScreen); + PlayerPrefs.SetInt("width", new_width); + PlayerPrefs.SetInt("height", new_height); + } + } + } + if (GameSystem.Instance.IsFullscreen) { - if (Button(new GUIContent("Windowed", "Toggle Fullscreen"))) + if (Button(new GUIContent("Click here to go Windowed to change these settings", "Toggle Fullscreen"))) { GameSystem.Instance.DeFullscreen(PlayerPrefs.GetInt("width"), PlayerPrefs.GetInt("height")); } } else { - if (Button(new GUIContent("Fullscreen", "Toggle Fullscreen"))) + if (Button(new GUIContent("Go Fullscreen", "Toggle Fullscreen"))) { GameSystem.Instance.GoFullscreen(); } } - screenHeightString = GUILayout.TextField(screenHeightString); - if (Button(new GUIContent("Set", "Sets a custom resolution - mainly for windowed mode.\n\n" + - "Height set automatically to maintain 16:9 aspect ratio."))) + GUILayout.EndHorizontal(); + } + + GUILayout.Space(20); + + Resolution detectedRes = GameSystem.Instance.GetFullscreenResolution(useOverride: false, doLogging: false); + Resolution actualRes = GameSystem.Instance.GetFullscreenResolution(useOverride: true, doLogging: false); + string overrideString = FullscreenOverrideEnabled() ? $"{actualRes.width} x {actualRes.height}" : "Off"; + Label($"Fullscreen Resolution Override (Detected: {detectedRes.width} x {detectedRes.height} Override: {overrideString})"); + { + GUILayout.BeginHorizontal(); + + GUILayout.BeginHorizontal(); + LabelRightAlign("Width:"); + fullscreenWidthOverrideString = GUILayout.TextField(fullscreenWidthOverrideString, 5); + GUILayout.EndHorizontal(); + + GUILayout.BeginHorizontal(); + LabelRightAlign("Height:"); + fullscreenHeightOverrideString = GUILayout.TextField(fullscreenHeightOverrideString, 5); + GUILayout.EndHorizontal(); + + + bool shouldUpdateFullscreenResolution = false; + string gameClearButtonText = overrideFullResCountdown > 0 ? $"Click {overrideFullResCountdown} times to override resolution" : $"Override Fullscreen Resolution"; + if (Button(new GUIContent(gameClearButtonText, overrideFullScreenResolutionDescription))) { - if (int.TryParse(screenHeightString, out int new_height)) + if (overrideFullResCountdown > 0) + { + overrideFullResCountdown--; + } + + if (overrideFullResCountdown <= 0) { - if (new_height < 480) + if(int.TryParse(fullscreenWidthOverrideString, out int widthOverride) && widthOverride >= 640) { - MODToaster.Show("Height too small - must be at least 480 pixels"); - new_height = 480; + if(int.TryParse(fullscreenHeightOverrideString, out int heightOverride) && heightOverride >= 480) + { + PlayerPrefs.SetInt("fullscreen_width_override", widthOverride); + PlayerPrefs.SetInt("fullscreen_height_override", heightOverride); + shouldUpdateFullscreenResolution = true; + MODToaster.Show($"Fullscreen: {widthOverride} x {heightOverride}"); + } + else + { + MODToaster.Show("Invalid Height"); + } } - else if (new_height > 15360) + else { - MODToaster.Show("Height too big - must be less than 15360 pixels"); - new_height = 15360; + MODToaster.Show("Invalid Width"); } - screenHeightString = $"{new_height}"; - int new_width = Mathf.RoundToInt(new_height * GameSystem.Instance.AspectRatio); - GameSystem.Instance.SetResolution(new_width, new_height, Screen.fullScreen); - PlayerPrefs.SetInt("width", new_width); - PlayerPrefs.SetInt("height", new_height); } } + + if (Button(new GUIContent("Clear Override", overrideFullScreenResolutionDescription))) + { + PlayerPrefs.SetInt("fullscreen_width_override", 0); + PlayerPrefs.SetInt("fullscreen_height_override", 0); + fullscreenWidthOverrideString = "0"; + fullscreenHeightOverrideString = "0"; + shouldUpdateFullscreenResolution = true; + } + + if (shouldUpdateFullscreenResolution && GameSystem.Instance.IsFullscreen) + { + GameSystem.Instance.GoFullscreen(); + } + GUILayout.EndHorizontal(); } } @@ -90,5 +186,11 @@ private void SetAndSaveResolution(int height) PlayerPrefs.SetInt("width", width); PlayerPrefs.SetInt("height", height); } + + private bool FullscreenOverrideEnabled() + { + return PlayerPrefs.GetInt("fullscreen_width_override", 0) != 0 || + PlayerPrefs.GetInt("fullscreen_height_override", 0) != 0; + } } } diff --git a/MOD.Scripts.UI/MODStyleManager.cs b/MOD.Scripts.UI/MODStyleManager.cs index c3108891..f13b0090 100644 --- a/MOD.Scripts.UI/MODStyleManager.cs +++ b/MOD.Scripts.UI/MODStyleManager.cs @@ -23,6 +23,7 @@ public class StyleGroup public GUIStyle button; public GUIStyle selectedButton; public GUIStyle label; //Used for normal Label widgets + public GUIStyle labelRightAlign; public GUIStyle headingLabel; public GUIStyle upperLeftHeadingLabel; } @@ -230,6 +231,11 @@ private StyleGroup GenerateWidgetStyles(int menuWidth, int menuHeight, float gui padding = padding, }; + GUIStyle labelStyleRightAlign = new GUIStyle(labelStyle) + { + alignment = TextAnchor.MiddleRight, + }; + // Heading text style GUIStyle headingLabelStyle = new GUIStyle(labelStyle) { @@ -264,6 +270,7 @@ private StyleGroup GenerateWidgetStyles(int menuWidth, int menuHeight, float gui button = buttonStyle, selectedButton = selectedButtonStyle, label = labelStyle, + labelRightAlign = labelStyleRightAlign, headingLabel = headingLabelStyle, upperLeftHeadingLabel = upperLeftHeadingLabelStyle, toolTipShrinkage = toolTipShrinkage,