Moved robots to separate folders and a dedicated robotlist in the UI
This commit is contained in:
@@ -6,12 +6,8 @@ public partial class CodingWindow : PanelContainer
|
||||
{
|
||||
[Export] VBoxContainer codeBlocks;
|
||||
[Export] VBoxContainer editorWindow;
|
||||
[Export] VBoxContainer robotList;
|
||||
[Signal]
|
||||
public delegate void OnRobotClickedEventHandler(Robot robot);
|
||||
[Signal]
|
||||
public delegate void OnInformationEventHandler(string title, string text);
|
||||
public Dictionary<ProgramNode, PackedScene> DSLNodes;
|
||||
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
@@ -23,14 +19,10 @@ public partial class CodingWindow : PanelContainer
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
//TODO: If robot that was pressed has a script, load script
|
||||
if (Input.IsActionJustPressed("codingwindow"))
|
||||
{
|
||||
Visible = !Visible;
|
||||
GameData.canMove = !Visible;
|
||||
if (Visible)
|
||||
{
|
||||
ReloadRobots();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,30 +46,6 @@ public partial class CodingWindow : PanelContainer
|
||||
}
|
||||
}
|
||||
|
||||
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())
|
||||
@@ -89,7 +57,6 @@ public partial class CodingWindow : PanelContainer
|
||||
|
||||
public void CompileProgram()
|
||||
{
|
||||
string errorMessage = "";
|
||||
bool didCompile;
|
||||
|
||||
for (int i = 0; i < editorWindow.GetChildCount(); i++)
|
||||
@@ -106,7 +73,7 @@ public partial class CodingWindow : PanelContainer
|
||||
|
||||
if (!didCompile)
|
||||
{
|
||||
EmitSignal(SignalName.OnInformation, "ERROR", "Compilation failed " + errorMessage);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,12 @@ public partial class ResourceLoader
|
||||
|
||||
public static PackedScene LoadRobotPrefab()
|
||||
{
|
||||
return GD.Load<PackedScene>($"res://Prefabs/Robot.tscn");
|
||||
return GD.Load<PackedScene>($"res://Prefabs/Robot/Robot.tscn");
|
||||
}
|
||||
|
||||
public static PackedScene LoadRobotDisplay()
|
||||
{
|
||||
return GD.Load<PackedScene>($"res://Prefabs/Robot/RobotDisplay.tscn");
|
||||
}
|
||||
|
||||
public static Dictionary<string, MeshInstance3D> LoadTiles()
|
||||
|
||||
@@ -5,6 +5,7 @@ using Godot;
|
||||
public partial class UIHandler : Control
|
||||
{
|
||||
[Export] CodingWindow codingWindow;
|
||||
[Export] RobotList robotList;
|
||||
[Export] PanelContainer robotNaming;
|
||||
[Export] Information information;
|
||||
[Export] Camera3D mainCam;
|
||||
@@ -16,12 +17,10 @@ public partial class UIHandler : Control
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
codingWindow.OnRobotClicked += (robot) =>
|
||||
robotList.OnRobotJumpTo += (robot) =>
|
||||
{
|
||||
mainCam.Position = new Vector3(robot.Position.X, mainCam.Position.Y, robot.Position.Z);
|
||||
};
|
||||
|
||||
codingWindow.OnInformation += information.DisplayInformation;
|
||||
}
|
||||
|
||||
public void ChangeColor(Color color)
|
||||
|
||||
@@ -3,6 +3,17 @@ using Godot;
|
||||
|
||||
public partial class Robot : Node3D
|
||||
{
|
||||
public ProgramInterpreter interpreter;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
public void Move()
|
||||
{
|
||||
|
||||
@@ -12,4 +23,5 @@ public partial class Robot : Node3D
|
||||
{
|
||||
GetNode<UIHandler>("/root/Main/CanvasLayer/UIHandler").ShowNamingPopup(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Godot;
|
||||
|
||||
public partial class RobotDisplay : PanelContainer
|
||||
{
|
||||
[Export] public RichTextLabel listItem;
|
||||
[Signal]
|
||||
public delegate void OnRobotJumpToEventHandler(Robot robot);
|
||||
public Robot robot;
|
||||
public override void _Ready()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void OnJumpToClicked()
|
||||
{
|
||||
EmitSignal(SignalName.OnRobotJumpTo, robot);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class RobotList : PanelContainer
|
||||
{
|
||||
[Export] VBoxContainer robotList;
|
||||
[Signal]
|
||||
public delegate void OnRobotJumpToEventHandler(Robot robot);
|
||||
public PackedScene robotDisplayPrefab;
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
robotDisplayPrefab = ResourceLoader.LoadRobotDisplay();
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (Input.IsActionJustPressed("robot_list"))
|
||||
{
|
||||
Visible = !Visible;
|
||||
if (Visible) ReloadRobots();
|
||||
}
|
||||
}
|
||||
|
||||
public void ReloadRobots()
|
||||
{
|
||||
foreach (Node node in robotList.GetChildren())
|
||||
{
|
||||
robotList.RemoveChild(node);
|
||||
node.QueueFree();
|
||||
}
|
||||
RobotDisplay display;
|
||||
|
||||
foreach (Robot robotObject in GameData.robots)
|
||||
{
|
||||
display = robotDisplayPrefab.Instantiate<RobotDisplay>();
|
||||
display.robot = robotObject;
|
||||
display.listItem.Text = robotObject.Name;
|
||||
display.OnRobotJumpTo += (robot) =>
|
||||
{
|
||||
EmitSignal(SignalName.OnRobotJumpTo, robot);
|
||||
};
|
||||
robotList.AddChild(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://k6vlo7ulvtep
|
||||
Reference in New Issue
Block a user