From 617164a4bccc46affd9fe8ad674e6b85d4399271 Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Fri, 27 Sep 2024 21:16:00 +0800 Subject: [PATCH] =?UTF-8?q?Fixed=20an=20issue=20where=20the=20inventory=20?= =?UTF-8?q?icon=20was=20not=20updated=20after=20the=20player=20threw=20an?= =?UTF-8?q?=20item.=20=E4=BF=AE=E5=A4=8D=E7=8E=A9=E5=AE=B6=E6=89=94?= =?UTF-8?q?=E5=87=BA=E7=89=A9=E5=93=81=E5=90=8E=EF=BC=8C=E7=89=A9=E5=93=81?= =?UTF-8?q?=E6=A0=8F=E6=B2=A1=E6=9C=89=E6=9B=B4=E6=96=B0=E5=9B=BE=E6=A0=87?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/character/CharacterTemplate.cs | 7 ++++--- scripts/inventory/ItemSlotNode.cs | 15 +++++++++------ scripts/inventory/UniversalItemContainer.cs | 12 ++++++++++++ 3 files changed, 25 insertions(+), 9 deletions(-) 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;