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
+39 -42
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();
}
@@ -27,68 +29,63 @@ public partial class CodingWindow : PanelContainer
{
ReloadRobots();
}
}
}
}
//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())
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();
}
}
public void CompileProgram()
{
}
}
+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
@@ -14,26 +14,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()
{
@@ -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);
}
}