Make Inventory remove item from hotbar as well

Inventory.Remove(ItemMetadata) removes the item from both the inventory
and the hotbar
master
John Montagu, the 4th Earl of Sandvich 2024-10-12 17:01:07 -07:00
parent df82248670
commit a8e4aca91e
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
2 changed files with 26 additions and 0 deletions

View File

@ -239,6 +239,21 @@ public partial class Inventory : Node2D, IItemCollection<ItemMetadata>
public bool Remove(ItemMetadata item)
{
int indexInInventory = Items.IndexOf(item);
if (indexInInventory < 0)
{
return false;
}
// remove instances of item from hotbar
int indexInHotbar = HotbarToItemIndexMap.IndexOf(indexInInventory);
if (indexInHotbar >= 0)
{
HotbarToItemIndexMap[indexInHotbar] = -1;
Hotbar[indexInHotbar].QueueFree();
}
Items[indexInInventory] = null;
return Items.Remove(item);
}

View File

@ -65,4 +65,15 @@ public abstract partial class Item : Node2D
{
}
public virtual void Remove()
{
if (IsUsing)
{
Deuse();
}
Unequip(CharacterOwner);
QueueFree();
}
}