blob: e8f0f09950d4bfa0b3fe64b48985c5791607fcf4 (
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
|
using Godot;
public partial class MessageLogData : Node
{
public static MessageLogData Instance { get; private set; }
private Godot.Collections.Array<Message> messages = [];
public Godot.Collections.Array<Message> Messages {get => messages;}
private Message LastMessage {
get {
if (messages.Count <= 0) {
return null;
}
return messages[^1];
}
}
public void ClearMessages() {
for (int i = messages.Count - 1; i >= 0; i--) {
Message message = messages[i];
messages.RemoveAt(i);
message.QueueFree();
}
}
public override void _Ready()
{
base._Ready();
Instance = this;
}
public void AddMessage(string text) {
if (LastMessage != null && LastMessage.PlainText == text) {
LastMessage.Count++;
return;
}
Message message = new(text);
messages.Add(message);
EmitSignal(SignalName.messageSent, message);
}
/// <summary>
/// Acionado sempre que uma mensagem for adicionada para o log.
/// </summary>
/// <param name="text">Mensagem.</param>
[Signal]
public delegate void messageSentEventHandler(Message message);
}
|