summaryrefslogtreecommitdiff
path: root/scripts/GUI/ItemMenuEntry.cs
blob: 449c97be7672f8e8fc1169b68a39ed673b28bb2d (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
using Godot;

public partial class ItemMenuEntry : HBoxContainer
{
	private TextureRect icon;
	private Label shortcutLabel;
	private Label nameLabel;
	private Button activateBtn;
	private Button dropBtn;

	[Signal]
	public delegate void ActivateEventHandler(ConsumableItem Item);

	[Signal]
	public delegate void DropEventHandler(ConsumableItem item);

	private ConsumableItem item;

	public void Initialize(ConsumableItem item, char? shortcut) {
		this.item = item;
		nameLabel.Text = item.DisplayName;
		if (shortcut != null) {
			shortcutLabel.Text = $"{shortcut}";
		} else {
			shortcutLabel.Text = "";
		}
		icon.Texture = item.Texture;
	}

	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);
	}
}