Change the index parameter when adding a slot to ItemContainer to automatically get the latest index , add a test slot for Packsack item
更改ItemContainer添加槽位时的index参数为自动获取最新索引,为Packsack加入一个测试用槽位
This commit is contained in:
parent
e5664f1553
commit
0f9e7d0283
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -219,8 +219,7 @@ public interface IItemContainer : IEnumerable<ItemSlotNode>
|
|||
/// <para>添加物品槽</para>
|
||||
/// </summary>
|
||||
/// <param name="rootNode"></param>
|
||||
/// <param name="index"></param>
|
||||
void AddItemSlot(Node rootNode, int index);
|
||||
void AddItemSlot(Node rootNode);
|
||||
|
||||
/// <summary>
|
||||
/// <para>SelectTheNextItemSlot</para>
|
||||
|
|
|
@ -22,7 +22,7 @@ public class UniversalItemContainer : IItemContainer
|
|||
{
|
||||
private readonly PackedScene? _itemSlotPackedScene = GD.Load<PackedScene>("res://prefab/ui/ItemSlot.tscn");
|
||||
|
||||
private readonly List<ItemSlotNode>? _itemSlotNodes = new();
|
||||
private readonly List<ItemSlotNode>? _itemSlotNodes = [];
|
||||
|
||||
/// <summary>
|
||||
/// <para>Character</para>
|
||||
|
@ -221,7 +221,7 @@ public class UniversalItemContainer : IItemContainer
|
|||
/// <para>Add items tank</para>
|
||||
/// <para>添加物品槽</para>
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -49,5 +49,8 @@ public partial class Packsack : RigidBody2D, IItem
|
|||
{
|
||||
base._Ready();
|
||||
ItemContainer = new UniversalItemContainer();
|
||||
|
||||
//Test: Add one ItemSlot for pack
|
||||
ItemContainer.AddItemSlot(this);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user