diff options
Diffstat (limited to 'scripts/GUI/InventoryMenu.cs')
| -rw-r--r-- | scripts/GUI/InventoryMenu.cs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/GUI/InventoryMenu.cs b/scripts/GUI/InventoryMenu.cs new file mode 100644 index 0000000..bfb1795 --- /dev/null +++ b/scripts/GUI/InventoryMenu.cs @@ -0,0 +1,52 @@ +using Godot; +using System; + +public partial class InventoryMenu : CanvasLayer +{ + private static readonly PackedScene itemMenuEntryScene = GD.Load<PackedScene>("res://scenes/GUI/item_menu_entry.tscn"); + [Signal] + public delegate void ItemSelectedEventHandler(ConsumableItem item); + [Signal] + public delegate void ItemDropEventHandler(ConsumableItem item); + + private VBoxContainer itemsNode; + + public override void _Ready() { + base._Ready(); + + itemsNode = GetNode<VBoxContainer>("CenterContainer/PanelContainer/VBoxContainer/Items"); + Hide(); + } + + public void OnActivate(ConsumableItem item) { + EmitSignal(SignalName.ItemSelected, item); + } + + public void OnDrop(ConsumableItem item) { + EmitSignal(SignalName.ItemDrop, item); + } + + private void RegisterItem(int index, ConsumableItem item) { + char? shortcut = null; + + // Só terá atalho para as letras do alfabeto. + if (index < 26) { + shortcut = (char)('a' + index); + } + + ItemMenuEntry itemEntry = itemMenuEntryScene.Instantiate<ItemMenuEntry>(); + + itemsNode.AddChild(itemEntry); + itemEntry.Initialize(item, shortcut); + itemEntry.Activate += OnActivate; + itemEntry.Drop += OnDrop; + } + + public void Initialize(Inventory inventory) { + for (int i = 0; i < inventory.Items.Count; i++) { + RegisterItem(i, inventory.Items[i]); + } + + Show(); + } +} |
