summaryrefslogtreecommitdiff
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
parentd7d2454d5ccc1e0acb47cb679c7550e74c4e1916 (diff)
Logs
-rw-r--r--assets/definitions/message_label_settings.tres5
-rw-r--r--project.godot4
-rw-r--r--scenes/Game.tscn4
-rw-r--r--scenes/hud.tscn67
-rw-r--r--scenes/ui.tscn39
-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.cs32
-rw-r--r--scripts/GUI/Message.cs.uid1
-rw-r--r--scripts/GUI/MessageLog.cs37
-rw-r--r--scripts/GUI/MessageLog.cs.uid1
-rw-r--r--scripts/Game.cs8
-rw-r--r--scripts/Time/TurnManager.cs2
-rw-r--r--scripts/Utils/SignalBus.cs25
-rw-r--r--scripts/Utils/SignalBus.cs.uid1
-rw-r--r--scripts/actors/Actor.cs2
-rw-r--r--scripts/actors/actions/MeleeAction.cs2
17 files changed, 185 insertions, 49 deletions
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/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);
}
}