Scenario play-test returns to the screen the editor was opened from

The play-test loads the game shell, which frees the screen the editor was
opened from (the novel_editor hub). Both the scenario's end and Stop used to
switch to the engine's main menu; the editor now remembers the route it left
and switches back to it, falling back to the main menu only when it was not
opened from a route. The tools_hub run of the windows suite plays its own
scenario and checks both ways back.
This commit is contained in:
cthangover committed 2026-10-17 21:44:34 +02:00
1 parent 55ef9416ef
commit 7b6ae80616
4 files changed
+142 -7

No files matched your search

+13 -2
View File
@@ -36,6 +36,7 @@ namespace Cthangover.Core.UI.Tool.ScenarioEditor
private Label _filePathLabel;
private bool _playActive;
private string _returnRoute;
private CanvasLayer _stopOverlay;
public ScenarioEditorWindow() : base("tools/scenario_editor/title")
@@ -294,6 +295,13 @@ namespace Cthangover.Core.UI.Tool.ScenarioEditor
Visible = false;
// The screen the editor was opened from (the novel_editor hub, a
// mod menu) is freed by the shell load below; remember its route so
// the play-test returns there instead of to the engine's main menu.
var sceneService = GetNodeOrNull<GodotSceneService>("/root/GodotSceneService");
var current = sceneService?.CurrentGodotSceneName;
_returnRoute = !string.IsNullOrEmpty(current) && SceneRouteRegistry.TryGet(current, out _) ? current : null;
_stopOverlay = CreateStopOverlay();
var tree = Godot.Engine.GetMainLoop() as SceneTree;
tree?.Root.AddChild(_stopOverlay);
@@ -305,7 +313,6 @@ namespace Cthangover.Core.UI.Tool.ScenarioEditor
sceneManager.PendingSceneName = metadata.Scene;
}
var sceneService = GetNodeOrNull<GodotSceneService>("/root/GodotSceneService");
sceneService?.LoadShell();
_playActive = true;
@@ -329,7 +336,11 @@ namespace Cthangover.Core.UI.Tool.ScenarioEditor
}
var sceneService = GetNodeOrNull<GodotSceneService>("/root/GodotSceneService");
sceneService?.SwitchToMenu();
if (_returnRoute != null && SceneRouteRegistry.TryGet(_returnRoute, out var route))
sceneService?.SwitchRoute(route);
else
sceneService?.SwitchToMenu();
_returnRoute = null;
SetStatus(ToolUi.Tr("tools/scenario_editor/play_stopped"));
}