PartnerEpiChangePanelCtrl.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 && PartnersData.Instance.UsePlanId == _planId)
  66. {
  67. Context.UI.OpenAsync(UIKeys.PartnerEpiDetailInfo, _curSelectId);
  68. Context.ClosePanel();
  69. return;
  70. }
  71. _curSelectId = id;
  72. RefreshList();
  73. }
  74. private void OnClickUpBtn(EventContext eventContext)
  75. {
  76. var id = _curSelectId;
  77. if (_planId == PartnersData.Instance.UsePlanId)
  78. {
  79. if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_sbId, out var info))
  80. {
  81. Context.ShowTips(StringDefine.PartnerEmptyTips);
  82. return;
  83. }
  84. if (id == info.EpigraphId)
  85. return;
  86. EpigraphService.Instance.RequestEpiInset(_sbId, id);
  87. Context.ClosePanel();
  88. }
  89. else if (_planId >= 0 && _slotId >= 0 && _sbId > 0)
  90. {
  91. var plan = PartnersData.Instance.GetPlanById(_planId);
  92. foreach (var slot in plan.PlanValues)
  93. {
  94. if (slot.MwId == id)
  95. {
  96. Context.ShowTips(StringDefine.EpigraphAlreadyUpTips);
  97. return;
  98. }
  99. }
  100. PartnersService.Instance.RequestUpdatePlanMw(_planId, _slotId, _sbId, id);
  101. Context.ClosePanel();
  102. }
  103. }
  104. #endregion
  105. #region 属性
  106. private bool _isInit = false;
  107. /// <summary>
  108. /// 圣兵id
  109. /// </summary>
  110. private int _sbId;
  111. private int _planId;
  112. private int _slotId;
  113. private List<EpiChangeListData> _list;
  114. private int _curSelectId;
  115. #endregion
  116. #region 页面
  117. private void InitView()
  118. {
  119. if (_isInit)
  120. return;
  121. _isInit = true;
  122. VM.List.ListType = EGListType.Virtual;
  123. }
  124. private void UpView()
  125. {
  126. var epiList = EpigraphData.Instance.EpiList;
  127. var list = new List<EpiChangeListData>();
  128. foreach (var epi in epiList)
  129. {
  130. list.Add(new EpiChangeListData(_planId, _sbId, epi.TableId));
  131. }
  132. _list = list;
  133. var slot = PartnersData.Instance.GetPlanSlot(_planId, _slotId);
  134. if (_planId == PartnersData.Instance.UsePlanId)
  135. {
  136. if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_sbId, out var attr))
  137. {
  138. Log.Error($"圣兵数据不存在,id:{_sbId}");
  139. return;
  140. }
  141. if (attr.EpigraphId > 0)
  142. {
  143. _curSelectId = attr.EpigraphId;
  144. }
  145. else
  146. {
  147. _curSelectId = epiList[0].TableId;
  148. }
  149. }
  150. else
  151. {
  152. if (slot == null || slot.MwId == 0)
  153. {
  154. _curSelectId = epiList[0].TableId;
  155. }
  156. else
  157. {
  158. _curSelectId = slot.MwId;
  159. }
  160. }
  161. VM.List.BindDatas(list);
  162. }
  163. private void RefreshList()
  164. {
  165. var epiList = EpigraphData.Instance.EpiList;
  166. var list = new List<EpiChangeListData>();
  167. foreach (var epi in epiList)
  168. {
  169. list.Add(new EpiChangeListData(_planId, _sbId, epi.TableId));
  170. }
  171. _list = list;
  172. VM.List.BindDatas(list);
  173. }
  174. #endregion
  175. }
  176. }