Finished first EA Version #1
+18
-1
@@ -326,7 +326,7 @@ size_flags_horizontal = 3
|
||||
layout_mode = 2
|
||||
text = "Close"
|
||||
|
||||
[node name="RobotList" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1469962195 node_paths=PackedStringArray("robotList")]
|
||||
[node name="RobotList" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=1469962195 node_paths=PackedStringArray("robotList", "selectableRobots", "spawnRobot")]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 11
|
||||
@@ -338,6 +338,8 @@ grow_horizontal = 0
|
||||
grow_vertical = 2
|
||||
script = ExtResource("7_2irst")
|
||||
robotList = NodePath("VBoxContainer/ScrollContainer/VBoxContainer")
|
||||
selectableRobots = NodePath("VBoxContainer/Spawning/OptionButton")
|
||||
spawnRobot = NodePath("VBoxContainer/Spawning/Button")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList" unique_id=1958138787]
|
||||
layout_mode = 2
|
||||
@@ -350,6 +352,19 @@ fit_content = true
|
||||
autowrap_mode = 0
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Spawning" type="HBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer" unique_id=243501895]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 26
|
||||
|
||||
[node name="OptionButton" type="OptionButton" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer/Spawning" unique_id=1230415850]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="Button" type="Button" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer/Spawning" unique_id=1513188650]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Spawn robot"
|
||||
|
||||
[node name="ScrollContainer" type="ScrollContainer" parent="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer" unique_id=592644944]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
@@ -580,6 +595,8 @@ texture_normal = ExtResource("12_3so38")
|
||||
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Saving/Save" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="SaveProgram"]
|
||||
[connection signal="item_selected" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Scripting/EditorWindow/Load" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="LoadProgram"]
|
||||
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/CodingWindow/VBoxContainer/Close" to="CanvasLayer/UIHandler/MainUI/Content/CodingWindow" method="CloseWindow"]
|
||||
[connection signal="item_selected" from="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer/Spawning/OptionButton" to="CanvasLayer/UIHandler/MainUI/Content/RobotList" method="OnRobotSelect"]
|
||||
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/RobotList/VBoxContainer/Spawning/Button" to="CanvasLayer/UIHandler/MainUI/Content/RobotList" method="SpawnRobot"]
|
||||
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button" to="CanvasLayer/UIHandler" method="HandleMenu"]
|
||||
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button2" to="CanvasLayer/UIHandler" method="ShowOptions"]
|
||||
[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button3" to="CanvasLayer/UIHandler" method="ExitGame"]
|
||||
|
||||
@@ -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