From 832fb47ec002e3ae57ca794737c36574a6ebe7bb Mon Sep 17 00:00:00 2001 From: = <=> Date: Wed, 29 Apr 2026 14:08:02 +0200 Subject: [PATCH] Moved robots to separate folders and a dedicated robotlist in the UI --- Prefabs/{ => Robot}/Robot.tscn | 4 +- Prefabs/Robot/RobotDisplay.tscn | 45 +++++++++++++++++++++ Prefabs/{ => Robot}/RobotVisual.tscn | 0 Scenes/Game.tscn | 35 +++++++++++++--- Scripts/DSL/CodingWindow.cs | 39 ++---------------- Scripts/DSL/RobotDisplay.cs | 0 Scripts/Helpers/ResourceLoader.cs | 7 +++- Scripts/Helpers/UIHandler.cs | 5 +-- Scripts/{ => Robot}/Robot.cs | 12 ++++++ Scripts/{ => Robot}/Robot.cs.uid | 0 Scripts/Robot/RobotDisplay.cs | 23 +++++++++++ Scripts/{DSL => Robot}/RobotDisplay.cs.uid | 0 Scripts/Robot/RobotList.cs | 47 ++++++++++++++++++++++ Scripts/Robot/RobotList.cs.uid | 1 + project.godot | 5 +++ 15 files changed, 176 insertions(+), 47 deletions(-) rename Prefabs/{ => Robot}/Robot.tscn (88%) create mode 100644 Prefabs/Robot/RobotDisplay.tscn rename Prefabs/{ => Robot}/RobotVisual.tscn (100%) delete mode 100644 Scripts/DSL/RobotDisplay.cs rename Scripts/{ => Robot}/Robot.cs (61%) rename Scripts/{ => Robot}/Robot.cs.uid (100%) create mode 100644 Scripts/Robot/RobotDisplay.cs rename Scripts/{DSL => Robot}/RobotDisplay.cs.uid (100%) create mode 100644 Scripts/Robot/RobotList.cs create mode 100644 Scripts/Robot/RobotList.cs.uid diff --git a/Prefabs/Robot.tscn b/Prefabs/Robot/Robot.tscn similarity index 88% rename from Prefabs/Robot.tscn rename to Prefabs/Robot/Robot.tscn index 81ca16b..94e7491 100644 --- a/Prefabs/Robot.tscn +++ b/Prefabs/Robot/Robot.tscn @@ -1,7 +1,7 @@ [gd_scene format=3 uid="uid://dciwxejdji2lg"] -[ext_resource type="PackedScene" uid="uid://cjae60v4c60vb" path="res://Prefabs/RobotVisual.tscn" id="2_3hvm5"] -[ext_resource type="Script" uid="uid://e0pgy7jya41y" path="res://Scripts/Robot.cs" id="2_j80uv"] +[ext_resource type="PackedScene" uid="uid://cjae60v4c60vb" path="res://Prefabs/Robot/RobotVisual.tscn" id="2_3hvm5"] +[ext_resource type="Script" uid="uid://e0pgy7jya41y" path="res://Scripts/Robot/Robot.cs" id="2_j80uv"] [sub_resource type="BoxShape3D" id="BoxShape3D_vquur"] size = Vector3(1.1176758, 0.7307129, 1.0234375) diff --git a/Prefabs/Robot/RobotDisplay.tscn b/Prefabs/Robot/RobotDisplay.tscn new file mode 100644 index 0000000..1edec0b --- /dev/null +++ b/Prefabs/Robot/RobotDisplay.tscn @@ -0,0 +1,45 @@ +[gd_scene format=3 uid="uid://dribqey54i62n"] + +[ext_resource type="Script" uid="uid://dcxom1paffp0p" path="res://Scripts/Robot/RobotDisplay.cs" id="1_ltmdd"] + +[node name="Robot" type="PanelContainer" unique_id=247502695 node_paths=PackedStringArray("listItem")] +anchors_preset = 14 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_bottom = 31.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_ltmdd") +listItem = NodePath("HBoxContainer/ListItem") + +[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=906487472] +layout_mode = 2 +theme_override_constants/separation = 20 +alignment = 1 + +[node name="ListItem" type="RichTextLabel" parent="HBoxContainer" unique_id=46246913] +layout_mode = 2 +text = "Robot #1" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Jump" type="Button" parent="HBoxContainer" unique_id=391426419] +layout_mode = 2 +text = "Jump to" + +[node name="CurrentScript" type="RichTextLabel" parent="HBoxContainer" unique_id=425408407] +layout_mode = 2 +text = "Scriptname" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ScriptSelect" type="MenuButton" parent="HBoxContainer" unique_id=63458827] +layout_mode = 2 +text = "Select script..." + +[connection signal="pressed" from="HBoxContainer/Jump" to="." method="OnJumpToClicked"] diff --git a/Prefabs/RobotVisual.tscn b/Prefabs/Robot/RobotVisual.tscn similarity index 100% rename from Prefabs/RobotVisual.tscn rename to Prefabs/Robot/RobotVisual.tscn diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index 83205fb..fdd74db 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -6,6 +6,7 @@ [ext_resource type="Script" uid="uid://bm7knir4552j5" path="res://Scripts/Helpers/UIHandler.cs" id="4_fgofq"] [ext_resource type="Texture2D" uid="uid://bmcpkt6mae2qi" path="res://Assets/AlarmSign.png" id="5_b2bpf"] [ext_resource type="Script" uid="uid://bsd6n6b06a4pe" path="res://Scripts/DSL/CodingWindow.cs" id="6_7lihs"] +[ext_resource type="Script" uid="uid://k6vlo7ulvtep" path="res://Scripts/Robot/RobotList.cs" id="7_2irst"] [ext_resource type="Script" uid="uid://c3v2vdj3ghp78" path="res://Scripts/Information.cs" id="7_fgofq"] [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_u44n3"] @@ -53,7 +54,7 @@ environment = SubResource("Environment_sb48q") [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386] follow_viewport_enabled = true -[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotNaming", "information", "mainCam")] +[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "robotNaming", "information", "mainCam")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -66,6 +67,7 @@ size_flags_horizontal = 3 size_flags_vertical = 3 script = ExtResource("4_fgofq") codingWindow = NodePath("MainUI/Content/CodingWindow") +robotList = NodePath("MainUI/Content/RobotList") robotNaming = NodePath("Popup/RobotNaming") information = NodePath("Popup/Information") mainCam = NodePath("../../Camera3D") @@ -119,7 +121,7 @@ text = "Choose Color..." layout_mode = 2 size_flags_vertical = 3 -[node name="CodingWindow" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1576652491 node_paths=PackedStringArray("codeBlocks", "editorWindow", "robotList")] +[node name="CodingWindow" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1576652491 node_paths=PackedStringArray("codeBlocks", "editorWindow")] layout_mode = 1 anchors_preset = 11 anchor_left = 1.0 @@ -132,7 +134,6 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_7lihs") script = ExtResource("6_7lihs") codeBlocks = NodePath("HBoxContainer/CodeBlocks/VBoxContainer") editorWindow = NodePath("HBoxContainer/EditorWindow/CodeContainer/VBoxContainer") -robotList = NodePath("HBoxContainer/Robotlist/VBoxContainer") [node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" unique_id=1934932205] layout_mode = 2 @@ -202,12 +203,36 @@ layout_mode = 2 size_flags_horizontal = 3 text = "Load script" -[node name="Robotlist" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer" unique_id=592644944] +[node name="RobotList" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1469962195 node_paths=PackedStringArray("robotList")] +layout_mode = 1 +anchors_preset = -1 +anchor_left = 0.25 +anchor_top = 0.25 +anchor_right = 0.75 +anchor_bottom = 0.75 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("7_2irst") +robotList = NodePath("VBoxContainer/ScrollContainer/VBoxContainer") + +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList" unique_id=1958138787] +layout_mode = 2 + +[node name="Title" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer" unique_id=1891991275] +layout_mode = 2 +bbcode_enabled = true +text = "[font_size=32]Robotlist[/font_size]" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 + +[node name="ScrollContainer" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer" unique_id=592644944] 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/CodingWindow/HBoxContainer/Robotlist" unique_id=963718788] +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer/ScrollContainer" unique_id=963718788] layout_mode = 2 size_flags_horizontal = 3 size_flags_vertical = 3 diff --git a/Scripts/DSL/CodingWindow.cs b/Scripts/DSL/CodingWindow.cs index 6853943..47a5525 100644 --- a/Scripts/DSL/CodingWindow.cs +++ b/Scripts/DSL/CodingWindow.cs @@ -6,12 +6,8 @@ public partial class CodingWindow : PanelContainer { [Export] VBoxContainer codeBlocks; [Export] VBoxContainer editorWindow; - [Export] VBoxContainer robotList; - [Signal] - public delegate void OnRobotClickedEventHandler(Robot robot); - [Signal] - public delegate void OnInformationEventHandler(string title, string text); public Dictionary DSLNodes; + // Called when the node enters the scene tree for the first time. public override void _Ready() @@ -23,14 +19,10 @@ public partial class CodingWindow : PanelContainer // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { + //TODO: If robot that was pressed has a script, load script if (Input.IsActionJustPressed("codingwindow")) { Visible = !Visible; - GameData.canMove = !Visible; - if (Visible) - { - ReloadRobots(); - } } } @@ -54,30 +46,6 @@ public partial class CodingWindow : PanelContainer } } - public void ReloadRobots() - { - foreach (Node node in robotList.GetChildren()) - { - robotList.RemoveChild(node); - node.QueueFree(); - } - Button button; - - foreach (Robot robotObject in GameData.robots) - { - button = new Button - { - Text = robotObject.Name, - Name = robotObject.Name - }; - button.Pressed += () => - { - EmitSignal(SignalName.OnRobotClicked, robotObject); - }; - robotList.AddChild(button); - } - } - public void ClearWindow() { foreach (Node node in editorWindow.GetChildren()) @@ -89,7 +57,6 @@ public partial class CodingWindow : PanelContainer public void CompileProgram() { - string errorMessage = ""; bool didCompile; for (int i = 0; i < editorWindow.GetChildCount(); i++) @@ -106,7 +73,7 @@ public partial class CodingWindow : PanelContainer if (!didCompile) { - EmitSignal(SignalName.OnInformation, "ERROR", "Compilation failed " + errorMessage); + } } } diff --git a/Scripts/DSL/RobotDisplay.cs b/Scripts/DSL/RobotDisplay.cs deleted file mode 100644 index e69de29..0000000 diff --git a/Scripts/Helpers/ResourceLoader.cs b/Scripts/Helpers/ResourceLoader.cs index 46dcd07..b168323 100644 --- a/Scripts/Helpers/ResourceLoader.cs +++ b/Scripts/Helpers/ResourceLoader.cs @@ -12,7 +12,12 @@ public partial class ResourceLoader public static PackedScene LoadRobotPrefab() { - return GD.Load($"res://Prefabs/Robot.tscn"); + return GD.Load($"res://Prefabs/Robot/Robot.tscn"); + } + + public static PackedScene LoadRobotDisplay() + { + return GD.Load($"res://Prefabs/Robot/RobotDisplay.tscn"); } public static Dictionary LoadTiles() diff --git a/Scripts/Helpers/UIHandler.cs b/Scripts/Helpers/UIHandler.cs index 97cdbf9..c93bca1 100644 --- a/Scripts/Helpers/UIHandler.cs +++ b/Scripts/Helpers/UIHandler.cs @@ -5,6 +5,7 @@ using Godot; public partial class UIHandler : Control { [Export] CodingWindow codingWindow; + [Export] RobotList robotList; [Export] PanelContainer robotNaming; [Export] Information information; [Export] Camera3D mainCam; @@ -16,12 +17,10 @@ public partial class UIHandler : Control // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { - codingWindow.OnRobotClicked += (robot) => + robotList.OnRobotJumpTo += (robot) => { mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z); }; - - codingWindow.OnInformation += information.DisplayInformation; } public void ChangeColor(Color color) diff --git a/Scripts/Robot.cs b/Scripts/Robot/Robot.cs similarity index 61% rename from Scripts/Robot.cs rename to Scripts/Robot/Robot.cs index 284506f..f19019d 100644 --- a/Scripts/Robot.cs +++ b/Scripts/Robot/Robot.cs @@ -3,6 +3,17 @@ using Godot; public partial class Robot : Node3D { + public ProgramInterpreter interpreter; + + public override void _Ready() + { + + } + + public override void _Process(double delta) + { + + } public void Move() { @@ -12,4 +23,5 @@ public partial class Robot : Node3D { GetNode("/root/Main/CanvasLayer/UIHandler").ShowNamingPopup(this); } + } diff --git a/Scripts/Robot.cs.uid b/Scripts/Robot/Robot.cs.uid similarity index 100% rename from Scripts/Robot.cs.uid rename to Scripts/Robot/Robot.cs.uid diff --git a/Scripts/Robot/RobotDisplay.cs b/Scripts/Robot/RobotDisplay.cs new file mode 100644 index 0000000..50593d1 --- /dev/null +++ b/Scripts/Robot/RobotDisplay.cs @@ -0,0 +1,23 @@ +using Godot; + +public partial class RobotDisplay : PanelContainer +{ + [Export] public RichTextLabel listItem; + [Signal] + public delegate void OnRobotJumpToEventHandler(Robot robot); + public Robot robot; + public override void _Ready() + { + + } + + public override void _Process(double delta) + { + + } + + public void OnJumpToClicked() + { + EmitSignal(SignalName.OnRobotJumpTo, robot); + } +} diff --git a/Scripts/DSL/RobotDisplay.cs.uid b/Scripts/Robot/RobotDisplay.cs.uid similarity index 100% rename from Scripts/DSL/RobotDisplay.cs.uid rename to Scripts/Robot/RobotDisplay.cs.uid diff --git a/Scripts/Robot/RobotList.cs b/Scripts/Robot/RobotList.cs new file mode 100644 index 0000000..aec2fc3 --- /dev/null +++ b/Scripts/Robot/RobotList.cs @@ -0,0 +1,47 @@ +using Godot; +using System; + +public partial class RobotList : PanelContainer +{ + [Export] VBoxContainer robotList; + [Signal] + public delegate void OnRobotJumpToEventHandler(Robot robot); + public PackedScene robotDisplayPrefab; + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + robotDisplayPrefab = ResourceLoader.LoadRobotDisplay(); + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + if (Input.IsActionJustPressed("robot_list")) + { + Visible = !Visible; + if (Visible) ReloadRobots(); + } + } + + public void ReloadRobots() + { + foreach (Node node in robotList.GetChildren()) + { + robotList.RemoveChild(node); + node.QueueFree(); + } + RobotDisplay display; + + foreach (Robot robotObject in GameData.robots) + { + display = robotDisplayPrefab.Instantiate(); + display.robot = robotObject; + display.listItem.Text = robotObject.Name; + display.OnRobotJumpTo += (robot) => + { + EmitSignal(SignalName.OnRobotJumpTo, robot); + }; + robotList.AddChild(display); + } + } +} diff --git a/Scripts/Robot/RobotList.cs.uid b/Scripts/Robot/RobotList.cs.uid new file mode 100644 index 0000000..6b217a6 --- /dev/null +++ b/Scripts/Robot/RobotList.cs.uid @@ -0,0 +1 @@ +uid://k6vlo7ulvtep diff --git a/project.godot b/project.godot index da0ccbd..8a248fc 100644 --- a/project.godot +++ b/project.godot @@ -87,6 +87,11 @@ left_click={ "events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(394, 15),"global_position":Vector2(403, 63),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null) ] } +robot_list={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null) +] +} [layer_names]