PlayerAwakePanelCtrl.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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. Context.AddListener(EventDefine.UpdataItemData, UpdataItemData);
  171. Context.AddListener(EventDefine.WakeUpRuneSucess, WakeUpRuneSucess);
  172. Context.AddListener(EventDefine.UpgradeRuneLvSucess, UpgradeRuneLvSucess);
  173. Context.AddListener(EventDefine.ChangePlanIndexSucess, ChangePlanIndexSucess);
  174. Context.AddListener(EventDefine.ResetCurrentPlanSucess,ResetCurrentPlanSucess);
  175. Context.AddListener(EventDefine.ChangePlanNameSucess, ChangePlanNameSucess);
  176. Context.AddListener(EventDefine.ChangeRuneTypeSucess, ChangeRuneTypeSucess);
  177. }
  178. private void RemoveEventListner()
  179. {
  180. Context.RemoveListener(EventDefine.UpdataItemData, UpdataItemData);
  181. Context.RemoveListener(EventDefine.WakeUpRuneSucess, WakeUpRuneSucess);
  182. Context.RemoveListener(EventDefine.UpgradeRuneLvSucess, UpgradeRuneLvSucess);
  183. Context.RemoveListener(EventDefine.ChangePlanIndexSucess, ChangePlanIndexSucess);
  184. Context.RemoveListener(EventDefine.ResetCurrentPlanSucess,ResetCurrentPlanSucess);
  185. Context.RemoveListener(EventDefine.ChangePlanNameSucess, ChangePlanNameSucess);
  186. Context.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 + 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. int attrValue = 0;
  390. var sb = StringBuilderUtils.Acquire();
  391. for (int i = 0; i < runeInfo.Value_plus.Length; i+=2)
  392. {
  393. var attributeInfo = AttrDescTableRepo.Get(runeInfo.Value_plus[i]);
  394. if (attributeInfo != null)
  395. {
  396. attrValue = runeInfo.Value_plus[i + 1];
  397. sb.Append(attributeInfo.ShowName);
  398. sb.Append("[color=#1EF369]+");
  399. sb.Append((attributeInfo.Num_type == 1 || attributeInfo.Id == (int)EAttributeType.AtkSpeed) ? attrValue.ToRealFloatPercentage() :
  400. (attrValue == 0 ? "0" : attrValue.ToString()));
  401. sb.Append("[/color]");
  402. }
  403. }
  404. VM.ImprintDescLabel.text = sb.ToString();
  405. StringBuilderUtils.Release(sb);
  406. }
  407. }
  408. /// <summary>
  409. /// 道具变化
  410. /// </summary>
  411. /// <param name="eventId"></param>
  412. /// <param name="args"></param>
  413. private void UpdataItemData(int eventId, object args)
  414. {
  415. int runeId = GetRuneId(_selectImprint+1);
  416. var itemDataList = args as List<ActItem>;
  417. if (itemDataList?.Count > 0)
  418. {
  419. for (int i = 0; i < itemDataList.Count; i++)
  420. {
  421. if (itemDataList[i].count > 0)
  422. {
  423. if (itemDataList[i].id == _awakeItemId)
  424. {
  425. ShowAwakeCostUI(1);
  426. }
  427. if (runeId > 0 && itemDataList[i].id == _upgradeItemId)
  428. {
  429. ShowUpgradeCostUI(runeId);
  430. }
  431. }
  432. }
  433. }
  434. }
  435. /// <summary>
  436. /// 成功激活印记(镶嵌符文)
  437. /// </summary>
  438. /// <param name="eventId"></param>
  439. /// <param name="args"></param>
  440. private void WakeUpRuneSucess(int eventId, object args)
  441. {
  442. ShowImprintUI();
  443. }
  444. /// <summary>
  445. /// 成功提升印记(符文)等级
  446. /// </summary>
  447. /// <param name="eventId"></param>
  448. /// <param name="args"></param>
  449. private void UpgradeRuneLvSucess(int eventId, object args)
  450. {
  451. ShowImprintUI();
  452. }
  453. /// <summary>
  454. /// 切换符文方案
  455. /// </summary>
  456. /// <param name="eventId"></param>
  457. /// <param name="args"></param>
  458. private void ChangePlanIndexSucess(int eventId, object args)
  459. {
  460. _selectImprint = 0;
  461. _selectPlanIndex = PlayerData.Instance.CurPlanIndex;
  462. ShowImprintUI();
  463. }
  464. /// <summary>
  465. /// 成功重置当前方案
  466. /// </summary>
  467. /// <param name="eventId"></param>
  468. /// <param name="args"></param>
  469. private void ResetCurrentPlanSucess(int eventId, object args)
  470. {
  471. ShowImprintUI();
  472. }
  473. /// <summary>
  474. /// 成功更换印记类型
  475. /// </summary>
  476. /// <param name="eventId"></param>
  477. /// <param name="args"></param>
  478. private void ChangeRuneTypeSucess(int eventId, object args)
  479. {
  480. ShowImprintItemUI(_selectImprint);
  481. }
  482. /// <summary>
  483. /// 成功修改符文方案名字
  484. /// </summary>
  485. /// <param name="eventId"></param>
  486. /// <param name="args"></param>
  487. private void ChangePlanNameSucess(int eventId, object args)
  488. {
  489. SelectPlanNameItem(_selectPlanIndex);
  490. }
  491. /// <summary>
  492. /// 修改方案名
  493. /// </summary>
  494. /// <param name="rename">要修改的名称</param>
  495. /// <param name="bChange">确定修改</param>
  496. private void RenameCallback(string changeName, bool bChange)
  497. {
  498. if (bChange)
  499. {
  500. PlayerService.Instance.SendToAlterPlanName(changeName,_selectPlanIndex);
  501. }
  502. }
  503. /// <summary>
  504. /// 显示印记方案列表UI
  505. /// </summary>
  506. /// <param name="bShow"></param>
  507. private void ShowPlansNameNestedItem(bool bShow)
  508. {
  509. _bShowPlansName = bShow;
  510. VM.PlansNameBtn.GetController("ComboBoxCtrl").selectedIndex = bShow ? 1 : 0;
  511. if (bShow)
  512. {
  513. VM.PlansNameNestedItem.Enable(null);
  514. VM.PlansNameNestedItem.Ctrl.ShowUI((int index) =>
  515. {
  516. SelectPlanNameItem(index);
  517. });
  518. }
  519. else
  520. {
  521. VM.PlansNameNestedItem.Disable();
  522. }
  523. }
  524. /// <summary>
  525. /// 选择(符文升级)方案
  526. /// </summary>
  527. /// <param name="index"></param>
  528. private void SelectPlanNameItem(int index, bool bInit=false)
  529. {
  530. if (index > 0 && PlayerData.Instance.RunePlanNamesArray.Count > 0)
  531. {
  532. if (!bInit)
  533. PlayerService.Instance.SendToChangePlanIndex(index);
  534. VM.PlansNameBtn.title = PlayerData.Instance.RunePlanNamesArray[index-1];
  535. }
  536. ShowPlansNameNestedItem(false);
  537. }
  538. }
  539. }