summaryrefslogtreecommitdiff
path: root/scripts/InputHandling
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/InputHandling')
-rw-r--r--scripts/InputHandling/CastSpellInputHandler.cs93
-rw-r--r--scripts/InputHandling/CastSpellInputHandler.cs.uid1
-rw-r--r--scripts/InputHandling/InputHandler.cs12
3 files changed, 105 insertions, 1 deletions
diff --git a/scripts/InputHandling/CastSpellInputHandler.cs b/scripts/InputHandling/CastSpellInputHandler.cs
new file mode 100644
index 0000000..1c5d005
--- /dev/null
+++ b/scripts/InputHandling/CastSpellInputHandler.cs
@@ -0,0 +1,93 @@
+using Godot;
+using TheLegendOfGustav.Entities.Actors;
+using TheLegendOfGustav.Entities.Actions;
+using TheLegendOfGustav.Utils;
+
+using TheLegendOfGustav.InputHandling;
+using TheLegendOfGustav.Map;
+using TheLegendOfGustav.Magic;
+
+namespace TheLengendOfGustav.InputHandling;
+
+/// <summary>
+/// Esquema de controles para quando o jogador precisar escolher um alvo
+/// de feitiço.
+///
+/// É bem similar ao InspectorInputHandler.
+/// </summary>
+public partial class CastSpellInputHandler : BaseInputHandler
+{
+ private static readonly PackedScene inspectorScene = GD.Load<PackedScene>("res://scenes/Inspector.tscn");
+
+ private static readonly Godot.Collections.Dictionary<string, Vector2I> directions = new()
+ {
+ {"walk-up", Vector2I.Up},
+ {"walk-down", Vector2I.Down},
+ {"walk-left", Vector2I.Left},
+ {"walk-right", Vector2I.Right},
+ {"walk-up-right", Vector2I.Up + Vector2I.Right},
+ {"walk-up-left", Vector2I.Up + Vector2I.Left},
+ {"walk-down-right", Vector2I.Down + Vector2I.Right},
+ {"walk-down-left", Vector2I.Down + Vector2I.Left},
+ };
+
+ private Inspector inspector = null;
+ private SpellResource selectedSpell = null;
+ [Export]
+ private Map map;
+
+ public override void _Ready()
+ {
+ base._Ready();
+
+ // O jogador informa qual feitiço será usado.
+ SignalBus.Instance.PlayerSpellChooseLocation += (SpellResource spell) => selectedSpell = spell;
+ }
+
+ public override void Enter()
+ {
+ inspector = inspectorScene.Instantiate<Inspector>();
+
+ inspector.GridPosition = map.MapData.Player.GridPosition;
+
+ map.AddChild(inspector);
+ }
+
+ public override void Exit()
+ {
+ selectedSpell = null;
+ inspector.QueueFree();
+ }
+
+
+ public override Action GetAction(Player player)
+ {
+ Action action = null;
+
+ foreach (var direction in directions)
+ {
+ if (Input.IsActionJustPressed(direction.Key))
+ {
+ inspector.Walk(direction.Value);
+ }
+ }
+
+ if (selectedSpell != null && Input.IsActionJustPressed("ui_accept"))
+ {
+ action = new SpellAction(player, inspector.GridPosition - player.GridPosition, selectedSpell);
+
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.MainGame);
+ }
+
+ // Se o jogador cancelar a seleção,
+ // Mandamos um sinal avisando que o feitiço não foi executado com sucesso.
+ // Pergaminhos usam esta informação.
+ if (Input.IsActionJustPressed("quit"))
+ {
+ SignalBus.Instance.EmitSignal(SignalBus.SignalName.PlayerSpellCast, false);
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.MainGame);
+ }
+
+ return action;
+ }
+} \ No newline at end of file
diff --git a/scripts/InputHandling/CastSpellInputHandler.cs.uid b/scripts/InputHandling/CastSpellInputHandler.cs.uid
new file mode 100644
index 0000000..26ed706
--- /dev/null
+++ b/scripts/InputHandling/CastSpellInputHandler.cs.uid
@@ -0,0 +1 @@
+uid://ceck6d5tjpgwf
diff --git a/scripts/InputHandling/InputHandler.cs b/scripts/InputHandling/InputHandler.cs
index 55a17b4..a1e9b03 100644
--- a/scripts/InputHandling/InputHandler.cs
+++ b/scripts/InputHandling/InputHandler.cs
@@ -1,6 +1,8 @@
using Godot;
using TheLegendOfGustav.Entities.Actions;
using TheLegendOfGustav.Entities.Actors;
+using TheLegendOfGustav.Utils;
+using TheLengendOfGustav.InputHandling;
namespace TheLegendOfGustav.InputHandling;
@@ -10,7 +12,8 @@ public enum InputHandlers
GameOver,
Inspect,
Pickup,
- Inventory
+ Inventory,
+ CastSpell
}
/// <summary>
@@ -32,11 +35,18 @@ public partial class InputHandler : Node
InputHandlerDict.Add(InputHandlers.MainGame, GetNode<MainGameInputHandler>("MainGameInputHandler"));
// Controles para quando o jogador está morto.
InputHandlerDict.Add(InputHandlers.GameOver, GetNode<GameOverInputHandler>("GameOverInputHandler"));
+ // Controles para observar o cenário
InputHandlerDict.Add(InputHandlers.Inspect, GetNode<InspectInputHandler>("InspectInputHandler"));
+ // Controles para pegar um item do chão.
InputHandlerDict.Add(InputHandlers.Pickup, GetNode<PickupInputHandler>("PickupInputHandler"));
+ // Controles para quando o inventário for aberto.
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"));
SetInputHandler(StartingInputHandler);
+
+ SignalBus.Instance.CommandInputHandler += SetInputHandler;
}
public Action GetAction(Player player)