Added open close inventory

This commit is contained in:
cblech
2025-04-07 02:52:57 +02:00
parent c90687939c
commit 667ef6fb9b
5 changed files with 57 additions and 7 deletions
@@ -1,3 +1,4 @@
#nullable enable
using Godot;
namespace Babushka.scripts.CSharp.Common.Inventory;
@@ -9,6 +10,9 @@ public partial class InventoryUi : Control
private int? _slotOnMouse;
private bool _inventoryExtended = false;
private Tween? _inventoryExtensionTween;
public override void _Ready()
{
GD.Print("Ready inventory ui");
@@ -59,9 +63,12 @@ public partial class InventoryUi : Control
private void SlotClicked(int index)
{
if (!_inventoryExtended) return;
GD.Print($"Clicked slot {index}");
if (_slotOnMouse == null)
{
if (_playerInventory.Slots[index].IsEmpty()) return;
_slotOnMouse = index;
GD.Print($"Slot on mouse: {_slotOnMouse}");
}
@@ -74,4 +81,34 @@ public partial class InventoryUi : Control
SetSlotContent();
}
}
public override void _Process(double delta)
{
if (Input.IsActionJustPressed("ui_inventory_open_close"))
{
_inventoryExtensionTween?.Kill();
_inventoryExtended = !_inventoryExtended;
if (_inventoryExtended)
{
//GD.Print("Open inventory");
_inventoryExtensionTween = GetTree().CreateTween();
_inventoryExtensionTween
.TweenProperty(_slots, "offset_bottom", -100, 0.4)
.SetTrans(Tween.TransitionType.Quad)
.SetEase(Tween.EaseType.Out);
}
else
{
//GD.Print("Close inventory");
_inventoryExtensionTween = GetTree().CreateTween();
_inventoryExtensionTween
.TweenProperty(_slots, "offset_bottom", 200, 0.4)
.SetTrans(Tween.TransitionType.Quad)
.SetEase(Tween.EaseType.Out);
_slotOnMouse = null;
}
}
}
}