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;
|
|
|
|
|
|
|
|
public partial class SpellEditorUi : UiLoaderTemplate
|
|
|
|
{
|
|
|
|
private Button? _exitButton;
|
|
|
|
private IItemContainer? _itemContainer;
|
|
|
|
private ItemSlotNode? _itemSlot;
|
|
|
|
|
|
|
|
public override void InitializeUi()
|
|
|
|
{
|
|
|
|
_exitButton = GetNode<Button>("ExitButton");
|
|
|
|
_itemSlot = GetNode<ItemSlotNode>("ItemSlot");
|
|
|
|
_itemContainer = new UniversalItemContainer(1);
|
2024-10-01 07:01:34 +00:00
|
|
|
_itemContainer.ItemDataChangeEvent += OnItemDataChangeEvent;
|
2024-09-30 14:13:51 +00:00
|
|
|
_itemSlot.Update(_itemContainer.GetPlaceHolderItem(0));
|
|
|
|
}
|
|
|
|
|
2024-10-01 07:01:34 +00:00
|
|
|
private void OnItemDataChangeEvent(ItemDataChangeEvent itemDataChangeEvent)
|
|
|
|
{
|
2024-10-01 12:53:56 +00:00
|
|
|
if (_itemSlot == null || _itemContainer == 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)
|
|
|
|
{
|
|
|
|
item = _itemContainer.GetPlaceHolderItem(itemDataChangeEvent.NewIndex);
|
|
|
|
}
|
|
|
|
item.IsSelect = false;
|
|
|
|
_itemSlot.Update(item);
|
2024-10-01 07:01:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void _ExitTree()
|
|
|
|
{
|
|
|
|
base._ExitTree();
|
|
|
|
if (_itemContainer != null)
|
|
|
|
{
|
|
|
|
_itemContainer.ItemDataChangeEvent -= OnItemDataChangeEvent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-30 14:13:51 +00:00
|
|
|
public override void LoadUiActions()
|
|
|
|
{
|
|
|
|
if (_exitButton != null)
|
|
|
|
{
|
|
|
|
_exitButton.Pressed += () =>
|
|
|
|
{
|
|
|
|
GameSceneDepend.DynamicUiGroup?.HideControl(this);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|