blob: 2a698603d1b87bbfeb11190f4b41ece63fd11eaa (
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
|
using Godot;
using System.Threading.Tasks;
using TheLegendOfGustav.Utils;
namespace TheLegendOfGustav.GUI;
public partial class MessageLog : ScrollContainer
{
private VBoxContainer messageList;
private MessageLogData.messageSentEventHandler joinSignal;
public override void _Ready()
{
base._Ready();
messageList = GetNode<VBoxContainer>("MessageList");
foreach (Message msg in MessageLogData.Instance.Messages)
{
_ = AddMessageAsync(msg);
}
joinSignal = async (Message msg) => await AddMessageAsync(msg);
MessageLogData.Instance.messageSent += joinSignal;
}
public override void _Notification(int what)
{
if (what == NotificationPredelete)
{
if (joinSignal != null)
{
MessageLogData.Instance.messageSent -= joinSignal;
}
}
base._Notification(what);
}
private async Task AddMessageAsync(Message message)
{
messageList.AddChild(message);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
EnsureControlVisible(message);
}
}
|