1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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);
- }
- /// <summary>
- /// UI跳转
- /// jumpTable.Param有配置则用配置,否则用业务透传的参数
- /// </summary>
- /// <param name="context"></param>
- /// <param name="jumpId">JumpTable.Id</param>
- /// <param name="intent"></param>
- 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();
- }
- }
- }
- }
|