blob: bfb17958e2e67c5177b67ae378ae42f9d9ddf1d4 (
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
|
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();
}
}
|