Updated DSL node generation and added robot zoom-in function
This commit is contained in:
+39
-42
@@ -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()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ public abstract class ProgramNode
|
||||
{
|
||||
protected ProgramNode nextNode;
|
||||
public string DisplayText;
|
||||
public PackedScene editorDisplay;
|
||||
public ProgramNode()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user