Big project cleanup with overhaul of file responsibilities (KISS) and code (DRY, YAGNI)
This commit is contained in:
@@ -3,7 +3,8 @@ using Godot;
|
||||
|
||||
public partial class InventoryDisplay : PanelContainer
|
||||
{
|
||||
private PackedScene itemDisplayPrefab = ResourceLoader.LoadItemDisplay();
|
||||
private readonly PackedScene itemDisplayPrefab = ResourceLoader.LoadItemDisplay();
|
||||
|
||||
[Export] VBoxContainer itemList;
|
||||
[Export] RichTextLabel inventorySpace;
|
||||
|
||||
@@ -34,24 +35,32 @@ public partial class InventoryDisplay : PanelContainer
|
||||
}
|
||||
|
||||
public void ReloadItems()
|
||||
{
|
||||
ClearItems();
|
||||
|
||||
foreach (Item item in GameData.inventory.items)
|
||||
{
|
||||
itemList.AddChild(CreateItemDisplay(item));
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearItems()
|
||||
{
|
||||
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.data.GetReadableName();
|
||||
display.amount.Text = $"{item.currentAmount}/{item.data.StackSize}";
|
||||
display.texture.Texture = ResourceLoader.LoadPath(item.data.Texture);
|
||||
itemList.AddChild(display);
|
||||
}
|
||||
private ItemDisplay CreateItemDisplay(Item item)
|
||||
{
|
||||
ItemDisplay display = itemDisplayPrefab.Instantiate<ItemDisplay>();
|
||||
display.item = item;
|
||||
display.text.Text = item.data.GetReadableName();
|
||||
display.amount.Text = $"{item.currentAmount}/{item.data.StackSize}";
|
||||
display.texture.Texture = ResourceLoader.LoadPath(item.data.Texture);
|
||||
return display;
|
||||
}
|
||||
|
||||
public void OnInventoryUpdate(object sender, EventArgs args)
|
||||
|
||||
Reference in New Issue
Block a user