summaryrefslogtreecommitdiff
path: root/scripts/InputHandling
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/InputHandling
parent5958d9c071915ab71aea5a5c08d79e88024f6c58 (diff)
Magicas
Diffstat (limited to 'scripts/InputHandling')
-rw-r--r--scripts/InputHandling/InputHandler.cs5
-rw-r--r--scripts/InputHandling/MainGameInputHandler.cs5
-rw-r--r--scripts/InputHandling/SpellMenuInputHandler.cs68
-rw-r--r--scripts/InputHandling/SpellMenuInputHandler.cs.uid1
4 files changed, 78 insertions, 1 deletions
diff --git a/scripts/InputHandling/InputHandler.cs b/scripts/InputHandling/InputHandler.cs
index a1e9b03..ce265a1 100644
--- a/scripts/InputHandling/InputHandler.cs
+++ b/scripts/InputHandling/InputHandler.cs
@@ -13,7 +13,8 @@ public enum InputHandlers
Inspect,
Pickup,
Inventory,
- CastSpell
+ CastSpell,
+ SpellMenu
}
/// <summary>
@@ -43,6 +44,8 @@ public partial class InputHandler : Node
InputHandlerDict.Add(InputHandlers.Inventory, GetNode<InventoryInputHandler>("InventoryInputHandler"));
// Controles para quando o jogador precisar escolher um alvo de feitiço.
InputHandlerDict.Add(InputHandlers.CastSpell, GetNode<CastSpellInputHandler>("CastSpellInputHandler"));
+ // Controles para quando o menu de feitiços for aberto.
+ InputHandlerDict.Add(InputHandlers.SpellMenu, GetNode<SpellMenuInputHandler>("SpellMenuInputHandler"));
SetInputHandler(StartingInputHandler);
diff --git a/scripts/InputHandling/MainGameInputHandler.cs b/scripts/InputHandling/MainGameInputHandler.cs
index fe8e573..6a110d7 100644
--- a/scripts/InputHandling/MainGameInputHandler.cs
+++ b/scripts/InputHandling/MainGameInputHandler.cs
@@ -48,6 +48,11 @@ public partial class MainGameInputHandler : BaseInputHandler
GetParent<InputHandler>().SetInputHandler(InputHandlers.Inspect);
}
+ if (Input.IsActionJustPressed("open-spellbook"))
+ {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.SpellMenu);
+ }
+
if (Input.IsActionJustPressed("skip-turn"))
{
action = new WaitAction(player);
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
diff --git a/scripts/InputHandling/SpellMenuInputHandler.cs.uid b/scripts/InputHandling/SpellMenuInputHandler.cs.uid
new file mode 100644
index 0000000..443ac59
--- /dev/null
+++ b/scripts/InputHandling/SpellMenuInputHandler.cs.uid
@@ -0,0 +1 @@
+uid://bllj3j2wa4ebm