diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-09 19:09:34 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-09-09 19:09:34 -0300 |
| commit | c6bbb834f7758027c0df338f1520f34fad3befea (patch) | |
| tree | 1818cd23c24be16fbe19b16dd0a510874d440d83 /scripts/InputHandling/InventoryInputHandler.cs | |
| parent | f1b51bed52ffbd90b5b7cc8dcfc6f0484bbbeb3c (diff) | |
Organização
Diffstat (limited to 'scripts/InputHandling/InventoryInputHandler.cs')
| -rw-r--r-- | scripts/InputHandling/InventoryInputHandler.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/scripts/InputHandling/InventoryInputHandler.cs b/scripts/InputHandling/InventoryInputHandler.cs new file mode 100644 index 0000000..390e545 --- /dev/null +++ b/scripts/InputHandling/InventoryInputHandler.cs @@ -0,0 +1,75 @@ +using Godot; +using TheLegendOfGustav.GUI; +using TheLegendOfGustav.Entities.Actors; +using TheLegendOfGustav.Entities.Items; +using TheLegendOfGustav.Entities.Actions; + +namespace TheLegendOfGustav.InputHandling; + +public partial class InventoryInputHandler : BaseInputHandler +{ + private static readonly PackedScene inventoryScene = GD.Load<PackedScene>("res://scenes/GUI/invetory_menu.tscn"); + + + [Export] + private Map.Map Map { get; set; } + + private InventoryMenu InventoryMenu { get; set; } + private ConsumableItem ActivationItem { get; set; } = null; + private ConsumableItem DropItem { get; set; } = null; + + public override void Enter() + { + InventoryMenu = inventoryScene.Instantiate<InventoryMenu>(); + Map.MapData.Player.AddChild(InventoryMenu); + InventoryMenu.Initialize(Map.MapData.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 OnItemActivate(ConsumableItem item) + { + ActivationItem = item; + } + + private void OnItemDrop(ConsumableItem item) + { + DropItem = item; + } +}
\ No newline at end of file |
