Added Inventory space display and robot alert if not working currently. Added inventory live update.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Godot;
|
||||
|
||||
@@ -6,6 +7,7 @@ public class Inventory
|
||||
public List<Item> items = new();
|
||||
|
||||
public int maxInventorySize = 8;
|
||||
public event EventHandler OnInventoryUpdate;
|
||||
|
||||
public bool AddItem(Item item, int amount)
|
||||
{
|
||||
@@ -13,6 +15,7 @@ public class Inventory
|
||||
if (inventoryItem != null)
|
||||
{
|
||||
inventoryItem.currentAmount += amount;
|
||||
OnInventoryUpdate?.Invoke(this, EventArgs.Empty);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@@ -21,6 +24,7 @@ public class Inventory
|
||||
{
|
||||
items.Add(item);
|
||||
items[items.Count - 1].currentAmount += amount;
|
||||
OnInventoryUpdate?.Invoke(this, EventArgs.Empty);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -49,6 +53,7 @@ public class Inventory
|
||||
if (item != null)
|
||||
{
|
||||
item.currentAmount -= amount;
|
||||
OnInventoryUpdate?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,31 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
public partial class InventoryDisplay : PanelContainer
|
||||
{
|
||||
PackedScene itemDisplayPrefab = ResourceLoader.LoadItemDisplay();
|
||||
[Export] VBoxContainer itemList;
|
||||
[Export] RichTextLabel inventorySpace;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
GameData.inventory.OnInventoryUpdate += OnInventoryUpdate;
|
||||
}
|
||||
|
||||
public override void _Notification(int id)
|
||||
{
|
||||
if (id == NotificationVisibilityChanged)
|
||||
{
|
||||
if (Visible) ReloadItems();
|
||||
if (Visible) UpdateInventorySpace();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateInventorySpace()
|
||||
{
|
||||
inventorySpace.Text = $"Used space: {GameData.inventory.items.Count}/{GameData.inventory.maxInventorySize}";
|
||||
}
|
||||
|
||||
public void ReloadItems()
|
||||
{
|
||||
foreach (Node node in itemList.GetChildren())
|
||||
@@ -27,9 +40,15 @@ public partial class InventoryDisplay : PanelContainer
|
||||
display = itemDisplayPrefab.Instantiate<ItemDisplay>();
|
||||
display.item = item;
|
||||
display.text.Text = item.data.GetReadableName();
|
||||
display.amount.Text = item.currentAmount.ToString();
|
||||
display.amount.Text = $"{item.currentAmount}/{item.data.StackSize}";
|
||||
display.texture.Texture = ResourceLoader.LoadPath(item.data.Texture);
|
||||
itemList.AddChild(display);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnInventoryUpdate(object sender, EventArgs args)
|
||||
{
|
||||
ReloadItems();
|
||||
UpdateInventorySpace();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public partial class UIHandler : Control
|
||||
[Export] PanelContainer menu;
|
||||
[Export] PanelContainer inventory;
|
||||
[Export] ResearchList researchList;
|
||||
[Export] TextureRect robotAlarm;
|
||||
|
||||
bool receivedRobotJumpSignal = false;
|
||||
public override void _Ready()
|
||||
@@ -28,6 +29,7 @@ public partial class UIHandler : Control
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
DisplayStats();
|
||||
DisplayRobotAlarm();
|
||||
robotList.OnRobotJumpTo += (robot) =>
|
||||
{
|
||||
if(receivedRobotJumpSignal) return;
|
||||
@@ -113,4 +115,21 @@ public partial class UIHandler : Control
|
||||
child.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void DisplayRobotAlarm()
|
||||
{
|
||||
string messages = "";
|
||||
foreach (Robot robot in GameData.robots)
|
||||
{
|
||||
if(robot.currentMessage.Length > 0)
|
||||
{
|
||||
messages += $"{robot.Name}: {robot.currentMessage}";
|
||||
}
|
||||
}
|
||||
robotAlarm.Visible = messages.Length > 0;
|
||||
if (messages.Length >= 0)
|
||||
{
|
||||
robotAlarm.TooltipText = messages;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ public partial class Robot : Node3D
|
||||
bool isExecuting = false;
|
||||
ProgramNode currentNode;
|
||||
public string currentProgram;
|
||||
public string currentMessage = "";
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
@@ -22,22 +23,25 @@ public partial class Robot : Node3D
|
||||
switch (currentNode.Execute(this, delta))
|
||||
{
|
||||
case NodeResult.SUCCESS:
|
||||
GD.Print(currentNode.lastExecutionMessage);
|
||||
currentNode = currentNode.nextNode;
|
||||
if (currentNode == null)
|
||||
{
|
||||
{
|
||||
isExecuting = false;
|
||||
}
|
||||
break;
|
||||
case NodeResult.FAILURE:
|
||||
isExecuting = false;
|
||||
GD.Print(currentNode.lastExecutionMessage);
|
||||
currentMessage = "(FAILED)" + currentNode.lastExecutionMessage;
|
||||
break;
|
||||
case NodeResult.RUNNING:
|
||||
//Currently does nothing.
|
||||
currentMessage = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if(currentMessage.Length <= 0)
|
||||
{
|
||||
currentMessage = "No script executing";
|
||||
}
|
||||
|
||||
Visible = Math.Round(Math.Abs(Position.Y / GameData.tileHeight), 0) == GameData.visibleLayer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user