Traveller/scripts/loader/uiLoader/SpellEditorUi.cs
Cold-Mint 124c6ce0ba
The UI will be automatically closed when the player leaves the range of the furniture. The spell editor is now able to load information about items placed in it.
玩家离开家具的操作范围时会自动关闭UI了。法术编辑器现在能够加载放入的物品信息。
2024-10-04 16:13:34 +08:00

66 lines
2.1 KiB
C#

using ColdMint.scripts.inventory;
using ColdMint.scripts.map.events;
using Godot;
namespace ColdMint.scripts.loader.uiLoader;
/// <summary>
/// <para>SpellEditorUi</para>
/// <para>法术编辑器UI</para>
/// </summary>
public partial class SpellEditorUi : UiLoaderTemplate
{
private Button? _exitButton;
private IItemContainer? _projectileWeaponContainer;
private ItemSlotNode? _itemSlot;
private HFlowContainer? _flowContainer;
private IItemContainerDisplay? _itemContainerDisplay;
public override void InitializeUi()
{
_exitButton = GetNode<Button>("ExitButton");
_itemSlot = GetNode<ItemSlotNode>("ItemSlot");
_projectileWeaponContainer = new UniversalItemContainer(1);
_projectileWeaponContainer.AllowAddingItemByType(Config.ItemType.ProjectileWeapon);
_projectileWeaponContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
_itemSlot.Update(_projectileWeaponContainer.GetPlaceHolderItem(0));
_flowContainer = GetNode<HFlowContainer>("HFlowContainer");
_itemContainerDisplay = new ItemSlotContainerDisplay(_flowContainer);
}
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
{
if (_itemSlot == null || _projectileWeaponContainer == null)
{
return;
}
var item = itemDataChangeEvent.NewItem;
if (item == null)
{
item = _projectileWeaponContainer.GetPlaceHolderItem(itemDataChangeEvent.NewIndex);
}
item.IsSelect = false;
_itemSlot.Update(item);
_itemContainerDisplay?.BindItemContainer(item.SelfItemContainer);
}
public override void _ExitTree()
{
base._ExitTree();
if (_projectileWeaponContainer != null)
{
_projectileWeaponContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
}
}
public override void LoadUiActions()
{
if (_exitButton != null)
{
_exitButton.Pressed += () =>
{
GameSceneDepend.DynamicUiGroup?.HideControl(this);
};
}
}
}