From abeb8c09025b50767eba27c601b8c180dca4ac13 Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 5 May 2026 20:21:05 +0200 Subject: [PATCH] Improved UI calls --- Scenes/Game.tscn | 40 +++++++++++++++++-- Scripts/Camera3d.cs | 5 --- Scripts/DSL/CodingWindow.cs | 11 +++--- Scripts/Helpers/UIHandler.cs | 76 +++++++++++++++++++----------------- Scripts/Robot/RobotList.cs | 13 +++--- 5 files changed, 88 insertions(+), 57 deletions(-) diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index 5cce077..2fac78d 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -353,6 +353,40 @@ text = "Exit" visible = false layout_mode = 1 +[node name="Inventory" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=407422598] +visible = false +layout_mode = 1 +anchors_preset = 11 +anchor_left = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -525.0 +grow_horizontal = 0 +grow_vertical = 2 + +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/Inventory" unique_id=1776118554] +layout_mode = 2 + +[node name="Title" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/Content/Inventory/VBoxContainer" unique_id=1356874082] +layout_mode = 2 +bbcode_enabled = true +text = "[font_size=32]Inventory[/font_size]" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 + +[node name="ScrollContainer" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/Inventory/VBoxContainer" unique_id=1743833752] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme_override_styles/panel = SubResource("StyleBoxFlat_fgofq") + +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/Inventory/VBoxContainer/ScrollContainer" unique_id=158199023] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +theme_override_constants/separation = 10 + [node name="FooterContainer" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI" unique_id=1495029884] layout_mode = 2 @@ -391,6 +425,6 @@ texture_normal = ExtResource("12_3so38") [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button" to="CanvasLayer/UIHandler" method="HandleMenu"] [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button2" to="CanvasLayer/UIHandler" method="ShowOptions"] [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button3" to="CanvasLayer/UIHandler" method="ExitGame"] -[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Map" to="CanvasLayer/UIHandler/MainUI/Content/Map" method="ShowMap"] -[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Robots" to="CanvasLayer/UIHandler/MainUI/Content/RobotList" method="ShowList"] -[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Options" to="CanvasLayer/UIHandler" method="HandleMenu"] +[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Map" to="CanvasLayer/UIHandler" method="HandleMapButton"] +[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Robots" to="CanvasLayer/UIHandler" method="HandleRobotListButton"] +[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Options" to="CanvasLayer/UIHandler" method="HandleMenuButton"] diff --git a/Scripts/Camera3d.cs b/Scripts/Camera3d.cs index 3ea126b..c1c8135 100644 --- a/Scripts/Camera3d.cs +++ b/Scripts/Camera3d.cs @@ -20,11 +20,6 @@ public partial class Camera3d : Camera3D public override void _Process(double delta) { if (canMove) MoveCamera(delta); - if (Input.IsActionJustPressed("map")) - { - isShowingMap = !isShowingMap; - canMove = !isShowingMap; - } } public void MoveCamera(double delta) diff --git a/Scripts/DSL/CodingWindow.cs b/Scripts/DSL/CodingWindow.cs index 58b4576..3c2bb5e 100644 --- a/Scripts/DSL/CodingWindow.cs +++ b/Scripts/DSL/CodingWindow.cs @@ -23,12 +23,6 @@ public partial class CodingWindow : PanelContainer } - public void ShowWindow(Robot robot) - { - Visible = true; - this.robot = robot; - } - //Move, Harvest, Craft public void GenerateCodingBlocks() { @@ -74,4 +68,9 @@ public partial class CodingWindow : PanelContainer if(nodes.Count > 0) robot.SetupExecution(nodes); } + + public void SetRobot(Robot robot) + { + this.robot = robot; + } } diff --git a/Scripts/Helpers/UIHandler.cs b/Scripts/Helpers/UIHandler.cs index 4614224..6eec69a 100644 --- a/Scripts/Helpers/UIHandler.cs +++ b/Scripts/Helpers/UIHandler.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; using Godot; @@ -14,6 +15,8 @@ public partial class UIHandler : Control [Export] PanelContainer options; [Export] Control uiContent; [Export] PanelContainer menu; + + bool receivedRobotJumpSignal = false; public override void _Ready() { @@ -24,50 +27,33 @@ public partial class UIHandler : Control { robotList.OnRobotJumpTo += (robot) => { + if(receivedRobotJumpSignal) return; + receivedRobotJumpSignal = true; mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z + 3f); - ShowCodingWindow(robot); + codingWindow.SetRobot(robot); + OpenUIElement(codingWindow); }; - if (Input.IsActionJustPressed("map")) - { - map.ShowMap(false); - } - - if (Input.IsActionJustPressed("menu")) - { - HandleMenu(); - } - + if (Input.IsActionJustPressed("map")) HandleMapButton(); + if (Input.IsActionJustPressed("menu")) HandleMenuButton(); + if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton(); DisplayStats(); } - public void HandleMenu() + public void HandleMenuButton() { - bool shouldMenuOpen = true; - foreach (PanelContainer element in uiContent.GetChildren()) - { - if (element.Visible) - { - element.Visible = false; - shouldMenuOpen = false; - } - } - - if (shouldMenuOpen) - { - menu.Visible = true; - } + OpenUIElement(menu); } - public void ChangeColor(Color color) + public void HandleMapButton() { - GameData.lightColor = color; - LightHandler.RedrawLights(color); + OpenUIElement(map); } - public void ShowCodingWindow(Robot robot) + public void HandleRobotListButton() { - codingWindow.ShowWindow(robot); + receivedRobotJumpSignal = false; + OpenUIElement(robotList); } public void DisplayStats() @@ -78,13 +64,31 @@ public partial class UIHandler : Control RAM.Text = memoryDisplay; } - public void ShowOptions() - { - options.Visible = true; - } - public void ExitGame() { GetTree().ChangeSceneToFile("res://Scenes/MainMenu.tscn"); } + + public void OpenUIElement(Control element) + { + if (element.Visible) + { + element.Hide(); + } + else + { + element.Show(); + } + HideUIElements(element); + } + + private void HideUIElements(Control element) + { + foreach (PanelContainer child in uiContent.GetChildren()) + { + GD.Print(child == element); + if (child == element) continue; + child.Visible = false; + } + } } diff --git a/Scripts/Robot/RobotList.cs b/Scripts/Robot/RobotList.cs index 31270dc..3bfce06 100644 --- a/Scripts/Robot/RobotList.cs +++ b/Scripts/Robot/RobotList.cs @@ -16,16 +16,15 @@ public partial class RobotList : PanelContainer // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { - if (Input.IsActionJustPressed("robot_list")) - { - ShowList(); - } + } - public void ShowList() + public override void _Notification(int id) { - Visible = !Visible; - if (Visible) ReloadRobots(); + if (id == NotificationVisibilityChanged) + { + if (Visible) ReloadRobots(); + } } public void ReloadRobots()