item on ground and pickup
This commit is contained in:
@@ -60,4 +60,8 @@ public partial class InventoryManager : Node
|
||||
{
|
||||
return inventory.RemoveItem(inventorySlot);
|
||||
}
|
||||
public InventoryActionResult CollectItem(ItemInstance itemInstance)
|
||||
{
|
||||
return playerInventory.AddItem(itemInstance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ public partial class InventoryUi : Control
|
||||
PopulateSlots();
|
||||
SetSlotContent();
|
||||
SetSlotSelectPosition();
|
||||
InventoryManager.Instance.playerInventory.InventoryContentsChanged += SetSlotContent;
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
@@ -88,7 +89,7 @@ public partial class InventoryUi : Control
|
||||
var destinationSlot = index;
|
||||
InventoryManager.Instance.MoveItem(_playerInventory, sourceSlot, _playerInventory, destinationSlot);
|
||||
_slotOnMouse = null;
|
||||
SetSlotContent();
|
||||
//SetSlotContent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
using Godot;
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class ItemOnGround : Node3D
|
||||
{
|
||||
private ItemInstance _itemInstance;
|
||||
|
||||
public ItemInstance itemInstance
|
||||
{
|
||||
get => _itemInstance;
|
||||
set
|
||||
{
|
||||
_itemInstance = value;
|
||||
UpdateVisuals();
|
||||
}
|
||||
}
|
||||
|
||||
public void TryPickUp()
|
||||
{
|
||||
GD.Print("Trying to pick up item");
|
||||
|
||||
var result = InventoryManager.Instance.CollectItem(itemInstance);
|
||||
if (result == InventoryActionResult.Success)
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
else
|
||||
{
|
||||
GD.Print("Inventory is full");
|
||||
// TODO: player message
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateVisuals()
|
||||
{
|
||||
var label = GetNode<Label3D>("ItemLabel");
|
||||
if (itemInstance.blueprint != null)
|
||||
{
|
||||
label.Text = itemInstance.blueprint.name;
|
||||
}
|
||||
else
|
||||
{
|
||||
label.Text = "Error Item";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://udhigottc8rg
|
||||
@@ -0,0 +1,16 @@
|
||||
#nullable enable
|
||||
using Godot;
|
||||
namespace Babushka.scripts.CSharp.Common.Inventory;
|
||||
|
||||
public partial class ItemOnGroundSpawnWith : Node
|
||||
{
|
||||
[Export] private ItemResource? _blueprint = null;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
if(_blueprint == null) return;
|
||||
|
||||
var parent = GetParent<ItemOnGround>();
|
||||
parent.itemInstance = new ItemInstance { blueprint = _blueprint };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://c8suoi3i6kqai
|
||||
Reference in New Issue
Block a user