Fixed an issue where the inventory icon was not updated after the player threw an item.
修复玩家扔出物品后,物品栏没有更新图标的问题。
This commit is contained in:
parent
efff63ddd4
commit
617164a4bc
|
@ -766,7 +766,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
var actualQuantity = number < 0 ? item.Quantity : Math.Min(item.Quantity, number);
|
var actualQuantity = number < 0 ? item.Quantity : Math.Min(item.Quantity, number);
|
||||||
for (var i = 0; i < actualQuantity; i++)
|
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>Throw item</para>
|
||||||
/// <para>抛出物品</para>
|
/// <para>抛出物品</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="index"></param>
|
||||||
/// <param name="originalItem"></param>
|
/// <param name="originalItem"></param>
|
||||||
/// <param name="velocity">
|
/// <param name="velocity">
|
||||||
/// <para>The speed to be applied to the item</para>
|
/// <para>The speed to be applied to the item</para>
|
||||||
/// <para>要施加到物品上的速度</para>
|
/// <para>要施加到物品上的速度</para>
|
||||||
/// </param>
|
/// </param>
|
||||||
private void ThrowOneItem(IItem originalItem, Vector2 velocity)
|
private void ThrowOneItem(int index, IItem originalItem, Vector2 velocity)
|
||||||
{
|
{
|
||||||
//Remove the item from the item container
|
//Remove the item from the item container
|
||||||
//从物品容器内取出物品
|
//从物品容器内取出物品
|
||||||
|
@ -837,7 +838,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
originalItem.Quantity -= 1;
|
ProtectedItemContainer?.RemoveItem(index, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void UpdateTooltipText()
|
private void UpdateTooltipText()
|
||||||
{
|
{
|
||||||
if (Item == null)
|
if (Item is PlaceholderItem or null)
|
||||||
{
|
{
|
||||||
TooltipText = null;
|
TooltipText = null;
|
||||||
return;
|
return;
|
||||||
|
@ -149,6 +149,12 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Item is PlaceholderItem or null)
|
||||||
|
{
|
||||||
|
_quantityLabel.Hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (Item?.Quantity)
|
switch (Item?.Quantity)
|
||||||
{
|
{
|
||||||
case null or 1:
|
case null or 1:
|
||||||
|
@ -178,11 +184,8 @@ public partial class ItemSlotNode : MarginContainer, IItemDisplay
|
||||||
|
|
||||||
public void Update(IItem? item)
|
public void Update(IItem? item)
|
||||||
{
|
{
|
||||||
if (item is not PlaceholderItem)
|
Item = item;
|
||||||
{
|
UpdateAllDisplay();
|
||||||
Item = item;
|
|
||||||
UpdateAllDisplay();
|
|
||||||
}
|
|
||||||
UpdateBackground(item is { IsSelect: true });
|
UpdateBackground(item is { IsSelect: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,6 +230,12 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
||||||
item.Quantity = 0;
|
item.Quantity = 0;
|
||||||
_itemDictionary.Remove(itemIndex);
|
_itemDictionary.Remove(itemIndex);
|
||||||
UpdateNextAvailableIndex();
|
UpdateNextAvailableIndex();
|
||||||
|
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||||
|
{
|
||||||
|
NewItem = item,
|
||||||
|
NewIndex = itemIndex,
|
||||||
|
Type = Config.ItemDataChangeEventType.Remove
|
||||||
|
});
|
||||||
return originalQuantity;
|
return originalQuantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -239,6 +245,12 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
||||||
{
|
{
|
||||||
_itemDictionary.Remove(itemIndex);
|
_itemDictionary.Remove(itemIndex);
|
||||||
UpdateNextAvailableIndex();
|
UpdateNextAvailableIndex();
|
||||||
|
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||||
|
{
|
||||||
|
NewItem = item,
|
||||||
|
NewIndex = itemIndex,
|
||||||
|
Type = Config.ItemDataChangeEventType.Remove
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return removed;
|
return removed;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user