switching items with controller
parent
236e21c7c9
commit
24001c4ba1
|
@ -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)
|
||||
|
|
|
@ -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"))
|
||||
{
|
||||
|
|
|
@ -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]
|
||||
|
||||
|
|
Loading…
Reference in New Issue