summaryrefslogtreecommitdiff
path: root/scripts/input
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/input')
-rw-r--r--scripts/input/InputHandler.cs4
-rw-r--r--scripts/input/InventoryInputHandler.cs65
-rw-r--r--scripts/input/InventoryInputHandler.cs.uid1
-rw-r--r--scripts/input/MainGameInputHandler.cs6
4 files changed, 74 insertions, 2 deletions
diff --git a/scripts/input/InputHandler.cs b/scripts/input/InputHandler.cs
index 7ee2be1..67f4abf 100644
--- a/scripts/input/InputHandler.cs
+++ b/scripts/input/InputHandler.cs
@@ -5,7 +5,8 @@ public enum InputHandlers
MainGame,
GameOver,
Inspect,
- Pickup
+ Pickup,
+ Inventory
}
/// <summary>
@@ -29,6 +30,7 @@ public partial class InputHandler : Node
inputHandlers.Add(InputHandlers.GameOver, GetNode<GameOverInputHandler>("GameOverInputHandler"));
inputHandlers.Add(InputHandlers.Inspect, GetNode<InspectInputHandler>("InspectInputHandler"));
inputHandlers.Add(InputHandlers.Pickup, GetNode<PickupInputHandler>("PickupInputHandler"));
+ inputHandlers.Add(InputHandlers.Inventory, GetNode<InventoryInputHandler>("InventoryInputHandler"));
SetInputHandler(startingInputHandler);
}
diff --git a/scripts/input/InventoryInputHandler.cs b/scripts/input/InventoryInputHandler.cs
new file mode 100644
index 0000000..98f8576
--- /dev/null
+++ b/scripts/input/InventoryInputHandler.cs
@@ -0,0 +1,65 @@
+using Godot;
+
+public partial class InventoryInputHandler : BaseInputHandler
+{
+ private static readonly PackedScene inventoryScene = GD.Load<PackedScene>("res://scenes/GUI/invetory_menu.tscn");
+
+ private InventoryMenu inventoryMenu;
+
+ ConsumableItem activationItem = null;
+ ConsumableItem dropItem = null;
+
+ [Export]
+ private Map map;
+
+ public override void Enter() {
+ inventoryMenu = inventoryScene.Instantiate<InventoryMenu>();
+ map.Map_Data.Player.AddChild(inventoryMenu);
+ inventoryMenu.Initialize(map.Map_Data.Player.inventory);
+ inventoryMenu.ItemSelected += OnItemActivate;
+ inventoryMenu.ItemDrop += OnItemDrop;
+ }
+
+ public override void Exit() {
+ activationItem = null;
+ dropItem = null;
+ inventoryMenu.QueueFree();
+ }
+
+ public override Action GetAction(Player player)
+ {
+ Action action = null;
+
+ if (activationItem != null) {
+ action = new ItemAction(player, activationItem);
+ Close();
+ }
+
+ if (dropItem != null) {
+ action = new DropAction(player, dropItem);
+ Close();
+ }
+
+ if (Input.IsActionJustPressed("quit")) {
+ Close();
+ }
+
+ return action;
+ }
+
+ private void Close() {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.MainGame);
+ }
+
+ private void ActivateItem() {
+
+ }
+
+ private void OnItemActivate(ConsumableItem item) {
+ activationItem = item;
+ }
+
+ private void OnItemDrop(ConsumableItem item) {
+ dropItem = item;
+ }
+} \ No newline at end of file
diff --git a/scripts/input/InventoryInputHandler.cs.uid b/scripts/input/InventoryInputHandler.cs.uid
new file mode 100644
index 0000000..b5d0ed9
--- /dev/null
+++ b/scripts/input/InventoryInputHandler.cs.uid
@@ -0,0 +1 @@
+uid://bjcjktvyrdh10
diff --git a/scripts/input/MainGameInputHandler.cs b/scripts/input/MainGameInputHandler.cs
index 6fb6aac..6bda004 100644
--- a/scripts/input/MainGameInputHandler.cs
+++ b/scripts/input/MainGameInputHandler.cs
@@ -4,7 +4,7 @@ using Godot;
/// Esquema de controles principal do jogo.
/// </summary>
public partial class MainGameInputHandler : BaseInputHandler {
- private readonly Godot.Collections.Dictionary<string, Vector2I> directions = new()
+ private static readonly Godot.Collections.Dictionary<string, Vector2I> directions = new()
{
{"walk-up", Vector2I.Up},
{"walk-down", Vector2I.Down},
@@ -25,6 +25,10 @@ public partial class MainGameInputHandler : BaseInputHandler {
}
}
+ if (Input.IsActionJustPressed("open-inventory")) {
+ GetParent<InputHandler>().SetInputHandler(InputHandlers.Inventory);
+ }
+
if (Input.IsActionJustPressed("pick-item")) {
GetParent<InputHandler>().SetInputHandler(InputHandlers.Pickup);
}