PlayerAwakePanelCtrl.cs 20 KB

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