summaryrefslogtreecommitdiff
path: root/scripts/GUI
diff options
context:
space:
mode:
authorMatheus <matheus.guedes.mg.m@gmail.com>2025-09-14 10:41:08 -0300
committerMatheus <matheus.guedes.mg.m@gmail.com>2025-09-14 10:41:08 -0300
commit1e17a31e3eeed8ccf76982534002513cee6593f1 (patch)
tree74d8e4fbf706b1008edcd699b0ba7af2d6bb34ea /scripts/GUI
parent5958d9c071915ab71aea5a5c08d79e88024f6c58 (diff)
Magicas
Diffstat (limited to 'scripts/GUI')
-rw-r--r--scripts/GUI/Hud.cs17
-rw-r--r--scripts/GUI/SpellBookMenu.cs55
-rw-r--r--scripts/GUI/SpellBookMenu.cs.uid1
-rw-r--r--scripts/GUI/SpellMenuEntry.cs43
-rw-r--r--scripts/GUI/SpellMenuEntry.cs.uid1
5 files changed, 113 insertions, 4 deletions
diff --git a/scripts/GUI/Hud.cs b/scripts/GUI/Hud.cs
index 1149728..227ca32 100644
--- a/scripts/GUI/Hud.cs
+++ b/scripts/GUI/Hud.cs
@@ -1,20 +1,29 @@
+using System.Runtime.InteropServices;
using Godot;
namespace TheLegendOfGustav.GUI;
public partial class Hud : Node
{
- private TextureProgressBar HpBar { get; set; }
+ private TextureProgressBar hpBar;
+ private TextureProgressBar mpBar;
public override void _Ready()
{
base._Ready();
- HpBar = GetNode<TextureProgressBar>("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer/HPbar");
+ hpBar = GetNode<TextureProgressBar>("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer/HPbar");
+ mpBar = GetNode<TextureProgressBar>("VBoxContainer/InfoBar/Stats/MarginContainer/HBoxContainer/AspectRatioContainer2/MPbar");
}
public void OnHealthChanged(int hp, int maxHp)
{
- HpBar.Value = hp;
- HpBar.MaxValue = maxHp;
+ hpBar.Value = hp;
+ hpBar.MaxValue = maxHp;
+ }
+
+ public void OnManaChanged(int mp, int maxMp)
+ {
+ mpBar.Value = mp;
+ mpBar.MaxValue = maxMp;
}
}
diff --git a/scripts/GUI/SpellBookMenu.cs b/scripts/GUI/SpellBookMenu.cs
new file mode 100644
index 0000000..ecd89a3
--- /dev/null
+++ b/scripts/GUI/SpellBookMenu.cs
@@ -0,0 +1,55 @@
+using Godot;
+using System;
+using TheLegendOfGustav.Magic;
+
+namespace TheLegendOfGustav.GUI;
+
+public partial class SpellBookMenu : CanvasLayer
+{
+ private static readonly PackedScene spellMenuEntryScene = GD.Load<PackedScene>("res://scenes/GUI/spell_menu_entry.tscn");
+
+ private VBoxContainer spellsNode;
+
+ [Signal]
+ public delegate void SpellSelectedEventHandler(SpellResource spell);
+
+ public override void _Ready()
+ {
+ base._Ready();
+
+ spellsNode = GetNode<VBoxContainer>("CenterContainer/PanelContainer/VBoxContainer/Spells");
+ Hide();
+ }
+
+ public void OnCast(SpellResource spell)
+ {
+ EmitSignal(SignalName.SpellSelected, spell);
+ }
+
+ public void Initialize(SpellBook spellBook)
+ {
+ for (int i = 0; i < spellBook.KnownSpells.Count; i++)
+ {
+ RegisterSpell(i, spellBook.KnownSpells[i]);
+ }
+
+ Show();
+ }
+
+ private void RegisterSpell(int index, SpellResource spell)
+ {
+ char? shortcut = null;
+
+ // Só terá atalho para as letras do alfabeto.
+ if (index < 26)
+ {
+ shortcut = (char)('a' + index);
+ }
+
+ SpellMenuEntry spellEntry = spellMenuEntryScene.Instantiate<SpellMenuEntry>();
+
+ spellsNode.AddChild(spellEntry);
+ spellEntry.Initialize(spell, shortcut);
+ spellEntry.Cast += OnCast;
+ }
+}
diff --git a/scripts/GUI/SpellBookMenu.cs.uid b/scripts/GUI/SpellBookMenu.cs.uid
new file mode 100644
index 0000000..d4100bc
--- /dev/null
+++ b/scripts/GUI/SpellBookMenu.cs.uid
@@ -0,0 +1 @@
+uid://7y0q058tvq7y
diff --git a/scripts/GUI/SpellMenuEntry.cs b/scripts/GUI/SpellMenuEntry.cs
new file mode 100644
index 0000000..2be0fcc
--- /dev/null
+++ b/scripts/GUI/SpellMenuEntry.cs
@@ -0,0 +1,43 @@
+using Godot;
+using System;
+using TheLegendOfGustav.Magic;
+
+namespace TheLegendOfGustav.GUI;
+
+public partial class SpellMenuEntry : HBoxContainer
+{
+ private TextureRect icon;
+ private Label shortcutLabel;
+ private Label nameLabel;
+ private Button castBtn;
+ private SpellResource spell;
+
+ [Signal]
+ public delegate void CastEventHandler(SpellResource Item);
+
+ public override void _Ready()
+ {
+ base._Ready();
+ icon = GetNode<TextureRect>("Icon");
+ shortcutLabel = GetNode<Label>("Shortcut");
+ nameLabel = GetNode<Label>("SpellName");
+ castBtn = GetNode<Button>("CastButton");
+
+ castBtn.Pressed += () => EmitSignal(SignalName.Cast, spell);
+ }
+
+ public void Initialize(SpellResource spell, char? shortcut)
+ {
+ this.spell = spell;
+ nameLabel.Text = spell.SpellName;
+ if (shortcut != null)
+ {
+ shortcutLabel.Text = $"{shortcut}";
+ }
+ else
+ {
+ shortcutLabel.Text = "";
+ }
+ icon.Texture = spell.Icon;
+ }
+}
diff --git a/scripts/GUI/SpellMenuEntry.cs.uid b/scripts/GUI/SpellMenuEntry.cs.uid
new file mode 100644
index 0000000..eb17e04
--- /dev/null
+++ b/scripts/GUI/SpellMenuEntry.cs.uid
@@ -0,0 +1 @@
+uid://bg766ly1f747t