move ui to mods

This commit is contained in:
cthangover committed 2026-09-24 10:42:44 +03:00
1 parent 6c5c717e32
commit 4dc53b648b
5 files changed
+22 -94

No files matched your search

+9 -42
View File
@@ -1,19 +1,15 @@
using Cthangover.Core.Scenes;
using Cthangover.Core.Actions.Atomic;
using Cthangover.Core.Actions;
using Cthangover.Core.Actions.Atomic;
using Cthangover.Core.UI;
using Cthangover.Core.Utils;
using Godot;
namespace Mods.Cooking.Workbench
{
/// <summary>
/// Scenario action registered under <c>toggle_cooking_workbench</c>
/// that toggles the cooking workbench UI panel on the scenario screen.
/// Called from scenario script directives via the action system.
/// Locates the <c>ModLastPanel</c> root node in the scene tree,
/// finds the <c>CookingWorkbenchPanel</c> child (a <see cref="WorkbenchPanel"/>),
/// and calls <c>Switch()</c> to show or hide it. No-op if the root
/// or panel node is missing.
/// Scenario action registered under <c>toggle_cooking_workbench</c>.
/// Delegates to <see cref="UiRegistry.Toggle"/>, which owns the workbench
/// panel instance and its visibility state — the action no longer searches
/// the tree or builds the scene itself, so the panel survives scene changes.
/// </summary>
public class ToggleCookingPanelAction : IScenarioAction
{
@@ -24,41 +20,12 @@ namespace Mods.Cooking.Workbench
public string Name => "toggle_cooking_workbench";
/// <summary>
/// Executes the toggle: finds the <c>CookingWorkbenchPanel</c>
/// under <c>ModLastPanel</c> and calls <c>Switch()</c> to
/// alternate its visibility state.
/// Toggles the <c>cooking_workbench</c> entry through the UI registry.
/// </summary>
public void Run(IActionContext ctx)
{
GameLogger.Log("COOKING", "ToggleCookingPanelAction.Run: looking for CookingWorkbenchPanel...");
var root = SceneContextNode.FindNode<Control>("ModLastPanel");
if (root == null)
{
GameLogger.Log("COOKING", "ToggleCookingPanelAction.Run: ModLastPanel NOT FOUND", LogLevel.Error);
return;
}
var panel = root.GetNodeOrNull<WorkbenchPanel>("CookingWorkbenchPanel");
if (panel == null)
{
GameLogger.Log("COOKING", "ToggleCookingPanelAction.Run: creating panel via TscnScenes.LoadAndBuild...");
var loaded = TscnScenes.LoadAndBuild("scenes/cooking_panel.tscn");
if (loaded == null)
{
GameLogger.Log("COOKING", "ToggleCookingPanelAction.Run: LoadAndBuild returned NULL", LogLevel.Error);
return;
}
var control = loaded as Control;
if (control == null) return;
control.Name = "CookingWorkbenchPanel";
control.Visible = false;
control.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.FullRect);
root.AddChild(control);
panel = control as WorkbenchPanel;
}
GameLogger.Log("COOKING", $"ToggleCookingPanelAction.Run: switching panel (currently Visible={panel?.Visible})");
panel?.Switch();
GameLogger.Log("COOKING", "ToggleCookingPanelAction.Run: toggling 'cooking_workbench'");
UiRegistry.Toggle("cooking_workbench");
}
}
}