PartnerMwStrengthPanelCtrl.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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 FL.Data.Items;
  10. using XGame.Database;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUI
  13. {
  14. /// <summary>
  15. /// UI逻辑处理类
  16. /// </summary>
  17. /// <typeparam name=""></typeparam>
  18. public partial class PartnerMwStrengthPanelCtrl : UIController<PartnerMwStrengthPanelVM>
  19. {
  20. protected override void OnEnable(object intent)
  21. {
  22. AddUIListenres();
  23. InitView();
  24. _curSelectId = (int)intent;
  25. ShowUI();
  26. }
  27. protected override void OnDisable()
  28. {
  29. RemoveUIListenres();
  30. }
  31. #region UI事件
  32. private void AddUIListenres()
  33. {
  34. VM.UpBtn.onClick.Add(OnClickUpBtn);
  35. VM.LeftBtn.onClick.Add(OnClickLeftBtn);
  36. VM.RightBtn.onClick.Add(OnClickRightBtn);
  37. //VM.MwSet.VM.PanelEvent.Add(OnClickMwSet);
  38. VM.StarUpBtn.VM.PanelEvent.Add(OnClickStarUp);
  39. VM.DownBtn.onClick.Add(OnClickDownBtn);
  40. Context.AddListener(EventDefine.EpigraphUpStar, OnUpInfo);
  41. Context.AddListener(EventDefine.PartnerBinding, OnEpiChange);
  42. }
  43. private void RemoveUIListenres()
  44. {
  45. VM.UpBtn.onClick.Remove(OnClickUpBtn);
  46. VM.LeftBtn.onClick.Remove(OnClickLeftBtn);
  47. VM.RightBtn.onClick.Remove(OnClickRightBtn);
  48. //VM.MwSet.VM.PanelEvent.Remove(OnClickMwSet);
  49. VM.StarUpBtn.VM.PanelEvent.Remove(OnClickStarUp);
  50. VM.DownBtn.onClick.Remove(OnClickDownBtn);
  51. Context.RemoveListener(EventDefine.EpigraphUpStar, OnUpInfo);
  52. Context.RemoveListener(EventDefine.PartnerBinding, OnEpiChange);
  53. }
  54. private void OnClickDownBtn(EventContext eventContext)
  55. {
  56. var mwData = EpigraphData.Instance.GetEpigraphAttrByTableId(_curSelectId);
  57. EpigraphService.Instance.RequestEpiInset(mwData.PartnerId, 0);
  58. Context.ClosePanel();
  59. }
  60. public void OnEpiChange(int eventId, object args)
  61. {
  62. ShowUI();
  63. }
  64. private void OnUpInfo(int eventId, object args)
  65. {
  66. ShowInfo();
  67. }
  68. private void OnClickStarUp(EventContext context)
  69. {
  70. var attr = EpigraphData.Instance.GetEpigraphAttrByTableId(_curSelectId);
  71. var star = attr?.StarLv ?? 1;
  72. var starUpTable = epigraphUpTableRepo.GetEpiragphUp(_curSelectId, star);
  73. XGame.Framework.Assert.IsNotNull(
  74. starUpTable,
  75. $"铭文升星表不存在,id:{_curSelectId},starlv:{star}"
  76. );
  77. if (ItemService.Instance.IsEnough(starUpTable.PetId, starUpTable.LevelUpCost, true))
  78. {
  79. EpigraphService.Instance.RequestEpiStarUp(_curSelectId);
  80. }
  81. }
  82. private void OnClickUpBtn(EventContext context)
  83. {
  84. if (PartnersData.Instance.UpSbPosMap.Count <= 0)
  85. {
  86. Context.ShowTips(EStringDefine.PartnerNoUp);
  87. return;
  88. }
  89. EpigraphService.Instance.OpenUpMode(_curSelectId);
  90. Context.UI.Close(UIKeys.PartnerSbBagPanel);
  91. Context.ClosePanel();
  92. }
  93. private void OnClickLeftBtn(EventContext context)
  94. {
  95. OnSelectPartnerOffset(-1);
  96. }
  97. private void OnClickRightBtn(EventContext context)
  98. {
  99. OnSelectPartnerOffset(1);
  100. }
  101. #endregion
  102. private bool _init = false;
  103. private List<int> _mwList = new List<int>();
  104. private int _curSelectId;
  105. private void InitView()
  106. {
  107. if (_init)
  108. return;
  109. _init = true;
  110. var tableList = EpigraphTableRepo.GetAll();
  111. foreach (var item in tableList)
  112. {
  113. _mwList.Add(item.Id);
  114. }
  115. }
  116. private void ShowUI()
  117. {
  118. ShowInfo();
  119. ShowSb();
  120. }
  121. private void ShowInfo()
  122. {
  123. var table = EpigraphTableRepo.Get(_curSelectId);
  124. XGame.Framework.Assert.IsNotNull(table, $"铭文表不存在,id:{_curSelectId}");
  125. VM.NameLabel.text = table.Name;
  126. VM.MwBase.Ctrl.SetEpiIcon(_curSelectId);
  127. var mwData = EpigraphData.Instance.GetEpigraphAttrByTableId(table.Id);
  128. var star = mwData?.StarLv ?? 1;
  129. if (mwData == null)
  130. {
  131. VM.StarUpBtn.Disable();
  132. VM.Have.selectedIndex = 1;
  133. }
  134. else
  135. {
  136. if (epigraphUpTableRepo.GetEpiragphUp(_curSelectId, star + 1) == null)
  137. {
  138. VM.StarUpBtn.Disable();
  139. }
  140. else
  141. {
  142. VM.StarUpBtn.Enable(null);
  143. }
  144. VM.Have.selectedIndex = 0;
  145. var sbId = mwData?.PartnerId ?? 0;
  146. VM.IsUp.selectedIndex = sbId <= 0 ? 0 : 1;
  147. }
  148. ShowStar(star);
  149. VM.DetailNested.Ctrl.ShowUI(_curSelectId);
  150. if (mwData != null)
  151. {
  152. ShowUpBtn(mwData.TableId);
  153. }
  154. }
  155. private void ShowStar(int starLv)
  156. {
  157. var curNum = PartnersService.Instance.GetStarLv(starLv);
  158. var curStep = PartnersService.Instance.GetStarStep(starLv);
  159. var list = new List<int>();
  160. for (int i = 0; i < curNum; i++)
  161. {
  162. list.Add(curStep);
  163. }
  164. VM.StarList.BindDatas(list);
  165. }
  166. private void ShowSb()
  167. {
  168. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_curSelectId);
  169. if (info == null)
  170. {
  171. VM.SbSetItem.Disable();
  172. }
  173. else
  174. {
  175. if (info.PartnerId > 0)
  176. {
  177. var data = ItemBase.Create(info.PartnerId);
  178. VM.SbSetItem.Enable(null);
  179. VM.SbSetItem.VM.ItemBase.Ctrl.ShowUI(data);
  180. }
  181. else
  182. {
  183. VM.SbSetItem.VM.ItemBase.Ctrl.ShowEmptyUI();
  184. }
  185. }
  186. }
  187. private void ShowUpBtn(int sbId)
  188. {
  189. VM.StarUpBtn.Ctrl.SetData(sbId);
  190. }
  191. private void OnSelectPartnerOffset(int offset)
  192. {
  193. var index = _mwList.IndexOf(_curSelectId);
  194. index += offset;
  195. if (index < 0)
  196. {
  197. index += _mwList.Count;
  198. }
  199. else if (index >= _mwList.Count)
  200. {
  201. index -= _mwList.Count;
  202. }
  203. _curSelectId = _mwList[index];
  204. ShowUI();
  205. }
  206. }
  207. }