PartnerMainPanelCtrl.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using System.Text;
  8. using FairyGUI;
  9. using FL.Data;
  10. using XGame;
  11. using XGame.Database;
  12. using XGame.Framework.UI;
  13. using XGame.Framework.Utils;
  14. namespace FL.FGUI
  15. {
  16. /// <summary>
  17. /// UI逻辑处理类
  18. /// </summary>
  19. /// <typeparam name=""></typeparam>
  20. public partial class PartnerMainPanelCtrl : UIController<PartnerMainPanelVM>
  21. {
  22. #region 属性
  23. private bool _showPlanSwitch = false;
  24. private bool _initView = false;
  25. private Controller _switchBtnCtrl;
  26. #endregion
  27. protected override void OnEnable(object intent)
  28. {
  29. AddUIListenres();
  30. AddEventListenres();
  31. InitView();
  32. UpView();
  33. }
  34. protected override void OnDisable()
  35. {
  36. RemoveUIListenres();
  37. RemoveEventListenres();
  38. ClearView();
  39. }
  40. #region UI事件
  41. private void AddUIListenres()
  42. {
  43. VM.OneKeyUpBtn.onClick.Add(OnClickOneKeyUpBtn);
  44. VM.OneKeyStrongBtn.onClick.Add(OnClickOneKeyStrongBtn);
  45. VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
  46. VM.MaskBtn.onClick.Add(OnClickMaskBtn);
  47. }
  48. private void RemoveUIListenres()
  49. {
  50. VM.OneKeyUpBtn.onClick.Remove(OnClickOneKeyUpBtn);
  51. VM.OneKeyStrongBtn.onClick.Remove(OnClickOneKeyStrongBtn);
  52. VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
  53. VM.MaskBtn.onClick.Remove(OnClickMaskBtn);
  54. }
  55. private void OnClickOneKeyUpBtn(EventContext context)
  56. {
  57. PartnersService.Instance.RequestPartnerOneKeyUp();
  58. }
  59. private void OnClickOneKeyStrongBtn(EventContext context)
  60. {
  61. var list = PartnersData.Instance.PartnerList;
  62. var isFind = false;
  63. foreach (var partner in list)
  64. {
  65. var starLvTable = partnerStarUpTableRepo.GetPartnerStarTable(
  66. partner.TableId,
  67. partner.RisingStarLv
  68. );
  69. if (starLvTable == null)
  70. {
  71. Log.Error(
  72. $"圣兵升星表不存在,id:{partner.TableId},starLv:{partner.RisingStarLv}"
  73. );
  74. continue;
  75. }
  76. if (starLvTable.StarUpCost <= ItemData.Instance.GetItemNum(starLvTable.PetId))
  77. {
  78. isFind = true;
  79. break;
  80. }
  81. }
  82. if (isFind)
  83. PartnersService.Instance.RequestPartnerOneKeyStarUp();
  84. else
  85. {
  86. Context.ShowTips(StringDefine.PartnerCantStarUpAll);
  87. }
  88. }
  89. private void OnClickChangeBtn(EventContext context)
  90. {
  91. _showPlanSwitch = !_showPlanSwitch;
  92. if (PartnersData.Instance.UpModeSelect > 0)
  93. {
  94. PartnersService.Instance.FinishUpPartnerMode();
  95. }
  96. ShowPlanNested();
  97. RefreshAllPartners();
  98. }
  99. #endregion
  100. #region 事件监听
  101. private void AddEventListenres()
  102. {
  103. EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnUpdateAll);
  104. EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnUpdateAll);
  105. EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnUpdateAll);
  106. EventSingle.Instance.AddListener(EventDefine.PartnerPlanChange, OnPlanChange);
  107. EventSingle.Instance.AddListener(EventDefine.PartnerStrongAll, OnUpdateAll);
  108. EventSingle.Instance.AddListener(EventDefine.PartnerUpLevel, OnUpdateAll);
  109. EventSingle.Instance.AddListener(EventDefine.PartnerUpStar, OnUpdateAll);
  110. EventSingle.Instance.AddListener(EventDefine.PartnerWearAll, OnUpdateAll);
  111. EventSingle.Instance.AddListener(EventDefine.EpigraphWearAll, OnUpdateAll);
  112. EventSingle.Instance.AddListener(EventDefine.PartnerFinishUpMode, OnFinishUpMode);
  113. EventSingle.Instance.AddListener(EventDefine.PartnerOpenUpMode, OnOpenUpMode);
  114. EventSingle.Instance.AddListener(
  115. EventDefine.PartnerMainSelect,
  116. OnPartnerUpModeSelect
  117. );
  118. EventSingle.Instance.AddListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
  119. EventSingle.Instance.AddListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
  120. EventSingle.Instance.AddListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect);
  121. }
  122. private void RemoveEventListenres()
  123. {
  124. EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnUpdateAll);
  125. EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnUpdateAll);
  126. EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnUpdateAll);
  127. EventSingle.Instance.RemoveListener(EventDefine.PartnerPlanChange, OnPlanChange);
  128. EventSingle.Instance.RemoveListener(EventDefine.PartnerStrongAll, OnUpdateAll);
  129. EventSingle.Instance.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateAll);
  130. EventSingle.Instance.RemoveListener(EventDefine.PartnerUpStar, OnUpdateAll);
  131. EventSingle.Instance.RemoveListener(EventDefine.PartnerWearAll, OnUpdateAll);
  132. EventSingle.Instance.RemoveListener(EventDefine.EpigraphWearAll, OnUpdateAll);
  133. EventSingle.Instance.RemoveListener(EventDefine.PartnerFinishUpMode, OnFinishUpMode);
  134. EventSingle.Instance.RemoveListener(EventDefine.PartnerOpenUpMode, OnOpenUpMode);
  135. EventSingle.Instance.RemoveListener(
  136. EventDefine.PartnerMainSelect,
  137. OnPartnerUpModeSelect
  138. );
  139. EventSingle.Instance.RemoveListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
  140. EventSingle.Instance.RemoveListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
  141. EventSingle.Instance.RemoveListener(EventDefine.EpigraphUpModeSelect, OnEpiUpSelect);
  142. }
  143. private void OnUpdateAll(int eventId, object args)
  144. {
  145. RefreshGoneUpPartners();
  146. RefreshAllPartners();
  147. }
  148. private void OnPlanChange(int eventId, object args)
  149. {
  150. ShowPlanName();
  151. RefreshGoneUpPartners();
  152. RefreshAllPartners();
  153. }
  154. private void OnClickMaskBtn(EventContext eventContext)
  155. {
  156. PartnersService.Instance.FinishUpPartnerMode();
  157. }
  158. private void OnPartnerUpModeSelect(int eventId, object args)
  159. {
  160. if (args is not int pos)
  161. return;
  162. if (PartnersData.Instance.UpModeSelect > 0)
  163. {
  164. PartnersService.Instance.RequestPartnerUp(pos, PartnersData.Instance.UpModeSelect);
  165. }
  166. }
  167. private void OnEpiUpSelect(int eventId, object args)
  168. {
  169. var sbId = (int)args;
  170. if (EpigraphData.Instance.UpModeSelect > 0)
  171. {
  172. EpigraphService.Instance.RequestEpiInset(sbId, EpigraphData.Instance.UpModeSelect);
  173. }
  174. }
  175. /// <summary>
  176. /// 圣兵上阵打开事件
  177. /// </summary>
  178. /// <param name="eventId"></param>
  179. /// <param name="args"></param>
  180. private void OnOpenUpMode(int eventId, object args)
  181. {
  182. if (_showPlanSwitch)
  183. {
  184. _showPlanSwitch = false;
  185. ShowPlanNested();
  186. RefreshAllPartners();
  187. }
  188. ShowUpMode();
  189. }
  190. private void OnFinishUpMode(int eventId, object args)
  191. {
  192. ShowUpMode();
  193. }
  194. #endregion
  195. #region 页面
  196. private void InitView()
  197. {
  198. if (_initView)
  199. return;
  200. VM.UpList.ListType = EGListType.None;
  201. VM.ParentAllList.ListType = EGListType.Virtual;
  202. _switchBtnCtrl = VM.ChangeBtn.GetController("arr");
  203. }
  204. private void ClearView()
  205. {
  206. PartnersService.Instance.FinishUpPartnerMode();
  207. EpigraphService.Instance.FinishUpMode();
  208. _showPlanSwitch = false;
  209. VM.PlanNested.Disable();
  210. }
  211. private void UpView()
  212. {
  213. ShowPlanName();
  214. RefreshGoneUpPartners();
  215. RefreshAllPartners();
  216. ShowPlanNested();
  217. ShowUpMode();
  218. }
  219. private void RefreshGoneUpPartners()
  220. {
  221. var plan = PartnersData.Instance.CurUsePlan;
  222. var list = new List<int>();
  223. for (int i = 0; i < PartnersData.GoneUpLimit; i++)
  224. {
  225. list.Add(i);
  226. }
  227. VM.UpList.BindDatas(list);
  228. }
  229. private void ShowPlanName()
  230. {
  231. var plan = PartnersData.Instance.CurUsePlan;
  232. VM.PlanLabel.text = plan.Name;
  233. }
  234. private void RefreshAllPartners()
  235. {
  236. if (VM.SwitchPlan.selectedIndex == 1)
  237. return;
  238. var table = PartnerTableRepo.GetAll();
  239. var list = new List<int>();
  240. foreach (var partner in table)
  241. {
  242. list.Add(partner.Id);
  243. }
  244. list.Sort(
  245. (a, b) =>
  246. {
  247. return a - b;
  248. }
  249. );
  250. //已上阵的排最前,已拥有其次,未解锁排最后,
  251. //已拥有的的等级高的排前面,
  252. //未解锁的根据id排序
  253. list.Sort(
  254. (a, b) =>
  255. {
  256. PartnersData.Instance.TryGetPartnerAttrByTableId(a, out var aAttr);
  257. PartnersData.Instance.TryGetPartnerAttrByTableId(b, out var bAttr);
  258. if (aAttr != null && bAttr != null)
  259. {
  260. if (aAttr.Status != bAttr.Status)
  261. {
  262. return bAttr.Status - aAttr.Status;
  263. }
  264. else if (bAttr.Level != aAttr.Level)
  265. {
  266. return bAttr.Level - aAttr.Level;
  267. }
  268. }
  269. else if (aAttr == null && bAttr != null)
  270. {
  271. return 1;
  272. }
  273. else if (aAttr != null && bAttr == null)
  274. {
  275. return -1;
  276. }
  277. return b - a;
  278. }
  279. );
  280. VM.ParentAllList.BindDatas(list);
  281. ShowOwnerAttr();
  282. }
  283. private void ShowUpMode()
  284. {
  285. if (PartnersData.Instance.UpModeSelect > 0)
  286. {
  287. VM.UpPartner.selectedIndex = 1;
  288. }
  289. else if (EpigraphData.Instance.UpModeSelect > 0)
  290. {
  291. VM.UpPartner.selectedIndex = 1;
  292. }
  293. else
  294. {
  295. VM.UpPartner.selectedIndex = 0;
  296. }
  297. }
  298. #endregion
  299. private void ShowPlanNested()
  300. {
  301. VM.SwitchPlan.selectedIndex = _showPlanSwitch ? 1 : 0;
  302. _switchBtnCtrl.selectedIndex = _showPlanSwitch ? 1 : 0;
  303. if (_showPlanSwitch)
  304. {
  305. VM.PlanNested.Enable(null);
  306. VM.PlanNested.Ctrl.ShowUI();
  307. }
  308. else
  309. {
  310. VM.PlanNested.Disable();
  311. }
  312. }
  313. public void ShowOwnerAttr()
  314. {
  315. var list = PartnersData.Instance.PartnerList;
  316. var map = new Dictionary<int, int>();
  317. foreach (var partner in list)
  318. {
  319. partnerStarUpTable starTable = partnerStarUpTableRepo.GetPartnerStarTable(
  320. partner.TableId,
  321. partner.RisingStarLv
  322. );
  323. if (starTable == null)
  324. {
  325. Log.Error(
  326. $"圣兵升星表不存在id:{partner.TableId}, starLv:{partner.RisingStarLv}"
  327. );
  328. continue;
  329. }
  330. var attrsArray = starTable.StarOwnAttr;
  331. if (attrsArray?.Length > 0)
  332. {
  333. for (int i = 0; i < attrsArray.Length; i += 2)
  334. {
  335. if (map.TryGetValue(attrsArray[i], out var attr))
  336. {
  337. map.Remove(attrsArray[i]);
  338. map.Add(attrsArray[i], attr + attrsArray[i + 1]);
  339. }
  340. else
  341. {
  342. map.Add(attrsArray[i], attrsArray[i + 1]);
  343. }
  344. }
  345. }
  346. }
  347. if (map.Count > 0)
  348. {
  349. var desc = StringBuilderUtils.Acquire();
  350. int index = 0;
  351. foreach (var pair in map)
  352. {
  353. if (index > 0)
  354. {
  355. desc.Append(",");
  356. index++;
  357. }
  358. GetAttributeDesc(pair.Key, pair.Value, ref desc);
  359. }
  360. VM.AttrLabel.text = desc.ToString();
  361. VM.HaveLabel.visible = true;
  362. VM.AttrLabel.visible = true;
  363. }
  364. else
  365. {
  366. VM.HaveLabel.visible = false;
  367. VM.AttrLabel.visible = false;
  368. }
  369. }
  370. private void GetAttributeDesc(int attrType, int attrValue, ref StringBuilder desc)
  371. {
  372. var attributeInfo = AttrDescTableRepo.Get(attrType);
  373. string valStr = attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
  374. desc.Append(attributeInfo?.ShowName);
  375. desc.Append(valStr);
  376. desc.Append("%");
  377. }
  378. }
  379. }