PartnerReplacePartnerPanelCtrl.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using FairyGUI;
  8. using FL.Data;
  9. using XGame;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. public class PartnerReplacePartnerPanelCtrlParam
  14. {
  15. public int PlanId;
  16. public int SlotId;
  17. }
  18. /// <summary>
  19. /// UI逻辑处理类
  20. /// </summary>
  21. /// <typeparam name=""></typeparam>
  22. public partial class PartnerReplacePartnerPanelCtrl
  23. : UIController<PartnerReplacePartnerPanelVM>,
  24. IPartnerReplacePanelCtrl
  25. {
  26. private int _planId;
  27. private int _slotId;
  28. private int _curSelectId;
  29. public int PlanId => _planId;
  30. public int SlotId => _slotId;
  31. public int CurSelectId => _curSelectId;
  32. protected override void OnEnable(object intent)
  33. {
  34. AddUIListenres();
  35. AddEventListener();
  36. ShowUI(intent as PartnerReplacePartnerPanelCtrlParam);
  37. }
  38. protected override void OnDisable()
  39. {
  40. RemoveUIListenres();
  41. RemoveEventListener();
  42. }
  43. #region UI事件
  44. private void AddUIListenres()
  45. {
  46. VM.UpBtn.onClick.Add(OnClickUpPartner);
  47. }
  48. private void RemoveUIListenres()
  49. {
  50. VM.UpBtn.onClick.Remove(OnClickUpPartner);
  51. }
  52. private void OnClickUpPartner(EventContext context)
  53. {
  54. if (_curSelectId <= 0)
  55. {
  56. Log.Error("当前选择圣兵id为0");
  57. return;
  58. }
  59. var plan = PartnersData.Instance.GetPlanById(_planId);
  60. if (plan == null)
  61. {
  62. Log.Error($"方案信息不存在id: {_planId}");
  63. return;
  64. }
  65. foreach (var slot in plan.Slots)
  66. {
  67. if (slot.SbId == CurSelectId)
  68. {
  69. Context.ShowTips(StringDefine.PartnerAlreadyUpTips);
  70. return;
  71. }
  72. }
  73. Context.ClosePanel();
  74. if (_planId == PartnersData.Instance.UsePlanId)
  75. {
  76. PartnersService.Instance.RequestPartnerUp(_slotId, _curSelectId);
  77. }
  78. else
  79. {
  80. PartnersService.Instance.RequestUpdatePlanSb(_planId, _slotId, _curSelectId);
  81. }
  82. }
  83. #endregion
  84. private void AddEventListener()
  85. {
  86. EventSingle.Instance.AddListener(
  87. EventDefine.PartnerSelectReplace,
  88. SelectReplacePartner
  89. );
  90. EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnInfoUpdate);
  91. EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnInfoUpdate);
  92. EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnInfoUpdate);
  93. EventSingle.Instance.AddListener(EventDefine.PartnerUpdatePlan, OnInfoUpdate);
  94. }
  95. private void RemoveEventListener()
  96. {
  97. EventSingle.Instance.RemoveListener(
  98. EventDefine.PartnerSelectReplace,
  99. SelectReplacePartner
  100. );
  101. EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnInfoUpdate);
  102. EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnInfoUpdate);
  103. EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnInfoUpdate);
  104. EventSingle.Instance.RemoveListener(EventDefine.PartnerUpdatePlan, OnInfoUpdate);
  105. }
  106. private void OnInfoUpdate(int eventId, object args)
  107. {
  108. UpdateList();
  109. }
  110. private void SelectReplacePartner(int eventId, object args)
  111. {
  112. var id = (int)args;
  113. if (id == _curSelectId)
  114. {
  115. Context.UI.OpenAsync(
  116. UIKeys.PartnerDetailsPanel,
  117. new PartnerDetailsPanelParam()
  118. {
  119. PlanId = _planId,
  120. SlotId = _slotId,
  121. PartnerId = _curSelectId,
  122. }
  123. );
  124. Context.ClosePanel();
  125. return;
  126. }
  127. _curSelectId = id;
  128. UpdateList();
  129. }
  130. private void ShowUI(PartnerReplacePartnerPanelCtrlParam param)
  131. {
  132. _slotId = param.SlotId;
  133. _planId = param.PlanId;
  134. var slot = PartnersData.Instance.GetPlanSlot(_planId, _slotId);
  135. var list = PartnersData.Instance.PartnerList;
  136. if (list.Count <= 0)
  137. {
  138. Log.Error($"圣兵库内不存在圣兵");
  139. return;
  140. }
  141. var sbId = slot?.SbId ?? 0;
  142. _curSelectId = sbId > 0 ? sbId : list[0].TableId;
  143. UpdateList();
  144. }
  145. private void UpdateList()
  146. {
  147. var list = PartnersData.Instance.PartnerList;
  148. var datas = new List<PartnerReplacePartnerListItemCtrlParam>();
  149. foreach (var partner in list)
  150. {
  151. datas.Add(
  152. new PartnerReplacePartnerListItemCtrlParam()
  153. {
  154. PartnerId = partner.TableId,
  155. Ctrl = this,
  156. }
  157. );
  158. }
  159. VM.PartnerList.BindDatas(datas);
  160. }
  161. }
  162. }