Added open close inventory
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user