Added inventory display and item display.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
using Godot;
|
||||
|
||||
public partial class InventoryDisplay : PanelContainer
|
||||
{
|
||||
PackedScene itemDisplayPrefab = ResourceLoader.LoadItemDisplay();
|
||||
[Export] VBoxContainer itemList;
|
||||
|
||||
public override void _Notification(int id)
|
||||
{
|
||||
if (id == NotificationVisibilityChanged)
|
||||
{
|
||||
if (Visible) ReloadItems();
|
||||
}
|
||||
}
|
||||
|
||||
public void ReloadItems()
|
||||
{
|
||||
foreach (Node node in itemList.GetChildren())
|
||||
{
|
||||
itemList.RemoveChild(node);
|
||||
node.QueueFree();
|
||||
}
|
||||
ItemDisplay display;
|
||||
|
||||
foreach (Item item in GameData.inventory.items)
|
||||
{
|
||||
display = itemDisplayPrefab.Instantiate<ItemDisplay>();
|
||||
display.item = item;
|
||||
display.text.Text = item.GetReadableName();
|
||||
display.amount.Text = item.currentAmount.ToString();
|
||||
display.texture.Texture = ResourceLoader.LoadPath(item.data.Texture);
|
||||
itemList.AddChild(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user