PartnerSbStrengthPanelCtrl.cs 8.0 KB

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