Skip to content

Commit 802efc1

Browse files
authored
Converted the pause menu to a singleton to reduce allocations (#6454)
* Switched the main menu to only create the Thriveopedia when necessary to slightly cut on the time needed to create the main menu instance * Fixed unhandled errors GUI eating mouse clicks in the top right * Don't allow scroll escape from Thriveopedia * Made Thriveopedia museum page only load content when shown instead of immediately on Thriveopedia open * Started converting the pause menu to a singleton * Fixed some duplicate sound playing for Thriveopedia * A few small changes related to singleton pause menu with hooking up new ways things are reported to it * Fixed multiple Thriveopedia world page adds * Open help menu directly from tutorial * Random change Godot wanted to do * Singleton pause menu should now be working for all stages but I didn't super comprehensively test that the menu suppressions between prototypes work sensibly
1 parent ef01d52 commit 802efc1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+438
-357
lines changed

project.godot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ DiskCache="*res://src/engine/caching/DiskCache.cs"
5454
ProceduralDataCache="*res://src/engine/ProceduralDataCache.cs"
5555
PhotoStudio="*res://src/engine/PhotoStudio.tscn"
5656
PauseManager="*res://src/engine/PauseManager.cs"
57+
PauseMenu="*res://src/general/PauseMenu.tscn"
5758
GUIFocusSetter="*res://src/engine/GUIFocusSetter.cs"
5859
UnHandledErrorsGUI="*res://src/engine/UnHandledErrorsGUI.tscn"
5960
DebugDrawer="*res://src/engine/DebugDrawer.tscn"

src/engine/LogInterceptor.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ public override void _LogError(string function, string file, int line, string co
8181
if (code.Contains("with non-equal opposite anchors"))
8282
return;
8383

84+
// We might want to ignore this somewhat intermittent error: Parent node is busy adding
85+
// that sometimes happens on scene switch but doesn't seem to cause any problems
86+
8487
// Avoid recursion
8588
if (code.Contains("Unhandled Exception Log"))
8689
return;

src/engine/UnHandledErrorsGUI.tscn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ anchor_right = 1.0
1414
anchor_bottom = 1.0
1515
grow_horizontal = 2
1616
grow_vertical = 2
17+
mouse_filter = 2
1718
script = ExtResource("1_ca0xl")
1819
errorCount = NodePath("CanvasLayer/MarginContainer/VBoxContainer/ErrorCountLabel")
1920
errorPopup = NodePath("ErrorDialog")
@@ -31,11 +32,13 @@ anchor_right = 1.0
3132
offset_left = -40.0
3233
offset_bottom = 40.0
3334
grow_horizontal = 0
35+
mouse_filter = 2
3436
theme_override_constants/margin_top = 8
3537
theme_override_constants/margin_right = 10
3638

3739
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/MarginContainer"]
3840
layout_mode = 2
41+
mouse_filter = 2
3942

4043
[node name="ErrorCountLabel" type="Label" parent="CanvasLayer/MarginContainer/VBoxContainer"]
4144
visible = false

src/general/MainMenu.cs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public partial class MainMenu : NodeWithInput
4848
private NewGameSettings newGameSettings = null!;
4949
private AnimationPlayer guiAnimations = null!;
5050
private SaveManagerGUI saves = null!;
51-
private Thriveopedia thriveopedia = null!;
51+
52+
private Thriveopedia? thriveopedia;
5253

5354
[Export]
5455
private ModManager modManager = null!;
@@ -139,6 +140,9 @@ public partial class MainMenu : NodeWithInput
139140

140141
[Export]
141142
private CenterContainer menus = null!;
143+
144+
[Export]
145+
private PackedScene thriveopediaScene = null!;
142146
#pragma warning restore CA2213
143147

144148
private Array<Node>? menuArray;
@@ -189,6 +193,8 @@ public override void _Ready()
189193
// Unpause the game as the MainMenu should never be paused.
190194
PauseManager.Instance.ForceClear();
191195
MouseCaptureManager.ForceDisableCapture();
196+
PauseMenu.Instance.ReportStageTransition();
197+
PauseMenu.Instance.ForgetCurrentlyOpenPage();
192198

193199
RunMenuSetup();
194200

@@ -386,7 +392,7 @@ public bool OnEscapePressed()
386392
}
387393

388394
/// <summary>
389-
/// Setup the main menu.
395+
/// Set up the main menu.
390396
/// </summary>
391397
private void RunMenuSetup()
392398
{
@@ -406,7 +412,6 @@ private void RunMenuSetup()
406412
options = GetNode<OptionsMenu>("OptionsMenu");
407413
newGameSettings = GetNode<NewGameSettings>("NewGameSettings");
408414
saves = GetNode<SaveManagerGUI>("SaveManagerGUI");
409-
thriveopedia = GetNode<Thriveopedia>("Thriveopedia");
410415

411416
// Set initial menu
412417
SwitchMenu();
@@ -932,7 +937,9 @@ private void OnRedirectedToOptionsMenuFromNewGameSettings()
932937

933938
private void OnReturnFromThriveopedia()
934939
{
935-
thriveopedia.Visible = false;
940+
if (thriveopedia != null)
941+
thriveopedia.Visible = false;
942+
936943
SetCurrentMenu(0, false);
937944
}
938945

@@ -989,6 +996,21 @@ private void ThriveopediaPressed()
989996
// Hide all the other menus
990997
SetCurrentMenu(uint.MaxValue, false);
991998

999+
// Create the Thriveopedia if it doesn't exist yet
1000+
if (thriveopedia == null)
1001+
{
1002+
thriveopedia = thriveopediaScene.Instantiate<Thriveopedia>();
1003+
1004+
// Thriveopedia needs to start off hidden to work correctly
1005+
thriveopedia.Visible = false;
1006+
1007+
// Hook up the necessary signals
1008+
thriveopedia.Connect(Thriveopedia.SignalName.OnThriveopediaClosed,
1009+
new Callable(this, nameof(OnReturnFromThriveopedia)));
1010+
1011+
AddChild(thriveopedia);
1012+
}
1013+
9921014
// Show the Thriveopedia
9931015
thriveopedia.OpenFromMainMenu();
9941016
}
@@ -1116,8 +1138,17 @@ private void OnNewGameIntroVideoStarted()
11161138

11171139
private void OnThriveopediaOpened(string pageName)
11181140
{
1119-
thriveopedia.OpenFromMainMenu();
1120-
thriveopedia.ChangePage(pageName);
1141+
// Make sure Thriveopedia is created if missing
1142+
if (thriveopedia == null)
1143+
{
1144+
GD.Print("Creating Thriveopedia due to page open request");
1145+
ThriveopediaPressed();
1146+
}
1147+
1148+
thriveopedia!.OpenFromMainMenu();
1149+
1150+
// TODO: does something already play a sound or not in this case?
1151+
thriveopedia.ChangePage(pageName, false);
11211152
}
11221153

11231154
private void ResetPerformanceTracking()

src/general/MainMenu.tscn

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ modsInstalledButNotEnabledWarning = NodePath("ModsInstalledButNothingEnabledWarn
160160
lowPerformanceWarning = NodePath("LowPerformanceDialog")
161161
thanksDialog = NodePath("ThanksForBuyingDialog")
162162
menus = NodePath("MenuContainers/Menus")
163+
thriveopediaScene = ExtResource("49")
163164

164165
[node name="Background" type="TextureRect" parent="."]
165166
layout_mode = 1
@@ -846,10 +847,6 @@ grow_vertical = 2
846847
visible = false
847848
layout_mode = 1
848849

849-
[node name="Thriveopedia" parent="." instance=ExtResource("49")]
850-
visible = false
851-
layout_mode = 1
852-
853850
[node name="LicensesDisplay" parent="." instance=ExtResource("12")]
854851
layout_mode = 1
855852

@@ -1029,7 +1026,6 @@ ShowCloseButton = false
10291026
[connection signal="OnNewGameSettingsClosed" from="NewGameSettings" to="." method="OnReturnFromNewGameSettings"]
10301027
[connection signal="OnNewGameVideoStarted" from="NewGameSettings" to="." method="OnNewGameIntroVideoStarted"]
10311028
[connection signal="OnWantToSwitchToOptionsMenu" from="NewGameSettings" to="." method="OnRedirectedToOptionsMenuFromNewGameSettings"]
1032-
[connection signal="OnThriveopediaClosed" from="Thriveopedia" to="." method="OnReturnFromThriveopedia"]
10331029
[connection signal="hidden" from="LicensesDisplay" to="." method="OnReturnFromLicenses"]
10341030
[connection signal="hidden" from="GalleryViewer" to="." method="OnReturnFromArtGallery"]
10351031
[connection signal="OnFinishedSignal" from="CreditsView/CreditsScroll" to="." method="OnReturnFromCredits"]

0 commit comments

Comments
 (0)