diff --git a/Items/Inventory.cs b/Items/Inventory.cs index 56ef5aa..c8e9ef8 100644 --- a/Items/Inventory.cs +++ b/Items/Inventory.cs @@ -27,6 +27,20 @@ public partial class Inventory : Node2D set => EquipItem(value, ref _selectedItem); } + private int _quickSwitchIndex = -1; + + public const int QUICKSWITCH_SIZE = 3; + + public int CurrentQuickSwitchIndex + { + get => _quickSwitchIndex; + set + { + const int size = QUICKSWITCH_SIZE; + _quickSwitchIndex = (value % size + size) % size; + } + } + public bool IsUsingItem => SelectedItem?.IsUsing ?? false; public Inventory() @@ -57,6 +71,16 @@ public partial class Inventory : Node2D base._Ready(); } + public bool EquipIndex(int index) + { + if (index < Items.Count) + { + return EquipItem(Items[index], ref _selectedItem); + } + + return EquipItem(null, ref _selectedItem); + } + private bool EquipItem(Item item, ref Item slot) { if (item is not null) diff --git a/State/Character/PlayerState.cs b/State/Character/PlayerState.cs index 73adcc5..b780fa0 100644 --- a/State/Character/PlayerState.cs +++ b/State/Character/PlayerState.cs @@ -30,6 +30,14 @@ public abstract partial class PlayerState : CharacterState { inventory.SelectedItem = inventory.GetItemByMap("equip_3"); } + else if (@event.IsActionPressed("next_item")) + { + inventory.EquipIndex(++inventory.CurrentQuickSwitchIndex); + } + else if (@event.IsActionPressed("prev_item")) + { + inventory.EquipIndex(--inventory.CurrentQuickSwitchIndex); + } if (@event.IsActionPressed("interact")) { diff --git a/project.godot b/project.godot index 55cbffc..854203e 100644 --- a/project.godot +++ b/project.godot @@ -172,6 +172,16 @@ look_right={ "events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) ] } +next_item={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":5,"pressure":0.0,"pressed":false,"script":null) +] +} +prev_item={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":4,"pressure":0.0,"pressed":false,"script":null) +] +} [internationalization]