PlayerAwakePanelCtrl.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data;
  8. using FL.Network;
  9. using System.Collections.Generic;
  10. using XGame.Database;
  11. using XGame.Framework.UI;
  12. using XGame.Framework.Utils;
  13. namespace FL.FGUI
  14. {
  15. /// <summary>
  16. /// UI逻辑处理类
  17. /// </summary>
  18. /// <typeparam name=""></typeparam>
  19. public partial class PlayerAwakePanelCtrl : UIController<PlayerAwakePanelVM>
  20. {
  21. private bool _bShowPlansName; // 方案名称下拉列表UI是否显示状态
  22. private int _selectPlanIndex; // 当前选中的方案索引
  23. private int _selectImprint; // 当前选中的印记索引
  24. private int _awakeItemId; // 觉醒道具id
  25. private int _awakeCostVal; // 觉醒需要的道具数量
  26. private int _upgradeItemId; // 升级印记道具id
  27. private int _upgradeCostVal;// 升级需要的道具数量
  28. private List<PlayerImprintItemNestedView> _imprintItemList;
  29. private List<runeTable> _runeTableList;
  30. private int[] _runeIdArray; // 印记槽位镶嵌的符文id数组
  31. protected override void OnEnable(object intent)
  32. {
  33. AddUIListenres();
  34. AddEventListner();
  35. InitUI();
  36. ShowUI();
  37. }
  38. protected override void OnDisable()
  39. {
  40. RemoveUIListenres();
  41. RemoveEventListner();
  42. _selectImprint = 0;
  43. if (_imprintItemList != null)
  44. {
  45. foreach (var item in _imprintItemList)
  46. {
  47. item.Disable();
  48. }
  49. _imprintItemList.Clear();
  50. _imprintItemList = null;
  51. }
  52. if (_runeTableList != null)
  53. {
  54. _runeTableList.Clear();
  55. _runeTableList = null;
  56. }
  57. if (_runeIdArray != null) _runeIdArray = null;
  58. }
  59. #region UI事件
  60. private void AddUIListenres()
  61. {
  62. VM.PlansNameBtn.onClick.Add(OnClickPlansNameBtn);
  63. VM.RenameBtn.onClick.Add(OnClickRenameBtn);
  64. VM.WakeupBtn.onClick.Add(OnClickWakeupBtn);
  65. VM.ResetBtn.onClick.Add(OnClickResetBtn);
  66. VM.ChangeImprintBtn.onClick.Add(OnClickChangeImprintBtn);
  67. VM.BackBtn.onClick.Add(OnClickBackBtn);
  68. VM.UpgradeBtn.onClick.Add(OnClickUpgradeBtn);
  69. VM.TenBtn.onClick.Add(OnClickTenBtn);
  70. }
  71. private void RemoveUIListenres()
  72. {
  73. VM.PlansNameBtn.onClick.Remove(OnClickPlansNameBtn);
  74. VM.RenameBtn.onClick.Remove(OnClickRenameBtn);
  75. VM.WakeupBtn.onClick.Remove(OnClickWakeupBtn);
  76. VM.ResetBtn.onClick.Remove(OnClickResetBtn);
  77. VM.ChangeImprintBtn.onClick.Remove(OnClickChangeImprintBtn);
  78. VM.BackBtn.onClick.Remove(OnClickBackBtn);
  79. VM.UpgradeBtn.onClick.Remove(OnClickUpgradeBtn);
  80. VM.TenBtn.onClick.Remove(OnClickTenBtn);
  81. }
  82. /// <summary>
  83. /// 显示方案选择列表
  84. /// </summary>
  85. /// <param name="context"></param>
  86. private void OnClickPlansNameBtn(EventContext context)
  87. {
  88. ShowPlansNameNestedItem(!_bShowPlansName);
  89. }
  90. /// <summary>
  91. /// 修改方案名
  92. /// </summary>
  93. /// <param name="context"></param>
  94. private void OnClickRenameBtn(EventContext context)
  95. {
  96. var param = new RenameParam()
  97. {
  98. title = StringDefine.AwakeRenameTitle,
  99. tipsDesc = StringDefine.AwakeRenameDesc,
  100. limitWordCount = 5,
  101. renameCallback = RenameCallback,
  102. };
  103. Context.UI.OpenAsync(UIKeys.CommonRenamePanel, param);
  104. }
  105. /// <summary>
  106. /// 随机觉醒按钮
  107. /// </summary>
  108. /// <param name="context"></param>
  109. private void OnClickWakeupBtn(EventContext context)
  110. {
  111. if (VM.AwakeCtrl.selectedIndex == 1)
  112. {
  113. // 前往觉醒
  114. Context.UI.OpenAsync(UIKeys.PlayerTransferPanel);
  115. Context.ClosePanel();
  116. return;
  117. }
  118. else if (VM.AwakeCtrl.selectedIndex == 2)
  119. {
  120. // 职业预览
  121. Context.UI.OpenAsync(UIKeys.PlayerJobCareerPreviewPanel);
  122. Context.ClosePanel();
  123. return;
  124. }
  125. // 随机觉醒槽位(符文)
  126. if (!ItemService.Instance.IsEnough(_awakeItemId, _awakeCostVal, true))
  127. return;
  128. PlayerService.Instance.SendToWakeupRune();
  129. }
  130. private void OnClickResetBtn(EventContext context)
  131. {
  132. ConfirmationBoxParam dialogParam = new ConfirmationBoxParam()
  133. {
  134. cnt = StringDefine.resetCurrentPlan,
  135. onPromiseCallback = PlayerService.Instance.SendToResetPlan
  136. };
  137. Context.UI.OpenAsync(UIKeys.CommonConfirmationBox, dialogParam);
  138. }
  139. private void OnClickChangeImprintBtn(EventContext context)
  140. {
  141. Context.UI.OpenAsync(UIKeys.PlayerChangeImprintPanel,_selectImprint);
  142. }
  143. private void OnClickBackBtn(EventContext context)
  144. {
  145. Context.ClosePanel();
  146. }
  147. /// <summary>
  148. /// 升级1次印记
  149. /// </summary>
  150. /// <param name="context"></param>
  151. private void OnClickUpgradeBtn(EventContext context)
  152. {
  153. if (!ItemService.Instance.IsEnough(_upgradeItemId, _upgradeCostVal, true))
  154. return;
  155. PlayerService.Instance.SendToUpgradeRune(_selectImprint+1,1);
  156. }
  157. /// <summary>
  158. /// 升级10次印记
  159. /// </summary>
  160. /// <param name="context"></param>
  161. private void OnClickTenBtn(EventContext context)
  162. {
  163. if (!ItemService.Instance.IsEnough(_upgradeItemId, _upgradeCostVal*10, true))
  164. return;
  165. PlayerService.Instance.SendToUpgradeRune(_selectImprint+1, 10);
  166. }
  167. #endregion
  168. private void AddEventListner()
  169. {
  170. EventSingle.Instance.AddListener(EventDefine.UpdataItemData, UpdataItemData);
  171. EventSingle.Instance.AddListener(EventDefine.WakeUpRuneSucess, WakeUpRuneSucess);
  172. EventSingle.Instance.AddListener(EventDefine.UpgradeRuneLvSucess, UpgradeRuneLvSucess);
  173. EventSingle.Instance.AddListener(EventDefine.ChangePlanIndexSucess, ChangePlanIndexSucess);
  174. EventSingle.Instance.AddListener(EventDefine.ResetCurrentPlanSucess,ResetCurrentPlanSucess);
  175. EventSingle.Instance.AddListener(EventDefine.ChangePlanNameSucess, ChangePlanNameSucess);
  176. EventSingle.Instance.AddListener(EventDefine.ChangeRuneTypeSucess, ChangeRuneTypeSucess);
  177. }
  178. private void RemoveEventListner()
  179. {
  180. EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, UpdataItemData);
  181. EventSingle.Instance.RemoveListener(EventDefine.WakeUpRuneSucess, WakeUpRuneSucess);
  182. EventSingle.Instance.RemoveListener(EventDefine.UpgradeRuneLvSucess, UpgradeRuneLvSucess);
  183. EventSingle.Instance.RemoveListener(EventDefine.ChangePlanIndexSucess, ChangePlanIndexSucess);
  184. EventSingle.Instance.RemoveListener(EventDefine.ResetCurrentPlanSucess,ResetCurrentPlanSucess);
  185. EventSingle.Instance.RemoveListener(EventDefine.ChangePlanNameSucess, ChangePlanNameSucess);
  186. EventSingle.Instance.RemoveListener(EventDefine.ChangeRuneTypeSucess, ChangeRuneTypeSucess);
  187. }
  188. private void InitUI()
  189. {
  190. _selectImprint = 0;
  191. _selectPlanIndex = PlayerData.Instance.CurPlanIndex;
  192. SelectPlanNameItem(_selectPlanIndex, true);
  193. if (_imprintItemList == null)
  194. {
  195. _imprintItemList = new List<PlayerImprintItemNestedView>
  196. {
  197. VM.ImprintItem1,VM.ImprintItem2,VM.ImprintItem3,
  198. VM.ImprintItem4,VM.ImprintItem5,VM.ImprintItem6,
  199. };
  200. }
  201. if (_runeTableList == null)
  202. {
  203. _runeTableList = new List<runeTable>();
  204. _runeTableList.AddRange(runeTableRepo.GetAll());
  205. _runeTableList.Sort((a, b) =>
  206. {
  207. return a.Id.CompareTo(b.Id);//升序
  208. });
  209. }
  210. if (_runeIdArray == null) _runeIdArray = new int[_runeTableList.Count];
  211. }
  212. private void ShowUI()
  213. {
  214. ShowPlayerSpine("info_job_1001_1_SkeletonData");
  215. ShowImprintUI(true);
  216. ShowAwakeCostUI(1);
  217. }
  218. /// <summary>
  219. /// 加载主角的spine
  220. /// </summary>
  221. /// <param name="spineName"></param>
  222. private void ShowPlayerSpine(string spineName)
  223. {
  224. VM.JobSpine.LoadSpine(spineName, "stand", true);
  225. }
  226. private void ShowImprintUI(bool bInit = false)
  227. {
  228. RunePlan runePlanData = PlayerData.Instance.RunePlanMap[_selectPlanIndex];
  229. bool bAllLock = true;
  230. bool bHighestJob = false; // 已到达觉醒最高阶
  231. bool bWaitAwake = false;
  232. int index = 0;
  233. foreach (var rune in runePlanData.slot)
  234. {
  235. _runeIdArray[index] = rune.runeId;
  236. index++;
  237. if (bAllLock && rune.runeId > 0)
  238. {
  239. bAllLock = false;
  240. }
  241. if (!bWaitAwake && rune.runeId == 0)
  242. {
  243. bWaitAwake = true;
  244. }
  245. }
  246. VM.LockCtrl.selectedIndex = bAllLock ? 1 : 0;
  247. if (!bWaitAwake)
  248. {
  249. var curJobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
  250. if (curJobInfo?.Job_change.Length == 0)
  251. {
  252. bHighestJob = true;
  253. }
  254. }
  255. VM.AwakeCtrl.selectedIndex = bWaitAwake ? 0 : (bHighestJob ? 2 : 1);
  256. if (bInit && _runeIdArray[_selectImprint] == 0)
  257. {
  258. for (int i = 0; i < _runeIdArray.Length; i++)
  259. {
  260. if (_runeIdArray[i] > 0)
  261. {
  262. _selectImprint = i;
  263. break;
  264. }
  265. }
  266. }
  267. ShowImprintRuneUI();
  268. }
  269. /// <summary>
  270. /// 显示印记镶嵌的符文UI
  271. /// </summary>
  272. private void ShowImprintRuneUI()
  273. {
  274. for (int i = 0; i < _runeIdArray.Length; i++)
  275. {
  276. if (_imprintItemList[i] != null)
  277. {
  278. _imprintItemList[i].Ctrl.ShowUI(i,_runeIdArray[i], OnclcickImprintItem);
  279. }
  280. }
  281. OnclcickImprintItem(_selectImprint);
  282. }
  283. /// <summary>
  284. /// 觉醒印记消耗
  285. /// </summary>
  286. /// <param name="index"></param>
  287. private void ShowAwakeCostUI(int index)
  288. {
  289. var info = _runeTableList[index];
  290. if (info != null)
  291. {
  292. _awakeItemId = info.LevelUpCost[0];
  293. _awakeCostVal = info.LevelUpCost[1];
  294. VM.AwakeCostItem.Ctrl.ShowCostUI(_awakeItemId, _awakeCostVal, 0);
  295. }
  296. }
  297. /// <summary>
  298. /// 升级印记消耗
  299. /// </summary>
  300. /// <param name="runeId"></param>
  301. private void ShowUpgradeCostUI(int runeId)
  302. {
  303. var runeLvInfo = rune_levelTableRepo.Get(runeId);
  304. if (runeLvInfo == null) return;
  305. var runeExpInfo = rune_expTableRepo.Get(runeLvInfo.Level);
  306. if (runeExpInfo?.Cost?.Length > 1)
  307. {
  308. _upgradeItemId = runeExpInfo.Cost[0];
  309. _upgradeCostVal = runeExpInfo.Cost[1];
  310. RunePlan runePlanData = PlayerData.Instance.RunePlanMap[_selectPlanIndex];
  311. // allPoint - 当前方案的subPoint) + 玩家的道具
  312. int upgradePoint = PlayerData.Instance.AllPoint - runePlanData.subPoint + (int)ItemData.Instance.GetItemNum(_upgradeItemId);
  313. VM.UpgradeCostItem.Ctrl.ShowCostUI(_upgradeItemId, _upgradeCostVal, upgradePoint);
  314. VM.TenCostItem.Ctrl.ShowCostUI(_upgradeItemId, _upgradeCostVal*10, upgradePoint);
  315. }
  316. }
  317. /// <summary>
  318. /// 点击印记项
  319. /// </summary>
  320. /// <param name="imprintIndex"></param>
  321. private void OnclcickImprintItem(int imprintIndex)
  322. {
  323. _selectImprint = imprintIndex;
  324. ShowImprintItemUI(imprintIndex);
  325. for (int i = 0; i < _imprintItemList.Count; i++)
  326. {
  327. _imprintItemList[i].Ctrl.ShowSelectUI(i == imprintIndex);
  328. }
  329. }
  330. /// <summary>
  331. /// 获取某个槽位上的符文id
  332. /// </summary>
  333. /// <param name="index"></param>
  334. private int GetRuneId(int index)
  335. {
  336. RunePlan runePlanData = PlayerData.Instance.RunePlanMap[_selectPlanIndex];
  337. foreach (var item in runePlanData.slot)
  338. {
  339. if (item.id == index)
  340. {
  341. return item.runeId;
  342. }
  343. }
  344. return 0;
  345. }
  346. /// <summary>
  347. /// 显示点击的印记项信息
  348. /// </summary>
  349. /// <param name="index"></param>
  350. private void ShowImprintItemUI(int index)
  351. {
  352. int runeId = GetRuneId(index+1);
  353. bool bShowChangeImprintBtn = true;
  354. int lvCtrlIndex = 0;
  355. if (runeId == 0)
  356. {
  357. // 展示信息 槽位id * 10000 + 符文类型 * 1000
  358. runeId = (index+1) * 10000 + 1001;
  359. bShowChangeImprintBtn = false;
  360. }
  361. else
  362. {
  363. var runeLevelInfo = rune_levelTableRepo.Get(runeId);
  364. if (runeLevelInfo == null)
  365. lvCtrlIndex = 2;
  366. else
  367. {
  368. var runeExpInfo = rune_expTableRepo.Get(runeLevelInfo.Level +1);
  369. lvCtrlIndex = runeExpInfo == null ? 2 : 1;
  370. }
  371. }
  372. var imprintInfo = _runeTableList[index];
  373. if (imprintInfo != null)
  374. {
  375. int runeType = (runeId - (index+1) * 10000) / 1000 - 1;
  376. VM.ImprintNameLabel.text = imprintInfo.Name[runeType];
  377. if (bShowChangeImprintBtn && imprintInfo.Handoff.Length == 1) bShowChangeImprintBtn = false;
  378. }
  379. ShowRuneAttrUI(runeId);
  380. ShowUpgradeCostUI(runeId);
  381. VM.ChangeImprintBtn.visible = bShowChangeImprintBtn;
  382. VM.LevelCtrl.selectedIndex = lvCtrlIndex;
  383. }
  384. private void ShowRuneAttrUI(int runeId)
  385. {
  386. var runeInfo = rune_levelTableRepo.Get(runeId);
  387. if (runeInfo != null)
  388. {
  389. var sb = StringBuilderUtils.Acquire();
  390. for (int i = 0; i < runeInfo.Value_plus.Length; i+=2)
  391. {
  392. var attributeInfo = AttrDescTableRepo.Get(runeInfo.Value_plus[i]);
  393. if (attributeInfo != null)
  394. {
  395. sb.Append(attributeInfo.ShowName);
  396. sb.Append("[color=#1EF369]+");
  397. sb.Append(attributeInfo.Num_type == 1 ? TableUtils.ToRealDouble(runeInfo.Value_plus[i+1]).ToString("F3") + "%" :
  398. (attributeInfo.Id == (int)EAttributeType.AtkSpeed ? TableUtils.ToRealDouble(runeInfo.Value_plus[i + 1]).ToString("F1") : runeInfo.Value_plus[i + 1].ToString()));
  399. sb.Append("[/color]");
  400. }
  401. }
  402. VM.ImprintDescLabel.text = sb.ToString();
  403. StringBuilderUtils.Release(sb);
  404. }
  405. }
  406. /// <summary>
  407. /// 道具变化
  408. /// </summary>
  409. /// <param name="eventId"></param>
  410. /// <param name="args"></param>
  411. private void UpdataItemData(int eventId, object args)
  412. {
  413. int runeId = GetRuneId(_selectImprint+1);
  414. var itemDataList = args as List<ActItem>;
  415. if (itemDataList?.Count > 0)
  416. {
  417. for (int i = 0; i < itemDataList.Count; i++)
  418. {
  419. if (itemDataList[i].count > 0)
  420. {
  421. if (itemDataList[i].id == _awakeItemId)
  422. {
  423. ShowAwakeCostUI(1);
  424. }
  425. if (runeId > 0 && itemDataList[i].id == _upgradeItemId)
  426. {
  427. ShowUpgradeCostUI(runeId);
  428. }
  429. }
  430. }
  431. }
  432. }
  433. /// <summary>
  434. /// 成功激活印记(镶嵌符文)
  435. /// </summary>
  436. /// <param name="eventId"></param>
  437. /// <param name="args"></param>
  438. private void WakeUpRuneSucess(int eventId, object args)
  439. {
  440. ShowImprintUI();
  441. }
  442. /// <summary>
  443. /// 成功提升印记(符文)等级
  444. /// </summary>
  445. /// <param name="eventId"></param>
  446. /// <param name="args"></param>
  447. private void UpgradeRuneLvSucess(int eventId, object args)
  448. {
  449. ShowImprintUI();
  450. }
  451. /// <summary>
  452. /// 切换符文方案
  453. /// </summary>
  454. /// <param name="eventId"></param>
  455. /// <param name="args"></param>
  456. private void ChangePlanIndexSucess(int eventId, object args)
  457. {
  458. _selectImprint = 0;
  459. _selectPlanIndex = PlayerData.Instance.CurPlanIndex;
  460. ShowImprintUI();
  461. }
  462. /// <summary>
  463. /// 成功重置当前方案
  464. /// </summary>
  465. /// <param name="eventId"></param>
  466. /// <param name="args"></param>
  467. private void ResetCurrentPlanSucess(int eventId, object args)
  468. {
  469. ShowImprintUI();
  470. }
  471. /// <summary>
  472. /// 成功更换印记类型
  473. /// </summary>
  474. /// <param name="eventId"></param>
  475. /// <param name="args"></param>
  476. private void ChangeRuneTypeSucess(int eventId, object args)
  477. {
  478. ShowImprintItemUI(_selectImprint);
  479. }
  480. /// <summary>
  481. /// 成功修改符文方案名字
  482. /// </summary>
  483. /// <param name="eventId"></param>
  484. /// <param name="args"></param>
  485. private void ChangePlanNameSucess(int eventId, object args)
  486. {
  487. SelectPlanNameItem(_selectPlanIndex);
  488. }
  489. /// <summary>
  490. /// 修改方案名
  491. /// </summary>
  492. /// <param name="rename">要修改的名称</param>
  493. /// <param name="bChange">确定修改</param>
  494. private void RenameCallback(string changeName, bool bChange)
  495. {
  496. if (bChange)
  497. {
  498. PlayerService.Instance.SendToAlterPlanName(changeName,_selectPlanIndex);
  499. }
  500. }
  501. /// <summary>
  502. /// 显示印记方案列表UI
  503. /// </summary>
  504. /// <param name="bShow"></param>
  505. private void ShowPlansNameNestedItem(bool bShow)
  506. {
  507. _bShowPlansName = bShow;
  508. VM.PlansNameBtn.GetController("ComboBoxCtrl").selectedIndex = bShow ? 1 : 0;
  509. if (bShow)
  510. {
  511. VM.PlansNameNestedItem.Enable(null);
  512. VM.PlansNameNestedItem.Ctrl.ShowUI((int index) =>
  513. {
  514. SelectPlanNameItem(index);
  515. });
  516. }
  517. else
  518. {
  519. VM.PlansNameNestedItem.Disable();
  520. }
  521. }
  522. /// <summary>
  523. /// 选择(符文升级)方案
  524. /// </summary>
  525. /// <param name="index"></param>
  526. private void SelectPlanNameItem(int index, bool bInit=false)
  527. {
  528. if (index > 0 && PlayerData.Instance.RunePlanNamesArray.Count > 0)
  529. {
  530. if (!bInit)
  531. PlayerService.Instance.SendToChangePlanIndex(index);
  532. VM.PlansNameBtn.title = PlayerData.Instance.RunePlanNamesArray[index-1];
  533. }
  534. ShowPlansNameNestedItem(false);
  535. }
  536. }
  537. }