blob: 364c6947a4b21b24bef545d5e3895ab4de0b2a6b (
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
{
private TextureRect icon;
private Label shortcutLabel;
private Label nameLabel;
private Button activateBtn;
private Button dropBtn;
private Item item;
[Signal]
public delegate void ActivateEventHandler(Item Item);
[Signal]
public delegate void DropEventHandler(Item Item);
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(Item item, char? shortcut)
{
this.item = item;
nameLabel.Text = item.Definition.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.Definition.Icon;
}
}
|