53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
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)
|
|
{
|
|
|
|
}
|
|
|
|
public override void _Notification(int id)
|
|
{
|
|
if (id == NotificationVisibilityChanged)
|
|
{
|
|
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);
|
|
Visible = false;
|
|
};
|
|
robotList.AddChild(display);
|
|
}
|
|
}
|
|
}
|