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);
|
ProtectedItemContainer?.RemoveItem(index, 1);
|
||||||
|
originalItem.QueueFreeSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,24 @@ public interface IItem
|
||||||
/// </summary>
|
/// </summary>
|
||||||
string Id { get; set; }
|
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>
|
/// <summary>
|
||||||
/// <para>Icon of current item</para>
|
/// <para>Icon of current item</para>
|
||||||
/// <para>当前项目的图标</para>
|
/// <para>当前项目的图标</para>
|
||||||
|
|
|
@ -10,6 +10,22 @@ public class PlaceholderItem : IItem
|
||||||
{
|
{
|
||||||
public int Index { get; set; }
|
public int Index { get; set; }
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
|
public void ShowSelf()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void QueueFreeSelf()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HideSelf()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public Texture2D Icon { get; }
|
public Texture2D Icon { get; }
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
public string? Description { get; } = null;
|
public string? Description { get; } = null;
|
||||||
|
|
|
@ -118,6 +118,10 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
||||||
_itemDictionary[nextAvailableIndex] = item;
|
_itemDictionary[nextAvailableIndex] = item;
|
||||||
item.Index = nextAvailableIndex;
|
item.Index = nextAvailableIndex;
|
||||||
item.ItemContainer = this;
|
item.ItemContainer = this;
|
||||||
|
if (nextAvailableIndex != _selectIndex)
|
||||||
|
{
|
||||||
|
item.HideSelf();
|
||||||
|
}
|
||||||
UpdateNextAvailableIndex();
|
UpdateNextAvailableIndex();
|
||||||
UpdateSelectStatus(nextAvailableIndex, item);
|
UpdateSelectStatus(nextAvailableIndex, item);
|
||||||
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||||
|
@ -154,6 +158,7 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
||||||
{
|
{
|
||||||
//New items are fully shared.
|
//New items are fully shared.
|
||||||
//新物品完全被均摊。
|
//新物品完全被均摊。
|
||||||
|
item.HideSelf();
|
||||||
return originalQuantity;
|
return originalQuantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,6 +184,10 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
||||||
_itemDictionary[finalNextAvailableIndex] = item;
|
_itemDictionary[finalNextAvailableIndex] = item;
|
||||||
item.Index = finalNextAvailableIndex;
|
item.Index = finalNextAvailableIndex;
|
||||||
item.ItemContainer = this;
|
item.ItemContainer = this;
|
||||||
|
if (finalNextAvailableIndex != _selectIndex)
|
||||||
|
{
|
||||||
|
item.HideSelf();
|
||||||
|
}
|
||||||
UpdateNextAvailableIndex();
|
UpdateNextAvailableIndex();
|
||||||
UpdateSelectStatus(finalNextAvailableIndex, item);
|
UpdateSelectStatus(finalNextAvailableIndex, item);
|
||||||
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
ItemDataChangeEvent?.Invoke(new ItemDataChangeEvent
|
||||||
|
@ -380,6 +389,7 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
||||||
var oldItem = GetItem(oldIndex);
|
var oldItem = GetItem(oldIndex);
|
||||||
if (oldItem != null)
|
if (oldItem != null)
|
||||||
{
|
{
|
||||||
|
oldItem.HideSelf();
|
||||||
oldItem.IsSelect = false;
|
oldItem.IsSelect = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,6 +398,7 @@ public class UniversalItemContainer(int totalCapacity) : IItemContainer
|
||||||
var newItem = GetItem(newIndex);
|
var newItem = GetItem(newIndex);
|
||||||
if (newItem != null)
|
if (newItem != null)
|
||||||
{
|
{
|
||||||
|
newItem.ShowSelf();
|
||||||
newItem.IsSelect = true;
|
newItem.IsSelect = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,22 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
|
||||||
//不要导出此字段,因为ID是在yaml内指定的。
|
//不要导出此字段,因为ID是在yaml内指定的。
|
||||||
public virtual string Id { get; set; } = "ID";
|
public virtual string Id { get; set; } = "ID";
|
||||||
[Export] protected Texture2D? UniqueIcon { get; set; }
|
[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 Texture2D Icon => UniqueIcon ?? ItemTypeManager.DefaultIconOf(Id);
|
||||||
|
|
||||||
public new string Name
|
public new string Name
|
||||||
|
|
Loading…
Reference in New Issue
Block a user