summaryrefslogtreecommitdiff
path: root/scripts/GUI/MessageLog.cs
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-01 17:50:25 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-01 17:50:25 -0300
commit0456e7cd82b232a38fd9b6e008be7d49b2f9e90f (patch)
treeea2285eaca0d68c269d07212bc6a1e3688b9aef8 /scripts/GUI/MessageLog.cs
parentd7d2454d5ccc1e0acb47cb679c7550e74c4e1916 (diff)
Logs
Diffstat (limited to 'scripts/GUI/MessageLog.cs')
-rw-r--r--scripts/GUI/MessageLog.cs37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/GUI/MessageLog.cs b/scripts/GUI/MessageLog.cs
new file mode 100644
index 0000000..ebfb488
--- /dev/null
+++ b/scripts/GUI/MessageLog.cs
@@ -0,0 +1,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);
+ }
+}