Skip to content

Commit b17f210

Browse files
authored
Fix multiple, overlapping, instances HouseRules UI appearing. (#575)
Issue: When changing pages in the HR UI, multiple pages are overlapping onto one another. Root cause: The process that determines whether or not to load UIs (our `OnSceneLoaded()` hook function) is triggering the HR UI be loaded multiple times. Solution: Our `OnSceneLoaded()` is re-written to be more explicit about how to determine when to load in the UI. It follows the same approach as #549: to be very explicit about which scenes, and on which platforms, constitute being in the "lobby" where we want to UI rendered. --- Additional background: Some time back, RG added helpers as part of their `MotherbrainGlobalVars` class, capturing the exact platform the game is being run on. This didn't exist before, and so at the time we introduced a helper (`Common.UI/Environments`) to help us determine that ourselves. Our method has become a bit flaky as the game as been ported to different platforms and seen changes in scene numbers. It is now uneeded as RG has captured that info on their end, which we can piggyback on to determine the platform and scene more precisely. Hence the removal of some of the code in `Common.UI/Environments`.
1 parent 7804637 commit b17f210

File tree

3 files changed

+50
-44
lines changed

3 files changed

+50
-44
lines changed

Common.UI/Environments.cs

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,20 @@
22
{
33
using UnityEngine.SceneManagement;
44

5-
public enum Environment
6-
{
7-
Hangouts,
8-
NonVr,
9-
Vr,
10-
}
11-
125
public static class Environments
136
{
14-
private const int SteamHangoutsSceneIndex = 45;
15-
private const int OculusHangoutsSceneIndex = 43;
7+
private const int SteamVRHangoutsSceneIndex = 45;
8+
private const int RiftHangoutsSceneIndex = 43;
169

17-
public static Environment CurrentEnvironment()
10+
public static bool IsInHangouts()
1811
{
19-
if (IsPcEdition())
20-
{
21-
return Environment.NonVr;
22-
}
23-
24-
if (IsInHangouts())
12+
if (!MotherbrainGlobalVars.IsRunningOnVRPlatform)
2513
{
26-
return Environment.Hangouts;
14+
return false;
2715
}
2816

29-
return Environment.Vr;
30-
}
31-
32-
public static bool IsPcEdition()
33-
{
34-
return MotherbrainGlobalVars.IsRunningOnNonVRPlatform;
35-
}
36-
37-
public static bool IsInHangouts()
38-
{
39-
return SceneManager.GetActiveScene().buildIndex == SteamHangoutsSceneIndex
40-
|| SceneManager.GetActiveScene().buildIndex == OculusHangoutsSceneIndex;
17+
return SceneManager.GetActiveScene().buildIndex == SteamVRHangoutsSceneIndex
18+
|| SceneManager.GetActiveScene().buildIndex == RiftHangoutsSceneIndex;
4119
}
4220
}
4321
}

Common.UI/PageStackNavigation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private PageStackNavigation(PageStack pageStack, IElementCreator elementCreator)
3434
_nextButton = elementCreator.CreateButton(OnNextPageClick);
3535
_nextButtonText = elementCreator.CreateButtonText(">");
3636

37-
if (Environments.CurrentEnvironment() == Environment.NonVr)
37+
if (MotherbrainGlobalVars.IsRunningOnNonVRPlatform)
3838
{
3939
InitializeForNonVr();
4040
}

HouseRules.Configuration/HouseRulesConfigurationBase.cs

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ internal static class HouseRulesConfigurationBase
1515
internal const string ModName = "HouseRules.Configuration";
1616
internal const string ModAuthor = "DemeoMods Team";
1717

18-
private const int NonVrSteamLobbySceneIndex = 2;
19-
private const int NonVrCombinedSteamLobbySceneIndex = 3;
18+
private const int NonVrSteamWindowsLobbySceneIndex = 2;
19+
private const int NonVrOculusWindowsLobbySceneIndex = 2;
20+
private const int SteamVRLobbySceneIndex = 1;
21+
private const int RiftLobbySceneIndex = 1;
2022

2123
private static Action<object>? _logInfo;
2224
private static Action<object>? _logDebug;
@@ -92,36 +94,62 @@ internal static void OnSceneUnloaded(int buildIndex, string sceneName)
9294

9395
internal static void OnSceneLoaded(int buildIndex, string sceneName)
9496
{
95-
if (buildIndex == 0 || sceneName.Contains("Startup"))
97+
if (MotherbrainGlobalVars.SelectedPlatform == MotherbrainPlatform.NonVrSteamWindows)
9698
{
99+
if (buildIndex == NonVrSteamWindowsLobbySceneIndex)
100+
{
101+
LogDebug("Recognized lobby in NonVrSteamWindows. Loading UI.");
102+
_ = new GameObject("HouseRulesUiNonVr", typeof(HouseRulesUiNonVr));
103+
}
104+
97105
return;
98106
}
99107

100-
if (Environments.IsPcEdition())
108+
if (MotherbrainGlobalVars.SelectedPlatform == MotherbrainPlatform.NonVrOculusWindows)
101109
{
102-
if (buildIndex == NonVrSteamLobbySceneIndex || buildIndex == NonVrCombinedSteamLobbySceneIndex)
110+
if (buildIndex == NonVrOculusWindowsLobbySceneIndex)
103111
{
104-
LogDebug("Recognized lobby in PC. Loading UI.");
112+
LogDebug("Recognized lobby in NonVrOculusWindows. Loading UI.");
105113
_ = new GameObject("HouseRulesUiNonVr", typeof(HouseRulesUiNonVr));
106114
}
115+
116+
return;
107117
}
108-
else if (Environments.IsInHangouts() || sceneName.Contains("HobbyShop"))
118+
119+
if (Environments.IsInHangouts())
109120
{
110121
LogDebug("Recognized lobby in Hangouts. Loading UI.");
111122
_ = new GameObject("HouseRulesUiHangouts", typeof(HouseRulesUiHangouts));
123+
return;
112124
}
113-
else if (sceneName.Contains("Lobby"))
125+
126+
if (MotherbrainGlobalVars.SelectedPlatform == MotherbrainPlatform.SteamVR)
114127
{
115-
LogDebug("Recognized lobby in VR. Loading UI.");
116-
_ = new GameObject("HouseRulesUiVr", typeof(HouseRulesUiVr));
128+
if (buildIndex == SteamVRLobbySceneIndex)
129+
{
130+
LogDebug("Recognized lobby in SteamVR. Loading UI.");
131+
_ = new GameObject("HouseRulesUiVr", typeof(HouseRulesUiVr));
132+
}
133+
134+
return;
117135
}
118-
else
136+
137+
if (MotherbrainGlobalVars.SelectedPlatform == MotherbrainPlatform.Rift)
119138
{
120-
if (HR.SelectedRuleset != Ruleset.None)
139+
if (buildIndex == RiftLobbySceneIndex)
121140
{
122-
LogDebug("Recognized modded game in VR. Loading UI.");
123-
_ = new GameObject("HouseRulesUiGameVr", typeof(HouseRulesUiGameVr));
141+
LogDebug("Recognized lobby in Rift. Loading UI.");
142+
_ = new GameObject("HouseRulesUiVr", typeof(HouseRulesUiVr));
124143
}
144+
145+
return;
146+
}
147+
148+
// If a scene is loaded while a ruleset is selected, we must have loaded a game level.
149+
if (MotherbrainGlobalVars.IsRunningOnVRPlatform && HR.SelectedRuleset != Ruleset.None)
150+
{
151+
LogDebug("Recognized modded game in VR. Loading UI.");
152+
_ = new GameObject("HouseRulesUiGameVr", typeof(HouseRulesUiGameVr));
125153
}
126154
}
127155

0 commit comments

Comments
 (0)