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 HFlowContainer? _hFlowContainer;
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 (_hFlowContainer == null || itemContainer == null)
{
return;
}
NodeUtils.DeleteAllChild(_hFlowContainer);
//todo:实现使用物品数据刷新物品槽的方法。
// foreach (var item in itemContainer)
// {
// itemSlotNode.Reparent(_hFlowContainer);
// itemSlotNode.Show();
// }
}
///
/// 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()
{
_hFlowContainer = GetNode("HFlowContainer");
_titleLabel = GetNode