diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-08 22:10:45 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-08 22:10:45 -0300 |
| commit | f1b51bed52ffbd90b5b7cc8dcfc6f0484bbbeb3c (patch) | |
| tree | d607142daee4948765a97008bdef21fa6efa2d2b /scripts/GUI | |
| parent | 4b2afd3e2144e42bfa7f11a870584b9255052cf7 (diff) | |
inventário acessivel
Diffstat (limited to 'scripts/GUI')
| -rw-r--r-- | scripts/GUI/InventoryMenu.cs | 52 | ||||
| -rw-r--r-- | scripts/GUI/InventoryMenu.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/GUI/ItemMenuEntry.cs | 41 | ||||
| -rw-r--r-- | scripts/GUI/ItemMenuEntry.cs.uid | 1 |
4 files changed, 95 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(); + } +} diff --git a/scripts/GUI/InventoryMenu.cs.uid b/scripts/GUI/InventoryMenu.cs.uid new file mode 100644 index 0000000..594b644 --- /dev/null +++ b/scripts/GUI/InventoryMenu.cs.uid @@ -0,0 +1 @@ +uid://dukpdkyy365y4 diff --git a/scripts/GUI/ItemMenuEntry.cs b/scripts/GUI/ItemMenuEntry.cs new file mode 100644 index 0000000..449c97b --- /dev/null +++ b/scripts/GUI/ItemMenuEntry.cs @@ -0,0 +1,41 @@ +using Godot; + +public partial class ItemMenuEntry : HBoxContainer +{ + private TextureRect icon; + private Label shortcutLabel; + private Label nameLabel; + private Button activateBtn; + private Button dropBtn; + + [Signal] + public delegate void ActivateEventHandler(ConsumableItem Item); + + [Signal] + public delegate void DropEventHandler(ConsumableItem item); + + private ConsumableItem item; + + public void Initialize(ConsumableItem item, char? shortcut) { + this.item = item; + nameLabel.Text = item.DisplayName; + if (shortcut != null) { + shortcutLabel.Text = $"{shortcut}"; + } else { + shortcutLabel.Text = ""; + } + icon.Texture = item.Texture; + } + + public override void _Ready() { + base._Ready(); + icon = GetNode<TextureRect>("Icon"); + shortcutLabel = GetNode<Label>("Shortcut"); + nameLabel = GetNode<Label>("ItemName"); + activateBtn = GetNode<Button>("ActivateBtn"); + dropBtn = GetNode<Button>("DropButton"); + + activateBtn.Pressed += () => EmitSignal(SignalName.Activate, item); + dropBtn.Pressed += () => EmitSignal(SignalName.Drop, item); + } +} diff --git a/scripts/GUI/ItemMenuEntry.cs.uid b/scripts/GUI/ItemMenuEntry.cs.uid new file mode 100644 index 0000000..9ebeb06 --- /dev/null +++ b/scripts/GUI/ItemMenuEntry.cs.uid @@ -0,0 +1 @@ +uid://bdejwf8qmlii0 |
