blob: ebfb488e30a3485a60b6aa1c02d2ae5c44c7fe70 (
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
|
using Godot;
using System;
using System.Threading.Tasks;
public partial class MessageLog : ScrollContainer
{
private Message lastMessage = null;
private VBoxContainer MessageList;
public override void _Ready()
{
base._Ready();
MessageList = GetNode<VBoxContainer>("MessageList");
SignalBus.Instance.messageSent += async (string text) => await AddMessageAsync(text);
}
private async Task AddMessageAsync(string text) {
if (lastMessage != null && lastMessage.PlainText == text) {
lastMessage.Count++;
return;
}
Message message = new(text);
lastMessage = message;
MessageList.AddChild(message);
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
EnsureControlVisible(message);
}
/// <summary>
/// Método estático disponível em todo o escopo do jogo.
/// </summary>
/// <param name="text"></param>
public static void SendMessage(string text) {
SignalBus.Instance.EmitSignal(SignalBus.SignalName.messageSent, text);
}
}
|