using ColdMint.scripts.debug; using ColdMint.scripts.inventory; using ColdMint.scripts.utils; using Godot; namespace ColdMint.scripts.loader.uiLoader; /// /// Backpack UI /// 背包UI /// public partial class PacksackUi : UiLoaderTemplate { private IItemContainer? _itemContainer; private PackedScene? _packedScene; private GridContainer? _gridContainer; private Label? _titleLabel; private string? _title; private Button? _exitButton; /// /// title /// 标题 /// public string? Title { get => _title; set { _title = value; SetTile(value); } } /// /// Packsack /// 背包 /// public IItemContainer? ItemContainer { get => _itemContainer; set { _itemContainer = value; PlaceItemSlot(value); } } /// /// Place item slots according to item information /// 根据物品信息放置物品槽 /// /// private void PlaceItemSlot(IItemContainer? itemContainer) { if (_gridContainer == null || itemContainer == null) { return; } NodeUtils.DeleteAllChild(_gridContainer); foreach (var itemSlotNode in itemContainer) { itemSlotNode.Reparent(_gridContainer); } } /// /// SetTile /// 设置标题 /// /// private void SetTile(string? title) { if (_titleLabel == null) { return; } _titleLabel.Text = title; } public override void InitializeData() { _packedScene = GD.Load("res://prefab/ui/ItemSlot.tscn"); } public override void InitializeUi() { _gridContainer = GetNode("GridContainer"); _titleLabel = GetNode