118 lines
3.5 KiB
C#
118 lines
3.5 KiB
C#
using System;
|
|
using Cysharp.Threading.Tasks;
|
|
using SepCore.Event;
|
|
using SepCore.Definition;
|
|
using GameFramework.Event;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
public class ItemTooltipController : UIControllerBase<ItemTooltipContext, ItemTooltipForm>
|
|
{
|
|
protected override UIFormType UIFormType => UIFormType.ItemTooltipForm;
|
|
|
|
private Action<int, int> _onRecycle;
|
|
|
|
private bool _subscribed = false;
|
|
|
|
protected override void SubscribeCustomEvents()
|
|
{
|
|
if (_subscribed) return;
|
|
GameEntry.Event.Subscribe(ItemTooltipRecycleEventArgs.EventId, ItemTooltipRecycle);
|
|
GameEntry.Event.Subscribe(ItemTooltipHideEventArgs.EventId, ItemTooltipHide);
|
|
_subscribed = true;
|
|
}
|
|
|
|
protected override void UnsubscribeCustomEvents()
|
|
{
|
|
if (!_subscribed) return;
|
|
GameEntry.Event.Unsubscribe(ItemTooltipRecycleEventArgs.EventId, ItemTooltipRecycle);
|
|
GameEntry.Event.Unsubscribe(ItemTooltipHideEventArgs.EventId, ItemTooltipHide);
|
|
_subscribed = false;
|
|
}
|
|
|
|
protected override void RefreshUI(ItemTooltipForm form, ItemTooltipContext context)
|
|
{
|
|
form.RefreshUI(context).Forget();
|
|
}
|
|
|
|
protected override void CloseLoadedFormDirect(ItemTooltipForm form)
|
|
{
|
|
GameEntry.UI.CloseUIForm(form);
|
|
}
|
|
|
|
private static ItemTooltipContext BuildContext(ItemTooltipRawData rawData)
|
|
{
|
|
if (rawData == null)
|
|
{
|
|
Log.Error("ItemTooltipController.BuildContext() rawData is null.");
|
|
return null;
|
|
}
|
|
|
|
return new ItemTooltipContext(rawData);
|
|
}
|
|
|
|
public override async UniTask OpenUIAsync(object userData = null, float timeout = 30f)
|
|
{
|
|
if (userData is not ItemTooltipRawData rawData)
|
|
{
|
|
if (userData != null)
|
|
{
|
|
Log.Warning("ItemTooltipController.OpenUIAsync() userData type is invalid.");
|
|
}
|
|
else
|
|
{
|
|
Log.Warning("ItemTooltipController.OpenUIAsync() rawData is required.");
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
ItemTooltipContext context = BuildContext(rawData);
|
|
if (context == null)
|
|
{
|
|
Log.Warning("ItemTooltipController.OpenUIAsync() rawData is invalid.");
|
|
return;
|
|
}
|
|
|
|
_onRecycle = rawData.OnRecycle;
|
|
await OpenFormAsync(context, timeout);
|
|
}
|
|
|
|
public override async UniTask CloseUIAsync(object userData = null, float timeout = 30f)
|
|
{
|
|
_onRecycle = null;
|
|
await base.CloseUIAsync(userData, timeout);
|
|
}
|
|
|
|
public override void BindUseCase(IUIUseCase useCase)
|
|
{
|
|
if (useCase != null)
|
|
{
|
|
Log.Warning("ItemTooltipController does not use a use case.");
|
|
}
|
|
}
|
|
|
|
#region Event Handlers
|
|
|
|
private void ItemTooltipRecycle(object sender, GameEventArgs e)
|
|
{
|
|
if (e is not ItemTooltipRecycleEventArgs args)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_onRecycle?.Invoke(args.Index, args.Price);
|
|
}
|
|
|
|
private void ItemTooltipHide(object sender, GameEventArgs e)
|
|
{
|
|
if (e is not ItemTooltipHideEventArgs args) return;
|
|
|
|
CloseUIAsync().Forget();
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|