From dc72f9116a30177c174317b8b78076ccf18733bd Mon Sep 17 00:00:00 2001 From: Daniel Wong Date: Wed, 12 Oct 2022 11:06:49 +1100 Subject: [PATCH] Add fullscreen lock setup menu --- Assembly-CSharp.csproj | 1 + .../BurikoScriptFile.cs | 5 ++ MOD.Scripts.Core/MODWindowManager.cs | 20 ++++- MOD.Scripts.UI/MODMenu.cs | 7 +- MOD.Scripts.UI/MODMenuAudioSetup.cs | 2 +- MOD.Scripts.UI/MODMenuNormal.cs | 26 +++++++ MOD.Scripts.UI/MODSubMenuWindowSetup.cs | 75 +++++++++++++++++++ 7 files changed, 130 insertions(+), 6 deletions(-) create mode 100644 MOD.Scripts.UI/MODSubMenuWindowSetup.cs diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index c6303376..6e6ff5ab 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -251,6 +251,7 @@ + diff --git a/Assets.Scripts.Core.Buriko/BurikoScriptFile.cs b/Assets.Scripts.Core.Buriko/BurikoScriptFile.cs index a638e493..76b69428 100644 --- a/Assets.Scripts.Core.Buriko/BurikoScriptFile.cs +++ b/Assets.Scripts.Core.Buriko/BurikoScriptFile.cs @@ -2782,6 +2782,11 @@ private void ShowSetupMenuIfRequired() { GameSystem.Instance.MainUIController.modMenu.PushSubMenuAndShow(ModSubMenu.AudioSetup); } + + if (!MODWindowManager.FullscreenLockConfigured()) + { + GameSystem.Instance.MainUIController.modMenu.PushSubMenuAndShow(ModSubMenu.WindowSetup); + } } public BurikoVariable OperationMODGenericCall() diff --git a/MOD.Scripts.Core/MODWindowManager.cs b/MOD.Scripts.Core/MODWindowManager.cs index 3817eea2..4641977a 100644 --- a/MOD.Scripts.Core/MODWindowManager.cs +++ b/MOD.Scripts.Core/MODWindowManager.cs @@ -73,7 +73,7 @@ public static void RefreshWindowAspect(bool showToast = false) SetResolution(maybe_width: null, maybe_height: null, maybe_fullscreen: null, showToast: showToast); } - private static void SetResolution(int? maybe_width, int? maybe_height, bool? maybe_fullscreen, bool showToast=false) + public static void SetResolution(int? maybe_width, int? maybe_height, bool? maybe_fullscreen, bool showToast=false) { int height = 480; int width = 640; @@ -151,9 +151,14 @@ private static void SetResolution(int? maybe_width, int? maybe_height, bool? may // Update playerprefs (won't be saved until game exits or PlayerPrefs.Save() is called SetPlayerPrefs(); - if(showToast) + if (showToast) { - MODToaster.Show($"Set Res: {width}x{height}"); + string prefix = "Set Res"; + if(maybe_fullscreen == false && FullscreenLocked()) + { + prefix = "Fullscreen Locked"; + } + MODToaster.Show($"{prefix}: {width}x{height}"); } } @@ -209,6 +214,7 @@ public static void GameSystemInitSetResolution() if (PlayerPrefsNeedsReset()) { + ForceUnconfigureFullscreenLock(); // TODO: could fully reset playerprefs by calling PlayerPrefs.DeleteAll(), but not sure if such drastic measures are necessary? GoFullscreen(); Debug.Log("WARNING: Crash or corrupted playerprefs detected. Reverting to fullscreen mode!"); @@ -288,6 +294,10 @@ public static void OnApplicationReallyQuit(string context) public static void SetFullScreenLock(bool enableLock) { PlayerPrefs.SetInt(FULLSCREEN_LOCK_KEY, enableLock ? 1 : 0); + if(FullscreenLocked()) + { + GoFullscreen(); + } } public static bool FullscreenLocked() @@ -299,6 +309,10 @@ public static bool FullscreenLockConfigured() { return PlayerPrefs.HasKey(FULLSCREEN_LOCK_KEY); } + public static void ForceUnconfigureFullscreenLock() + { + PlayerPrefs.DeleteKey(FULLSCREEN_LOCK_KEY); + } private static Resolution GetFullscreenResolution() { diff --git a/MOD.Scripts.UI/MODMenu.cs b/MOD.Scripts.UI/MODMenu.cs index ad8e6929..c759cf1b 100644 --- a/MOD.Scripts.UI/MODMenu.cs +++ b/MOD.Scripts.UI/MODMenu.cs @@ -17,6 +17,7 @@ public enum ModSubMenu { Normal, AudioSetup, + WindowSetup, } public class MODMenu @@ -67,6 +68,7 @@ public bool TryPop() private MODMenuNormal normalMenu; private MODMenuAudioOptions audioOptionsMenu; private MODMenuAudioSetup audioSetupMenu; + private MODSubMenuWindowSetup windowSetupMenu; private SubMenuManager subMenuManager; @@ -103,6 +105,7 @@ public MODMenu(GameSystem gameSystem) this.audioOptionsMenu = new MODMenuAudioOptions(this); this.normalMenu = new MODMenuNormal(this, this.audioOptionsMenu); this.audioSetupMenu = new MODMenuAudioSetup(this, this.audioOptionsMenu); + this.windowSetupMenu = new MODSubMenuWindowSetup(this, this.normalMenu); subMenuManager = new SubMenuManager(this.normalMenu); @@ -372,8 +375,8 @@ public void PushSubMenuAndShow(ModSubMenu subMenu) subMenuToPush = audioSetupMenu; break; - case ModSubMenu.ResolutionSetup: - subMenuToPush = resolutionSetupMenu; + case ModSubMenu.WindowSetup: + subMenuToPush = windowSetupMenu; break; case ModSubMenu.Normal: diff --git a/MOD.Scripts.UI/MODMenuAudioSetup.cs b/MOD.Scripts.UI/MODMenuAudioSetup.cs index d1aed0de..4bcf4a68 100644 --- a/MOD.Scripts.UI/MODMenuAudioSetup.cs +++ b/MOD.Scripts.UI/MODMenuAudioSetup.cs @@ -38,7 +38,7 @@ public void OnGUI() } public bool UserCanClose() => false; - public string Heading() => "First-Time Setup Menu"; + public string Heading() => "Audio Setup Menu"; public string DefaultTooltip() => "Please choose the options on the left before continuing. You can hover over a button to view its description."; } } diff --git a/MOD.Scripts.UI/MODMenuNormal.cs b/MOD.Scripts.UI/MODMenuNormal.cs index 1180b3e7..7391010f 100644 --- a/MOD.Scripts.UI/MODMenuNormal.cs +++ b/MOD.Scripts.UI/MODMenuNormal.cs @@ -1,4 +1,5 @@ using Assets.Scripts.Core; +using MOD.Scripts.Core; using MOD.Scripts.Core.Audio; using System; using System.Collections.Generic; @@ -31,6 +32,7 @@ class MODMenuNormal : MODMenuModuleInterface private readonly MODRadio radioStretchBackgrounds; private readonly MODRadio radioTextWindowModeAndCrop; private readonly MODRadio radioForceComputedLipsync; + private readonly MODRadio radioFullscreenLock; private readonly MODTabControl tabControl; @@ -136,6 +138,11 @@ Sets the script censorship level new GUIContent("Computed Always", "Always use computed lipsync for all voices. Any 'spectrum' files will be ignored.") }); + radioFullscreenLock = new MODRadio("Fullscreen Lock", new GUIContent[] { + new GUIContent("No Lock", "Allow switching to Windowed mode at any time"), + new GUIContent("Force Fullscreen Always", "Force fullscreen mode always - do not allow switching to windowed mode.") + }); + tabControl = new MODTabControl(new List { new MODTabControl.TabProperties("Gameplay", "Voice Matching and Opening Videos", GameplayTabOnGUI), @@ -282,6 +289,8 @@ private void GraphicsTabOnGUI() HeadingLabel("Resolution"); resolutionMenu.OnGUI(); + + OnGUIFullscreenLock(); } private void GameplayTabOnGUI() @@ -485,6 +494,23 @@ private void OnGUIComputedLipsync() } } + public void OnGUIFullscreenLock() + { + HeadingLabel("Fullscreen Lock"); + + int currentValue = -1; + if(MODWindowManager.FullscreenLockConfigured()) + { + currentValue = MODWindowManager.FullscreenLocked() ? 1 : 0; + } + + if (this.radioFullscreenLock.OnGUIFragment(currentValue) is int newFullscreenlock) + { + MODWindowManager.SetFullScreenLock(newFullscreenlock == 0 ? false : true); + MODToaster.Show(MODWindowManager.FullscreenLocked() ? "Fullscreen lock enabled" : "Fullscreen lock disabled"); + } + } + public bool UserCanClose() => true; public string Heading() => "Mod Options Menu"; diff --git a/MOD.Scripts.UI/MODSubMenuWindowSetup.cs b/MOD.Scripts.UI/MODSubMenuWindowSetup.cs new file mode 100644 index 00000000..3e9e75a0 --- /dev/null +++ b/MOD.Scripts.UI/MODSubMenuWindowSetup.cs @@ -0,0 +1,75 @@ +using MOD.Scripts.Core; +using System; +using System.Collections.Generic; +using System.Text; +using UnityEngine; +using static MOD.Scripts.UI.MODMenuCommon; + +namespace MOD.Scripts.UI +{ + class MODSubMenuWindowSetup : MODMenuModuleInterface + { + MODMenu modMenu; + MODMenuNormal normalMenu; + + public MODSubMenuWindowSetup(MODMenu modMenu, MODMenuNormal normalMenu) + { + this.modMenu = modMenu; + this.normalMenu = normalMenu; + } + + public void OnBeforeMenuVisible() + { + + } + + public void OnGUI() + { + HeadingLabel("Linux Resolution/Windowed Mode Setup"); + + GUILayout.Space(20); + + Label("Some Native Linux users experience crashes or softlocks when entering windowed mode, or when moving the window around (the 'Gnome Crash Bug').\n\n" + + "Please click the button below to enter windowed mode, then drag the window around."); + + GUILayout.Space(20); + + if(Button( + new GUIContent( + "Click here to test Windowed Mode", + "This button will switch the game to Windowed mode.\n\n" + + "Please try moving the window around to see if the game crashes\n\n" + + "If the game freezes, you may need to force close it and open the game again." + ))) + { + MODWindowManager.SetResolution(maybe_width: null, maybe_height: null, maybe_fullscreen: false, showToast: true); + } + + GUILayout.Space(20); + + Label("If your game crashed in windowed mode, choose 'Force Fullscreen Always'. Otherwise choose 'No Lock'"); + + GUILayout.Space(20); + + normalMenu.OnGUIFullscreenLock(); + + GUILayout.Space(20); + + if (MODWindowManager.FullscreenLockConfigured()) + { + if(Button(new GUIContent("Click here when you're finished."))) + { + modMenu.PopSubMenu(); + } + } + else + { + Label("You must choose an option to continue."); + } + } + + public bool UserCanClose() => false; + public string Heading() => "Linux Resolution/Windowed Mode Setup Menu"; + public string DefaultTooltip() => "Please choose the options on the left before continuing. You can hover over a button to view its description."; + } +}