将原来遗漏的脚本文件夹改名为正确的 DisplayItemInfo -> ItemTooltip
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using SepCore.Event;
|
||||
using SepCore.Definition;
|
||||
using GameFramework.Event;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace SepCore.UI
|
||||
{
|
||||
public class ItemTooltipController : UIControllerBase<ItemTooltipContext, ItemTooltipForm>
|
||||
{
|
||||
protected override UIFormType UIFormType => UIFormType.ItemTooltipForm;
|
||||
|
||||
private bool _locked = false;
|
||||
private Action<int, int> _onRecycle;
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(DisplayItemLockEventArgs.EventId, OnDisplayItemLock);
|
||||
GameEntry.Event.Subscribe(DisplayItemHideEventArgs.EventId, OnDisplayItemHide);
|
||||
GameEntry.Event.Subscribe(ItemTooltipRecycleEventArgs.EventId, ItemTooltipRecycle);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(DisplayItemLockEventArgs.EventId, OnDisplayItemLock);
|
||||
GameEntry.Event.Unsubscribe(DisplayItemHideEventArgs.EventId, OnDisplayItemHide);
|
||||
GameEntry.Event.Unsubscribe(ItemTooltipRecycleEventArgs.EventId, ItemTooltipRecycle);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
_locked = false;
|
||||
_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.");
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsCurrentFormSender(object sender)
|
||||
{
|
||||
if (sender is ItemTooltipForm ItemTooltipForm)
|
||||
{
|
||||
return ItemTooltipForm == Form;
|
||||
}
|
||||
|
||||
if (sender is Component component && Form != null)
|
||||
{
|
||||
return component.transform.IsChildOf(Form.transform);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#region Event Handlers
|
||||
|
||||
private void OnDisplayItemLock(object sender, GameEventArgs e)
|
||||
{
|
||||
if (e is not DisplayItemLockEventArgs)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_locked = true;
|
||||
}
|
||||
|
||||
private void OnDisplayItemHide(object sender, GameEventArgs e)
|
||||
{
|
||||
if (e is not DisplayItemHideEventArgs args)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_locked && !args.Force) return;
|
||||
|
||||
GameEntry.UIRouter.CloseUIAsync(UIFormType.ItemTooltipForm).Forget();
|
||||
}
|
||||
|
||||
private void ItemTooltipRecycle(object sender, GameEventArgs e)
|
||||
{
|
||||
if (e is not ItemTooltipRecycleEventArgs args)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!IsCurrentFormSender(sender))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_onRecycle?.Invoke(args.Index, args.Price);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user