summaryrefslogtreecommitdiff
path: root/scripts/GUI/Details.cs
blob: 0e342aae3bb1bdd7e2f1bfb3a1a83b2c5b727464 (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 System;

public partial class Details : CanvasLayer
{
	private static readonly LabelSettings lblSettings = GD.Load<LabelSettings>("res://assets/definitions/message_label_settings.tres");
	private Map map;
	private VBoxContainer entityNames;
	private Godot.Collections.Array<Actor> actors = [];

	private Godot.Collections.Array<Label> actorsLabel = [];

	public override void _Ready()
	{
		base._Ready();
		map = GetParent<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.Map_Data;
		actors = mapData.GetActorsAtPosition(pos);
		UpdateLabels();
	}

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

		foreach (Actor actor in actors) {
			Label label = new()
			{
				Text = actor.ActorName,
				LabelSettings = lblSettings
			};

			actorsLabel.Add(label);
			entityNames.AddChild(label);
		}
	}
}