|
|
|
|
@ -4,29 +4,22 @@ namespace Babushka.scripts.CSharp.Common.Inventory;
|
|
|
|
|
|
|
|
|
|
public partial class InventoryUi : Control
|
|
|
|
|
{
|
|
|
|
|
private Control _slots;
|
|
|
|
|
private Control _slotsMover;
|
|
|
|
|
private InventoryInstance _playerInventory;
|
|
|
|
|
private Control _slotSelect;
|
|
|
|
|
[Export] private Control _slotsParent;
|
|
|
|
|
[Export] private Control _slotsMover;
|
|
|
|
|
[Export] private Control[] _headerSlots;
|
|
|
|
|
[Export] private Control _slotSelect;
|
|
|
|
|
|
|
|
|
|
private InventoryInstance _playerInventory;
|
|
|
|
|
private int? _slotOnMouse;
|
|
|
|
|
|
|
|
|
|
private bool _inventoryExtended = false;
|
|
|
|
|
private Tween? _inventoryExtensionTween;
|
|
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
|
private float _inventoryClosedOffset = 0f;
|
|
|
|
|
|
|
|
|
|
[Export]
|
|
|
|
|
private float _inventoryOpenedOffset = 200f;
|
|
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
{
|
|
|
|
|
GD.Print("Ready inventory ui");
|
|
|
|
|
_slots = GetNode<Control>("SlotsContainer/SlotsMover/Slots");
|
|
|
|
|
_slotsMover = GetNode<Control>("SlotsContainer/SlotsMover");
|
|
|
|
|
_playerInventory = InventoryManager.Instance.playerInventory;
|
|
|
|
|
_slotSelect = GetNode<Control>("SlotsContainer/SlotSelectContainer/Selector");
|
|
|
|
|
//PopulateSlots();
|
|
|
|
|
SubscribeSlots();
|
|
|
|
|
SetSlotContent();
|
|
|
|
|
@ -44,7 +37,7 @@ public partial class InventoryUi : Control
|
|
|
|
|
for (var i = 0; i < _playerInventory.Slots.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var inventorySlot = _playerInventory.Slots[i];
|
|
|
|
|
var uiSlot = _slots.GetChild(i) as SlotUi;
|
|
|
|
|
var uiSlot = _slotsParent.GetChild(i) as SlotUi;
|
|
|
|
|
|
|
|
|
|
if (inventorySlot.itemInstance != null)
|
|
|
|
|
{
|
|
|
|
|
@ -82,7 +75,7 @@ public partial class InventoryUi : Control
|
|
|
|
|
|
|
|
|
|
private void SetSlotSelectPosition()
|
|
|
|
|
{
|
|
|
|
|
_slotSelect.Position = new Vector2(InventoryManager.Instance.CurrentSelectedSlotIndex * 100, 0);
|
|
|
|
|
_slotSelect.GlobalPosition = _headerSlots[InventoryManager.Instance.CurrentSelectedSlotIndex].GlobalPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PopulateSlots()
|
|
|
|
|
@ -93,7 +86,7 @@ public partial class InventoryUi : Control
|
|
|
|
|
var slotInstance = slotPackedScene.Instantiate<SlotUi>();
|
|
|
|
|
slotInstance.index = index;
|
|
|
|
|
slotInstance.Clicked += SlotClicked;
|
|
|
|
|
_slots.AddChild(slotInstance);
|
|
|
|
|
_slotsParent.AddChild(slotInstance);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -101,7 +94,7 @@ public partial class InventoryUi : Control
|
|
|
|
|
{
|
|
|
|
|
for (var index = 0; index < _playerInventory.Slots.Count; index++)
|
|
|
|
|
{
|
|
|
|
|
var slotInstance = _slots.GetChild<SlotUi>(index);
|
|
|
|
|
var slotInstance = _slotsParent.GetChild<SlotUi>(index);
|
|
|
|
|
slotInstance.index = index;
|
|
|
|
|
slotInstance.Clicked += SlotClicked;
|
|
|
|
|
}
|
|
|
|
|
@ -111,7 +104,7 @@ public partial class InventoryUi : Control
|
|
|
|
|
{
|
|
|
|
|
for (var index = 0; index < _playerInventory.Slots.Count; index++)
|
|
|
|
|
{
|
|
|
|
|
var slotInstance = _slots.GetChild(index) as SlotUi;
|
|
|
|
|
var slotInstance = _slotsParent.GetChild(index) as SlotUi;
|
|
|
|
|
slotInstance!.Clicked -= SlotClicked;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -141,6 +134,8 @@ public partial class InventoryUi : Control
|
|
|
|
|
{
|
|
|
|
|
if (Input.IsActionJustPressed("ui_inventory_open_close"))
|
|
|
|
|
{
|
|
|
|
|
// We adjust the offset value in accordance with the screen height to make sure that the inventory is always in the middle of the screen.
|
|
|
|
|
_inventoryOpenedOffset = (GetViewportRect().Size.Y / 2 + 400) * (-1);
|
|
|
|
|
InputInventoryOpenClose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|