Fixed When switching items, players would have multiple items stacked on their hands.
修复切换物品时,玩家手上会叠加多个物品。
This commit is contained in:
parent
c1c3fce58a
commit
bfec07a0de
|
@ -839,6 +839,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
|||
}
|
||||
|
||||
ProtectedItemContainer?.RemoveItem(index, 1);
|
||||
originalItem.QueueFreeSelf();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,6 +14,24 @@ public interface IItem
|
|||
/// <para>当前物品的ID</para>
|
||||
/// </summary>
|
||||
string Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>ShowSelf</para>
|
||||
/// <para>显示自身</para>
|
||||
/// </summary>
|
||||
void ShowSelf();
|
||||
|
||||
/// <summary>
|
||||
/// <para>QueueFreeSelf</para>
|
||||
/// <para>销毁自身</para>
|
||||
/// </summary>
|
||||
void QueueFreeSelf();
|
||||
|
||||
/// <summary>
|
||||
/// <para>HideSelf</para>
|
||||
/// <para>隐藏自身</para>
|
||||
/// </summary>
|
||||
void HideSelf();
|
||||
|
||||
/// <summary>
|
||||
/// <para>Icon of current item</para>
|
||||
|
|
|
@ -10,6 +10,22 @@ public class PlaceholderItem : IItem
|
|||
{
|
||||
public int Index { get; set; }
|
||||
public string Id { get; set; }
|
||||
|
||||
public void ShowSelf()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void QueueFreeSelf()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void HideSelf()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Texture2D Icon { get; }
|
||||
public string Name { get; }
|
||||
public string? Description { get; } = null;
|
||||
|
|
|
@ -118,6 +118,10 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
_itemDictionary[nextAvailableIndex] = item;
|
||||
item.Index = nextAvailableIndex;
|
||||
item.ItemContainer = this;
|
||||
if (nextAvailableIndex != _selectIndex)
|
||||
{
|
||||
item.HideSelf();
|
||||
}
|
||||
UpdateNextAvailableIndex();
|
||||
UpdateSelectStatus(nextAvailableIndex, item);
|
||||
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||
|
@ -154,6 +158,7 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
{
|
||||
//New items are fully shared.
|
||||
//新物品完全被均摊。
|
||||
item.HideSelf();
|
||||
return originalQuantity;
|
||||
}
|
||||
|
||||
|
@ -179,6 +184,10 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
_itemDictionary[finalNextAvailableIndex] = item;
|
||||
item.Index = finalNextAvailableIndex;
|
||||
item.ItemContainer = this;
|
||||
if (finalNextAvailableIndex != _selectIndex)
|
||||
{
|
||||
item.HideSelf();
|
||||
}
|
||||
UpdateNextAvailableIndex();
|
||||
UpdateSelectStatus(finalNextAvailableIndex, item);
|
||||
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||
|
@ -380,6 +389,7 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
var oldItem = GetItem(oldIndex);
|
||||
if (oldItem != null)
|
||||
{
|
||||
oldItem.HideSelf();
|
||||
oldItem.IsSelect = false;
|
||||
}
|
||||
|
||||
|
@ -388,6 +398,7 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
|||
var newItem = GetItem(newIndex);
|
||||
if (newItem != null)
|
||||
{
|
||||
newItem.ShowSelf();
|
||||
newItem.IsSelect = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,22 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
|
|||
//不要导出此字段,因为ID是在yaml内指定的。
|
||||
public virtual string Id { get; set; } = "ID";
|
||||
[Export] protected Texture2D? UniqueIcon { get; set; }
|
||||
|
||||
public void ShowSelf()
|
||||
{
|
||||
Show();
|
||||
}
|
||||
|
||||
public void QueueFreeSelf()
|
||||
{
|
||||
QueueFree();
|
||||
}
|
||||
|
||||
public void HideSelf()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
public Texture2D Icon => UniqueIcon ?? ItemTypeManager.DefaultIconOf(Id);
|
||||
|
||||
public new string Name
|
||||
|
|
Loading…
Reference in New Issue
Block a user