Fixed an issue where the inventory icon was not updated after the player threw an item.

修复玩家扔出物品后,物品栏没有更新图标的问题。
This commit is contained in:
Cold-Mint 2024-09-27 21:16:00 +08:00
parent efff63ddd4
commit 617164a4bc
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
3 changed files with 25 additions and 9 deletions

View File

@ -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
/// <para>Throw item</para>
/// <para>抛出物品</para>
/// </summary>
/// <param name="index"></param>
/// <param name="originalItem"></param>
/// <param name="velocity">
/// <para>The speed to be applied to the item</para>
/// <para>要施加到物品上的速度</para>
/// </param>
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);
}

View File

@ -114,7 +114,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
/// </summary>
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 });
}

View File

@ -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;