diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-14 10:41:08 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-14 10:41:08 -0300 |
| commit | 1e17a31e3eeed8ccf76982534002513cee6593f1 (patch) | |
| tree | 74d8e4fbf706b1008edcd699b0ba7af2d6bb34ea /scripts/InputHandling/SpellMenuInputHandler.cs | |
| parent | 5958d9c071915ab71aea5a5c08d79e88024f6c58 (diff) | |
Magicas
Diffstat (limited to 'scripts/InputHandling/SpellMenuInputHandler.cs')
| -rw-r--r-- | scripts/InputHandling/SpellMenuInputHandler.cs | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/scripts/InputHandling/SpellMenuInputHandler.cs b/scripts/InputHandling/SpellMenuInputHandler.cs new file mode 100644 index 0000000..ba9c128 --- /dev/null +++ b/scripts/InputHandling/SpellMenuInputHandler.cs @@ -0,0 +1,68 @@ +using Godot; +using TheLegendOfGustav.Entities.Actions; +using TheLegendOfGustav.Entities.Actors; +using TheLegendOfGustav.GUI; +using TheLegendOfGustav.Magic; +using TheLegendOfGustav.Utils; + +namespace TheLegendOfGustav.InputHandling; + +public partial class SpellMenuInputHandler : BaseInputHandler +{ + private static readonly PackedScene spellMenuScene = GD.Load<PackedScene>("res://scenes/GUI/spellbook_menu.tscn"); + + [Export] + private Map.Map map; + + private SpellBookMenu spellBookMenu; + private SpellResource spellCast = null; + + public override void Enter() + { + spellBookMenu = spellMenuScene.Instantiate<SpellBookMenu>(); + map.MapData.Player.AddChild(spellBookMenu); + spellBookMenu.Initialize(map.MapData.Player.SpellBook); + spellBookMenu.SpellSelected += OnSpellCast; + } + + public override void Exit() + { + spellCast = null; + spellBookMenu.QueueFree(); + } + + public override Action GetAction(Player player) + { + Action action = null; + + if (spellCast != null) + { + if (spellCast.Type == SpellType.Ranged) + { + SignalBus.Instance.EmitSignal(SignalBus.SignalName.PlayerSpellChooseLocation, spellCast); + GetParent<InputHandler>().SetInputHandler(InputHandlers.CastSpell); + return action; + } + action = new SpellAction(player, Vector2I.Zero, spellCast); + Close(); + return action; + } + + if (Input.IsActionJustPressed("quit")) + { + Close(); + } + + return action; + } + + private void Close() + { + GetParent<InputHandler>().SetInputHandler(InputHandlers.MainGame); + } + + private void OnSpellCast(SpellResource spell) + { + spellCast = spell; + } +}
\ No newline at end of file |
