using ColdMint.scripts.pickable; using ColdMint.scripts.utils; using Godot; using PacksackUi = ColdMint.scripts.loader.uiLoader.PacksackUi; namespace ColdMint.scripts.inventory; /// /// packsack /// 背包 /// public partial class Packsack : PickAbleTemplate { private const string Path = "res://prefab/ui/packsackUI.tscn"; [Export] public int NumberSlots { get; set; } /// /// Whether to allow backpacks /// 是否允许放置背包 /// /// ///Can a new backpack be placed in the slot of the backpack? ///即此背包的槽位内是否可以再放置新的背包? /// [Export] public bool BackpackAllowed { get; set; } public override bool CanPutInPack => false; public override void Use(Node2D? owner, Vector2 targetGlobalPosition) { GameSceneDepend.DynamicUiGroup?.ShowControl(Path, control => { if (control is PacksackUi packsackUi) { packsackUi.Title = Name; packsackUi.ItemContainer = ItemContainer; } }); } public IItemContainer? ItemContainer { get; private set; } public override void _Ready() { base._Ready(); ItemContainer = new UniversalItemContainer(); ItemContainer.SupportSelect = false; //When the backpack is created, the item slot is generated. //当背包被创建时,物品槽就被生成出来了。 for (var i = 0; i < NumberSlots; i++) { var itemSlotNode = ItemContainer.AddItemSlot(this); if (itemSlotNode == null) { continue; } itemSlotNode.BackpackAllowed = BackpackAllowed; itemSlotNode.Hide(); } GameSceneDepend.DynamicUiGroup?.RegisterControl(Path, () => { var packedScene = GD.Load(Path); return NodeUtils.InstantiatePackedScene(packedScene); }); } }