PartnerSbMainPanelCtrl.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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 PartnerSbMainPanelCtrl : UIController<PartnerSbMainPanelVM>
  18. {
  19. protected override void OnEnable(object intent)
  20. {
  21. AddUIListenres();
  22. InitView();
  23. ShowUI();
  24. }
  25. protected override void OnDisable()
  26. {
  27. RemoveUIListenres();
  28. clearUpMode();
  29. }
  30. #region UI事件
  31. private void AddUIListenres()
  32. {
  33. VM.ReplaceBtn.onClick.Add(OnClickReplaceBtn);
  34. VM.StrengthBtn.onClick.Add(OnClickStrengthBtn);
  35. VM.OneUpBtn.onClick.Add(OnClickOneUpBtn);
  36. VM.RecommendBtn.onClick.Add(OnClickRecommendBtn);
  37. //VM.BagBtn.onClick.Add(OnClickBagBtn);
  38. VM.SbBagBtn.onClick.Add(OnClickSbBagBtn);
  39. VM.MwBagBtn.onClick.Add(OnClickMwBagBtn);
  40. VM.ConfirmBtn.onClick.Add(OnClickConfirmBtn);
  41. VM.CancelBtn.onClick.Add(OnClickCancelBtn);
  42. Context.AddListener(EventDefine.PartnerFinishUpMode, OnFinishUpMode);
  43. Context.AddListener(EventDefine.PartnerOpenUpMode, OnOpenUpMode);
  44. Context.AddListener(EventDefine.PartnerMainSbSelect, OnSelectSb);
  45. Context.AddListener(EventDefine.PartnerUpLevel, OnUpLevel);
  46. Context.AddListener(EventDefine.PartnerUpStar, OnUpStar);
  47. Context.AddListener(EventDefine.PartnerDown, OnSbUp);
  48. Context.AddListener(EventDefine.PartnerUp, OnSbUp);
  49. Context.AddListener(EventDefine.PartnerWearAll, OnSbUp);
  50. Context.AddListener(EventDefine.PartnerBinding, OnSbUp);
  51. Context.AddListener(EventDefine.PartnerMainMwSelect, OnSelectMw);
  52. Context.AddListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
  53. Context.AddListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
  54. Context.AddListener(EventDefine.EpigraphWearAll, OnSbUp);
  55. }
  56. private void RemoveUIListenres()
  57. {
  58. VM.ReplaceBtn.onClick.Remove(OnClickReplaceBtn);
  59. VM.StrengthBtn.onClick.Remove(OnClickStrengthBtn);
  60. VM.OneUpBtn.onClick.Remove(OnClickOneUpBtn);
  61. VM.RecommendBtn.onClick.Remove(OnClickRecommendBtn);
  62. //VM.BagBtn.onClick.Remove(OnClickBagBtn);
  63. VM.SbBagBtn.onClick.Remove(OnClickSbBagBtn);
  64. VM.MwBagBtn.onClick.Remove(OnClickMwBagBtn);
  65. VM.ConfirmBtn.onClick.Remove(OnClickConfirmBtn);
  66. VM.CancelBtn.onClick.Remove(OnClickCancelBtn);
  67. Context.RemoveListener(EventDefine.PartnerFinishUpMode, OnFinishUpMode);
  68. Context.RemoveListener(EventDefine.PartnerOpenUpMode, OnOpenUpMode);
  69. Context.RemoveListener(EventDefine.PartnerMainSbSelect, OnSelectSb);
  70. Context.RemoveListener(EventDefine.PartnerUpLevel, OnUpLevel);
  71. Context.RemoveListener(EventDefine.PartnerUpStar, OnUpStar);
  72. Context.RemoveListener(EventDefine.PartnerDown, OnSbUp);
  73. Context.RemoveListener(EventDefine.PartnerUp, OnSbUp);
  74. Context.RemoveListener(EventDefine.PartnerWearAll, OnSbUp);
  75. Context.RemoveListener(EventDefine.PartnerBinding, OnSbUp);
  76. Context.RemoveListener(EventDefine.PartnerMainMwSelect, OnSelectMw);
  77. Context.RemoveListener(EventDefine.EpigraphOpenUpMode, OnOpenUpMode);
  78. Context.RemoveListener(EventDefine.EpigraphFinishUpMode, OnFinishUpMode);
  79. Context.RemoveListener(EventDefine.EpigraphWearAll, OnSbUp);
  80. }
  81. private void OnClickMwBagBtn()
  82. {
  83. Context.UI.OpenAsync(UIKeys.PartnerSbBagPanel, 1);
  84. }
  85. private void OnClickSbBagBtn()
  86. {
  87. Context.UI.OpenAsync(UIKeys.PartnerSbBagPanel, 0);
  88. }
  89. private void OnSelectMw(int eventId, object args)
  90. {
  91. var pos = (int)args;
  92. if (PartnersData.Instance.UpModeSelect > 0)
  93. {
  94. if (_selectType == 0 && pos == _curSelectPos)
  95. return;
  96. _selectType = 0;
  97. _curSelectPos = pos;
  98. RefreshGoneUpPartners(false);
  99. UpdateDetail();
  100. }
  101. else if (EpigraphData.Instance.UpModeSelect > 0)
  102. {
  103. if (_selectType == 1 && pos == _curSelectPos)
  104. return;
  105. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
  106. if (sbId == 0)
  107. {
  108. Context.ShowTips(EStringDefine.PartnerCurSlotNoSbTips);
  109. return;
  110. }
  111. _selectType = 1;
  112. _curSelectPos = pos;
  113. RefreshGoneUpPartners(false);
  114. UpdateDetail();
  115. }
  116. else
  117. {
  118. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(pos, 0);
  119. var sbData = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
  120. var mwId = sbData?.EpigraphId ?? 0;
  121. if (mwId == 0)
  122. {
  123. Context.UI.OpenAsync(UIKeys.PartnerMwUpPanel, sbId);
  124. }
  125. _selectType = 1;
  126. _curSelectPos = pos;
  127. RefreshGoneUpPartners(false);
  128. UpdateDetail();
  129. }
  130. }
  131. private void OnSelectSb(int eventId, object args)
  132. {
  133. var pos = (int)args;
  134. if (PartnersData.Instance.UpModeSelect > 0)
  135. {
  136. if (_selectType == 0 && pos == _curSelectPos)
  137. return;
  138. _selectType = 0;
  139. _curSelectPos = pos;
  140. RefreshGoneUpPartners(false);
  141. UpdateDetail();
  142. }
  143. else if (EpigraphData.Instance.UpModeSelect > 0)
  144. {
  145. if (_selectType == 1 && pos == _curSelectPos)
  146. return;
  147. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
  148. if (sbId == 0)
  149. {
  150. Context.ShowTips(EStringDefine.PartnerCurSlotNoSbTips);
  151. return;
  152. }
  153. _selectType = 1;
  154. _curSelectPos = pos;
  155. RefreshGoneUpPartners(false);
  156. UpdateDetail();
  157. }
  158. else
  159. {
  160. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(pos, 0);
  161. if (sbId == 0)
  162. {
  163. Context.UI.OpenAsync(UIKeys.PartnerSbUpPanel, pos);
  164. }
  165. if (_selectType == 0 && pos == _curSelectPos)
  166. return;
  167. _selectType = 0;
  168. _curSelectPos = pos;
  169. RefreshGoneUpPartners(false);
  170. UpdateDetail();
  171. }
  172. }
  173. private void OnSbUp(int eventId, object args)
  174. {
  175. RefreshGoneUpPartners(false);
  176. UpdateDetail();
  177. }
  178. private void OnUpLevel(int eventId, object args)
  179. {
  180. RefreshGoneUpPartners(false);
  181. UpdateDetail();
  182. }
  183. private void OnUpStar(int eventId, object args)
  184. {
  185. RefreshGoneUpPartners(false);
  186. UpdateDetail();
  187. }
  188. private void OnClickReplaceBtn(EventContext context)
  189. {
  190. if (_selectType == 0)
  191. {
  192. Context.UI.OpenAsync(UIKeys.PartnerSbReplacePanel, _curSelectPos);
  193. }
  194. else
  195. {
  196. Context.UI.OpenAsync(UIKeys.PartnerMwReplacePanel, _curSelectPos);
  197. }
  198. }
  199. private void OnClickStrengthBtn(EventContext context)
  200. {
  201. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
  202. if (sbId <= 0)
  203. {
  204. Context.ShowTips(EStringDefine.PartnerEmptyTips);
  205. return;
  206. }
  207. if (_selectType == 0)
  208. {
  209. Context.UI.OpenAsync(UIKeys.PartnerSbStrengthPanel, sbId);
  210. }
  211. else
  212. {
  213. var sbData = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
  214. Context.UI.OpenAsync(UIKeys.PartnerMwStrengthPanel, sbData.EpigraphId);
  215. }
  216. }
  217. private void OnClickOneUpBtn(EventContext context)
  218. {
  219. if (_selectType == 0)
  220. {
  221. PartnersService.Instance.RequestPartnerOneKeyUp();
  222. }
  223. else
  224. {
  225. EpigraphService.Instance.RequestEpiWearAll();
  226. }
  227. }
  228. private void OnClickRecommendBtn(EventContext context)
  229. {
  230. Context.UI.OpenAsync(UIKeys.PartnerSbRecommendPanel);
  231. }
  232. private void OnClickConfirmBtn(EventContext context)
  233. {
  234. if (PartnersData.Instance.UpModeSelect > 0)
  235. {
  236. PartnersService.Instance.RequestPartnerUpNew(
  237. _curSelectPos,
  238. PartnersData.Instance.UpModeSelect
  239. );
  240. }
  241. else if (EpigraphData.Instance.UpModeSelect > 0)
  242. {
  243. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
  244. if (sbId == 0)
  245. {
  246. Context.ShowTips(EStringDefine.PartnerCurSlotNoSbTips);
  247. return;
  248. }
  249. EpigraphService.Instance.RequestEpiInset(sbId, EpigraphData.Instance.UpModeSelect);
  250. }
  251. }
  252. private void OnClickCancelBtn(EventContext context)
  253. {
  254. if (PartnersData.Instance.UpModeSelect > 0)
  255. {
  256. PartnersService.Instance.FinishUpPartnerMode();
  257. }
  258. else if (EpigraphData.Instance.UpModeSelect > 0)
  259. {
  260. EpigraphService.Instance.FinishUpMode();
  261. }
  262. }
  263. /// <summary>
  264. /// 圣兵上阵打开事件
  265. /// </summary>
  266. /// <param name="eventId"></param>
  267. /// <param name="args"></param>
  268. private void OnOpenUpMode(int eventId, object args)
  269. {
  270. ShowUpMode();
  271. }
  272. private void OnFinishUpMode(int eventId, object args)
  273. {
  274. ShowUpMode();
  275. }
  276. #endregion
  277. #region 属性
  278. private bool _initView = false;
  279. private int _curSelectPos = 0;
  280. /// <summary>
  281. /// 选择类型,0圣兵,1铭文
  282. /// </summary>
  283. private int _selectType = 0;
  284. #endregion
  285. #region 页面
  286. private void clearUpMode()
  287. {
  288. EpigraphData.Instance.UpModeSelect = 0;
  289. PartnersData.Instance.UpModeSelect = 0;
  290. }
  291. private void InitView()
  292. {
  293. if (_initView)
  294. return;
  295. _initView = true;
  296. VM.SbList.ListType = EGListType.None;
  297. }
  298. private void ShowUI()
  299. {
  300. ShowUpMode();
  301. RefreshGoneUpPartners(true);
  302. UpdateDetail();
  303. UpdateAttr();
  304. }
  305. private void ShowUpMode()
  306. {
  307. if (PartnersData.Instance.UpModeSelect > 0)
  308. {
  309. VM.UpPartner.selectedIndex = 1;
  310. if (_selectType != 0)
  311. {
  312. _selectType = 0;
  313. RefreshGoneUpPartners(false);
  314. UpdateDetail();
  315. }
  316. }
  317. else if (EpigraphData.Instance.UpModeSelect > 0)
  318. {
  319. VM.UpPartner.selectedIndex = 1;
  320. if (_selectType != 1)
  321. {
  322. _selectType = 1;
  323. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
  324. if (sbId == 0)
  325. {
  326. RefreshGoneUpPartners(true);
  327. }
  328. else
  329. {
  330. RefreshGoneUpPartners(false);
  331. }
  332. UpdateDetail();
  333. }
  334. }
  335. else
  336. {
  337. VM.UpPartner.selectedIndex = 0;
  338. }
  339. }
  340. private void RefreshGoneUpPartners(bool chooseFirstSb)
  341. {
  342. if (chooseFirstSb)
  343. {
  344. _selectType = 0;
  345. SelectFirst();
  346. }
  347. else if (_selectType == 1)
  348. {
  349. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
  350. if (sbId == 0)
  351. {
  352. _selectType = 0;
  353. SelectFirst();
  354. }
  355. }
  356. var list = new List<PartnerSbUpListItemParam>();
  357. for (int i = 0; i < PartnersData.GoneUpLimit; i++)
  358. {
  359. var data = new PartnerSbUpListItemParam()
  360. {
  361. PosId = i,
  362. CurSelectPos = _curSelectPos,
  363. SelectType = _selectType,
  364. };
  365. list.Add(data);
  366. }
  367. VM.SbList.BindDatas(list);
  368. }
  369. private void SelectFirst()
  370. {
  371. _curSelectPos = 0;
  372. for (int i = 0; i < PartnersData.GoneUpLimit; i++)
  373. {
  374. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(i, 0);
  375. if (sbId > 0)
  376. {
  377. _curSelectPos = i;
  378. break;
  379. }
  380. }
  381. }
  382. private void UpdateDetail()
  383. {
  384. var sbId = PartnersData.Instance.UpSbMap.GetValueOrDefault(_curSelectPos, 0);
  385. VM.Page.selectedIndex = _selectType;
  386. if (_selectType > 0)
  387. {
  388. VM.SbDetailNested.Disable();
  389. VM.MwDetailNested.Enable(null);
  390. //选择铭文
  391. var sbData = PartnersData.Instance.GetPartnerAttrByTableId(sbId);
  392. var mwId = sbData?.EpigraphId ?? 0;
  393. VM.MwDetailNested.Ctrl.ShowUI(mwId);
  394. if (mwId > 0)
  395. {
  396. VM.IsEmpty.selectedIndex = 0;
  397. }
  398. else
  399. {
  400. VM.IsEmpty.selectedIndex = 1;
  401. }
  402. }
  403. else
  404. {
  405. VM.MwDetailNested.Disable();
  406. VM.SbDetailNested.Enable(null);
  407. //选择圣兵
  408. VM.SbDetailNested.Ctrl.ShowUI(sbId);
  409. if (sbId == 0)
  410. {
  411. VM.IsEmpty.selectedIndex = 1;
  412. }
  413. else
  414. {
  415. VM.IsEmpty.selectedIndex = 0;
  416. }
  417. }
  418. var gObj = VM.SbList.GetChildAt(_curSelectPos);
  419. var localPos = gObj.position + VM.SbList.position;
  420. localPos.x += gObj.width / 2;
  421. VM.DownArr.x = localPos.x;
  422. VM.ChangeArr.position = VM.DownArr.position;
  423. }
  424. private void UpdateAttr()
  425. {
  426. var sbList = PartnersData.Instance.PartnerList;
  427. int val = 0;
  428. foreach (var sb in sbList)
  429. {
  430. var table = PartnerTableRepo.Get(sb.TableId);
  431. XGame.Framework.Assert.IsNotNull(table, $"圣兵表不存在,id:{sb.TableId}");
  432. val += table.Own_attr[1];
  433. }
  434. VM.AttrLabel.SetVar("val", (val / 100).ToString()).FlushVars();
  435. }
  436. #endregion
  437. }
  438. }