Bind the backpack to the ui.

使背包和ui绑定。
This commit is contained in:
Cold-Mint 2024-09-26 22:43:10 +08:00
parent b53f5bc2df
commit f881d43c3b
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99

View File

@ -1,5 +1,4 @@
using ColdMint.scripts.inventory; using ColdMint.scripts.inventory;
using ColdMint.scripts.utils;
using Godot; using Godot;
namespace ColdMint.scripts.loader.uiLoader; namespace ColdMint.scripts.loader.uiLoader;
@ -22,6 +21,8 @@ public partial class PacksackUi : UiLoaderTemplate
private Button? _exitButton; private Button? _exitButton;
private IItemContainerDisplay? _itemContainerDisplay;
/// <summary> /// <summary>
/// <para>title</para> /// <para>title</para>
/// <para>标题</para> /// <para>标题</para>
@ -46,30 +47,10 @@ public partial class PacksackUi : UiLoaderTemplate
set set
{ {
_itemContainer = value; _itemContainer = value;
PlaceItemSlot(value); BindItemContainer();
} }
} }
/// <summary>
/// <para>Place item slots according to item information</para>
/// <para>根据物品信息放置物品槽</para>
/// </summary>
/// <param name="itemContainer"></param>
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();
// }
}
/// <summary> /// <summary>
/// <para>SetTile</para> /// <para>SetTile</para>
@ -91,14 +72,24 @@ public partial class PacksackUi : UiLoaderTemplate
_packedScene = GD.Load<PackedScene>("res://prefab/ui/ItemSlot.tscn"); _packedScene = GD.Load<PackedScene>("res://prefab/ui/ItemSlot.tscn");
} }
private void BindItemContainer()
{
if (ItemContainer == null)
{
return;
}
_itemContainerDisplay?.BindItemContainer(ItemContainer);
}
public override void InitializeUi() public override void InitializeUi()
{ {
_hFlowContainer = GetNode<HFlowContainer>("HFlowContainer"); _hFlowContainer = GetNode<HFlowContainer>("HFlowContainer");
_titleLabel = GetNode<Label>("TitleLabel"); _titleLabel = GetNode<Label>("TitleLabel");
_exitButton = GetNode<Button>("ExitButton"); _exitButton = GetNode<Button>("ExitButton");
_itemContainerDisplay = new ItemSlotContainerDisplay(_hFlowContainer);
//If the item container was set before this node was placed in the node tree, load it here. //If the item container was set before this node was placed in the node tree, load it here.
//若物品容器在此节点放置到节点树之前被设置了,那么在这里加载。 //若物品容器在此节点放置到节点树之前被设置了,那么在这里加载。
PlaceItemSlot(_itemContainer); BindItemContainer();
SetTile(_title); SetTile(_title);
} }