diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index ffc56af..826e57f 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -766,7 +766,7 @@ public partial class CharacterTemplate : CharacterBody2D var actualQuantity = number < 0 ? item.Quantity : Math.Min(item.Quantity, number); for (var i = 0; i < actualQuantity; i++) { - ThrowOneItem(item, velocity); + ThrowOneItem(index, item, velocity); } } @@ -774,12 +774,13 @@ public partial class CharacterTemplate : CharacterBody2D /// Throw item /// 抛出物品 /// + /// /// /// /// The speed to be applied to the item /// 要施加到物品上的速度 /// - private void ThrowOneItem(IItem originalItem, Vector2 velocity) + private void ThrowOneItem(int index, IItem originalItem, Vector2 velocity) { //Remove the item from the item container //从物品容器内取出物品 @@ -837,7 +838,7 @@ public partial class CharacterTemplate : CharacterBody2D break; } - originalItem.Quantity -= 1; + ProtectedItemContainer?.RemoveItem(index, 1); } diff --git a/scripts/inventory/ItemSlotNode.cs b/scripts/inventory/ItemSlotNode.cs index f1f3db9..34ce733 100644 --- a/scripts/inventory/ItemSlotNode.cs +++ b/scripts/inventory/ItemSlotNode.cs @@ -114,7 +114,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay /// private void UpdateTooltipText() { - if (Item == null) + if (Item is PlaceholderItem or null) { TooltipText = null; return; @@ -149,6 +149,12 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay return; } + if (Item is PlaceholderItem or null) + { + _quantityLabel.Hide(); + return; + } + switch (Item?.Quantity) { case null or 1: @@ -178,11 +184,8 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay public void Update(IItem? item) { - if (item is not PlaceholderItem) - { - Item = item; - UpdateAllDisplay(); - } + Item = item; + UpdateAllDisplay(); UpdateBackground(item is { IsSelect: true }); } diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs index 24e8969..5bbd4da 100644 --- a/scripts/inventory/UniversalItemContainer.cs +++ b/scripts/inventory/UniversalItemContainer.cs @@ -230,6 +230,12 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer item.Quantity = 0; _itemDictionary.Remove(itemIndex); UpdateNextAvailableIndex(); + ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent + { + NewItem = item, + NewIndex = itemIndex, + Type = Config.ItemDataChangeEventType.Remove + }); return originalQuantity; } @@ -239,6 +245,12 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer { _itemDictionary.Remove(itemIndex); UpdateNextAvailableIndex(); + ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent + { + NewItem = item, + NewIndex = itemIndex, + Type = Config.ItemDataChangeEventType.Remove + }); } return removed;