From c5ed30f45860b53c17336448f08201241c208d3d Mon Sep 17 00:00:00 2001 From: Marco Date: Fri, 21 Feb 2025 12:09:42 +0100 Subject: [PATCH] Use proper scene load function in all cases --- Scripts/GlobalState.cs | 5 ++++- Scripts/IntroManager.cs | 3 ++- Scripts/MainMenu.cs | 3 ++- Scripts/UI/IntroScenePlayer.cs | 3 ++- Scripts/UI/PauseMenu.cs | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Scripts/GlobalState.cs b/Scripts/GlobalState.cs index feb7ed7f..96146e9e 100644 --- a/Scripts/GlobalState.cs +++ b/Scripts/GlobalState.cs @@ -27,7 +27,7 @@ public partial class GlobalState : Node // The solution is to defer the load to a later time, when // we can be sure that no code from the current scene is running: - CallDeferred(MethodName.DeferredGotoScene, path); + CallDeferred(MethodName.DeferredGotoScene, path, new MapStartDataResource()); } public void GoToScene(string path, MapStartDataResource startData) @@ -53,6 +53,9 @@ public partial class GlobalState : Node // Optionally, to make it compatible with the SceneTree.change_scene_to_file() API. GetTree().CurrentScene = CurrentScene; + // // Update current scene here too + // CurrentScene = GetTree().Root.GetChild(-1); + if (startData is not null) { // Call deferred if it gives issues diff --git a/Scripts/IntroManager.cs b/Scripts/IntroManager.cs index d7789dd0..8dd4cc7c 100644 --- a/Scripts/IntroManager.cs +++ b/Scripts/IntroManager.cs @@ -29,7 +29,8 @@ public partial class IntroManager : Node private void DialogueEndAction() { - GetTree().ChangeSceneToFile(NextMap); + GlobalState.Instance.GotoScene(NextMap); + //GetTree().ChangeSceneToFile(NextMap); } } \ No newline at end of file diff --git a/Scripts/MainMenu.cs b/Scripts/MainMenu.cs index 8af9c790..87a5af0d 100644 --- a/Scripts/MainMenu.cs +++ b/Scripts/MainMenu.cs @@ -31,7 +31,8 @@ public partial class MainMenu : Control private void _on_start_button_pressed() { if (GameScene != null) { - GetTree().ChangeSceneToFile(GameScene); + GlobalState.Instance.GotoScene(GameScene); + //GetTree().ChangeSceneToFile(GameScene); } } diff --git a/Scripts/UI/IntroScenePlayer.cs b/Scripts/UI/IntroScenePlayer.cs index 206f98f0..f12c1f93 100644 --- a/Scripts/UI/IntroScenePlayer.cs +++ b/Scripts/UI/IntroScenePlayer.cs @@ -82,7 +82,8 @@ public partial class IntroScenePlayer : CanvasLayer private void Finished() { - GetTree().ChangeSceneToFile(NextSceneName); + GlobalState.Instance.GotoScene(NextSceneName); + //GetTree().ChangeSceneToFile(NextSceneName); } private async Task Transition() diff --git a/Scripts/UI/PauseMenu.cs b/Scripts/UI/PauseMenu.cs index 02dedb0e..a97647de 100644 --- a/Scripts/UI/PauseMenu.cs +++ b/Scripts/UI/PauseMenu.cs @@ -47,6 +47,7 @@ public partial class PauseMenu : Control private void QuitButtonOnPressed() { - GetTree().ChangeSceneToFile(MainMenuScene); + GlobalState.Instance.GotoScene(MainMenuScene); + //GetTree().ChangeSceneToFile(MainMenuScene); } } \ No newline at end of file