From c6bbb834f7758027c0df338f1520f34fad3befea Mon Sep 17 00:00:00 2001 From: Matheus Date: Tue, 9 Sep 2025 19:09:34 -0300 Subject: Organização MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/GUI/InventoryMenu.cs | 47 +++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 18 deletions(-) (limited to 'scripts/GUI/InventoryMenu.cs') diff --git a/scripts/GUI/InventoryMenu.cs b/scripts/GUI/InventoryMenu.cs index bfb1795..5bac62b 100644 --- a/scripts/GUI/InventoryMenu.cs +++ b/scripts/GUI/InventoryMenu.cs @@ -1,52 +1,63 @@ using Godot; -using System; +using TheLegendOfGustav.Entities.Items; +using TheLegendOfGustav.Entities.Actors; + +namespace TheLegendOfGustav.GUI; public partial class InventoryMenu : CanvasLayer { private static readonly PackedScene itemMenuEntryScene = GD.Load("res://scenes/GUI/item_menu_entry.tscn"); + [Signal] public delegate void ItemSelectedEventHandler(ConsumableItem item); [Signal] public delegate void ItemDropEventHandler(ConsumableItem item); - private VBoxContainer itemsNode; + private VBoxContainer ItemsNode { get; set; } - public override void _Ready() { + public override void _Ready() + { base._Ready(); - itemsNode = GetNode("CenterContainer/PanelContainer/VBoxContainer/Items"); + ItemsNode = GetNode("CenterContainer/PanelContainer/VBoxContainer/Items"); Hide(); } - public void OnActivate(ConsumableItem item) { + public void OnActivate(ConsumableItem item) + { EmitSignal(SignalName.ItemSelected, item); } - - public void OnDrop(ConsumableItem item) { + + public void OnDrop(ConsumableItem item) + { EmitSignal(SignalName.ItemDrop, item); } - private void RegisterItem(int index, ConsumableItem item) { + public void Initialize(Inventory inventory) + { + for (int i = 0; i < inventory.Items.Count; i++) + { + RegisterItem(i, inventory.Items[i]); + } + + Show(); + } + + private void RegisterItem(int index, ConsumableItem item) + { char? shortcut = null; // Só terá atalho para as letras do alfabeto. - if (index < 26) { + if (index < 26) + { shortcut = (char)('a' + index); } ItemMenuEntry itemEntry = itemMenuEntryScene.Instantiate(); - itemsNode.AddChild(itemEntry); + 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(); - } } -- cgit v1.2.3