From 0f9e7d028333b5c635a51e0e2329b913f53eb4b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9C=A7=E9=9B=A8=E7=83=A8?= Date: Fri, 14 Jun 2024 12:44:31 +0800 Subject: [PATCH] =?UTF-8?q?Change=20the=20index=20parameter=20when=20addin?= =?UTF-8?q?g=20a=20slot=20to=20ItemContainer=20to=20automatically=20get=20?= =?UTF-8?q?the=20latest=20index=20,=20add=20a=20test=20slot=20for=20Packsa?= =?UTF-8?q?ck=20item=20=E6=9B=B4=E6=94=B9ItemContainer=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=A7=BD=E4=BD=8D=E6=97=B6=E7=9A=84index=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=B8=BA=E8=87=AA=E5=8A=A8=E8=8E=B7=E5=8F=96=E6=9C=80=E6=96=B0?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=EF=BC=8C=E4=B8=BAPacksack=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=B5=8B=E8=AF=95=E7=94=A8=E6=A7=BD=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/inventory/HotBar.cs | 2 +- scripts/inventory/IItemContainer.cs | 3 +-- scripts/inventory/UniversalItemContainer.cs | 6 +++--- scripts/item/Packsack.cs | 3 +++ 4 files changed, 8 insertions(+), 6 deletions(-) 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