using FL.FGUI;
using System;
using XGame.Database;
using XGame.Framework;
namespace FL
{
internal static class ContextExtensions
{
public static void ShowTips(this IContext context, string tips)
{
EventSingle.Instance.Notify(EventDefine.ShowTips, tips);
}
public static void AddListener(this IContext context, EventDefine eventId, EventDelegate handler)
{
EventSingle.Instance.AddListener(eventId, handler);
}
public static void RemoveListener(this IContext context, EventDefine eventId, EventDelegate handler)
{
EventSingle.Instance.RemoveListener(eventId, handler);
}
///
/// UI跳转
/// jumpTable.Param有配置则用配置,否则用业务透传的参数
///
///
/// JumpTable.Id
///
public static void JumpUI(this IContext context, int jumpId, object intent = null)
{
JumpInner(context, jumpId, intent, null);
}
private static void JumpInner(IContext context, int jumpId, object intent, Action callback)
{
var jumpTable = JumpTableRepo.Get(jumpId);
Assert.IsNotNull(jumpTable, $"跳转配置错误: 找不到配置. JumpId:{jumpId}");
void OnParentOpened()
{
var uikey = UIKeys.NameToKey(jumpTable.UI);
if (uikey == null)
{
context.ShowTips($"跳转配置错误: 找不到UI. JumpId:{jumpId} UI:{jumpTable.UI}");
return;
}
//TODO jumpTable.Param有配置则用配置,否则用业务透传的参数
var async = context.UI.OpenAsync(uikey, jumpTable.Param.Length > 0 ? jumpTable.Param : intent);
async.On(_ =>
{
callback.SafeInvoke();
});
}
if (jumpTable.Parent > 0)
{
JumpInner(context, jumpTable.Parent, intent, OnParentOpened);
}
else
{
OnParentOpened();
}
}
}
}