From 0456e7cd82b232a38fd9b6e008be7d49b2f9e90f Mon Sep 17 00:00:00 2001 From: Matheus Date: Mon, 1 Sep 2025 17:50:25 -0300 Subject: Logs --- assets/definitions/message_label_settings.tres | 5 ++ project.godot | 4 ++ scenes/Game.tscn | 4 +- scenes/hud.tscn | 67 ++++++++++++++++++++++++++ scenes/ui.tscn | 39 --------------- scripts/GUI/Hud.cs | 17 +++++++ scripts/GUI/Hud.cs.uid | 1 + scripts/GUI/Message.cs | 32 ++++++++++++ scripts/GUI/Message.cs.uid | 1 + scripts/GUI/MessageLog.cs | 37 ++++++++++++++ scripts/GUI/MessageLog.cs.uid | 1 + scripts/Game.cs | 8 +-- scripts/Time/TurnManager.cs | 2 +- scripts/UI.cs | 17 ------- scripts/UI.cs.uid | 1 - scripts/Utils/SignalBus.cs | 25 ++++++++++ scripts/Utils/SignalBus.cs.uid | 1 + scripts/actors/Actor.cs | 2 +- scripts/actors/actions/MeleeAction.cs | 2 +- 19 files changed, 201 insertions(+), 65 deletions(-) create mode 100644 assets/definitions/message_label_settings.tres create mode 100644 scenes/hud.tscn delete mode 100644 scenes/ui.tscn create mode 100644 scripts/GUI/Hud.cs create mode 100644 scripts/GUI/Hud.cs.uid create mode 100644 scripts/GUI/Message.cs create mode 100644 scripts/GUI/Message.cs.uid create mode 100644 scripts/GUI/MessageLog.cs create mode 100644 scripts/GUI/MessageLog.cs.uid delete mode 100644 scripts/UI.cs delete mode 100644 scripts/UI.cs.uid create mode 100644 scripts/Utils/SignalBus.cs create mode 100644 scripts/Utils/SignalBus.cs.uid diff --git a/assets/definitions/message_label_settings.tres b/assets/definitions/message_label_settings.tres new file mode 100644 index 0000000..60cef37 --- /dev/null +++ b/assets/definitions/message_label_settings.tres @@ -0,0 +1,5 @@ +[gd_resource type="LabelSettings" format=3 uid="uid://rc5sqsn7w8we"] + +[resource] +line_spacing = 0.0 +font_size = 5 diff --git a/project.godot b/project.godot index ad05970..268b87d 100644 --- a/project.godot +++ b/project.godot @@ -16,6 +16,10 @@ run/main_scene="uid://u5h6iqyi8wd0" config/features=PackedStringArray("4.4", "C#", "Forward Plus") config/icon="res://icon.svg" +[autoload] + +signalBus="*res://scripts/Utils/SignalBus.cs" + [display] window/size/viewport_width=320 diff --git a/scenes/Game.tscn b/scenes/Game.tscn index ef60cc2..a409a23 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -7,7 +7,7 @@ [ext_resource type="Script" uid="uid://dwyr067lwqcsj" path="res://scripts/map/DungeonGenerator.cs" id="4_78awf"] [ext_resource type="Script" uid="uid://ogqlb3purl6n" path="res://scripts/input/GameOverInputHandler.cs" id="4_g4kob"] [ext_resource type="Script" uid="uid://bereyrj1s46y5" path="res://scripts/map/FieldOfView.cs" id="5_s0nni"] -[ext_resource type="PackedScene" uid="uid://b4h4xyr1g8o50" path="res://scenes/ui.tscn" id="6_aug50"] +[ext_resource type="PackedScene" uid="uid://b4h4xyr1g8o50" path="res://scenes/hud.tscn" id="6_aug50"] [node name="Game" type="Node"] script = ExtResource("1_cpr0p") @@ -41,4 +41,4 @@ script = ExtResource("5_s0nni") offset = Vector2(8, 8) zoom = Vector2(0.5, 0.5) -[node name="UI" parent="." instance=ExtResource("6_aug50")] +[node name="HUD" parent="." instance=ExtResource("6_aug50")] diff --git a/scenes/hud.tscn b/scenes/hud.tscn new file mode 100644 index 0000000..4554c06 --- /dev/null +++ b/scenes/hud.tscn @@ -0,0 +1,67 @@ +[gd_scene load_steps=9 format=3 uid="uid://b4h4xyr1g8o50"] + +[ext_resource type="Script" uid="uid://br7w3abe0boqb" path="res://scripts/GUI/Hud.cs" id="1_gdt2y"] +[ext_resource type="Texture2D" uid="uid://cbqd3s1065am6" path="res://assets/sprites/inter-face/HP/HealthBarUnder2.png" id="2_p7vwb"] +[ext_resource type="Texture2D" uid="uid://c1cktg2arnphx" path="res://assets/sprites/inter-face/HP/HealthBarOverlay2.png" id="3_ktti3"] +[ext_resource type="Texture2D" uid="uid://sgqb6ccdbt4h" path="res://assets/sprites/inter-face/MP/ManaBarUnder2.png" id="4_8dubc"] +[ext_resource type="Texture2D" uid="uid://do06pptudsqdp" path="res://assets/sprites/inter-face/HP/HealthBar2.png" id="4_cgfq5"] +[ext_resource type="Texture2D" uid="uid://b2msd7khjxtat" path="res://assets/sprites/inter-face/MP/ManaBarOverlay.png" id="5_p7vwb"] +[ext_resource type="Texture2D" uid="uid://b1rotmrfynpau" path="res://assets/sprites/inter-face/MP/ManaBar.png" id="6_ktti3"] +[ext_resource type="Script" uid="uid://0al5sptrm0fn" path="res://scripts/GUI/MessageLog.cs" id="8_hd3ao"] + +[node name="HUD" type="CanvasLayer"] +script = ExtResource("1_gdt2y") + +[node name="InfoBar" type="HBoxContainer" parent="."] +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -10.0 +grow_horizontal = 2 +grow_vertical = 0 +size_flags_horizontal = 0 +size_flags_vertical = 0 +theme_override_constants/separation = 0 + +[node name="Stats" type="PanelContainer" parent="InfoBar"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="MarginContainer" type="MarginContainer" parent="InfoBar/Stats"] +layout_mode = 2 +theme_override_constants/margin_left = 5 +theme_override_constants/margin_top = 5 +theme_override_constants/margin_right = 5 +theme_override_constants/margin_bottom = 5 + +[node name="HBoxContainer" type="HBoxContainer" parent="InfoBar/Stats/MarginContainer"] +layout_mode = 2 + +[node name="HPbar" type="TextureProgressBar" parent="InfoBar/Stats/MarginContainer/HBoxContainer"] +layout_mode = 2 +value = 100.0 +texture_under = ExtResource("2_p7vwb") +texture_over = ExtResource("3_ktti3") +texture_progress = ExtResource("4_cgfq5") + +[node name="MPbar" type="TextureProgressBar" parent="InfoBar/Stats/MarginContainer/HBoxContainer"] +layout_mode = 2 +value = 100.0 +texture_under = ExtResource("4_8dubc") +texture_over = ExtResource("5_p7vwb") +texture_progress = ExtResource("6_ktti3") + +[node name="MessagelogContainer" type="PanelContainer" parent="InfoBar"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_stretch_ratio = 2.0 + +[node name="MessageLog" type="ScrollContainer" parent="InfoBar/MessagelogContainer"] +layout_mode = 2 +script = ExtResource("8_hd3ao") + +[node name="MessageList" type="VBoxContainer" parent="InfoBar/MessagelogContainer/MessageLog"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_constants/separation = 0 diff --git a/scenes/ui.tscn b/scenes/ui.tscn deleted file mode 100644 index 113e6ff..0000000 --- a/scenes/ui.tscn +++ /dev/null @@ -1,39 +0,0 @@ -[gd_scene load_steps=8 format=3 uid="uid://b4h4xyr1g8o50"] - -[ext_resource type="Script" uid="uid://br7w3abe0boqb" path="res://scripts/UI.cs" id="1_gdt2y"] -[ext_resource type="Texture2D" uid="uid://cbqd3s1065am6" path="res://assets/sprites/inter-face/HP/HealthBarUnder2.png" id="2_p7vwb"] -[ext_resource type="Texture2D" uid="uid://c1cktg2arnphx" path="res://assets/sprites/inter-face/HP/HealthBarOverlay2.png" id="3_ktti3"] -[ext_resource type="Texture2D" uid="uid://sgqb6ccdbt4h" path="res://assets/sprites/inter-face/MP/ManaBarUnder2.png" id="4_8dubc"] -[ext_resource type="Texture2D" uid="uid://do06pptudsqdp" path="res://assets/sprites/inter-face/HP/HealthBar2.png" id="4_cgfq5"] -[ext_resource type="Texture2D" uid="uid://b2msd7khjxtat" path="res://assets/sprites/inter-face/MP/ManaBarOverlay.png" id="5_p7vwb"] -[ext_resource type="Texture2D" uid="uid://b1rotmrfynpau" path="res://assets/sprites/inter-face/MP/ManaBar.png" id="6_ktti3"] - -[node name="UI" type="Node"] -script = ExtResource("1_gdt2y") - -[node name="CanvasLayer" type="CanvasLayer" parent="."] - -[node name="MainContainer" type="HBoxContainer" parent="CanvasLayer"] -anchors_preset = 12 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_top = -10.0 -grow_horizontal = 2 -grow_vertical = 0 -size_flags_horizontal = 0 -size_flags_vertical = 0 - -[node name="HPbar" type="TextureProgressBar" parent="CanvasLayer/MainContainer"] -layout_mode = 2 -value = 100.0 -texture_under = ExtResource("2_p7vwb") -texture_over = ExtResource("3_ktti3") -texture_progress = ExtResource("4_cgfq5") - -[node name="MPbar" type="TextureProgressBar" parent="CanvasLayer/MainContainer"] -layout_mode = 2 -value = 100.0 -texture_under = ExtResource("4_8dubc") -texture_over = ExtResource("5_p7vwb") -texture_progress = ExtResource("6_ktti3") diff --git a/scripts/GUI/Hud.cs b/scripts/GUI/Hud.cs new file mode 100644 index 0000000..5f49121 --- /dev/null +++ b/scripts/GUI/Hud.cs @@ -0,0 +1,17 @@ +using Godot; +using System; + +public partial class Hud : Node +{ + private TextureProgressBar hpBar; + + public override void _Ready() { + base._Ready(); + hpBar = GetNode("InfoBar/Stats/MarginContainer/HBoxContainer/HPbar"); + } + + public void OnHealthChanged(int hp, int maxHp) { + hpBar.Value = hp; + hpBar.MaxValue = maxHp; + } +} diff --git a/scripts/GUI/Hud.cs.uid b/scripts/GUI/Hud.cs.uid new file mode 100644 index 0000000..2ee1ac6 --- /dev/null +++ b/scripts/GUI/Hud.cs.uid @@ -0,0 +1 @@ +uid://br7w3abe0boqb 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("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("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); + } + + /// + /// Método estático disponível em todo o escopo do jogo. + /// + /// + 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 { /// 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"); inputHandler = GetNode("InputHandler"); - ui = GetNode("UI"); + hud = GetNode("HUD"); // O jogador é criado pelo jogo. Player player = new Player(Vector2I.Zero, null, playerDefinition); Camera2D camera = GetNode("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"); } /// 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/UI.cs b/scripts/UI.cs deleted file mode 100644 index 781c14a..0000000 --- a/scripts/UI.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Godot; -using System; - -public partial class UI : Node -{ - private TextureProgressBar hpBar; - - public override void _Ready() { - base._Ready(); - hpBar = GetNode("CanvasLayer/MainContainer/HPbar"); - } - - public void OnHealthChanged(int hp, int maxHp) { - hpBar.Value = hp; - hpBar.MaxValue = maxHp; - } -} diff --git a/scripts/UI.cs.uid b/scripts/UI.cs.uid deleted file mode 100644 index 2ee1ac6..0000000 --- a/scripts/UI.cs.uid +++ /dev/null @@ -1 +0,0 @@ -uid://br7w3abe0boqb 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; + +/// +/// Objeto global com sinais, fortes sinais. +/// +public partial class SignalBus : Node +{ + /// + /// Pois é. + /// + public static SignalBus Instance { get; private set; } + + public override void _Ready() + { + base._Ready(); + Instance = this; + } + /// + /// Acionado sempre que uma mensagem for adicionada para o log. + /// + /// Mensagem. + [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); } } -- cgit v1.2.3