summaryrefslogtreecommitdiff
path: root/scripts/GUI/ItemMenuEntry.cs
blob: 7ee3fcdcf53e973debfd0a365071c3e1ee3424d2 (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
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}";
		}
		else
		{
			ShortcutLabel.Text = "";
		}
		Icon.Texture = item.Texture;
	}
}