diff --git a/scripts/character/CharacterTemplate.cs b/scripts/character/CharacterTemplate.cs index faa6cf8..294cdd6 100644 --- a/scripts/character/CharacterTemplate.cs +++ b/scripts/character/CharacterTemplate.cs @@ -839,6 +839,7 @@ public partial class CharacterTemplate : CharacterBody2D } ProtectedItemContainer?.RemoveItem(index, 1); + originalItem.QueueFreeSelf(); } diff --git a/scripts/inventory/IItem.cs b/scripts/inventory/IItem.cs index 9a16648..70e2242 100644 --- a/scripts/inventory/IItem.cs +++ b/scripts/inventory/IItem.cs @@ -14,6 +14,24 @@ public interface IItem /// 当前物品的ID /// string Id { get; set; } + + /// + /// ShowSelf + /// 显示自身 + /// + void ShowSelf(); + + /// + /// QueueFreeSelf + /// 销毁自身 + /// + void QueueFreeSelf(); + + /// + /// HideSelf + /// 隐藏自身 + /// + void HideSelf(); /// /// Icon of current item diff --git a/scripts/inventory/PlaceholderItem.cs b/scripts/inventory/PlaceholderItem.cs index 1037615..f26e0aa 100644 --- a/scripts/inventory/PlaceholderItem.cs +++ b/scripts/inventory/PlaceholderItem.cs @@ -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; diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs index 4f1cd2d..97146f3 100644 --- a/scripts/inventory/UniversalItemContainer.cs +++ b/scripts/inventory/UniversalItemContainer.cs @@ -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; } diff --git a/scripts/pickable/PickAbleTemplate.cs b/scripts/pickable/PickAbleTemplate.cs index 6b9ce6f..8d91e54 100644 --- a/scripts/pickable/PickAbleTemplate.cs +++ b/scripts/pickable/PickAbleTemplate.cs @@ -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