PartnerSbStrengthPanelCtrl.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. /// <summary>
  14. /// UI逻辑处理类
  15. /// </summary>
  16. /// <typeparam name=""></typeparam>
  17. public partial class PartnerSbStrengthPanelCtrl : UIController<PartnerSbStrengthPanelVM>
  18. {
  19. protected override void OnEnable(object intent)
  20. {
  21. AddUIListenres();
  22. InitView();
  23. _curSelectId = (int)intent;
  24. ShowUI();
  25. }
  26. protected override void OnDisable()
  27. {
  28. RemoveUIListenres();
  29. }
  30. #region UI事件
  31. private void AddUIListenres()
  32. {
  33. VM.UpBtn.onClick.Add(OnClickUpBtn);
  34. VM.LeftBtn.onClick.Add(OnClickLeftBtn);
  35. VM.RightBtn.onClick.Add(OnClickRightBtn);
  36. VM.MwSet.VM.PanelEvent.Add(OnClickMwSet);
  37. VM.StarUpBtn.VM.PanelEvent.Add(OnClickStarUp);
  38. VM.LevelUpBtn.VM.PanelEvent.Add(OnClickLevelUp);
  39. VM.DownBtn.onClick.Add(OnClickDownBtn);
  40. Context.AddListener(EventDefine.PartnerUpLevel, OnUpInfo);
  41. Context.AddListener(EventDefine.PartnerUpStar, OnUpInfo);
  42. Context.AddListener(EventDefine.PartnerBinding, OnEpiChange);
  43. }
  44. private void RemoveUIListenres()
  45. {
  46. VM.UpBtn.onClick.Remove(OnClickUpBtn);
  47. VM.LeftBtn.onClick.Remove(OnClickLeftBtn);
  48. VM.RightBtn.onClick.Remove(OnClickRightBtn);
  49. VM.MwSet.VM.PanelEvent.Remove(OnClickMwSet);
  50. VM.StarUpBtn.VM.PanelEvent.Remove(OnClickStarUp);
  51. VM.LevelUpBtn.VM.PanelEvent.Remove(OnClickLevelUp);
  52. VM.DownBtn.onClick.Remove(OnClickDownBtn);
  53. Context.RemoveListener(EventDefine.PartnerUpLevel, OnUpInfo);
  54. Context.RemoveListener(EventDefine.PartnerUpStar, OnUpInfo);
  55. Context.RemoveListener(EventDefine.PartnerBinding, OnEpiChange);
  56. }
  57. private void OnClickDownBtn(EventContext eventContext)
  58. {
  59. PartnersService.Instance.RequestPartnerDownNew(_curSelectId);
  60. Context.ClosePanel();
  61. }
  62. public void OnEpiChange(int eventId, object args)
  63. {
  64. ShowEpi();
  65. }
  66. private void OnUpInfo(int eventId, object args)
  67. {
  68. ShowInfo();
  69. }
  70. private void OnClickLevelUp()
  71. {
  72. var attr = PartnersData.Instance.GetPartnerAttrByTableId(_curSelectId);
  73. var level = attr?.Level ?? 1;
  74. var upLevelTable = partnerLvUpTableRepo.GetPartnerLvUpTable(_curSelectId, level);
  75. XGame.Framework.Assert.IsNotNull(
  76. upLevelTable,
  77. $"圣兵升级表不存在,id:{_curSelectId},level:{level}"
  78. );
  79. if (
  80. ItemService.Instance.IsEnough(
  81. upLevelTable.LevelUpCost[0],
  82. upLevelTable.LevelUpCost[1],
  83. true
  84. )
  85. )
  86. {
  87. PartnersService.Instance.RequestLvUp(_curSelectId);
  88. }
  89. }
  90. private void OnClickStarUp(EventContext context)
  91. {
  92. var attr = PartnersData.Instance.GetPartnerAttrByTableId(_curSelectId);
  93. var star = attr?.RisingStarLv ?? 1;
  94. var starUpTable = partnerStarUpTableRepo.GetPartnerStarTable(_curSelectId, star);
  95. XGame.Framework.Assert.IsNotNull(
  96. starUpTable,
  97. $"圣兵升星表不存在,id:{_curSelectId},starlv:{star}"
  98. );
  99. if (ItemService.Instance.IsEnough(starUpTable.PetId, starUpTable.StarUpCost, true))
  100. {
  101. PartnersService.Instance.RequestStarUp(_curSelectId);
  102. }
  103. }
  104. private void OnClickUpBtn(EventContext context)
  105. {
  106. PartnersService.Instance.OpenUpPartnerMode(_curSelectId);
  107. Context.UI.Close(UIKeys.PartnerSbBagPanel);
  108. Context.ClosePanel();
  109. }
  110. private void OnClickLeftBtn(EventContext context)
  111. {
  112. OnSelectPartnerOffset(-1);
  113. }
  114. private void OnClickRightBtn(EventContext context)
  115. {
  116. OnSelectPartnerOffset(1);
  117. }
  118. private void OnClickMwSet(EventContext context)
  119. {
  120. Context.UI.OpenAsync(
  121. UIKeys.PartnerEpiChangePanel,
  122. new PartnerEpiChangePanelCtrlParam() { SbId = _curSelectId }
  123. );
  124. }
  125. #endregion
  126. private bool _init = false;
  127. private List<int> _sbList = new List<int>();
  128. private int _curSelectId;
  129. private void InitView()
  130. {
  131. if (_init)
  132. return;
  133. _init = true;
  134. var tableList = PartnerTableRepo.GetAll();
  135. foreach (var item in tableList)
  136. {
  137. _sbList.Add(item.Id);
  138. }
  139. }
  140. private void ShowUI()
  141. {
  142. ShowInfo();
  143. ShowEpi();
  144. }
  145. private void ShowInfo()
  146. {
  147. var table = PartnerTableRepo.Get(_curSelectId);
  148. XGame.Framework.Assert.IsNotNull(table, $"圣兵表不存在,id:{_curSelectId}");
  149. VM.NameLabel.text = table.Name;
  150. VM.PictureLoader.url = AddressableDefine.PartnerPicture(table.Id);
  151. var attr = PartnersData.Instance.GetPartnerAttrByTableId(table.Id);
  152. var level = attr == null ? 1 : attr.Level;
  153. var star = attr == null ? 1 : attr.RisingStarLv;
  154. if (attr == null)
  155. {
  156. VM.StarUpBtn.Disable();
  157. VM.LevelUpBtn.Disable();
  158. VM.Have.selectedIndex = 1;
  159. }
  160. else
  161. {
  162. if (partnerStarUpTableRepo.GetPartnerStarTable(_curSelectId, star + 1) == null)
  163. {
  164. VM.StarUpBtn.Disable();
  165. }
  166. else
  167. {
  168. VM.StarUpBtn.Enable(null);
  169. }
  170. if (partnerLvUpTableRepo.GetPartnerLvUpTable(_curSelectId, level + 1) == null)
  171. {
  172. VM.LevelUpBtn.Disable();
  173. }
  174. else
  175. {
  176. VM.LevelUpBtn.Enable(null);
  177. }
  178. VM.Have.selectedIndex = 0;
  179. var pos = PartnersData.Instance.UpSbPosMap.GetValueOrDefault(_curSelectId, -1);
  180. VM.IsUp.selectedIndex = pos < 0 ? 0 : 1;
  181. }
  182. ShowStar(star);
  183. VM.LvLabel.text = $"Lv {level}";
  184. VM.DetailNested.Ctrl.ShowUI(_curSelectId);
  185. if (attr != null)
  186. {
  187. ShowUpBtn(attr.TableId);
  188. }
  189. }
  190. private void ShowStar(int starLv)
  191. {
  192. var curNum = PartnersService.Instance.GetStarLv(starLv);
  193. var curStep = PartnersService.Instance.GetStarStep(starLv);
  194. var list = new List<int>();
  195. for (int i = 0; i < curNum; i++)
  196. {
  197. list.Add(curStep);
  198. }
  199. VM.StarList.BindDatas(list);
  200. }
  201. private void ShowEpi()
  202. {
  203. var info = PartnersData.Instance.GetPartnerAttrByTableId(_curSelectId);
  204. if (info == null)
  205. {
  206. VM.MwSet.Disable();
  207. }
  208. else
  209. {
  210. VM.MwSet.Enable(null);
  211. VM.MwSet.Ctrl.SetData(info.EpigraphId, _curSelectId, true);
  212. }
  213. }
  214. private void ShowUpBtn(int sbId)
  215. {
  216. VM.StarUpBtn.Ctrl.SetData(sbId);
  217. VM.LevelUpBtn.Ctrl.ShowUI(sbId);
  218. }
  219. private void OnSelectPartnerOffset(int offset)
  220. {
  221. var index = _sbList.IndexOf(_curSelectId);
  222. index += offset;
  223. if (index < 0)
  224. {
  225. index += _sbList.Count;
  226. }
  227. else if (index >= _sbList.Count)
  228. {
  229. index -= _sbList.Count;
  230. }
  231. _curSelectId = _sbList[index];
  232. ShowUI();
  233. }
  234. }
  235. }