using System.Collections.Generic; using System.Linq; using Godot; namespace ColdMint.scripts.inventory; public partial class HotBar : HBoxContainer { private PackedScene _itemSlotPackedScene; private List _itemSlotNodes; public override void _Ready() { base._Ready(); _itemSlotNodes = new List(); _itemSlotPackedScene = GD.Load("res://prefab/ui/ItemSlot.tscn"); for (int i = 0; i < 10; i++) { AddItemSlot(); } } /// /// Add an item to the HotBar /// 在HotBar内添加一个物品 /// /// /// public bool AddItem(IItem item) { return _itemSlotNodes.Count != 0 && _itemSlotNodes.Any(itemSlotNode => itemSlotNode.SetItem(item)); } /// /// Add items tank /// 添加物品槽 /// private void AddItemSlot() { var node = _itemSlotPackedScene.Instantiate(); AddChild(node); _itemSlotNodes.Add(node as ItemSlotNode); } }