From 1e17a31e3eeed8ccf76982534002513cee6593f1 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 14 Sep 2025 10:41:08 -0300 Subject: Magicas --- scripts/GUI/SpellBookMenu.cs | 55 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 scripts/GUI/SpellBookMenu.cs (limited to 'scripts/GUI/SpellBookMenu.cs') 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("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("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(); + + spellsNode.AddChild(spellEntry); + spellEntry.Initialize(spell, shortcut); + spellEntry.Cast += OnCast; + } +} -- cgit v1.2.3