Added renaming to the robots onclick.

This commit is contained in:
=
2026-04-28 14:37:12 +02:00
parent b926be307e
commit 4b460926c5
6 changed files with 103 additions and 7 deletions
+16 -1
View File
@@ -72,8 +72,23 @@ public partial class CodingWindow : PanelContainer
foreach (Robot robotObject in GameData.robots)
{
robot = nodePrefab.Instantiate<Control>();
robot.GetNode<RichTextLabel>("./Node/NodeContainer/NodeText").Text = robotObject.Position.ToString();
robot.GetNode<RichTextLabel>("./Node/NodeContainer/NodeText").Text = robotObject.Name;
GetNode<VBoxContainer>("./HBoxContainer/Robotlist/VBoxContainer").AddChild(robot);
}
}
public void ClearWindow()
{
VBoxContainer nodeList = GetNode<VBoxContainer>("./HBoxContainer/EditorWindow/CodeContainer/VBoxContainer");
foreach(Node node in nodeList.GetChildren())
{
nodeList.RemoveChild(node);
node.QueueFree();
}
}
public void CompileProgram()
{
}
}
+1 -1
View File
@@ -46,7 +46,7 @@ public partial class NodeDisplay : RichTextLabel
{
if (input is InputEventMouseButton mouseEvent && mouseEvent.ButtonIndex == MouseButton.Left && mouseEvent.IsReleased())
{
GetNode<Control>("../../../EditorWindow/VBoxContainer").AddChild(node.editorDisplay.Instantiate());
GetNode<Control>("../../../EditorWindow/CodeContainer/VBoxContainer").AddChild(node.editorDisplay.Instantiate());
}
}
}
+24 -1
View File
@@ -1,3 +1,5 @@
using System;
using System.Threading.Tasks;
using Godot;
public partial class UIHandler : Control
@@ -10,7 +12,7 @@ public partial class UIHandler : Control
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public void ChangeColor(Color color)
@@ -19,4 +21,25 @@ public partial class UIHandler : Control
LightHandler.RedrawLights(color);
}
public void ShowNamingPopup(Robot robot)
{
VBoxContainer namingContainer = GetNode<VBoxContainer>("./Popup/RobotNaming");
namingContainer.Visible = true;
GameData.canMove = false;
LineEdit name = namingContainer.GetNode<LineEdit>("./LineEdit");
Button button = namingContainer.GetNode<Button>("./Button");
Action handler = null;
handler = () =>
{
robot.Name = name.Text;
name.Text = "";
namingContainer.Visible = false;
GameData.canMove = true;
button.ButtonUp -= handler;
};
button.ButtonUp += handler;
}
}
+2 -1
View File
@@ -1,3 +1,4 @@
using System.Threading.Tasks;
using Godot;
public partial class Robot : Node3D
@@ -9,6 +10,6 @@ public partial class Robot : Node3D
public void OnClicked()
{
GD.Print("Test!");
GetNode<UIHandler>("/root/Main/CanvasLayer/Control").ShowNamingPopup(this);
}
}
+1
View File
@@ -75,6 +75,7 @@ public partial class World : Node3D
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
if (!canMove) return;
if (Input.IsActionJustPressed("layer_up") && currentLayer > 0) currentLayer--;
if (Input.IsActionJustPressed("layer_down") && currentLayer < ruinSize - 1) currentLayer++;
if (currentLayer != visibleLayer)