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/GUI | |
| parent | d7d2454d5ccc1e0acb47cb679c7550e74c4e1916 (diff) | |
Logs
Diffstat (limited to 'scripts/GUI')
| -rw-r--r-- | scripts/GUI/Hud.cs | 17 | ||||
| -rw-r--r-- | scripts/GUI/Hud.cs.uid | 1 | ||||
| -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 |
6 files changed, 89 insertions, 0 deletions
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<TextureProgressBar>("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<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 |
