summaryrefslogtreecommitdiff
path: root/scripts/input/InventoryInputHandler.cs
blob: 98f8576092754e1fd063f74cffec2dd1dd38a2e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
	}
}