summaryrefslogtreecommitdiff
path: root/scripts/GUI/InventoryMenu.cs
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-08 22:10:45 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-08 22:10:45 -0300
commitf1b51bed52ffbd90b5b7cc8dcfc6f0484bbbeb3c (patch)
treed607142daee4948765a97008bdef21fa6efa2d2b /scripts/GUI/InventoryMenu.cs
parent4b2afd3e2144e42bfa7f11a870584b9255052cf7 (diff)
inventário acessivel
Diffstat (limited to 'scripts/GUI/InventoryMenu.cs')
-rw-r--r--scripts/GUI/InventoryMenu.cs52
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();
+ }
+}