Moved Bar slot selection handling to inventory manager
This commit is contained in:
@@ -2,5 +2,6 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0B2502BD29F5EC4798EEFD2950AA7E06/Description/@EntryValue">Godot Signal</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0B2502BD29F5EC4798EEFD2950AA7E06/Text/@EntryValue">[Signal]
|
||||||
|
public delegate void $SignalName$EventHandler($END$);</s:String>
|
||||||
|
<s:String x:Key="/Default/PatternsAndTemplates/LiveTemplates/Template/=0B2502BD29F5EC4798EEFD2950AA7E06/Field/=SignalName/Expression/@EntryValue">suggestVariableName()</s:String></wpf:ResourceDictionary>
|
||||||
@@ -1,13 +1,27 @@
|
|||||||
#nullable enable
|
using System;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
|
|
||||||
public partial class InventoryManager : Node
|
public partial class InventoryManager : Node
|
||||||
{
|
{
|
||||||
public static InventoryManager Instance { get; private set; }
|
[Signal]
|
||||||
|
public delegate void SlotIndexChangedEventHandler(int newIndex);
|
||||||
|
|
||||||
|
public static InventoryManager Instance { get; private set; } = null!;
|
||||||
|
public int CurrentSelectedSlotIndex
|
||||||
|
{
|
||||||
|
get => _currentSelectedSlotIndex;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_currentSelectedSlotIndex = value;
|
||||||
|
EmitSignalSlotIndexChanged(_currentSelectedSlotIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public InventoryInstance playerInventory;
|
public InventoryInstance playerInventory = new InventoryInstance();
|
||||||
|
|
||||||
|
private int _currentSelectedSlotIndex = 0;
|
||||||
|
|
||||||
public override void _EnterTree()
|
public override void _EnterTree()
|
||||||
{
|
{
|
||||||
@@ -16,7 +30,6 @@ public partial class InventoryManager : Node
|
|||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
playerInventory = new InventoryInstance();
|
|
||||||
playerInventory.SlotAmount = 37;
|
playerInventory.SlotAmount = 37;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,4 +81,14 @@ public partial class InventoryManager : Node
|
|||||||
{
|
{
|
||||||
return playerInventory.AddItem(itemInstance);
|
return playerInventory.AddItem(itemInstance);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
public InventorySlot GetCurrentSelectedSlot()
|
||||||
|
{
|
||||||
|
if (CurrentSelectedSlotIndex < 0 || CurrentSelectedSlotIndex > 8)
|
||||||
|
throw new ArgumentOutOfRangeException(
|
||||||
|
nameof(CurrentSelectedSlotIndex),
|
||||||
|
"currentInventoryBarIndex must be between 0 and 8 (inclusively)");
|
||||||
|
|
||||||
|
return playerInventory.Slots[CurrentSelectedSlotIndex];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#nullable enable
|
|
||||||
using Godot;
|
using Godot;
|
||||||
|
|
||||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||||
@@ -12,8 +11,6 @@ public partial class InventoryUi : Control
|
|||||||
|
|
||||||
private int? _slotOnMouse;
|
private int? _slotOnMouse;
|
||||||
|
|
||||||
private int _selectedSlot = 0;
|
|
||||||
|
|
||||||
private bool _inventoryExtended = false;
|
private bool _inventoryExtended = false;
|
||||||
private Tween? _inventoryExtensionTween;
|
private Tween? _inventoryExtensionTween;
|
||||||
|
|
||||||
@@ -63,7 +60,7 @@ public partial class InventoryUi : Control
|
|||||||
|
|
||||||
private void SetSlotSelectPosition()
|
private void SetSlotSelectPosition()
|
||||||
{
|
{
|
||||||
_slotSelect.Position = new Vector2(_selectedSlot * 100, 0);
|
_slotSelect.Position = new Vector2(InventoryManager.Instance.CurrentSelectedSlotIndex * 100, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PopulateSlots()
|
private void PopulateSlots()
|
||||||
@@ -128,17 +125,17 @@ public partial class InventoryUi : Control
|
|||||||
|
|
||||||
if (Input.IsActionJustPressed("ui_inventory_disadvance"))
|
if (Input.IsActionJustPressed("ui_inventory_disadvance"))
|
||||||
{
|
{
|
||||||
_selectedSlot++;
|
InventoryManager.Instance.CurrentSelectedSlotIndex++;
|
||||||
if (_selectedSlot > 9)
|
if (InventoryManager.Instance.CurrentSelectedSlotIndex > 8)
|
||||||
_selectedSlot = 0;
|
InventoryManager.Instance.CurrentSelectedSlotIndex = 0;
|
||||||
SetSlotSelectPosition();
|
SetSlotSelectPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Input.IsActionJustPressed("ui_inventory_advance"))
|
if (Input.IsActionJustPressed("ui_inventory_advance"))
|
||||||
{
|
{
|
||||||
_selectedSlot--;
|
InventoryManager.Instance.CurrentSelectedSlotIndex--;
|
||||||
if (_selectedSlot < 0)
|
if (InventoryManager.Instance.CurrentSelectedSlotIndex < 0)
|
||||||
_selectedSlot = 9;
|
InventoryManager.Instance.CurrentSelectedSlotIndex = 8;
|
||||||
SetSlotSelectPosition();
|
SetSlotSelectPosition();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user