Updated DSL node generation and added robot zoom-in function

This commit is contained in:
=
2026-04-29 10:27:17 +02:00
parent c8debc316f
commit 2cc6e31157
8 changed files with 106 additions and 159 deletions
-30
View File
@@ -1,30 +0,0 @@
[gd_scene format=3 uid="uid://bst1eqq4jxq5h"]
[node name="ProgramNode" type="Control" unique_id=854534882]
custom_minimum_size = Vector2(0, 20)
layout_mode = 3
anchors_preset = 14
anchor_top = 0.5
anchor_right = 1.0
anchor_bottom = 0.5
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
[node name="Node" type="PanelContainer" parent="." unique_id=545984394]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="NodeContainer" type="CenterContainer" parent="Node" unique_id=1325851867]
layout_mode = 2
[node name="NodeText" type="RichTextLabel" parent="Node/NodeContainer" unique_id=1944532693]
layout_mode = 2
bbcode_enabled = true
text = "[font_size=30]Text[/font_size]"
fit_content = true
autowrap_mode = 0
+42 -36
View File
@@ -52,7 +52,7 @@ environment = SubResource("Environment_sb48q")
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386]
follow_viewport_enabled = true
[node name="Control" type="Control" parent="CanvasLayer" unique_id=1713248285]
[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotNaming", "mainCam")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@@ -64,8 +64,11 @@ grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("4_fgofq")
codingWindow = NodePath("MainUI/Content/CodingWindow")
robotNaming = NodePath("Popup/RobotNaming")
mainCam = NodePath("../../Camera3D")
[node name="MainUI" type="VBoxContainer" parent="CanvasLayer/Control" unique_id=1437975209]
[node name="MainUI" type="VBoxContainer" parent="CanvasLayer/UIHandler" unique_id=1437975209]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
@@ -73,48 +76,48 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="HeaderContainer" type="PanelContainer" parent="CanvasLayer/Control/MainUI" unique_id=1744492333]
[node name="HeaderContainer" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI" unique_id=1744492333]
layout_mode = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_b2bpf")
[node name="Header" type="HBoxContainer" parent="CanvasLayer/Control/MainUI/HeaderContainer" unique_id=1048237062]
[node name="Header" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer" unique_id=1048237062]
layout_mode = 2
theme_override_constants/separation = 200
alignment = 1
[node name="Robotcount" type="RichTextLabel" parent="CanvasLayer/Control/MainUI/HeaderContainer/Header" unique_id=1955918671]
[node name="Robotcount" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/Header" unique_id=1955918671]
layout_mode = 2
text = "Roboter: 0/0"
fit_content = true
autowrap_mode = 0
[node name="RobotWarning" type="TextureRect" parent="CanvasLayer/Control/MainUI/HeaderContainer/Header" unique_id=759915558]
[node name="RobotWarning" type="TextureRect" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/Header" unique_id=759915558]
layout_mode = 2
texture = ExtResource("5_b2bpf")
expand_mode = 2
[node name="DayCount" type="RichTextLabel" parent="CanvasLayer/Control/MainUI/HeaderContainer/Header" unique_id=1228850272]
[node name="DayCount" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/Header" unique_id=1228850272]
layout_mode = 2
text = "Tag 1"
fit_content = true
autowrap_mode = 0
[node name="Time" type="RichTextLabel" parent="CanvasLayer/Control/MainUI/HeaderContainer/Header" unique_id=1457538761]
[node name="Time" type="RichTextLabel" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/Header" unique_id=1457538761]
layout_mode = 2
text = "19:20"
fit_content = true
autowrap_mode = 0
[node name="LightColor" type="ColorPickerButton" parent="CanvasLayer/Control/MainUI/HeaderContainer/Header" unique_id=395026790]
[node name="LightColor" type="ColorPickerButton" parent="CanvasLayer/UIHandler/MainUI/HeaderContainer/Header" unique_id=395026790]
layout_mode = 2
theme_override_colors/font_color = Color(1, 1, 1, 1)
text = "Choose Color..."
[node name="Content" type="Control" parent="CanvasLayer/Control/MainUI" unique_id=45665557]
[node name="Content" type="Control" parent="CanvasLayer/UIHandler/MainUI" unique_id=45665557]
layout_mode = 2
size_flags_vertical = 3
[node name="CodingWindow" type="PanelContainer" parent="CanvasLayer/Control/MainUI/Content" unique_id=1576652491]
[node name="CodingWindow" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1576652491 node_paths=PackedStringArray("codeBlocks", "editorWindow", "robotList")]
layout_mode = 1
anchors_preset = 11
anchor_left = 1.0
@@ -125,28 +128,31 @@ grow_horizontal = 0
grow_vertical = 2
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/Control/MainUI/Content/CodingWindow" unique_id=1934932205]
[node name="HBoxContainer" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" unique_id=1934932205]
layout_mode = 2
size_flags_vertical = 3
[node name="CodeBlocks" type="ScrollContainer" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer" unique_id=1196874464]
[node name="CodeBlocks" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer" unique_id=1196874464]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_fgofq")
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/CodeBlocks" unique_id=1751038712]
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/CodeBlocks" unique_id=1751038712]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 10
[node name="EditorWindow" type="VBoxContainer" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer" unique_id=919757187]
[node name="EditorWindow" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer" unique_id=919757187]
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 2.0
[node name="CodeContainer" type="ScrollContainer" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=2045306791]
[node name="CodeContainer" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=2045306791]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
@@ -154,52 +160,52 @@ size_flags_stretch_ratio = 2.0
theme_override_styles/panel = SubResource("StyleBoxFlat_2irst")
horizontal_scroll_mode = 0
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/CodeContainer" unique_id=632191528]
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/CodeContainer" unique_id=632191528]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 10
[node name="Buttons" type="HBoxContainer" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=265797151]
[node name="Buttons" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=265797151]
layout_mode = 2
theme_override_constants/separation = 20
[node name="Clear" type="Button" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons" unique_id=1191148341]
[node name="Clear" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons" unique_id=1191148341]
layout_mode = 2
size_flags_horizontal = 3
text = "Clear"
[node name="Compile" type="Button" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons" unique_id=1559980287]
[node name="Compile" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons" unique_id=1559980287]
layout_mode = 2
size_flags_horizontal = 3
text = "Compile"
[node name="Robotlist" type="ScrollContainer" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer" unique_id=592644944]
[node name="Robotlist" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer" unique_id=592644944]
layout_mode = 2
size_flags_horizontal = 3
theme_override_styles/panel = SubResource("StyleBoxFlat_fgofq")
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/Robotlist" unique_id=963718788]
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/Robotlist" unique_id=963718788]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
theme_override_constants/separation = 10
[node name="Popup" type="Control" parent="CanvasLayer" unique_id=1989677138]
layout_mode = 3
[node name="Popup" type="Control" parent="CanvasLayer/UIHandler" unique_id=1989677138]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -20.0
offset_top = -20.0
offset_right = 20.0
offset_bottom = 20.0
offset_left = -19.0
offset_top = -21.0
offset_right = 21.0
offset_bottom = 19.0
grow_horizontal = 2
grow_vertical = 2
[node name="RobotNaming" type="PanelContainer" parent="CanvasLayer/Popup" unique_id=311359170]
[node name="RobotNaming" type="PanelContainer" parent="CanvasLayer/UIHandler/Popup" unique_id=311359170]
visible = false
layout_mode = 1
anchors_preset = 15
@@ -208,24 +214,24 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/Popup/RobotNaming" unique_id=39200128]
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/Popup/RobotNaming" unique_id=39200128]
layout_mode = 2
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/Popup/RobotNaming/VBoxContainer" unique_id=1964282829]
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/UIHandler/Popup/RobotNaming/VBoxContainer" unique_id=1964282829]
layout_mode = 2
text = "Name your robot:"
fit_content = true
autowrap_mode = 0
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/Popup/RobotNaming/VBoxContainer" unique_id=1713423672]
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/UIHandler/Popup/RobotNaming/VBoxContainer" unique_id=1713423672]
layout_mode = 2
placeholder_text = "Name..."
max_length = 24
[node name="Button" type="Button" parent="CanvasLayer/Popup/RobotNaming/VBoxContainer" unique_id=279251707]
[node name="Button" type="Button" parent="CanvasLayer/UIHandler/Popup/RobotNaming/VBoxContainer" unique_id=279251707]
layout_mode = 2
text = "Submit"
[connection signal="color_changed" from="CanvasLayer/Control/MainUI/HeaderContainer/Header/LightColor" to="CanvasLayer/Control" method="ChangeColor"]
[connection signal="button_up" from="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons/Clear" to="CanvasLayer/Control/MainUI/Content/CodingWindow" method="ClearWindow"]
[connection signal="button_up" from="CanvasLayer/Control/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons/Compile" to="CanvasLayer/Control/MainUI/Content/CodingWindow" method="CompileProgram"]
[connection signal="color_changed" from="CanvasLayer/UIHandler/MainUI/HeaderContainer/Header/LightColor" to="CanvasLayer/UIHandler" method="ChangeColor"]
[connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons/Clear" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="ClearWindow"]
[connection signal="button_up" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Buttons/Compile" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="CompileProgram"]
+35 -38
View File
@@ -1,18 +1,20 @@
using Godot;
using System;
using System.Collections.Generic;
public partial class CodingWindow : PanelContainer
{
public PackedScene movePrefab;
public PackedScene craftPrefab;
public PackedScene harvestPrefab;
[Export] VBoxContainer codeBlocks;
[Export] VBoxContainer editorWindow;
[Export] VBoxContainer robotList;
[Signal]
public delegate void OnRobotClickedEventHandler(Robot robot);
public Dictionary<ProgramNode, PackedScene> DSLNodes;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
movePrefab = ResourceLoader.LoadMoveNodePrefab();
craftPrefab = ResourceLoader.LoadCraftNodePrefab();
harvestPrefab = ResourceLoader.LoadHarvestNodePrefab();
DSLNodes = ResourceLoader.LoadDSLNodes();
GenerateCodingBlocks();
}
@@ -33,56 +35,51 @@ public partial class CodingWindow : PanelContainer
//Move, Harvest, Craft
public void GenerateCodingBlocks()
{
VBoxContainer codingBlocks = GetNode<VBoxContainer>("./HBoxContainer/CodeBlocks/VBoxContainer");
NodeDisplay node = new NodeDisplay();
MoveNode move = new MoveNode();
move.editorDisplay = movePrefab;
node.SetNode(move);
node.SetupUIElement();
codingBlocks.AddChild(node);
node = new NodeDisplay();
CraftNode craft = new CraftNode();
craft.editorDisplay = craftPrefab;
node.SetNode(craft);
node.SetupUIElement();
codingBlocks.AddChild(node);
node = new NodeDisplay();
HarvestNode harvest = new HarvestNode();
harvest.editorDisplay = harvestPrefab;
node.SetNode(harvest);
node.SetupUIElement();
codingBlocks.AddChild(node);
Button button;
foreach (ProgramNode node in DSLNodes.Keys)
{
button = new Button
{
Text = node.DisplayText,
Name = node.DisplayText
};
button.Pressed += () =>
{
editorWindow.AddChild(DSLNodes[node].Instantiate());
};
codeBlocks.AddChild(button);
}
}
public void ReloadRobots()
{
VBoxContainer robotList = GetNode<VBoxContainer>("./HBoxContainer/Robotlist/VBoxContainer");
foreach (Node node in robotList.GetChildren())
{
robotList.RemoveChild(node);
node.QueueFree();
}
PackedScene nodePrefab = ResourceLoader.LoadProgramNodePrefab();
Control robot;
Button button;
foreach (Robot robotObject in GameData.robots)
{
robot = nodePrefab.Instantiate<Control>();
robot.GetNode<RichTextLabel>("./Node/NodeContainer/NodeText").Text = robotObject.Name;
GetNode<VBoxContainer>("./HBoxContainer/Robotlist/VBoxContainer").AddChild(robot);
button = new Button
{
Text = robotObject.Name,
Name = robotObject.Name
};
button.Pressed += () =>
{
EmitSignal(SignalName.OnRobotClicked, robotObject);
};
robotList.AddChild(button);
}
}
public void ClearWindow()
{
VBoxContainer nodeList = GetNode<VBoxContainer>("./HBoxContainer/EditorWindow/CodeContainer/VBoxContainer");
foreach(Node node in nodeList.GetChildren())
foreach (Node node in editorWindow.GetChildren())
{
nodeList.RemoveChild(node);
editorWindow.RemoveChild(node);
node.QueueFree();
}
}
+1 -23
View File
@@ -4,8 +4,6 @@ using Godot;
public partial class NodeDisplay : RichTextLabel
{
ProgramNode node;
bool isHovering = false;
bool isDragging = false;
public void SetNode(ProgramNode node)
{
@@ -14,19 +12,7 @@ public partial class NodeDisplay : RichTextLabel
public void SetupUIElement()
{
Text = node.DisplayText;
FitContent = true;
HorizontalAlignment = HorizontalAlignment.Center;
AutowrapMode = TextServer.AutowrapMode.Off;
GuiInput += HandleInput;
StyleBoxFlat styleBox = new StyleBoxFlat
{
BorderColor = new Color(1, 1, 1),
BgColor = new Color(0, 0, 0, 0.5f)
};
styleBox.SetBorderWidthAll(2);
styleBox.SetCornerRadiusAll(6);
AddThemeStyleboxOverride("normal", styleBox);
}
public override void _Ready()
@@ -41,12 +27,4 @@ public partial class NodeDisplay : RichTextLabel
}
}
public void HandleInput(InputEvent input)
{
if (input is InputEventMouseButton mouseEvent && mouseEvent.ButtonIndex == MouseButton.Left && mouseEvent.IsReleased())
{
GetNode<Control>("../../../EditorWindow/CodeContainer/VBoxContainer").AddChild(node.editorDisplay.Instantiate());
}
}
}
-1
View File
@@ -4,7 +4,6 @@ public abstract class ProgramNode
{
protected ProgramNode nextNode;
public string DisplayText;
public PackedScene editorDisplay;
public ProgramNode()
{
+11 -20
View File
@@ -15,26 +15,6 @@ public partial class ResourceLoader
return GD.Load<PackedScene>($"res://Prefabs/Robot.tscn");
}
public static PackedScene LoadProgramNodePrefab()
{
return GD.Load<PackedScene>($"res://Prefabs/ProgramNode.tscn");
}
public static PackedScene LoadMoveNodePrefab()
{
return GD.Load<PackedScene>($"res://Prefabs/DSL/MoveNode.tscn");
}
public static PackedScene LoadHarvestNodePrefab()
{
return GD.Load<PackedScene>($"res://Prefabs/DSL/HarvestNode.tscn");
}
public static PackedScene LoadCraftNodePrefab()
{
return GD.Load<PackedScene>($"res://Prefabs/DSL/CraftNode.tscn");
}
public static Dictionary<string, MeshInstance3D> LoadTiles()
{
Dictionary<string, MeshInstance3D> tileMeshes = new Dictionary<string, MeshInstance3D>();
@@ -60,4 +40,15 @@ public partial class ResourceLoader
return decorationMeshes;
}
public static Dictionary<ProgramNode, PackedScene> LoadDSLNodes()
{
Dictionary<ProgramNode, PackedScene> nodes = new()
{
{ new MoveNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/MoveNode.tscn") },
{ new HarvestNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/HarvestNode.tscn") },
{ new CraftNode(), GD.Load<PackedScene>($"res://Prefabs/DSL/CraftNode.tscn") }
};
return nodes;
}
}
+12 -6
View File
@@ -4,6 +4,9 @@ using Godot;
public partial class UIHandler : Control
{
[Export] CodingWindow codingWindow;
[Export] PanelContainer robotNaming;
[Export] Camera3D mainCam;
public override void _Ready()
{
GetNode<ColorPickerButton>("./MainUI/HeaderContainer/Header/LightColor").Color = GameData.lightColor;
@@ -12,7 +15,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) =>
{
mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z);
};
}
public void ChangeColor(Color color)
@@ -23,18 +29,18 @@ public partial class UIHandler : Control
public void ShowNamingPopup(Robot robot)
{
PanelContainer namingContainer = GetNode<PanelContainer>("../Popup/RobotNaming");
namingContainer.Visible = true;
robotNaming.Visible = true;
GameData.canMove = false;
LineEdit name = namingContainer.GetNode<LineEdit>("./VBoxContainer/LineEdit");
Button button = namingContainer.GetNode<Button>("./VBoxContainer/Button");
LineEdit name = robotNaming.GetNode<LineEdit>("./VBoxContainer/LineEdit");
name.Text = robot.Name;
Button button = robotNaming.GetNode<Button>("./VBoxContainer/Button");
Action handler = null;
handler = () =>
{
robot.Name = name.Text;
name.Text = "";
namingContainer.Visible = false;
robotNaming.Visible = false;
GameData.canMove = true;
button.ButtonUp -= handler;
};
+1 -1
View File
@@ -10,6 +10,6 @@ public partial class Robot : Node3D
public void OnClicked()
{
GetNode<UIHandler>("/root/Main/CanvasLayer/Control").ShowNamingPopup(this);
GetNode<UIHandler>("/root/Main/CanvasLayer/UIHandler").ShowNamingPopup(this);
}
}