PartnerMainPanelCtrl.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data;
  8. using System.Collections.Generic;
  9. using XGame.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. /// <summary>
  14. /// UI逻辑处理类
  15. /// </summary>
  16. /// <typeparam name=""></typeparam>
  17. public partial class PartnerMainPanelCtrl : UIController<PartnerMainPanelVM>
  18. {
  19. #region 属性
  20. private bool _bShowLineupPlanNested;
  21. #endregion
  22. protected override void OnEnable(object intent)
  23. {
  24. _bShowLineupPlanNested = false;
  25. AddUIListenres();
  26. AddEventListenres();
  27. InitView();
  28. RefreshGoneUpPartners();
  29. RefreshAllPartners();
  30. ShowLineupPlanNested();
  31. }
  32. protected override void OnDisable()
  33. {
  34. RemoveUIListenres();
  35. RemoveEventListenres();
  36. }
  37. #region UI事件
  38. private void AddUIListenres()
  39. {
  40. VM.OneKeyUpBtn.onClick.Add(OnClickOneKeyUpBtn);
  41. VM.OneKeyStrongBtn.onClick.Add(OnClickOneKeyStrongBtn);
  42. VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
  43. }
  44. private void RemoveUIListenres()
  45. {
  46. VM.OneKeyUpBtn.onClick.Remove(OnClickOneKeyUpBtn);
  47. VM.OneKeyStrongBtn.onClick.Remove(OnClickOneKeyStrongBtn);
  48. VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
  49. }
  50. private void OnClickOneKeyUpBtn(EventContext context)
  51. {
  52. XGame.Log.Info("OnClickOneKeyUpBtn.");
  53. }
  54. private void OnClickOneKeyStrongBtn(EventContext context)
  55. {
  56. XGame.Log.Info("OnClickOneKeyStrongBtn.");
  57. }
  58. private void OnClickChangeBtn(EventContext context)
  59. {
  60. EventSingle.Instance.Notify(EventDefine.ShowTips, "方案切换");
  61. _bShowLineupPlanNested = !_bShowLineupPlanNested;
  62. ShowLineupPlanNested();
  63. }
  64. #endregion
  65. #region 事件监听
  66. private void AddEventListenres()
  67. {
  68. EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnPartnerDown);
  69. EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnPartnerUp);
  70. EventSingle.Instance.AddListener(EventDefine.WaitForDownPartner,WaitForDownPartner);
  71. }
  72. private void RemoveEventListenres()
  73. {
  74. EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnPartnerDown);
  75. EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnPartnerUp);
  76. EventSingle.Instance.RemoveListener(EventDefine.WaitForDownPartner, WaitForDownPartner);
  77. }
  78. private void OnPartnerUp(int eventId, object args)
  79. {
  80. RefreshGoneUpPartners();
  81. RefreshAllPartners();
  82. }
  83. private void OnPartnerDown(int eventId, object args)
  84. {
  85. RefreshGoneUpPartners();
  86. RefreshAllPartners();
  87. }
  88. #endregion
  89. #region 随从列表
  90. private void InitView()
  91. {
  92. VM.GoneUpList.ListType = EGListType.None;
  93. VM.ParentAllList.ListType = EGListType.Virtual;
  94. }
  95. private void RefreshGoneUpPartners()
  96. {
  97. var list = new List<PartnerListItemData>();
  98. var curPlan = PartnersData.Instance.CurUsePlan;
  99. for (int i = 0; i < PartnersData.GoneUpLimit; i++)
  100. {
  101. var slot = curPlan.GetSlot(i);
  102. list.Add(new PartnerListItemData() { tableId = slot?.sbId ?? 0, type = PartnerListItemType.Up });
  103. }
  104. VM.GoneUpList.BindDatas(list);
  105. }
  106. private void RefreshAllPartners()
  107. {
  108. var table = PartnerTableRepo.GetAll();
  109. var list = new List<PartnerListItemData>();
  110. foreach (var partner in table)
  111. {
  112. list.Add(new PartnerListItemData()
  113. {
  114. tableId = partner.Id,
  115. type = PartnerListItemType.Bag,
  116. });
  117. }
  118. //list.Sort((a,b) =>
  119. //{
  120. // var partnerInfo = PartnersData.Instance.get
  121. //});
  122. //.Sort((a, b) =>
  123. //{
  124. // // 已上阵的排前面
  125. // var result = b.state - a.state;
  126. // if (result != 0)
  127. // return result;
  128. // // id小的排前面
  129. // return a.tableId - b.tableId;
  130. //});
  131. VM.ParentAllList.BindDatas(list);
  132. }
  133. #endregion
  134. private void ShowLineupPlanNested()
  135. {
  136. VM.SwitchPlan.selectedIndex = _bShowLineupPlanNested ? 1 : 0;
  137. if (_bShowLineupPlanNested)
  138. {
  139. VM.LineupPlanNested.Ctrl.ShowUI();
  140. }
  141. }
  142. /// <summary>
  143. /// 圣兵待下阵监听事件
  144. /// </summary>
  145. /// <param name="eventId"></param>
  146. /// <param name="args"></param>
  147. private void WaitForDownPartner(int eventId, object args)
  148. {
  149. PartnersData.Instance.IsWaitForDownState = (bool)args;
  150. VM.UpPartner.selectedIndex = PartnersData.Instance.IsWaitForDownState ? 1 : 0;
  151. }
  152. }
  153. }