PlayerAwakePanelCtrl.cs 20 KB

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