2024-09-30 14:13:51 +00:00
|
|
|
using ColdMint.scripts.inventory;
|
2024-10-01 07:01:34 +00:00
|
|
|
using ColdMint.scripts.map.events;
|
2024-09-30 14:13:51 +00:00
|
|
|
using Godot;
|
|
|
|
|
|
|
|
namespace ColdMint.scripts.loader.uiLoader;
|
|
|
|
|
2024-10-04 08:13:34 +00:00
|
|
|
/// <summary>
|
|
|
|
/// <para>SpellEditorUi</para>
|
|
|
|
/// <para>法术编辑器UI</para>
|
|
|
|
/// </summary>
|
2024-09-30 14:13:51 +00:00
|
|
|
public partial class SpellEditorUi : UiLoaderTemplate
|
|
|
|
{
|
|
|
|
private Button? _exitButton;
|
2024-10-04 08:13:34 +00:00
|
|
|
private IItemContainer? _projectileWeaponContainer;
|
2024-09-30 14:13:51 +00:00
|
|
|
private ItemSlotNode? _itemSlot;
|
2024-10-04 08:13:34 +00:00
|
|
|
private HFlowContainer? _flowContainer;
|
|
|
|
private IItemContainerDisplay? _itemContainerDisplay;
|
2024-09-30 14:13:51 +00:00
|
|
|
|
|
|
|
public override void InitializeUi()
|
|
|
|
{
|
|
|
|
_exitButton = GetNode<Button>("ExitButton");
|
|
|
|
_itemSlot = GetNode<ItemSlotNode>("ItemSlot");
|
2024-10-04 08:13:34 +00:00
|
|
|
_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);
|
2024-09-30 14:13:51 +00:00
|
|
|
}
|
|
|
|
|
2024-10-01 07:01:34 +00:00
|
|
|
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
|
|
|
|
{
|
2024-10-04 08:13:34 +00:00
|
|
|
if (_itemSlot == null || _projectileWeaponContainer == null)
|
2024-10-01 07:01:34 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2024-10-01 12:53:56 +00:00
|
|
|
var item = itemDataChangeEvent.NewItem;
|
|
|
|
if (item == null)
|
|
|
|
{
|
2024-10-04 08:13:34 +00:00
|
|
|
item = _projectileWeaponContainer.GetPlaceHolderItem(itemDataChangeEvent.NewIndex);
|
2024-10-01 12:53:56 +00:00
|
|
|
}
|
|
|
|
item.IsSelect = false;
|
|
|
|
_itemSlot.Update(item);
|
2024-10-04 08:13:34 +00:00
|
|
|
_itemContainerDisplay?.BindItemContainer(item.SelfItemContainer);
|
2024-10-01 07:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void _ExitTree()
|
|
|
|
{
|
|
|
|
base._ExitTree();
|
2024-10-04 08:13:34 +00:00
|
|
|
if (_projectileWeaponContainer != null)
|
2024-10-01 07:01:34 +00:00
|
|
|
{
|
2024-10-04 08:13:34 +00:00
|
|
|
_projectileWeaponContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
|
2024-10-01 07:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-30 14:13:51 +00:00
|
|
|
public override void LoadUiActions()
|
|
|
|
{
|
|
|
|
if (_exitButton != null)
|
|
|
|
{
|
|
|
|
_exitButton.Pressed += () =>
|
|
|
|
{
|
|
|
|
GameSceneDepend.DynamicUiGroup?.HideControl(this);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|