Added the ability to spawn more robots if research allows it.
This commit is contained in:
@@ -3,9 +3,12 @@ using Godot;
|
||||
public partial class RobotList : PanelContainer
|
||||
{
|
||||
[Export] VBoxContainer robotList;
|
||||
[Export] OptionButton selectableRobots;
|
||||
[Export] Button spawnRobot;
|
||||
[Signal]
|
||||
public delegate void OnRobotJumpToEventHandler(Robot robot);
|
||||
private PackedScene robotDisplayPrefab;
|
||||
private string spawnId = "";
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -16,7 +19,11 @@ public partial class RobotList : PanelContainer
|
||||
{
|
||||
if (id == NotificationVisibilityChanged)
|
||||
{
|
||||
if (Visible) ReloadRobots();
|
||||
if (Visible)
|
||||
{
|
||||
ReloadRobots();
|
||||
ReloadSelectableRobots();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,4 +49,49 @@ public partial class RobotList : PanelContainer
|
||||
robotList.AddChild(display);
|
||||
}
|
||||
}
|
||||
|
||||
public void ReloadSelectableRobots()
|
||||
{
|
||||
selectableRobots.Clear();
|
||||
if(GameData.robots.Count >= GameData.maxRobotCount)
|
||||
{
|
||||
selectableRobots.AddItem("You can't have more robots currently!");
|
||||
selectableRobots.Disabled = true;
|
||||
spawnRobot.Disabled = true;
|
||||
return;
|
||||
}
|
||||
selectableRobots.Disabled = false;
|
||||
spawnRobot.Disabled = false;
|
||||
selectableRobots.AddItem("Select robot...");
|
||||
foreach (Item item in GameData.inventory.items)
|
||||
{
|
||||
if (GameData.robotStats.RobotTypes.ContainsKey(item.data.Id))
|
||||
{
|
||||
selectableRobots.AddItem(item.data.GetReadableName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SpawnRobot()
|
||||
{
|
||||
if(spawnId.Length <= 0) return;
|
||||
GameData.inventory.RemoveItem(spawnId, 1);
|
||||
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
|
||||
robot.Name = $"Robot #{GameData.robots.Count}";
|
||||
robot.Position = GameData.map[0].tiles[0, 0].Position;
|
||||
robot.robotType = spawnId;
|
||||
GetNode("/root/Main/World").AddChild(robot);
|
||||
GameData.robots.Add(robot);
|
||||
spawnId = "";
|
||||
|
||||
ReloadRobots();
|
||||
ReloadSelectableRobots();
|
||||
}
|
||||
|
||||
public void OnRobotSelect(int index)
|
||||
{
|
||||
//Selected option is the "please select..." option
|
||||
if(index == 0) return;
|
||||
spawnId = ItemData.GetIndex(selectableRobots.GetItemText(index));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user