diff --git a/Prefabs/DSL/CraftNode.tscn b/Prefabs/DSL/CraftNode.tscn index 23bf126..4f32c32 100644 --- a/Prefabs/DSL/CraftNode.tscn +++ b/Prefabs/DSL/CraftNode.tscn @@ -1,24 +1,47 @@ -[gd_scene format=3 uid="uid://cpdfm3wluj3a6"] +[gd_scene format=3 uid="uid://cinn18bl736rk"] -[node name="CraftNode" type="PanelContainer" unique_id=1839537826] +[ext_resource type="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/DSL/NodeDisplay.cs" id="1_qemp1"] -[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=945032897] +[node name="Craft" type="PanelContainer" unique_id=247502695 node_paths=PackedStringArray("editorDisplay", "listDisplay")] +anchors_preset = 14 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_bottom = 31.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_qemp1") +editorDisplay = NodePath("EditorDisplay") +listDisplay = NodePath("ListDisplay") + +[node name="EditorDisplay" type="PanelContainer" parent="." unique_id=1839537826] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="HBoxContainer" type="HBoxContainer" parent="EditorDisplay" unique_id=945032897] layout_mode = 2 alignment = 1 -[node name="Flavour" type="RichTextLabel" parent="HBoxContainer" unique_id=1994560318] +[node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1994560318] layout_mode = 2 +size_flags_horizontal = 3 text = "Craft: " fit_content = true autowrap_mode = 0 horizontal_alignment = 1 vertical_alignment = 1 -[node name="Item" type="OptionButton" parent="HBoxContainer" unique_id=117577134] +[node name="Item" type="OptionButton" parent="EditorDisplay/HBoxContainer" unique_id=117577134] layout_mode = 2 +size_flags_horizontal = 3 -[node name="Amount" type="SpinBox" parent="HBoxContainer" unique_id=1195061461] +[node name="Amount" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=1195061461] layout_mode = 2 +size_flags_horizontal = 3 rounded = true alignment = 1 prefix = "x" + +[node name="ListDisplay" type="Button" parent="." unique_id=200731038] +layout_mode = 2 +text = "Craft" diff --git a/Prefabs/DSL/HarvestNode.tscn b/Prefabs/DSL/HarvestNode.tscn index e692d34..a5688ef 100644 --- a/Prefabs/DSL/HarvestNode.tscn +++ b/Prefabs/DSL/HarvestNode.tscn @@ -1,12 +1,28 @@ [gd_scene format=3 uid="uid://com0ou37wj2xo"] -[node name="HarvestNode" type="PanelContainer" unique_id=970168969] +[ext_resource type="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/DSL/NodeDisplay.cs" id="1_ve3v1"] -[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=793343398] +[node name="Harvest" type="PanelContainer" unique_id=1323721153 node_paths=PackedStringArray("editorDisplay", "listDisplay")] +anchors_preset = 14 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_bottom = 31.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +script = ExtResource("1_ve3v1") +editorDisplay = NodePath("EditorDisplay") +listDisplay = NodePath("ListDisplay") + +[node name="EditorDisplay" type="PanelContainer" parent="." unique_id=970168969] +layout_mode = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="EditorDisplay" unique_id=793343398] layout_mode = 2 alignment = 1 -[node name="Flavour" type="RichTextLabel" parent="HBoxContainer" unique_id=1393328640] +[node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1393328640] layout_mode = 2 text = "Harvest: " fit_content = true @@ -14,11 +30,15 @@ autowrap_mode = 0 horizontal_alignment = 1 vertical_alignment = 1 -[node name="Item" type="OptionButton" parent="HBoxContainer" unique_id=912931137] +[node name="Item" type="OptionButton" parent="EditorDisplay/HBoxContainer" unique_id=912931137] layout_mode = 2 -[node name="Amount" type="SpinBox" parent="HBoxContainer" unique_id=1234084123] +[node name="Amount" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=1234084123] layout_mode = 2 rounded = true alignment = 1 prefix = "x" + +[node name="ListDisplay" type="Button" parent="." unique_id=884865258] +layout_mode = 2 +text = "Harvest" diff --git a/Prefabs/DSL/MoveNode.tscn b/Prefabs/DSL/MoveNode.tscn index 96f55ff..ca57d02 100644 --- a/Prefabs/DSL/MoveNode.tscn +++ b/Prefabs/DSL/MoveNode.tscn @@ -1,12 +1,28 @@ [gd_scene format=3 uid="uid://by0khq5dmxjvm"] -[node name="MoveNode" type="PanelContainer" unique_id=245583237] +[ext_resource type="Script" uid="uid://b6kxwmuhmruul" path="res://Scripts/DSL/NodeDisplay.cs" id="1_mexpj"] -[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=1629099069] +[node name="Move" type="PanelContainer" unique_id=1474470717 node_paths=PackedStringArray("editorDisplay", "listDisplay")] +anchors_preset = 14 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_bottom = 31.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +script = ExtResource("1_mexpj") +editorDisplay = NodePath("EditorDisplay") +listDisplay = NodePath("ListDisplay") + +[node name="EditorDisplay" type="PanelContainer" parent="." unique_id=245583237] +layout_mode = 2 + +[node name="HBoxContainer" type="HBoxContainer" parent="EditorDisplay" unique_id=1629099069] layout_mode = 2 alignment = 1 -[node name="Flavour" type="RichTextLabel" parent="HBoxContainer" unique_id=1497013575] +[node name="Flavour" type="RichTextLabel" parent="EditorDisplay/HBoxContainer" unique_id=1497013575] layout_mode = 2 text = "Move to: " fit_content = true @@ -14,20 +30,24 @@ autowrap_mode = 0 horizontal_alignment = 1 vertical_alignment = 1 -[node name="CoordinateX" type="SpinBox" parent="HBoxContainer" unique_id=485214217] +[node name="CoordinateX" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=485214217] layout_mode = 2 rounded = true alignment = 1 prefix = "X" -[node name="CoordinateY" type="SpinBox" parent="HBoxContainer" unique_id=724940645] +[node name="CoordinateY" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=724940645] layout_mode = 2 rounded = true alignment = 1 prefix = "Y" -[node name="CoordinateZ" type="SpinBox" parent="HBoxContainer" unique_id=578943647] +[node name="CoordinateZ" type="SpinBox" parent="EditorDisplay/HBoxContainer" unique_id=578943647] layout_mode = 2 rounded = true alignment = 1 prefix = "Z" + +[node name="ListDisplay" type="Button" parent="." unique_id=347942160] +layout_mode = 2 +text = "Move" diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index 14d2b34..83205fb 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -6,6 +6,7 @@ [ext_resource type="Script" uid="uid://bm7knir4552j5" path="res://Scripts/Helpers/UIHandler.cs" id="4_fgofq"] [ext_resource type="Texture2D" uid="uid://bmcpkt6mae2qi" path="res://Assets/AlarmSign.png" id="5_b2bpf"] [ext_resource type="Script" uid="uid://bsd6n6b06a4pe" path="res://Scripts/DSL/CodingWindow.cs" id="6_7lihs"] +[ext_resource type="Script" uid="uid://c3v2vdj3ghp78" path="res://Scripts/Information.cs" id="7_fgofq"] [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_u44n3"] @@ -52,7 +53,7 @@ environment = SubResource("Environment_sb48q") [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386] follow_viewport_enabled = true -[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotNaming", "mainCam")] +[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotNaming", "information", "mainCam")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -66,6 +67,7 @@ size_flags_vertical = 3 script = ExtResource("4_fgofq") codingWindow = NodePath("MainUI/Content/CodingWindow") robotNaming = NodePath("Popup/RobotNaming") +information = NodePath("Popup/Information") mainCam = NodePath("../../Camera3D") [node name="MainUI" type="VBoxContainer" parent="CanvasLayer/UIHandler" unique_id=1437975209] @@ -180,6 +182,26 @@ layout_mode = 2 size_flags_horizontal = 3 text = "Compile" +[node name="Saving" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=404804163] +layout_mode = 2 +theme_override_constants/separation = 20 + +[node name="ScriptName" type="LineEdit" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Saving" unique_id=1831524214] +layout_mode = 2 +size_flags_horizontal = 3 +placeholder_text = "Name..." +max_length = 24 + +[node name="Save" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow/Saving" unique_id=599810254] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Save" + +[node name="Load" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer/EditorWindow" unique_id=2064954816] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Load script" + [node name="Robotlist" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/HBoxContainer" unique_id=592644944] layout_mode = 2 size_flags_horizontal = 3 @@ -232,6 +254,37 @@ max_length = 24 layout_mode = 2 text = "Submit" +[node name="Information" type="PanelContainer" parent="CanvasLayer/UIHandler/Popup" unique_id=1457118246 node_paths=PackedStringArray("title", "content")] +visible = false +layout_mode = 0 +offset_right = 40.0 +offset_bottom = 40.0 +script = ExtResource("7_fgofq") +title = NodePath("VBoxContainer/Title") +content = NodePath("VBoxContainer/Content") + +[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/Popup/Information" unique_id=302174818] +layout_mode = 2 + +[node name="Title" type="RichTextLabel" parent="CanvasLayer/UIHandler/Popup/Information/VBoxContainer" unique_id=680933734] +layout_mode = 2 +text = "Test" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 + +[node name="Content" type="RichTextLabel" parent="CanvasLayer/UIHandler/Popup/Information/VBoxContainer" unique_id=1438295895] +layout_mode = 2 +text = "Test" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 + +[node name="Button" type="Button" parent="CanvasLayer/UIHandler/Popup/Information/VBoxContainer" unique_id=1927576326] +layout_mode = 2 +text = "OK" + [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"] +[connection signal="pressed" from="CanvasLayer/UIHandler/Popup/Information/VBoxContainer/Button" to="CanvasLayer/UIHandler/Popup/Information" method="HideInformation"] diff --git a/Scripts/DSL/CodingWindow.cs b/Scripts/DSL/CodingWindow.cs index 7401dad..9552f52 100644 --- a/Scripts/DSL/CodingWindow.cs +++ b/Scripts/DSL/CodingWindow.cs @@ -9,6 +9,8 @@ public partial class CodingWindow : PanelContainer [Export] VBoxContainer robotList; [Signal] public delegate void OnRobotClickedEventHandler(Robot robot); + [Signal] + public delegate void OnInformationEventHandler(string title, string text); public Dictionary DSLNodes; // Called when the node enters the scene tree for the first time. @@ -35,19 +37,20 @@ public partial class CodingWindow : PanelContainer //Move, Harvest, Craft public void GenerateCodingBlocks() { - Button button; + NodeDisplay nodeDisplay; foreach (ProgramNode node in DSLNodes.Keys) { - button = new Button + nodeDisplay = DSLNodes[node].Instantiate(); + nodeDisplay.node = node; + codeBlocks.AddChild(nodeDisplay); + nodeDisplay.ShowListDisplay(); + nodeDisplay.listDisplay.Pressed += () => { - Text = node.DisplayText, - Name = node.DisplayText + NodeDisplay editorDisplay = DSLNodes[node].Instantiate(); + editorDisplay.node = node; + editorWindow.AddChild(editorDisplay); + editorDisplay.ShowEditorDisplay(); }; - button.Pressed += () => - { - editorWindow.AddChild(DSLNodes[node].Instantiate()); - }; - codeBlocks.AddChild(button); } } @@ -86,6 +89,20 @@ public partial class CodingWindow : PanelContainer public void CompileProgram() { + string errorMessage = ""; + bool didCompile; + for (int i = 1; i < editorWindow.GetChildCount(); i++) + { + editorWindow.GetChild(i - 1).node.LinkNode(editorWindow.GetChild(i).node); + } + + ProgramInterpreter interpreter = new ProgramInterpreter(editorWindow.GetChild(0).node); + didCompile = interpreter.Execute(GameData.robots[0]); + + if (!didCompile) + { + EmitSignal(SignalName.OnInformation, "ERROR", "Compilation failed " + errorMessage); + } } } diff --git a/Scripts/DSL/NodeDisplay.cs b/Scripts/DSL/NodeDisplay.cs index e944121..ff30915 100644 --- a/Scripts/DSL/NodeDisplay.cs +++ b/Scripts/DSL/NodeDisplay.cs @@ -1,30 +1,41 @@ using System; using Godot; -public partial class NodeDisplay : RichTextLabel +public partial class NodeDisplay : PanelContainer { - ProgramNode node; + [Export] PanelContainer editorDisplay; + [Export] public Button listDisplay; + public ProgramNode node; - public void SetNode(ProgramNode node) - { - this.node = node; - } + public void SetNode(ProgramNode node) + { + this.node = node; + } - public void SetupUIElement() - { - - } + public void SetupUIElement() + { + + } - public override void _Ready() - { + public override void _Ready() + { - } + } - public override void _Process(double delta) - { - if (Input.IsActionJustPressed("left_click")) - { + public override void _Process(double delta) + { + + } - } - } -} \ No newline at end of file + public void ShowListDisplay() + { + editorDisplay.Visible = false; + listDisplay.Visible = true; + } + + public void ShowEditorDisplay() + { + editorDisplay.Visible = true; + listDisplay.Visible = false; + } +} diff --git a/Scripts/DSL/Nodes/CraftNode.cs b/Scripts/DSL/Nodes/CraftNode.cs index 1d6a8cf..a2d2069 100644 --- a/Scripts/DSL/Nodes/CraftNode.cs +++ b/Scripts/DSL/Nodes/CraftNode.cs @@ -6,9 +6,16 @@ public class CraftNode : ProgramNode { DisplayText = "Craft"; } - public override void Execute(Robot robot) + public override bool Execute(Robot robot) { GD.Print("Craft"); - nextNode.Execute(robot); + if (nextNode != null) + { + return nextNode.Execute(robot); + } + else + { + return true; + } } } \ No newline at end of file diff --git a/Scripts/DSL/Nodes/HarvestNode.cs b/Scripts/DSL/Nodes/HarvestNode.cs index 54b8bfb..2f62a65 100644 --- a/Scripts/DSL/Nodes/HarvestNode.cs +++ b/Scripts/DSL/Nodes/HarvestNode.cs @@ -6,9 +6,16 @@ public class HarvestNode : ProgramNode { DisplayText = "Harvest"; } - public override void Execute(Robot robot) + public override bool Execute(Robot robot) { GD.Print("Harvest"); - nextNode.Execute(robot); + if (nextNode != null) + { + return nextNode.Execute(robot); + } + else + { + return true; + } } } \ No newline at end of file diff --git a/Scripts/DSL/Nodes/MoveNode.cs b/Scripts/DSL/Nodes/MoveNode.cs index b92fe78..a631152 100644 --- a/Scripts/DSL/Nodes/MoveNode.cs +++ b/Scripts/DSL/Nodes/MoveNode.cs @@ -8,9 +8,16 @@ public class MoveNode : ProgramNode { DisplayText = "Move"; } - public override void Execute(Robot robot) + public override bool Execute(Robot robot) { robot.Position = targetPosition; - nextNode.Execute(robot); + if (nextNode != null) + { + return nextNode.Execute(robot); + } + else + { + return true; + } } } \ No newline at end of file diff --git a/Scripts/DSL/Nodes/ProgramNode.cs b/Scripts/DSL/Nodes/ProgramNode.cs index 76939f5..dc6f663 100644 --- a/Scripts/DSL/Nodes/ProgramNode.cs +++ b/Scripts/DSL/Nodes/ProgramNode.cs @@ -9,7 +9,7 @@ public abstract class ProgramNode } - public abstract void Execute(Robot robot); + public abstract bool Execute(Robot robot); public void LinkNode(ProgramNode nextNode) { this.nextNode = nextNode; diff --git a/Scripts/DSL/ProgramInterpreter.cs b/Scripts/DSL/ProgramInterpreter.cs index e69de29..c43fb99 100644 --- a/Scripts/DSL/ProgramInterpreter.cs +++ b/Scripts/DSL/ProgramInterpreter.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using Godot; + +public class ProgramInterpreter +{ + ProgramNode startNode; + public ProgramInterpreter(ProgramNode startNode) + { + this.startNode = startNode; + } + + public bool Execute(Robot robot) + { + return startNode.Execute(robot); + } + + +} \ No newline at end of file diff --git a/Scripts/Helpers/UIHandler.cs b/Scripts/Helpers/UIHandler.cs index 8cd321f..97cdbf9 100644 --- a/Scripts/Helpers/UIHandler.cs +++ b/Scripts/Helpers/UIHandler.cs @@ -6,6 +6,7 @@ public partial class UIHandler : Control { [Export] CodingWindow codingWindow; [Export] PanelContainer robotNaming; + [Export] Information information; [Export] Camera3D mainCam; public override void _Ready() { @@ -19,6 +20,8 @@ public partial class UIHandler : Control { mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z); }; + + codingWindow.OnInformation += information.DisplayInformation; } public void ChangeColor(Color color) diff --git a/Scripts/Information.cs b/Scripts/Information.cs new file mode 100644 index 0000000..2a5fbce --- /dev/null +++ b/Scripts/Information.cs @@ -0,0 +1,29 @@ +using Godot; +using System; + +public partial class Information : PanelContainer +{ + [Export] RichTextLabel title; + [Export] RichTextLabel content; + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } + + public void DisplayInformation(string title, string content) + { + this.title.Text = title; + this.content.Text = content; + Visible = true; + } + + public void HideInformation() + { + Visible = false; + } +} diff --git a/Scripts/Information.cs.uid b/Scripts/Information.cs.uid new file mode 100644 index 0000000..bc7d751 --- /dev/null +++ b/Scripts/Information.cs.uid @@ -0,0 +1 @@ +uid://c3v2vdj3ghp78