From 1e17a31e3eeed8ccf76982534002513cee6593f1 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 14 Sep 2025 10:41:08 -0300 Subject: Magicas --- scripts/InputHandling/InputHandler.cs | 5 +- scripts/InputHandling/MainGameInputHandler.cs | 5 ++ scripts/InputHandling/SpellMenuInputHandler.cs | 68 ++++++++++++++++++++++ scripts/InputHandling/SpellMenuInputHandler.cs.uid | 1 + 4 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 scripts/InputHandling/SpellMenuInputHandler.cs create mode 100644 scripts/InputHandling/SpellMenuInputHandler.cs.uid (limited to 'scripts/InputHandling') 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 } /// @@ -43,6 +44,8 @@ public partial class InputHandler : Node InputHandlerDict.Add(InputHandlers.Inventory, GetNode("InventoryInputHandler")); // Controles para quando o jogador precisar escolher um alvo de feitiço. InputHandlerDict.Add(InputHandlers.CastSpell, GetNode("CastSpellInputHandler")); + // Controles para quando o menu de feitiços for aberto. + InputHandlerDict.Add(InputHandlers.SpellMenu, GetNode("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().SetInputHandler(InputHandlers.Inspect); } + if (Input.IsActionJustPressed("open-spellbook")) + { + GetParent().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("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(); + 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().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().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 -- cgit v1.2.3