2024-06-16 14:44:50 +00:00
|
|
|
|
using ColdMint.scripts.inventory;
|
2024-06-16 12:18:44 +00:00
|
|
|
|
using ColdMint.scripts.utils;
|
2024-06-16 07:28:16 +00:00
|
|
|
|
using Godot;
|
|
|
|
|
|
2024-06-16 12:18:44 +00:00
|
|
|
|
namespace ColdMint.scripts.loader.uiLoader;
|
2024-06-16 07:28:16 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Backpack UI</para>
|
|
|
|
|
/// <para>背包UI</para>
|
|
|
|
|
/// </summary>
|
2024-06-16 12:18:44 +00:00
|
|
|
|
public partial class PacksackUi : UiLoaderTemplate
|
2024-06-16 07:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
private IItemContainer? _itemContainer;
|
|
|
|
|
|
|
|
|
|
private PackedScene? _packedScene;
|
|
|
|
|
|
2024-06-17 14:12:51 +00:00
|
|
|
|
private HFlowContainer? _hFlowContainer;
|
2024-06-16 07:28:16 +00:00
|
|
|
|
|
2024-06-16 12:18:44 +00:00
|
|
|
|
private Label? _titleLabel;
|
|
|
|
|
|
|
|
|
|
private string? _title;
|
|
|
|
|
|
|
|
|
|
private Button? _exitButton;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>title</para>
|
|
|
|
|
/// <para>标题</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string? Title
|
|
|
|
|
{
|
|
|
|
|
get => _title;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_title = value;
|
|
|
|
|
SetTile(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 07:28:16 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Packsack</para>
|
|
|
|
|
/// <para>背包</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
public IItemContainer? ItemContainer
|
|
|
|
|
{
|
|
|
|
|
get => _itemContainer;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_itemContainer = value;
|
|
|
|
|
PlaceItemSlot(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>Place item slots according to item information</para>
|
|
|
|
|
/// <para>根据物品信息放置物品槽</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="itemContainer"></param>
|
|
|
|
|
private void PlaceItemSlot(IItemContainer? itemContainer)
|
|
|
|
|
{
|
2024-06-17 14:12:51 +00:00
|
|
|
|
if (_hFlowContainer == null || itemContainer == null)
|
2024-06-16 07:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-17 14:12:51 +00:00
|
|
|
|
NodeUtils.DeleteAllChild(_hFlowContainer);
|
2024-09-22 08:51:42 +00:00
|
|
|
|
//todo:实现使用物品数据刷新物品槽的方法。
|
|
|
|
|
// foreach (var item in itemContainer)
|
|
|
|
|
// {
|
|
|
|
|
// itemSlotNode.Reparent(_hFlowContainer);
|
|
|
|
|
// itemSlotNode.Show();
|
|
|
|
|
// }
|
2024-06-16 07:28:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-06-16 12:18:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>SetTile</para>
|
|
|
|
|
/// <para>设置标题</para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="title"></param>
|
|
|
|
|
private void SetTile(string? title)
|
|
|
|
|
{
|
|
|
|
|
if (_titleLabel == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_titleLabel.Text = title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void InitializeData()
|
2024-06-16 07:28:16 +00:00
|
|
|
|
{
|
|
|
|
|
_packedScene = GD.Load<PackedScene>("res://prefab/ui/ItemSlot.tscn");
|
2024-06-16 12:18:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void InitializeUi()
|
|
|
|
|
{
|
2024-06-17 14:12:51 +00:00
|
|
|
|
_hFlowContainer = GetNode<HFlowContainer>("HFlowContainer");
|
2024-06-16 12:18:44 +00:00
|
|
|
|
_titleLabel = GetNode<Label>("TitleLabel");
|
|
|
|
|
_exitButton = GetNode<Button>("ExitButton");
|
2024-06-16 07:28:16 +00:00
|
|
|
|
//If the item container was set before this node was placed in the node tree, load it here.
|
|
|
|
|
//若物品容器在此节点放置到节点树之前被设置了,那么在这里加载。
|
|
|
|
|
PlaceItemSlot(_itemContainer);
|
2024-06-16 12:18:44 +00:00
|
|
|
|
SetTile(_title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void LoadUiActions()
|
|
|
|
|
{
|
|
|
|
|
if (_exitButton != null)
|
|
|
|
|
{
|
2024-06-17 14:12:51 +00:00
|
|
|
|
_exitButton.Pressed += () =>
|
|
|
|
|
{
|
2024-09-18 12:20:02 +00:00
|
|
|
|
GameSceneDepend.DynamicUiGroup?.HideControl(this);
|
2024-06-17 14:12:51 +00:00
|
|
|
|
};
|
2024-06-16 12:18:44 +00:00
|
|
|
|
}
|
2024-06-16 07:28:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|