MountMainPanelCtrl.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using XGame.Framework.UI;
  8. namespace FL.FGUI
  9. {
  10. /// <summary>
  11. /// UI逻辑处理类
  12. /// </summary>
  13. /// <typeparam name=""></typeparam>
  14. public partial class MountMainPanelCtrl : UIController<MountMainPanelVM>
  15. {
  16. private int _pageIndex; // 当前显示的页签索引
  17. protected override void OnEnable(object intent)
  18. {
  19. AddUIListenres();
  20. AddEventListener();
  21. if (intent != null && intent is int)
  22. {
  23. _pageIndex = (int)intent;
  24. }
  25. else
  26. _pageIndex = 0;
  27. Init();
  28. }
  29. protected override void OnDisable()
  30. {
  31. RemoveUIListenres();
  32. RemoveEventListener();
  33. VM.UpgradeNestedItem.Ctrl.ClearData();
  34. VM.AdvancedNestedItem.Ctrl.ClearData();
  35. VM.TrainNestedItem.Ctrl.ClearData();
  36. }
  37. #region UI事件
  38. private void AddUIListenres()
  39. {
  40. VM.PageCtrl.onChanged.Add(OnPageCtrlChange);
  41. }
  42. private void RemoveUIListenres()
  43. {
  44. VM.PageCtrl.onChanged.Remove(OnPageCtrlChange);
  45. }
  46. /// <summary>
  47. /// 页签按钮切换事件
  48. /// </summary>
  49. /// <param name="context"></param>
  50. private void OnPageCtrlChange(EventContext context)
  51. {
  52. ShowPage(VM.PageCtrl.selectedIndex);
  53. }
  54. #endregion
  55. private void AddEventListener()
  56. {
  57. Context.AddListener(EventDefine.RefreshMountInfo, RefreshMountInfo);
  58. }
  59. private void RemoveEventListener()
  60. {
  61. Context.RemoveListener(EventDefine.RefreshMountInfo, RefreshMountInfo);
  62. }
  63. private void Init()
  64. {
  65. MountService.Instance.SendToMountData();
  66. }
  67. /// <summary>
  68. /// 页签切换事件
  69. /// </summary>
  70. /// <param name="pageIndex"></param>
  71. private void ShowPage(int pageIndex)
  72. {
  73. _pageIndex = pageIndex;
  74. ShowUpgradeMountsUI(pageIndex == 0);
  75. ShowTrainMountsUI(pageIndex == 1);
  76. ShowAdvancedMountUI(pageIndex == 2);
  77. }
  78. /// <summary>
  79. /// 通用坐骑升级界面
  80. /// </summary>
  81. /// <param name="bShow"></param>
  82. private void ShowUpgradeMountsUI(bool bShow)
  83. {
  84. if (bShow)
  85. {
  86. VM.UpgradeNestedItem.Enable(null);
  87. VM.UpgradeNestedItem.Ctrl.ShowUpgradeMountUI();
  88. }
  89. else
  90. VM.UpgradeNestedItem.Disable();
  91. }
  92. /// <summary>
  93. /// 坐骑驯养界面
  94. /// </summary>
  95. /// <param name="bShow"></param>
  96. private void ShowTrainMountsUI(bool bShow)
  97. {
  98. if (bShow)
  99. {
  100. VM.TrainNestedItem.Enable(null);
  101. VM.TrainNestedItem.Ctrl.ShowTrainMountUI(true);
  102. }
  103. else
  104. VM.TrainNestedItem.Disable();
  105. }
  106. /// <summary>
  107. /// 高级坐骑界面
  108. /// </summary>
  109. /// <param name="bShow"></param>
  110. private void ShowAdvancedMountUI(bool bShow)
  111. {
  112. if (bShow)
  113. {
  114. VM.AdvancedNestedItem.Enable(null);
  115. VM.AdvancedNestedItem.Ctrl.ShowAdvancedMountUI(true);
  116. }
  117. else
  118. VM.AdvancedNestedItem.Disable();
  119. }
  120. /// <summary>
  121. /// 返回坐骑数据,刷新坐骑界面UI
  122. /// </summary>
  123. /// <param name="eventId"></param>
  124. /// <param name="args"></param>
  125. private void RefreshMountInfo(int eventId, object args)
  126. {
  127. ShowPage(_pageIndex);
  128. }
  129. }
  130. }