PartnerEpiChangePanelCtrl.cs 5.8 KB

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