summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/GUI/MessageLog.cs23
-rw-r--r--scripts/Game.cs2
-rw-r--r--scripts/Utils/MessageLogData.cs48
-rw-r--r--scripts/Utils/MessageLogData.cs.uid1
-rw-r--r--scripts/Utils/SignalBus.cs6
-rw-r--r--scripts/actors/Actor.cs2
-rw-r--r--scripts/actors/actions/MeleeAction.cs2
7 files changed, 58 insertions, 26 deletions
diff --git a/scripts/GUI/MessageLog.cs b/scripts/GUI/MessageLog.cs
index ebfb488..d481b19 100644
--- a/scripts/GUI/MessageLog.cs
+++ b/scripts/GUI/MessageLog.cs
@@ -4,34 +4,23 @@ 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;
+ foreach (Message msg in MessageLogData.Instance.Messages) {
+ _ = AddMessageAsync(msg);
}
- Message message = new(text);
- lastMessage = message;
+ 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);
}
-
- /// <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);
- }
}
diff --git a/scripts/Game.cs b/scripts/Game.cs
index 3050e22..f25776e 100644
--- a/scripts/Game.cs
+++ b/scripts/Game.cs
@@ -48,7 +48,7 @@ public partial class Game : Node {
turnManager = new(Map);
- MessageLog.SendMessage("UMA FILA DE HOMENS EJACULANDO NA BOCA DA DALVA");
+ MessageLogData.Instance.AddMessage("Boa sorte!");
}
/// <summary>
diff --git a/scripts/Utils/MessageLogData.cs b/scripts/Utils/MessageLogData.cs
new file mode 100644
index 0000000..ed30062
--- /dev/null
+++ b/scripts/Utils/MessageLogData.cs
@@ -0,0 +1,48 @@
+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() {
+ foreach (Message message in messages) {
+ 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);
+
+} \ No newline at end of file
diff --git a/scripts/Utils/MessageLogData.cs.uid b/scripts/Utils/MessageLogData.cs.uid
new file mode 100644
index 0000000..0b8f55f
--- /dev/null
+++ b/scripts/Utils/MessageLogData.cs.uid
@@ -0,0 +1 @@
+uid://dgb6vauj2v8sm
diff --git a/scripts/Utils/SignalBus.cs b/scripts/Utils/SignalBus.cs
index 7408db2..f5cb0d2 100644
--- a/scripts/Utils/SignalBus.cs
+++ b/scripts/Utils/SignalBus.cs
@@ -16,10 +16,4 @@ public partial class SignalBus : Node
base._Ready();
Instance = this;
}
- /// <summary>
- /// Acionado sempre que uma mensagem for adicionada para o log.
- /// </summary>
- /// <param name="text">Mensagem.</param>
- [Signal]
- public delegate void messageSentEventHandler(string text);
}
diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs
index c03c8fa..2d22d44 100644
--- a/scripts/actors/Actor.cs
+++ b/scripts/actors/Actor.cs
@@ -236,7 +236,7 @@ public abstract partial class Actor : Sprite2D
deathMessage = $"{ActorName} morreu!";
}
- MessageLog.SendMessage(deathMessage);
+ MessageLogData.Instance.AddMessage(deathMessage);
Texture = definition.deathTexture;
blocksMovement = false;
diff --git a/scripts/actors/actions/MeleeAction.cs b/scripts/actors/actions/MeleeAction.cs
index e739159..ae94eff 100644
--- a/scripts/actors/actions/MeleeAction.cs
+++ b/scripts/actors/actions/MeleeAction.cs
@@ -33,6 +33,6 @@ public partial class MeleeAction : DirectionalAction
attackDesc += $" mas {target.ActorName} tem músculos de aço.";
}
- MessageLog.SendMessage(attackDesc);
+ MessageLogData.Instance.AddMessage(attackDesc);
}
}