using Godot; using System; using System.Collections.Generic; public partial class CodingWindow : PanelContainer { [Export] VBoxContainer codeBlocks; [Export] VBoxContainer editorWindow; [Export] VBoxContainer robotList; [Signal] public delegate void OnRobotClickedEventHandler(Robot robot); public Dictionary DSLNodes; // Called when the node enters the scene tree for the first time. public override void _Ready() { DSLNodes = ResourceLoader.LoadDSLNodes(); GenerateCodingBlocks(); } // Called every frame. 'delta' is the elapsed time since the previous frame. public override void _Process(double delta) { if (Input.IsActionJustPressed("codingwindow")) { Visible = !Visible; GameData.canMove = !Visible; if (Visible) { ReloadRobots(); } } } //Move, Harvest, Craft public void GenerateCodingBlocks() { 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() { foreach (Node node in robotList.GetChildren()) { robotList.RemoveChild(node); node.QueueFree(); } Button button; foreach (Robot robotObject in GameData.robots) { button = new Button { Text = robotObject.Name, Name = robotObject.Name }; button.Pressed += () => { EmitSignal(SignalName.OnRobotClicked, robotObject); }; robotList.AddChild(button); } } public void ClearWindow() { foreach (Node node in editorWindow.GetChildren()) { editorWindow.RemoveChild(node); node.QueueFree(); } } public void CompileProgram() { } }