Added basic components for DSL. Working on functionality next.
This commit is contained in:
+29
-10
@@ -3,9 +3,16 @@ using System;
|
||||
|
||||
public partial class CodingWindow : PanelContainer
|
||||
{
|
||||
public PackedScene movePrefab;
|
||||
public PackedScene craftPrefab;
|
||||
public PackedScene harvestPrefab;
|
||||
|
||||
// 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();
|
||||
GenerateCodingBlocks();
|
||||
}
|
||||
|
||||
@@ -15,6 +22,7 @@ public partial class CodingWindow : PanelContainer
|
||||
if (Input.IsActionJustPressed("codingwindow"))
|
||||
{
|
||||
Visible = !Visible;
|
||||
GameData.canMove = !Visible;
|
||||
if (Visible)
|
||||
{
|
||||
ReloadRobots();
|
||||
@@ -25,18 +33,29 @@ public partial class CodingWindow : PanelContainer
|
||||
//Move, Harvest, Craft
|
||||
public void GenerateCodingBlocks()
|
||||
{
|
||||
PackedScene nodePrefab = ResourceLoader.LoadProgramNodePrefab();
|
||||
Control node1 = nodePrefab.Instantiate<Control>();
|
||||
node1.GetNode<RichTextLabel>("./Node/NodeContainer/NodeText").Text = "Move";
|
||||
GetNode<VBoxContainer>("./HBoxContainer/CodeBlocks/VBoxContainer").AddChild(node1);
|
||||
VBoxContainer codingBlocks = GetNode<VBoxContainer>("./HBoxContainer/CodeBlocks/VBoxContainer");
|
||||
|
||||
Control node2 = nodePrefab.Instantiate<Control>();
|
||||
node2.GetNode<RichTextLabel>("./Node/NodeContainer/NodeText").Text = "Harvest";
|
||||
GetNode<VBoxContainer>("./HBoxContainer/CodeBlocks/VBoxContainer").AddChild(node2);
|
||||
NodeDisplay node = new NodeDisplay();
|
||||
MoveNode move = new MoveNode();
|
||||
move.editorDisplay = movePrefab;
|
||||
node.SetNode(move);
|
||||
node.SetupUIElement();
|
||||
codingBlocks.AddChild(node);
|
||||
|
||||
Control node3 = nodePrefab.Instantiate<Control>();
|
||||
node3.GetNode<RichTextLabel>("./Node/NodeContainer/NodeText").Text = "Craft";
|
||||
GetNode<VBoxContainer>("./HBoxContainer/CodeBlocks/VBoxContainer").AddChild(node3);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public void ReloadRobots()
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
public partial class NodeDisplay : RichTextLabel
|
||||
{
|
||||
ProgramNode node;
|
||||
bool isHovering = false;
|
||||
bool isDragging = false;
|
||||
|
||||
public void SetNode(ProgramNode node)
|
||||
{
|
||||
this.node = node;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click"))
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void HandleInput(InputEvent input)
|
||||
{
|
||||
if (input is InputEventMouseButton mouseEvent && mouseEvent.ButtonIndex == MouseButton.Left && mouseEvent.IsReleased())
|
||||
{
|
||||
GetNode<Control>("../../../EditorWindow/VBoxContainer").AddChild(node.editorDisplay.Instantiate());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://b6kxwmuhmruul
|
||||
@@ -0,0 +1,14 @@
|
||||
using Godot;
|
||||
|
||||
public class CraftNode : ProgramNode
|
||||
{
|
||||
public CraftNode()
|
||||
{
|
||||
DisplayText = "Craft";
|
||||
}
|
||||
public override void Execute(Robot robot)
|
||||
{
|
||||
GD.Print("Craft");
|
||||
nextNode.Execute(robot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://dcm23bpi37va
|
||||
@@ -0,0 +1,14 @@
|
||||
using Godot;
|
||||
|
||||
public class HarvestNode : ProgramNode
|
||||
{
|
||||
public HarvestNode()
|
||||
{
|
||||
DisplayText = "Harvest";
|
||||
}
|
||||
public override void Execute(Robot robot)
|
||||
{
|
||||
GD.Print("Harvest");
|
||||
nextNode.Execute(robot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://bb8g5ukg7xnw
|
||||
@@ -0,0 +1,16 @@
|
||||
using Godot;
|
||||
|
||||
public class MoveNode : ProgramNode
|
||||
{
|
||||
public Vector3 startPosition;
|
||||
public Vector3 targetPosition;
|
||||
public MoveNode()
|
||||
{
|
||||
DisplayText = "Move";
|
||||
}
|
||||
public override void Execute(Robot robot)
|
||||
{
|
||||
robot.Position = targetPosition;
|
||||
nextNode.Execute(robot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c1yd2vdej67q3
|
||||
@@ -0,0 +1,18 @@
|
||||
using Godot;
|
||||
|
||||
public abstract class ProgramNode
|
||||
{
|
||||
protected ProgramNode nextNode;
|
||||
public string DisplayText;
|
||||
public PackedScene editorDisplay;
|
||||
public ProgramNode()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public abstract void Execute(Robot robot);
|
||||
public void LinkNode(ProgramNode nextNode)
|
||||
{
|
||||
this.nextNode = nextNode;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://hc0yntn2d358
|
||||
@@ -0,0 +1 @@
|
||||
uid://hui5wolo5rbr
|
||||
@@ -0,0 +1 @@
|
||||
uid://dcxom1paffp0p
|
||||
Reference in New Issue
Block a user