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()
{
}
}