summaryrefslogtreecommitdiff
path: root/scripts/GUI/MessageLog.cs
blob: d481b19ae34a021dcfde9f40ad79e9baa64c42e2 (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
using Godot;
using System;
using System.Threading.Tasks;

public partial class MessageLog : ScrollContainer
{
	private VBoxContainer MessageList;

	public override void _Ready()
	{
		base._Ready();
		MessageList = GetNode<VBoxContainer>("MessageList");

		foreach (Message msg in MessageLogData.Instance.Messages) {
			_ = AddMessageAsync(msg);
		}

		MessageLogData.Instance.messageSent += async (Message msg) => await AddMessageAsync(msg);
	}

	private async Task AddMessageAsync(Message message) {
		MessageList.AddChild(message);
		await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
		EnsureControlVisible(message);
	}
}