ContextExtensions.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using FL.FGUI;
  2. using System;
  3. using XGame.Database;
  4. using XGame.Framework;
  5. namespace FL
  6. {
  7. internal static class ContextExtensions
  8. {
  9. public static void ShowTips(this IContext context, string tips)
  10. {
  11. EventSingle.Instance.Notify(EventDefine.ShowTips, tips);
  12. }
  13. public static void AddListener(this IContext context, EventDefine eventId, EventDelegate handler)
  14. {
  15. EventSingle.Instance.AddListener(eventId, handler);
  16. }
  17. public static void RemoveListener(this IContext context, EventDefine eventId, EventDelegate handler)
  18. {
  19. EventSingle.Instance.RemoveListener(eventId, handler);
  20. }
  21. /// <summary>
  22. /// UI跳转
  23. /// jumpTable.Param有配置则用配置,否则用业务透传的参数
  24. /// </summary>
  25. /// <param name="context"></param>
  26. /// <param name="jumpId">JumpTable.Id</param>
  27. /// <param name="intent"></param>
  28. public static void JumpUI(this IContext context, int jumpId, object intent = null)
  29. {
  30. JumpInner(context, jumpId, intent, null);
  31. }
  32. private static void JumpInner(IContext context, int jumpId, object intent, Action callback)
  33. {
  34. var jumpTable = JumpTableRepo.Get(jumpId);
  35. Assert.IsNotNull(jumpTable, $"跳转配置错误: 找不到配置. JumpId:{jumpId}");
  36. void OnParentOpened()
  37. {
  38. var uikey = UIKeys.NameToKey(jumpTable.UI);
  39. if (uikey == null)
  40. {
  41. context.ShowTips($"跳转配置错误: 找不到UI. JumpId:{jumpId} UI:{jumpTable.UI}");
  42. return;
  43. }
  44. //TODO jumpTable.Param有配置则用配置,否则用业务透传的参数
  45. var async = context.UI.OpenAsync(uikey, jumpTable.Param.Length > 0 ? jumpTable.Param : intent);
  46. async.On(_ =>
  47. {
  48. callback.SafeInvoke();
  49. });
  50. }
  51. if (jumpTable.Parent > 0)
  52. {
  53. JumpInner(context, jumpTable.Parent, intent, OnParentOpened);
  54. }
  55. else
  56. {
  57. OnParentOpened();
  58. }
  59. }
  60. }
  61. }