Skip to content

Commit

Permalink
Add fullscreen lock setup menu
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Oct 12, 2022
1 parent 2d0dbb8 commit dc72f91
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 6 deletions.
1 change: 1 addition & 0 deletions Assembly-CSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<Compile Include="MOD.Scripts.UI\MODActions.cs" />
<Compile Include="MOD.Scripts.UI\MODMenuAudioOptions.cs" />
<Compile Include="MOD.Scripts.UI\MODMenuAudioSetup.cs" />
<Compile Include="MOD.Scripts.UI\MODSubMenuWindowSetup.cs" />
<Compile Include="MOD.Scripts.UI\MODMenuSupport.cs" />
<Compile Include="MOD.Scripts.UI\MODMenuModuleInterface.cs" />
<Compile Include="MOD.Scripts.UI\MODMenuNormal.cs" />
Expand Down
5 changes: 5 additions & 0 deletions Assets.Scripts.Core.Buriko/BurikoScriptFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 17 additions & 3 deletions MOD.Scripts.Core/MODWindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}");
}
}

Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -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()
Expand All @@ -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()
{
Expand Down
7 changes: 5 additions & 2 deletions MOD.Scripts.UI/MODMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ModSubMenu
{
Normal,
AudioSetup,
WindowSetup,
}

public class MODMenu
Expand Down Expand Up @@ -67,6 +68,7 @@ public bool TryPop()
private MODMenuNormal normalMenu;
private MODMenuAudioOptions audioOptionsMenu;
private MODMenuAudioSetup audioSetupMenu;
private MODSubMenuWindowSetup windowSetupMenu;

private SubMenuManager subMenuManager;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion MOD.Scripts.UI/MODMenuAudioSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
}
26 changes: 26 additions & 0 deletions MOD.Scripts.UI/MODMenuNormal.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Assets.Scripts.Core;
using MOD.Scripts.Core;
using MOD.Scripts.Core.Audio;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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<MODTabControl.TabProperties>
{
new MODTabControl.TabProperties("Gameplay", "Voice Matching and Opening Videos", GameplayTabOnGUI),
Expand Down Expand Up @@ -282,6 +289,8 @@ private void GraphicsTabOnGUI()
HeadingLabel("Resolution");

resolutionMenu.OnGUI();

OnGUIFullscreenLock();
}

private void GameplayTabOnGUI()
Expand Down Expand Up @@ -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";

Expand Down
75 changes: 75 additions & 0 deletions MOD.Scripts.UI/MODSubMenuWindowSetup.cs
Original file line number Diff line number Diff line change
@@ -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.";
}
}

0 comments on commit dc72f91

Please sign in to comment.