diff --git a/scripts/inventory/HotBar.cs b/scripts/inventory/HotBar.cs index 0cc99dd..84e7a27 100644 --- a/scripts/inventory/HotBar.cs +++ b/scripts/inventory/HotBar.cs @@ -20,7 +20,7 @@ public partial class HotBar : HBoxContainer NodeUtils.DeleteAllChild(this); for (var i = 0; i < Config.HotBarSize; i++) { - _itemContainer.AddItemSlot(this, i); + _itemContainer.AddItemSlot(this); } } diff --git a/scripts/inventory/IItemContainer.cs b/scripts/inventory/IItemContainer.cs index 72ee577..1a5a36b 100644 --- a/scripts/inventory/IItemContainer.cs +++ b/scripts/inventory/IItemContainer.cs @@ -219,8 +219,7 @@ public interface IItemContainer : IEnumerable /// 添加物品槽 /// /// - /// - void AddItemSlot(Node rootNode, int index); + void AddItemSlot(Node rootNode); /// /// SelectTheNextItemSlot diff --git a/scripts/inventory/UniversalItemContainer.cs b/scripts/inventory/UniversalItemContainer.cs index 938f094..5d47e56 100644 --- a/scripts/inventory/UniversalItemContainer.cs +++ b/scripts/inventory/UniversalItemContainer.cs @@ -22,7 +22,7 @@ public class UniversalItemContainer : IItemContainer { private readonly PackedScene? _itemSlotPackedScene = GD.Load("res://prefab/ui/ItemSlot.tscn"); - private readonly List? _itemSlotNodes = new(); + private readonly List? _itemSlotNodes = []; /// /// Character @@ -221,7 +221,7 @@ public class UniversalItemContainer : IItemContainer /// Add items tank /// 添加物品槽 /// - public void AddItemSlot(Node rootNode, int index) + public void AddItemSlot(Node rootNode) { if (_itemSlotNodes == null || _itemSlotPackedScene == null) { @@ -234,7 +234,7 @@ public class UniversalItemContainer : IItemContainer return; } - itemSlotNode.IsSelect = index == _selectIndex; + itemSlotNode.IsSelect = (_itemSlotNodes.Count ) == _selectIndex; _itemSlotNodes.Add(itemSlotNode); } diff --git a/scripts/item/Packsack.cs b/scripts/item/Packsack.cs index 6a9aa16..6ac8e91 100644 --- a/scripts/item/Packsack.cs +++ b/scripts/item/Packsack.cs @@ -49,5 +49,8 @@ public partial class Packsack : RigidBody2D, IItem { base._Ready(); ItemContainer = new UniversalItemContainer(); + + //Test: Add one ItemSlot for pack + ItemContainer.AddItemSlot(this); } } \ No newline at end of file