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

+13 -14
View File
@@ -8,27 +8,26 @@
"src/*.cs"
],
"depends": [ "core>=1", "interface>=1" ],
"subscriptions": [
"ui": [
{
"id": "cooking_workbench",
"kind": "overlay",
"scene": "home_kitchen",
"template": "default",
"code": "cooking_panel_init",
"trigger": "on_enter",
"slot": "ModLastPanel",
"scene_path": "scenes/cooking_panel.tscn",
"once": true,
"show_on_start": false,
"priority": 10
},
{
"id": "ration_stats",
"kind": "overlay",
"scene": "home_kitchen",
"template": "default",
"code": "dinner_tools_show",
"trigger": "on_enter",
"slot": "Lastground",
"scene_path": "scenes/ration_statistics_panel.tscn",
"once": false,
"show_on_start": true,
"priority": 20
},
{
"scene": "home_kitchen",
"template": "default",
"code": "dinner_tools_hide",
"trigger": "on_exit",
"priority": 10
}
]
}
+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");
}
}
}
-15
View File
@@ -1,15 +0,0 @@
var modPanel = FindNode<Control>("ModLastPanel");
if (modPanel == null)
return;
if (modPanel.GetNodeOrNull("CookingWorkbenchPanel") != null)
return;
var panel = Cthangover.Core.Scenes.TscnScenes.LoadAndBuild("scenes/cooking_panel.tscn");
if (panel is Control control)
{
control.Name = "CookingWorkbenchPanel";
control.Visible = false;
control.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.FullRect);
modPanel.AddChild(control);
}
-7
View File
@@ -1,7 +0,0 @@
var modPanel = FindNode<Control>("Lastground");
if (modPanel == null)
return;
var dinner = modPanel.GetNodeOrNull<Mods.Cooking.Rations.RationStatisticsPanel>("RationStatistics");
if (dinner != null)
dinner.QueueFree();
-16
View File
@@ -1,16 +0,0 @@
var modPanel = FindNode<Control>("Lastground");
if (modPanel == null)
return;
var dinner = modPanel.GetNodeOrNull<Mods.Cooking.Rations.RationStatisticsPanel>("RationStatistics");
if (dinner == null)
{
dinner = (Mods.Cooking.Rations.RationStatisticsPanel)Cthangover.Core.Scenes.TscnScenes.LoadAndBuild("scenes/ration_statistics_panel.tscn");
dinner.Name = "RationStatistics";
dinner.SetAnchorsAndOffsetsPreset(Control.LayoutPreset.FullRect);
dinner.CustomMinimumSize = new Vector2(300, 300);
modPanel.AddChild(dinner);
dinner.Show();
modPanel.UpdateMinimumSize();
}