PartnerEpiChangePanelCtrl.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 PartnerEpiChangePanelCtrlParam
  14. {
  15. public int SbId;
  16. /// <summary>
  17. /// 方案id
  18. /// </summary>
  19. public int PlanId;
  20. /// <summary>
  21. /// 方案内槽位,如果有planId则必填
  22. /// </summary>
  23. public int SlotId;
  24. }
  25. /// <summary>
  26. /// UI逻辑处理类
  27. /// </summary>
  28. /// <typeparam name=""></typeparam>
  29. public partial class PartnerEpiChangePanelCtrl : UIController<PartnerEpiChangePanelVM>
  30. {
  31. protected override void OnEnable(object intent)
  32. {
  33. var param = intent as PartnerEpiChangePanelCtrlParam;
  34. _sbId = param.SbId;
  35. _planId = param.PlanId;
  36. _slotId = param.SlotId;
  37. AddUIListenres();
  38. InitView();
  39. UpView();
  40. }
  41. protected override void OnDisable()
  42. {
  43. RemoveUIListenres();
  44. }
  45. #region UI事件
  46. private void AddUIListenres()
  47. {
  48. EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnUpdateList);
  49. EventSingle.Instance.AddListener(EventDefine.EpigraphChangeSelect, OnClickItem);
  50. VM.UpBtn.onClick.Add(OnClickUpBtn);
  51. }
  52. private void RemoveUIListenres()
  53. {
  54. EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnUpdateList);
  55. EventSingle.Instance.RemoveListener(EventDefine.EpigraphChangeSelect, OnClickItem);
  56. VM.UpBtn.onClick.Remove(OnClickUpBtn);
  57. }
  58. private void OnUpdateList(int eventId, object args)
  59. {
  60. RefreshList();
  61. }
  62. private void OnClickItem(int eventId, object args)
  63. {
  64. var id = (int)args;
  65. if (id == _curSelectId)
  66. {
  67. Context.UI.OpenAsync(
  68. UIKeys.PartnerEpiDetailInfo,
  69. new PartnerEpiDetailInfoParam()
  70. {
  71. EpigraphId = _curSelectId,
  72. PlanId = _planId,
  73. SlotId = _slotId,
  74. PartnerId = _sbId,
  75. }
  76. );
  77. Context.ClosePanel();
  78. return;
  79. }
  80. _curSelectId = id;
  81. RefreshList();
  82. }
  83. private void OnClickUpBtn(EventContext eventContext)
  84. {
  85. var id = _curSelectId;
  86. if (_planId == PartnersData.Instance.UsePlanId)
  87. {
  88. if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_sbId, out var info))
  89. {
  90. Context.ShowTips(StringDefine.PartnerEmptyTips);
  91. return;
  92. }
  93. if (id == info.EpigraphId)
  94. return;
  95. EpigraphService.Instance.RequestEpiInset(_sbId, id);
  96. Context.ClosePanel();
  97. }
  98. else if (_planId >= 0 && _slotId >= 0 && _sbId > 0)
  99. {
  100. var plan = PartnersData.Instance.GetPlanById(_planId);
  101. foreach (var slot in plan.Slots)
  102. {
  103. if (slot.MwId == id)
  104. {
  105. Context.ShowTips(StringDefine.EpigraphAlreadyUpTips);
  106. return;
  107. }
  108. }
  109. PartnersService.Instance.RequestUpdatePlanMw(_planId, _slotId, _sbId, id);
  110. Context.ClosePanel();
  111. }
  112. }
  113. #endregion
  114. #region 属性
  115. private bool _isInit = false;
  116. /// <summary>
  117. /// 圣兵id
  118. /// </summary>
  119. private int _sbId;
  120. private int _planId;
  121. private int _slotId;
  122. private List<EpiChangeListData> _list;
  123. private int _curSelectId;
  124. #endregion
  125. #region 页面
  126. private void InitView()
  127. {
  128. if (_isInit)
  129. return;
  130. _isInit = true;
  131. VM.List.ListType = EGListType.Virtual;
  132. }
  133. private void UpView()
  134. {
  135. var epiList = EpigraphData.Instance.EpiList;
  136. if (_slotId < 0)
  137. {
  138. if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_sbId, out var attr))
  139. {
  140. Log.Error($"圣兵数据不存在,id:{_sbId}");
  141. return;
  142. }
  143. if (attr.EpigraphId > 0)
  144. {
  145. _curSelectId = attr.EpigraphId;
  146. }
  147. else
  148. {
  149. _curSelectId = epiList[0].TableId;
  150. }
  151. }
  152. else
  153. {
  154. var slot = PartnersData.Instance.GetPlanSlot(_planId, _slotId);
  155. if (slot == null || slot.MwId == 0)
  156. {
  157. _curSelectId = epiList[0].TableId;
  158. }
  159. else
  160. {
  161. _curSelectId = slot.MwId;
  162. }
  163. }
  164. var list = new List<EpiChangeListData>();
  165. _list = list;
  166. foreach (var epi in epiList)
  167. {
  168. list.Add(new EpiChangeListData(_planId, _sbId, epi.TableId, _curSelectId));
  169. }
  170. VM.List.BindDatas(list);
  171. }
  172. private void RefreshList()
  173. {
  174. var epiList = EpigraphData.Instance.EpiList;
  175. var list = new List<EpiChangeListData>();
  176. foreach (var epi in epiList)
  177. {
  178. list.Add(new EpiChangeListData(_planId, _sbId, epi.TableId, _curSelectId));
  179. }
  180. _list = list;
  181. VM.List.BindDatas(list);
  182. }
  183. #endregion
  184. }
  185. }