blob: 7070b21d94e19d68173cc488ee42616d31355a1f (
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
64
65
66
67
68
69
70
71
72
73
74
75
|
using System.Xml;
using Godot;
using TheLegendOfGustav.Entities.Items;
namespace TheLegendOfGustav.GUI;
public partial class ItemMenuEntry : HBoxContainer
{
[Signal]
public delegate void ActivateEventHandler(ConsumableItem Item);
[Signal]
public delegate void DropEventHandler(ConsumableItem Item);
private TextureRect Icon { get; set; }
private Label ShortcutLabel { get; set; }
private Label NameLabel { get; set; }
private Button ActivateBtn { get; set; }
private Button DropBtn { get; set; }
private ConsumableItem Item { get; set; }
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);
}
public void Initialize(ConsumableItem item, char? shortcut)
{
Item = item;
NameLabel.Text = item.DisplayName;
if (shortcut != null)
{
ShortcutLabel.Text = $"{shortcut}";
int index = (int)shortcut - 'a';
InputEventKey activateEvent = new()
{
Keycode = Key.A + index
};
InputEventKey dropEvent = new()
{
Keycode = Key.A + index,
ShiftPressed = true
};
Shortcut shortie = new()
{
Events = [activateEvent]
};
Shortcut dropperino = new()
{
Events = [dropEvent]
};
ActivateBtn.Shortcut = shortie;
DropBtn.Shortcut = dropperino;
}
else
{
ShortcutLabel.Text = "";
}
Icon.Texture = item.Texture;
}
}
|