diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-01 17:50:25 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-01 17:50:25 -0300 |
| commit | 0456e7cd82b232a38fd9b6e008be7d49b2f9e90f (patch) | |
| tree | ea2285eaca0d68c269d07212bc6a1e3688b9aef8 /scripts | |
| parent | d7d2454d5ccc1e0acb47cb679c7550e74c4e1916 (diff) | |
Logs
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/GUI/Hud.cs (renamed from scripts/UI.cs) | 4 | ||||
| -rw-r--r-- | scripts/GUI/Hud.cs.uid (renamed from scripts/UI.cs.uid) | 0 | ||||
| -rw-r--r-- | scripts/GUI/Message.cs | 32 | ||||
| -rw-r--r-- | scripts/GUI/Message.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/GUI/MessageLog.cs | 37 | ||||
| -rw-r--r-- | scripts/GUI/MessageLog.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/Game.cs | 8 | ||||
| -rw-r--r-- | scripts/Time/TurnManager.cs | 2 | ||||
| -rw-r--r-- | scripts/Utils/SignalBus.cs | 25 | ||||
| -rw-r--r-- | scripts/Utils/SignalBus.cs.uid | 1 | ||||
| -rw-r--r-- | scripts/actors/Actor.cs | 2 | ||||
| -rw-r--r-- | scripts/actors/actions/MeleeAction.cs | 2 |
12 files changed, 107 insertions, 8 deletions
diff --git a/scripts/UI.cs b/scripts/GUI/Hud.cs index 781c14a..5f49121 100644 --- a/scripts/UI.cs +++ b/scripts/GUI/Hud.cs @@ -1,13 +1,13 @@ using Godot; using System; -public partial class UI : Node +public partial class Hud : Node { private TextureProgressBar hpBar; public override void _Ready() { base._Ready(); - hpBar = GetNode<TextureProgressBar>("CanvasLayer/MainContainer/HPbar"); + hpBar = GetNode<TextureProgressBar>("InfoBar/Stats/MarginContainer/HBoxContainer/HPbar"); } public void OnHealthChanged(int hp, int maxHp) { diff --git a/scripts/UI.cs.uid b/scripts/GUI/Hud.cs.uid index 2ee1ac6..2ee1ac6 100644 --- a/scripts/UI.cs.uid +++ b/scripts/GUI/Hud.cs.uid diff --git a/scripts/GUI/Message.cs b/scripts/GUI/Message.cs new file mode 100644 index 0000000..b0472ee --- /dev/null +++ b/scripts/GUI/Message.cs @@ -0,0 +1,32 @@ +using Godot; + +public partial class Message : Label +{ + private static LabelSettings baseSettings = GD.Load<LabelSettings>("res://assets/definitions/message_label_settings.tres"); + private string plainText; + public string PlainText { get => plainText; } + private int count = 1; + public int Count { + get => count; + set { + count = value; + Text = FullText; + } + } + + public string FullText { + get { + if (count > 1) { + return $"{plainText} ({count})"; + } + return plainText; + } + } + + public Message(string text) { + plainText = text; + Text = text; + LabelSettings = (LabelSettings) baseSettings.Duplicate(); + AutowrapMode = TextServer.AutowrapMode.WordSmart; + } +} diff --git a/scripts/GUI/Message.cs.uid b/scripts/GUI/Message.cs.uid new file mode 100644 index 0000000..197535a --- /dev/null +++ b/scripts/GUI/Message.cs.uid @@ -0,0 +1 @@ +uid://bo71px6uye6be 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); + } +} diff --git a/scripts/GUI/MessageLog.cs.uid b/scripts/GUI/MessageLog.cs.uid new file mode 100644 index 0000000..2ef5aff --- /dev/null +++ b/scripts/GUI/MessageLog.cs.uid @@ -0,0 +1 @@ +uid://0al5sptrm0fn diff --git a/scripts/Game.cs b/scripts/Game.cs index 58a5957..3050e22 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -23,7 +23,7 @@ public partial class Game : Node { /// </summary> private TurnManager turnManager; - private UI ui; + private Hud hud; public override void _Ready() { base._Ready(); @@ -31,13 +31,13 @@ public partial class Game : Node { Map = GetNode<Map>("Map"); inputHandler = GetNode<InputHandler>("InputHandler"); - ui = GetNode<UI>("UI"); + hud = GetNode<Hud>("HUD"); // O jogador é criado pelo jogo. Player player = new Player(Vector2I.Zero, null, playerDefinition); Camera2D camera = GetNode<Camera2D>("Camera2D"); RemoveChild(camera); - player.HealthChanged += (int hp, int maxHp) => ui.OnHealthChanged(hp, maxHp); + player.HealthChanged += (int hp, int maxHp) => hud.OnHealthChanged(hp, maxHp); player.Died += () => inputHandler.SetInputHandler(InputHandlers.GameOver); player.AddChild(camera); @@ -47,6 +47,8 @@ public partial class Game : Node { Map.UpdateFOV(player.GridPosition); turnManager = new(Map); + + MessageLog.SendMessage("UMA FILA DE HOMENS EJACULANDO NA BOCA DA DALVA"); } /// <summary> diff --git a/scripts/Time/TurnManager.cs b/scripts/Time/TurnManager.cs index 0c2981c..af721ee 100644 --- a/scripts/Time/TurnManager.cs +++ b/scripts/Time/TurnManager.cs @@ -51,7 +51,7 @@ public partial class TurnManager : RefCounted } // Primeiro executamos a ação do jogador, se ele puder. - if (Player.Energy > 0) { + if (playerActionQueue.Count > 0 && Player.Energy > 0) { Action action = playerActionQueue[0]; playerActionQueue.RemoveAt(0); diff --git a/scripts/Utils/SignalBus.cs b/scripts/Utils/SignalBus.cs new file mode 100644 index 0000000..7408db2 --- /dev/null +++ b/scripts/Utils/SignalBus.cs @@ -0,0 +1,25 @@ +using Godot; +using System; + +/// <summary> +/// Objeto global com sinais, fortes sinais. +/// </summary> +public partial class SignalBus : Node +{ + /// <summary> + /// Pois é. + /// </summary> + public static SignalBus Instance { get; private set; } + + public override void _Ready() + { + 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/Utils/SignalBus.cs.uid b/scripts/Utils/SignalBus.cs.uid new file mode 100644 index 0000000..cc03c87 --- /dev/null +++ b/scripts/Utils/SignalBus.cs.uid @@ -0,0 +1 @@ +uid://dmn16je604itc diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs index 06cfd69..c03c8fa 100644 --- a/scripts/actors/Actor.cs +++ b/scripts/actors/Actor.cs @@ -236,7 +236,7 @@ public abstract partial class Actor : Sprite2D deathMessage = $"{ActorName} morreu!"; } - GD.Print(deathMessage); + MessageLog.SendMessage(deathMessage); Texture = definition.deathTexture; blocksMovement = false; diff --git a/scripts/actors/actions/MeleeAction.cs b/scripts/actors/actions/MeleeAction.cs index fe00422..e739159 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."; } - GD.Print(attackDesc); + MessageLog.SendMessage(attackDesc); } } |
