summaryrefslogtreecommitdiff
path: root/scripts/GUI/Details.cs
blob: 3c644270cdad9f20dd0bc2c9a4bc778769daf1af (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
using Godot;
using TheLegendOfGustav.Entities;
using TheLegendOfGustav.Map;
using TheLegendOfGustav.Utils;

namespace TheLegendOfGustav.GUI;

public partial class Details : CanvasLayer
{
	private static readonly LabelSettings lblSettings = GD.Load<LabelSettings>("res://assets/definitions/message_label_settings.tres");
	
	private Map.Map Map { get; set; }
	private VBoxContainer EntityNames { get; set; }
	private Godot.Collections.Array<Entity> Entities { get; set; } = [];

	private Godot.Collections.Array<Label> ActorsLabel { get; set; } = [];

	public override void _Ready()
	{
		base._Ready();
		Map = GetParent<Map.Map>();
		EntityNames = GetNode<VBoxContainer>("HBoxContainer/PanelContainer/ScrollContainer/Entities");

		SignalBus.Instance.InspectorMoved += OnInspectorWalk;
		SignalBus.Instance.EnterInspectionMode += () => Visible = true;
		SignalBus.Instance.ExitInspectionMode += () => Visible = false;
	}

	public void OnInspectorWalk(Vector2I pos)
	{
		MapData mapData = Map.MapData;
		Entities = mapData.GetEntitiesAtPosition(pos);
		UpdateLabels();
	}

	private void UpdateLabels()
	{
		foreach (Label label in ActorsLabel)
		{
			label.QueueFree();
		}

		ActorsLabel.Clear();

		foreach (Entity entity in Entities)
		{
			Label label = new()
			{
				Text = entity.DisplayName,
				LabelSettings = lblSettings
			};

			ActorsLabel.Add(label);
			EntityNames.AddChild(label);
		}
	}
}