summaryrefslogtreecommitdiff
path: root/scripts/InputHandling/SpellMenuInputHandler.cs
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/InputHandling/SpellMenuInputHandler.cs')
-rw-r--r--scripts/InputHandling/SpellMenuInputHandler.cs68
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