Added Inventory space display and robot alert if not working currently. Added inventory live update.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user