GongFaUpgradePanel.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Core.Audio;
  5. using Core.Language;
  6. using Excel2Json;
  7. using Fort23.Core;
  8. using Fort23.UTool;
  9. using GameLogic.Bag;
  10. using GameLogic.Combat.Buff;
  11. using GameLogic.Hero;
  12. using GameLogic.Player;
  13. using UnityEngine;
  14. using UnityEngine.UI;
  15. using Utility;
  16. namespace Fort23.Mono
  17. {
  18. [UIBinding(prefab = "GongFaUpgradePanel")]
  19. public partial class GongFaUpgradePanel : UIPanel
  20. {
  21. private SkillInfo _skillInfo;
  22. private List<SkillConfig> configs;
  23. List<GongFaUpgradeInfoWidget> _gongFaUpgradeInfoWidgets = new List<GongFaUpgradeInfoWidget>();
  24. private List<SkillPowerupConfig> _skillPowerupConfigs;
  25. // private SkillConstant skillConstant;
  26. List<ItemWidgetType1> _itemWidgetType1 = new List<ItemWidgetType1>();
  27. private List<SkillInfo> _skillInfos = new List<SkillInfo>();
  28. // List<EnergyWidget> _energyWidgets = new List<EnergyWidget>();
  29. bool isUpStar = false;
  30. bool isUpGrad = false;
  31. private void Init()
  32. {
  33. isAddStack = true;
  34. IsShowAppBar = false;
  35. }
  36. public async override CTask GetFocus()
  37. {
  38. // await AppBarPanel.OpenPanel(this);
  39. base.GetFocus();
  40. }
  41. protected override void AddEvent()
  42. {
  43. Text_GongFaDesc.onClickCallBack = OnClickBuff;
  44. }
  45. protected override void DelEvent()
  46. {
  47. }
  48. public async override CTask<bool> AsyncInit(object[] uiData)
  49. {
  50. _skillInfo = uiData[0] as SkillInfo;
  51. List<SkillConfig> allSkillConfigs = ConfigComponent.Instance.GetAll<SkillConfig>().ToList();
  52. configs = allSkillConfigs.Where(s => s.IDGroup == _skillInfo.skillConfig.IDGroup).ToList();
  53. using (CTaskAwaitBuffer<GongFaUpgradeInfoWidget> cts = new CTaskAwaitBuffer<GongFaUpgradeInfoWidget>())
  54. {
  55. for (var i = 0; i < configs.Count; i++)
  56. {
  57. if (configs[i].level == 1)
  58. continue;
  59. SkillInfo skillInfo1 =
  60. new SkillInfo(configs[i].IDGroup, _skillInfo.SkillPowerupConfig.ID, configs[i].level);
  61. _skillInfos.Add(skillInfo1);
  62. cts.AddTask(UIManager.Instance.CreateGComponent<GongFaUpgradeInfoWidget>(null, Content));
  63. }
  64. _gongFaUpgradeInfoWidgets = await cts.WaitAll();
  65. }
  66. return await base.AsyncInit(uiData);
  67. }
  68. public override void AddButtonEvent()
  69. {
  70. Btn_Back.onClick.AddListener(() =>
  71. {
  72. if (isUpStar || isUpGrad)
  73. {
  74. isUpStar = false;
  75. isUpGrad = false;
  76. UpdateStarBtn();
  77. return;
  78. }
  79. UIManager.Instance.HideUIUIPanel<GongFaUpgradePanel>();
  80. });
  81. Btn_UpGradeOk.onClick.AddListener(() => { UpgradeClick(); });
  82. Btn_UpGrade.onClick.AddListener(() => { UpgradeClick(); });
  83. Btn_UpStar.onClick.AddListener(() => { UpStarClick(); });
  84. Btn_UpStarOk.onClick.AddListener(() => { UpStarClick(); });
  85. Btn_UpGradeOkLongPress.longPress = () => { UpgradeClick(); };
  86. Btn_Rest.onClick.AddListener(async () =>
  87. {
  88. bool relust = await TipsPanle.OpenPnael(10799);
  89. if (!relust)
  90. {
  91. return;
  92. }
  93. Dictionary<int, ItemInfo> itemInfo = new Dictionary<int, ItemInfo>();
  94. for (int i = 1; i < _skillInfo.SkillPowerupConfig.ID; i++)
  95. {
  96. SkillPowerupConfig skillPowerupConfig = ConfigComponent.Instance.Get<SkillPowerupConfig>(i);
  97. for (var i1 = 0; i1 < skillPowerupConfig.LevelupItem.Length; i1++)
  98. {
  99. if (itemInfo.ContainsKey(skillPowerupConfig.LevelupItem[i1]))
  100. {
  101. itemInfo[skillPowerupConfig.LevelupItem[i1]].count += skillPowerupConfig.LevelupItemNum[i1];
  102. }
  103. else
  104. {
  105. itemInfo.Add(skillPowerupConfig.LevelupItem[i1], new ItemInfo(
  106. skillPowerupConfig.LevelupItem[i1],
  107. skillPowerupConfig.LevelupItemNum[i1]));
  108. }
  109. }
  110. }
  111. // ItemConfig itemConfig = ConfigComponent.Instance.Get<ItemConfig>(_skillInfo.skillConfig.PieceID);
  112. //
  113. // SkillConstant skillConstant = ConfigComponent.Instance.Get<SkillConstant>(itemConfig.quality);
  114. // int count = 0;
  115. // for (int i = 0; i < _skillInfo.skillConfig.level - 1; i++)
  116. // {
  117. // count += skillConstant.SkillPromoteNeedPieceNum[i];
  118. // }
  119. //
  120. // if (count > 0)
  121. // {
  122. // if (itemInfo.ContainsKey(_skillInfo.skillConfig.PieceID))
  123. // {
  124. // itemInfo[_skillInfo.skillConfig.PieceID].count += count;
  125. // }
  126. // else
  127. // {
  128. // itemInfo.Add(_skillInfo.skillConfig.PieceID, new ItemInfo(_skillInfo.skillConfig.PieceID,
  129. // count));
  130. // }
  131. // }
  132. // _skillInfo.SkillData.star = 1;
  133. _skillInfo.SkillData.level = 1;
  134. _skillInfo.CustomInt(_skillInfo.SkillData);
  135. PlayerManager.Instance.myHero.ComputeHeroInfo();
  136. CustomInit(_skillInfo);
  137. foreach (var keyValuePair in itemInfo)
  138. {
  139. //TODO 功法重置
  140. PlayerManager.Instance.BagController.AddItem(keyValuePair.Value);
  141. }
  142. RewardsPanel.OpenPanel(itemInfo);
  143. });
  144. }
  145. private void UpStarClick()
  146. {
  147. if (!isUpStar)
  148. {
  149. isUpStar = true;
  150. UpdateStarBtn();
  151. return;
  152. }
  153. if (_skillInfo.SkillData == null)
  154. {
  155. return;
  156. }
  157. if (_skillInfo.SkillData.star > _gongFaUpgradeInfoWidgets.Count)
  158. {
  159. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  160. TipMessagePanel.OpenTipMessagePanel("已经满星!");
  161. return;
  162. }
  163. ItemConfig itemConfig = ConfigComponent.Instance.Get<ItemConfig>(_skillInfo.skillConfig.PieceID);
  164. SkillConstant skillConstant = ConfigComponent.Instance.Get<SkillConstant>(itemConfig.quality);
  165. int count = skillConstant.SkillPromoteNeedPieceNum[_skillInfo.skillConfig.level - 1];
  166. //TODO 消耗:功法升星
  167. if (!PlayerManager.Instance.BagController.DeductItem(_skillInfo.skillConfig.PieceID, count))
  168. {
  169. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  170. ItemSourcePanel.OpenPanel(_skillInfo.skillConfig.PieceID);
  171. return;
  172. }
  173. _skillInfo.SkillData.star++;
  174. _skillInfo.CustomInt(_skillInfo.SkillData);
  175. PlayerManager.Instance.myHero.ComputeHeroInfo();
  176. CustomInit(_skillInfo);
  177. foreach (var gongFaUpgradeInfoWidget in _gongFaUpgradeInfoWidgets)
  178. {
  179. if (gongFaUpgradeInfoWidget._skillInfo.skillConfig.level == _skillInfo.skillConfig.level)
  180. {
  181. gongFaUpgradeInfoWidget.fx_ui_gongfa_tiaomu.gameObject.SetActive(true);
  182. gongFaUpgradeInfoWidget.fx_ui_gongfa_tiaomu.Play();
  183. break;
  184. }
  185. }
  186. AudioManager.Instance.PlayAudio("ui_tycg.wav");
  187. AccountFileInfo.Instance.SavePlayerData();
  188. }
  189. private async void UpgradeClick()
  190. {
  191. if (_skillInfo.SkillData == null)
  192. {
  193. return;
  194. }
  195. if (!isUpGrad)
  196. {
  197. isUpGrad = true;
  198. UpdateStarBtn();
  199. return;
  200. }
  201. if (_skillInfo.SkillData.level >= _skillPowerupConfigs.Count)
  202. {
  203. TipMessagePanel.OpenTipMessagePanel("已经满级!");
  204. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  205. return;
  206. }
  207. if (PlayerManager.Instance.myHero.level.Value < _skillInfo.SkillPowerupConfig.PlayerLevelLimit)
  208. {
  209. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  210. HeroPowerUpConfig heroPowerUpConfig =
  211. ConfigComponent.Instance.Get<HeroPowerUpConfig>(_skillInfo.SkillPowerupConfig.PlayerLevelLimit);
  212. TipMessagePanel.OpenTipMessagePanel(
  213. $"需境界达到{LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[0]) + LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[1]) + LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[2])}");
  214. return;
  215. }
  216. for (var i = 0; i < _skillInfo.SkillPowerupConfig.LevelupItem.Length; i++)
  217. {
  218. if (!PlayerManager.Instance.BagController.IsEnough(_skillInfo.SkillPowerupConfig.LevelupItem[i],
  219. _skillInfo.SkillPowerupConfig.LevelupItemNum[i]))
  220. {
  221. AudioManager.Instance.PlayAudio("ui_chaozuoshibai.wav");
  222. ItemSourcePanel.OpenPanel(_skillInfo.SkillPowerupConfig.LevelupItem[i]);
  223. return;
  224. }
  225. }
  226. //扣除道具
  227. for (var i = 0; i < _skillInfo.SkillPowerupConfig.LevelupItem.Length; i++)
  228. {
  229. //TODO 消耗:功法升级
  230. PlayerManager.Instance.BagController.DeductItem(_skillInfo.SkillPowerupConfig.LevelupItem[i],
  231. _skillInfo.SkillPowerupConfig.LevelupItemNum[i]);
  232. }
  233. // fx_ui_gongfa_shengji.gameObject.SetActive(true);
  234. // fx_ui_gongfa_shengji.Play();
  235. AudioManager.Instance.PlayAudio("ui_fbgfsj.wav");
  236. _skillInfo.SkillData.level++;
  237. _skillInfo.CustomInt(_skillInfo.SkillData);
  238. PlayerManager.Instance.myHero.ComputeHeroInfo();
  239. CustomInit(_skillInfo);
  240. AccountFileInfo.Instance.SavePlayerData();
  241. ParticleSystemPool particleSystemPool =
  242. await GObjectPool.Instance.FetchAsync<ParticleSystemPool>("fx_ui_gongfa_shengji.prefab");
  243. particleSystemPool.own.transform.parent = fx_ui_gongfa_shengji.transform.parent;
  244. particleSystemPool.own.transform.position = fx_ui_gongfa_shengji.transform.position;
  245. }
  246. private int index = 0;
  247. public async void CustomInit(SkillInfo skillInfo)
  248. {
  249. index = 0;
  250. for (var i = 0; i < configs.Count; i++)
  251. {
  252. if (configs[i].level == 1)
  253. continue;
  254. _gongFaUpgradeInfoWidgets[index].CustomInit(_skillInfo, _skillInfos[index], false);
  255. index++;
  256. }
  257. Btn_Rest.gameObject.SetActive(_skillInfo.SkillPowerupConfig.ID > 1);
  258. RedDotComType02.CustomInit(13, _skillInfo);
  259. RedDotComType01.CustomInit(12, _skillInfo);
  260. _skillPowerupConfigs = ConfigComponent.Instance.GetAll<SkillPowerupConfig>().ToList();
  261. SkillConfig skillConfig = _skillInfo.skillConfig;
  262. Icon_GongFaIcon.icon_name = skillConfig.icon;
  263. Text_Level1.text = LanguageManager.Instance.Text(10222, _skillInfo.SkillPowerupConfig.ID.ToString());
  264. Text_Level.text = LanguageManager.Instance.Text(10222, _skillInfo.SkillPowerupConfig.ID.ToString());
  265. Text_SkillCd.text = LanguageManager.Instance.Text(10208, skillConfig.addcd);
  266. ItemConfig itemConfig = ConfigComponent.Instance.Get<ItemConfig>(skillConfig.PieceID);
  267. if (itemConfig.quality == 3)
  268. {
  269. QualityCsc.ChangeState(0);
  270. Text_Quality.text = LanguageManager.Instance.Text(10797);
  271. }
  272. else if (itemConfig.quality == 4)
  273. {
  274. QualityCsc.ChangeState(1);
  275. Text_Quality.text = LanguageManager.Instance.Text(10796);
  276. }
  277. else if (itemConfig.quality == 5)
  278. {
  279. QualityCsc.ChangeState(2);
  280. Text_Quality.text = LanguageManager.Instance.Text(10795);
  281. }
  282. // skillConstant = ConfigComponent.Instance.Get<SkillConstant>(1);
  283. UpdateStarBtn();
  284. // Text_GongFaDesc.text =
  285. // UtilTools.GetString(LanguageManager.Instance.Text(skillConfig.dec), _skillInfo.effectValue);
  286. Text_GongFaName.text = LanguageManager.Instance.Text(skillConfig.name) + " ";
  287. LayoutRebuilder.ForceRebuildLayoutImmediate(Text_GongFaName.GetComponent<RectTransform>());
  288. LayoutRebuilder.ForceRebuildLayoutImmediate(Text_Level.GetComponent<RectTransform>());
  289. LayoutRebuilder.ForceRebuildLayoutImmediate(Text_GongFaName.transform.parent.GetComponent<RectTransform>());
  290. switch (skillConfig.attribute)
  291. {
  292. case 1:
  293. csc.ChangeState(0);
  294. Icon_Attribute.icon_name = "dec_jin2";
  295. break;
  296. case 4:
  297. csc.ChangeState(1);
  298. Icon_Attribute.icon_name = "dec_mu2";
  299. break;
  300. case 2:
  301. csc.ChangeState(2);
  302. Icon_Attribute.icon_name = "dec_shui2";
  303. break;
  304. case 8:
  305. csc.ChangeState(3);
  306. Icon_Attribute.icon_name = "dec_huo2";
  307. break;
  308. case 16:
  309. csc.ChangeState(4);
  310. Icon_Attribute.icon_name = "dec_tu2";
  311. break;
  312. case 0:
  313. csc.ChangeState(5);
  314. Icon_Attribute.icon_name = "dec_fuzhu2";
  315. break;
  316. }
  317. for (var i = 0; i < StarRoot.Count; i++)
  318. {
  319. MyImage icon = StarRoot[i] as MyImage;
  320. if (i < skillInfo.skillConfig.level - 1)
  321. {
  322. icon.gameObject.SetActive(true);
  323. }
  324. else
  325. {
  326. icon.gameObject.SetActive(false);
  327. }
  328. }
  329. }
  330. private async CTask UpdateStarBtn()
  331. {
  332. foreach (var itemWidgetType1 in _itemWidgetType1)
  333. {
  334. UIManager.Instance.DormancyGComponent(itemWidgetType1);
  335. }
  336. _itemWidgetType1.Clear();
  337. // foreach (var energyWidget in _energyWidgets)
  338. // {
  339. // UIManager.Instance.DormancyGComponent(energyWidget);
  340. // }
  341. //
  342. // _energyWidgets.Clear();
  343. if (isUpGrad)
  344. {
  345. Btn_UpStar.gameObject.SetActive(false);
  346. Btn_UpGrade.gameObject.SetActive(false);
  347. Btn_UpStarOk.gameObject.SetActive(false);
  348. Btn_UpGradeOk.gameObject.SetActive(true);
  349. if (_skillInfo.SkillData.level < _skillPowerupConfigs.Count)
  350. {
  351. AccountFileInfo.SkillData skillData = new AccountFileInfo.SkillData();
  352. skillData.id = _skillInfo.SkillData.id;
  353. skillData.level = _skillInfo.SkillData.level + 1;
  354. skillData.star = _skillInfo.SkillData.star;
  355. SkillInfo nextSkillInfo = new SkillInfo(skillData);
  356. string[] effs = new string[_skillInfo.effectValue.Length];
  357. for (var i = 0; i < _skillInfo.effectValue.Length; i++)
  358. {
  359. if (_skillInfo.effectValue[i] == nextSkillInfo.effectValue[i])
  360. {
  361. effs[i] = FormatNumber(_skillInfo.effectValue[i]);
  362. }
  363. else
  364. {
  365. effs[i] =
  366. $"{FormatNumber(_skillInfo.effectValue[i])}<color=green>→({FormatNumber(nextSkillInfo.effectValue[i])})</color>";
  367. }
  368. }
  369. Text_NextLevel.transform.parent.gameObject.SetActive(true);
  370. Text_NextLevel.text = LanguageManager.Instance.Text(10221, _skillInfo.SkillPowerupConfig.ID,
  371. nextSkillInfo.SkillPowerupConfig.ID);
  372. LayoutRebuilder.ForceRebuildLayoutImmediate(Text_NextLevel.GetComponent<RectTransform>());
  373. LayoutRebuilder.ForceRebuildLayoutImmediate(Text_NextLevel.transform.parent
  374. .GetComponent<RectTransform>());
  375. Text_GongFaDesc.text =
  376. UtilTools.GetString(LanguageManager.Instance.Text(_skillInfo.skillConfig.dec), effs);
  377. Text_GongFaDesc.onClickCallBack = OnClickBuff;
  378. // Btn_UpGrade.GetComponent<RectTransform>().sizeDelta = new Vector2(481, 80);
  379. if (PlayerManager.Instance.myHero.level.Value < _skillInfo.SkillPowerupConfig.PlayerLevelLimit)
  380. {
  381. HeroPowerUpConfig heroPowerUpConfig =
  382. ConfigComponent.Instance.Get<HeroPowerUpConfig>(_skillInfo.SkillPowerupConfig
  383. .PlayerLevelLimit);
  384. Text_UpGrade.text =
  385. $"需境界达到{LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[0]) + LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[1]) + LanguageManager.Instance.Text(heroPowerUpConfig.jingjieLanIDs[2])}";
  386. Btn_UpGradeOk.gameObject.transform.Gray(true);
  387. UpGradeItemRoot.SetActive(false);
  388. }
  389. else
  390. {
  391. Btn_UpGradeOk.gameObject.transform.RecoverColor();
  392. Text_UpGrade.text = LanguageManager.Instance.Text(10220);
  393. UpGradeItemRoot.SetActive(true);
  394. for (var i = 0; i < _skillInfo.SkillPowerupConfig.LevelupItem.Length; i++)
  395. {
  396. ItemWidgetType1 itemWidgetType1 =
  397. await UIManager.Instance.CreateGComponentForObject<ItemWidgetType1>(ItemWidgetType1Gam,
  398. null, UpGradeItemRoot.GetComponent<RectTransform>(), isInstance: true);
  399. itemWidgetType1.CustomInit(_skillInfo.SkillPowerupConfig.LevelupItem[i],
  400. _skillInfo.SkillPowerupConfig.LevelupItemNum[i]);
  401. _itemWidgetType1.Add(itemWidgetType1);
  402. // EnergyWidget energyWidget =
  403. // await UIManager.Instance.CreateGComponent<EnergyWidget>(null, EnergyRoot);
  404. // energyWidget.CustomInit(_skillInfo.SkillPowerupConfig.LevelupItem[i]);
  405. // _energyWidgets.Add(energyWidget);
  406. }
  407. // Text_GongFaDesc.text = UtilTools.GetString(LanguageManager.Instance.Text(_skillInfo.skillConfig.dec), _skillInfo.effectValue);
  408. }
  409. }
  410. else
  411. {
  412. Text_NextLevel.transform.parent.gameObject.SetActive(true);
  413. Text_NextLevel.text = LanguageManager.Instance.Text(10221, _skillInfo.skillConfig.level,
  414. "Max");
  415. Text_UpGrade.text = LanguageManager.Instance.Text(10264);
  416. // Btn_UpStarOk.gameObject.SetActive(false);
  417. UpGradeItemRoot.SetActive(false);
  418. }
  419. }
  420. if (isUpStar)
  421. {
  422. foreach (var gongFaUpgradeInfoWidget in _gongFaUpgradeInfoWidgets)
  423. {
  424. gongFaUpgradeInfoWidget.SelectWidget(true);
  425. }
  426. Btn_UpStar.gameObject.SetActive(false);
  427. Btn_UpGrade.gameObject.SetActive(false);
  428. Btn_UpGradeOk.gameObject.SetActive(false);
  429. Btn_UpStarOk.gameObject.SetActive(true);
  430. if (_skillInfo.skillConfig.level < 6)
  431. {
  432. Btn_UpStarOk.gameObject.transform.RecoverColor();
  433. Text_UpStar.text = LanguageManager.Instance.Text(10219);
  434. UpStarItemRoot.SetActive(true);
  435. ItemConfig itemConfig = ConfigComponent.Instance.Get<ItemConfig>(_skillInfo.skillConfig.PieceID);
  436. SkillConstant skillConstant = ConfigComponent.Instance.Get<SkillConstant>(itemConfig.quality);
  437. int count = skillConstant.SkillPromoteNeedPieceNum[_skillInfo.skillConfig.level - 1];
  438. ItemWidgetType1 itemWidgetType1 =
  439. await UIManager.Instance.CreateGComponentForObject<ItemWidgetType1>(ItemWidgetType1Gam, null,
  440. UpStarItemRoot.GetComponent<RectTransform>(), isInstance: true);
  441. itemWidgetType1.CustomInit(_skillInfo.skillConfig.PieceID, count);
  442. _itemWidgetType1.Add(itemWidgetType1);
  443. }
  444. else
  445. {
  446. Btn_UpStarOk.transform.Gray(true);
  447. Text_UpStar.text = LanguageManager.Instance.Text(10265);
  448. // Btn_UpStarOk.gameObject.SetActive(false);
  449. UpStarItemRoot.SetActive(false);
  450. }
  451. }
  452. if (!isUpGrad && !isUpStar)
  453. {
  454. Btn_UpGrade.gameObject.SetActive(true);
  455. Btn_UpStar.gameObject.SetActive(true);
  456. Btn_UpGradeOk.gameObject.SetActive(false);
  457. Btn_UpStarOk.gameObject.SetActive(false);
  458. UpStarItemRoot.SetActive(false);
  459. UpGradeItemRoot.SetActive(false);
  460. Text_UpStar.text = LanguageManager.Instance.Text(10219);
  461. Text_UpGrade.text = LanguageManager.Instance.Text(10220);
  462. Btn_UpGradeOk.gameObject.transform.RecoverColor();
  463. foreach (var gongFaUpgradeInfoWidget in _gongFaUpgradeInfoWidgets)
  464. {
  465. gongFaUpgradeInfoWidget.SelectWidget(false);
  466. }
  467. Text_NextLevel.transform.parent.gameObject.SetActive(false);
  468. string[] effs = new string[_skillInfo.effectValue.Length];
  469. for (var i = 0; i < _skillInfo.effectValue.Length; i++)
  470. {
  471. effs[i] = FormatNumber(_skillInfo.effectValue[i]);
  472. }
  473. Text_GongFaDesc.text = UtilTools.GetString(LanguageManager.Instance.Text(_skillInfo.skillConfig.dec),
  474. effs);
  475. }
  476. LayoutRebuilder.ForceRebuildLayoutImmediate(UpStarItemRoot.GetComponent<RectTransform>());
  477. LayoutRebuilder.ForceRebuildLayoutImmediate(UpGradeItemRoot.GetComponent<RectTransform>());
  478. LayoutRebuilder.ForceRebuildLayoutImmediate(Text_UpStar.GetComponent<RectTransform>());
  479. LayoutRebuilder.ForceRebuildLayoutImmediate(Text_UpGrade.GetComponent<RectTransform>());
  480. LayoutRebuilder.ForceRebuildLayoutImmediate(UpGradeItemRoot.transform.parent.GetComponent<RectTransform>());
  481. LayoutRebuilder.ForceRebuildLayoutImmediate(UpStarItemRoot.transform.parent.GetComponent<RectTransform>());
  482. LayoutRebuilder.ForceRebuildLayoutImmediate(Btn_UpGrade.GetComponent<RectTransform>());
  483. }
  484. public async static CTask<GongFaUpgradePanel> Open(SkillInfo skillInfo)
  485. {
  486. GongFaUpgradePanel gongFaUpgradePanel =
  487. await UIManager.Instance.LoadAndOpenPanel<GongFaUpgradePanel>(null, uiData: new object[] { skillInfo });
  488. gongFaUpgradePanel.CustomInit(skillInfo);
  489. return gongFaUpgradePanel;
  490. }
  491. private void OnClickBuff(string info)
  492. {
  493. int buffId = 0;
  494. if (int.TryParse(info, out buffId))
  495. {
  496. BuffInfo buffInfo = BuffInfo.GetBuffInfo(buffId, 1, null);
  497. SkillInfopanel.OpenPanle(buffInfo);
  498. }
  499. }
  500. public async override CTask Close()
  501. {
  502. foreach (var gongFaUpgradeInfoWidget in _gongFaUpgradeInfoWidgets)
  503. {
  504. UIManager.Instance.DormancyGComponent(gongFaUpgradeInfoWidget);
  505. }
  506. foreach (var itemWidgetType1 in _itemWidgetType1)
  507. {
  508. UIManager.Instance.DormancyGComponent(itemWidgetType1);
  509. }
  510. _skillInfos.Clear();
  511. //
  512. // foreach (var energyWidget in _energyWidgets)
  513. // {
  514. // UIManager.Instance.DormancyGComponent(energyWidget);
  515. // }
  516. //
  517. // _energyWidgets.Clear();
  518. fx_ui_gongfa_shengji.gameObject.SetActive(false);
  519. _itemWidgetType1.Clear();
  520. _gongFaUpgradeInfoWidgets.Clear();
  521. isUpStar = false;
  522. isUpGrad = false;
  523. _skillInfo = null;
  524. await base.Close();
  525. }
  526. public static string FormatNumber(double number)
  527. {
  528. const double tolerance = 1e-10;
  529. // 判断是否接近整数
  530. if (Math.Abs(number - Math.Round(number)) < tolerance)
  531. {
  532. return Math.Round(number).ToString();
  533. }
  534. double integerPart = Math.Truncate(number);
  535. double fraction = number - integerPart;
  536. // 检查小数部分是否超过一位
  537. double firstDigit = Math.Truncate(fraction * 10);
  538. double remainder = fraction * 10 - firstDigit;
  539. if (Math.Abs(remainder) > tolerance)
  540. {
  541. return Math.Round(number, 1).ToString("0.0");
  542. }
  543. else
  544. {
  545. return integerPart.ToString();
  546. }
  547. }
  548. }
  549. }