blob: 5bac62bd9e13efa5c6e08c0538fd1388191f7bb6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
using Godot;
using TheLegendOfGustav.Entities.Items;
using TheLegendOfGustav.Entities.Actors;
namespace TheLegendOfGustav.GUI;
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 { get; set; }
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);
}
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)
{
shortcut = (char)('a' + index);
}
ItemMenuEntry itemEntry = itemMenuEntryScene.Instantiate<ItemMenuEntry>();
ItemsNode.AddChild(itemEntry);
itemEntry.Initialize(item, shortcut);
itemEntry.Activate += OnActivate;
itemEntry.Drop += OnDrop;
}
}
|