PartnerDetailsPanelCtrl.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Security.Cryptography;
  9. using FairyGUI;
  10. using FL.Data;
  11. using XGame;
  12. using XGame.Database;
  13. using XGame.Framework.UI;
  14. namespace FL.FGUI
  15. {
  16. public class PartnerDetailsPanelParam
  17. {
  18. public int PlanId;
  19. /// <summary>
  20. /// 槽位id,-1为非更换界面打开的详情
  21. /// </summary>
  22. public int SlotId;
  23. public int PartnerId;
  24. }
  25. /// <summary>
  26. /// UI逻辑处理类
  27. /// </summary>
  28. /// <typeparam name=""></typeparam>
  29. public partial class PartnerDetailsPanelCtrl : UIController<PartnerDetailsPanelVM>
  30. {
  31. private int _partnerId;
  32. private int _slotId;
  33. private int _planId;
  34. private bool _initView = false;
  35. private List<int> _partnerIds = new List<int>();
  36. protected override void OnEnable(object intent)
  37. {
  38. var param = intent as PartnerDetailsPanelParam;
  39. _partnerId = param.PartnerId;
  40. _planId = param.PlanId;
  41. _slotId = param.SlotId;
  42. AddUIListenres();
  43. AddEventListener();
  44. InitPartnerIdList();
  45. ShowUI();
  46. }
  47. protected override void OnDisable()
  48. {
  49. RemoveUIListenres();
  50. RemoveEventListener();
  51. }
  52. #region 事件
  53. private void AddUIListenres()
  54. {
  55. VM.PreviousBtn.onClick.Add(OnClickPreviousBtn);
  56. VM.NextBtn.onClick.Add(OnClickNextBtn);
  57. VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
  58. VM.UpLvBtn.onClick.Add(OnClickUpLvBtn);
  59. VM.UpBtn.onClick.Add(OnClickUpBtn);
  60. VM.DownBtn.onClick.Add(OnClickDownBtn);
  61. VM.UpStarBtn.onClick.Add(OnClickUpStarBtn);
  62. VM.BackBtn.onClick.Add(OnClickBackBtn);
  63. VM.EpiItem.VM.PanelEvent.Add(OnClickEpiSet);
  64. }
  65. private void RemoveUIListenres()
  66. {
  67. VM.PreviousBtn.onClick.Remove(OnClickPreviousBtn);
  68. VM.NextBtn.onClick.Remove(OnClickNextBtn);
  69. VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
  70. VM.UpLvBtn.onClick.Remove(OnClickUpLvBtn);
  71. VM.UpBtn.onClick.Remove(OnClickUpBtn);
  72. VM.DownBtn.onClick.Remove(OnClickDownBtn);
  73. VM.UpStarBtn.onClick.Remove(OnClickUpStarBtn);
  74. VM.BackBtn.onClick.Remove(OnClickBackBtn);
  75. VM.EpiItem.VM.PanelEvent.Remove(OnClickEpiSet);
  76. }
  77. private void AddEventListener()
  78. {
  79. EventSingle.Instance.AddListener(EventDefine.PartnerUpLevel, OnUpdateLv);
  80. EventSingle.Instance.AddListener(EventDefine.PartnerUpStar, OnUpdateStar);
  81. EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnItemUpdate);
  82. EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnUpDownPartner);
  83. EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnUpDownPartner);
  84. EventSingle.Instance.AddListener(EventDefine.PartnerBinding, OnBinding);
  85. }
  86. private void RemoveEventListener()
  87. {
  88. EventSingle.Instance.RemoveListener(EventDefine.PartnerUpLevel, OnUpdateLv);
  89. EventSingle.Instance.RemoveListener(EventDefine.PartnerUpStar, OnUpdateStar);
  90. EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnItemUpdate);
  91. EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnUpDownPartner);
  92. EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnUpDownPartner);
  93. EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, OnBinding);
  94. }
  95. private void OnBinding(int eventId, object args)
  96. {
  97. ShowEpi();
  98. }
  99. private void OnUpdateStar(int eventId, object args)
  100. {
  101. ShowStarUI();
  102. }
  103. private void OnItemUpdate(int eventId, object args)
  104. {
  105. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  106. var starLv = info?.RisingStarLv ?? 1;
  107. ShowStarRatingCostUI(starLv);
  108. }
  109. private void OnClickPreviousBtn(EventContext context)
  110. {
  111. OnSelectPartnerOffset(1);
  112. }
  113. private void OnClickNextBtn(EventContext context)
  114. {
  115. OnSelectPartnerOffset(-1);
  116. }
  117. private void OnClickEpiSet(EventContext context)
  118. {
  119. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  120. if (info == null)
  121. {
  122. Context.ShowTips(StringDefine.PartnerEmptyTips);
  123. return;
  124. }
  125. Context.UI.OpenAsync(
  126. UIKeys.PartnerEpiChangePanel,
  127. new PartnerEpiChangePanelCtrlParam()
  128. {
  129. PlanId = PartnersData.Instance.UsePlanId,
  130. SlotId = -1,
  131. SbId = _partnerId,
  132. }
  133. );
  134. }
  135. private void OnClickChangeBtn(EventContext context)
  136. {
  137. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  138. if (info == null)
  139. {
  140. Context.ShowTips(StringDefine.PartnerEmptyTips);
  141. return;
  142. }
  143. Context.UI.OpenAsync(
  144. UIKeys.PartnerEpiChangePanel,
  145. new PartnerEpiChangePanelCtrlParam()
  146. {
  147. PlanId = PartnersData.Instance.UsePlanId,
  148. SlotId = -1,
  149. SbId = _partnerId,
  150. }
  151. );
  152. }
  153. private void OnClickUpLvBtn(EventContext context)
  154. {
  155. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  156. if (info == null)
  157. {
  158. Context.ShowTips(StringDefine.PartnerEmptyTips);
  159. return;
  160. }
  161. var lvTable = partnerLvUpTableRepo.GetPartnerLvUpTable(_partnerId, info.Level);
  162. if (lvTable == null)
  163. {
  164. Context.ShowTips(StringDefine.PartnerUpLvEmptyTips);
  165. return;
  166. }
  167. if (
  168. !ItemService.Instance.IsEnough(lvTable.LevelUpCost[0], lvTable.LevelUpCost[1], true)
  169. )
  170. return;
  171. PartnersService.Instance.RequestLvUp(_partnerId);
  172. }
  173. private void OnClickUpBtn(EventContext context)
  174. {
  175. if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_partnerId, out var info))
  176. {
  177. Context.ShowTips(StringDefine.PartnerEmptyTips);
  178. return;
  179. }
  180. if (PartnersData.Instance.UsePlanId == _planId)
  181. {
  182. if (info.Status > 0)
  183. {
  184. Context.ShowTips(StringDefine.PartnerAlreadyUpTips);
  185. return;
  186. }
  187. if (_slotId < 0)
  188. {
  189. PartnersService.Instance.OpenPartnerMode(_partnerId);
  190. }
  191. else
  192. {
  193. PartnersService.Instance.RequestPartnerUp(_slotId, _partnerId);
  194. }
  195. }
  196. else
  197. {
  198. PartnersService.Instance.RequestUpdatePlanSb(_planId, _slotId, _partnerId);
  199. }
  200. Context.ClosePanel();
  201. }
  202. /// <summary>
  203. /// 下阵按钮事件
  204. /// </summary>
  205. /// <param name="context"></param>
  206. private void OnClickDownBtn(EventContext context)
  207. {
  208. if (!PartnersData.Instance.TryGetPartnerAttrByTableId(_partnerId, out var info))
  209. {
  210. Context.ShowTips(StringDefine.PartnerEmptyTips);
  211. return;
  212. }
  213. if (_planId == PartnersData.Instance.UsePlanId)
  214. {
  215. PartnersService.Instance.RequestPartnerDown(_partnerId);
  216. }
  217. else
  218. {
  219. if (!PartnersData.Instance.TryGetPlan(_planId, out var plan))
  220. {
  221. Context.ShowTips(StringDefine.PartnerPlanEmptyTips);
  222. return;
  223. }
  224. if (!plan.TryGetUpPos(_partnerId, out var upPos))
  225. {
  226. Context.ShowTips(StringDefine.PartnerAlreadyUpTips);
  227. return;
  228. }
  229. PartnersService.Instance.RequestUpdatePlanSb(_planId, upPos, 0);
  230. }
  231. Context.ClosePanel();
  232. }
  233. private void OnClickUpStarBtn(EventContext context)
  234. {
  235. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  236. if (info == null)
  237. {
  238. Context.ShowTips(StringDefine.PartnerEmptyTips);
  239. return;
  240. }
  241. var starTable = partnerStarUpTableRepo.GetPartnerStarTable(
  242. _partnerId,
  243. info.RisingStarLv
  244. );
  245. if (starTable == null)
  246. {
  247. Context.ShowTips(StringDefine.PartnerUpStarEmptyTips);
  248. return;
  249. }
  250. if (!ItemService.Instance.IsEnough(starTable.PetId, starTable.StarUpCost, true))
  251. return;
  252. PartnersService.Instance.RequestStarUp(_partnerId);
  253. }
  254. private void OnClickBackBtn(EventContext context)
  255. {
  256. Context.ClosePanel();
  257. }
  258. private void OnUpDownPartner(int eventId, object args)
  259. {
  260. ShowUpDownBtn();
  261. }
  262. /// <summary>
  263. /// 圣兵升级监听事件
  264. /// </summary>
  265. /// <param name="eventId"></param>
  266. /// <param name="args"></param>
  267. private void OnUpdateLv(int eventId, object args)
  268. {
  269. ShowLevelUI();
  270. }
  271. #endregion
  272. #region 界面
  273. private void ShowUI()
  274. {
  275. ShowPartnerUI();
  276. ShowEpi();
  277. ShowSwitchState();
  278. }
  279. private void ShowEpi()
  280. {
  281. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  282. if (info == null)
  283. {
  284. VM.EpiItem.Disable();
  285. }
  286. else
  287. {
  288. VM.EpiItem.Enable(null);
  289. VM.EpiItem.Ctrl.SetData(info.EpigraphId, _partnerId, true);
  290. }
  291. }
  292. private void ShowPartnerUI()
  293. {
  294. var table = PartnerTableRepo.Get(_partnerId);
  295. if (table == null)
  296. {
  297. Log.Error($"圣兵tableId {_partnerId} 不存在");
  298. return;
  299. }
  300. VM.PartnerIcon.icon = table.Icon;
  301. //LoadPartnerSpine(partnerInfo?.Model);
  302. VM.QualityIcon.icon = AddressableDefine.ItemFrame(table.Quality);
  303. VM.SacredVesselsIcon.icon = table.SkillIcon;
  304. VM.AttrTypeIcon.icon = AddressableDefine.PartnerElementType((int)table.Element);
  305. VM.NameLabel.text = table.Name;
  306. VM.TypeLabel.text = StringDefine.partnerTypeList[table.Type - 1];
  307. ShowUpDownBtn();
  308. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  309. VM.Have.selectedIndex = info != null ? 1 : 0;
  310. ShowLevelUI();
  311. ShowStarUI();
  312. }
  313. private void ShowUpDownBtn()
  314. {
  315. if (!PartnersData.Instance.TryGetPlan(_planId, out var plan))
  316. {
  317. Log.Error($"圣兵信息不存在,id:{_planId}");
  318. return;
  319. }
  320. VM.ShowBtnCtrl.selectedIndex = plan.TryGetUpPos(_partnerId, out var upPos) ? 1 : 0;
  321. }
  322. private void ShowStarUI()
  323. {
  324. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  325. var starLv = info?.RisingStarLv ?? 1;
  326. ShowPartnerStarUI(starLv);
  327. ShowStarRatingCostUI(starLv);
  328. ShowStarOwnAttr(starLv);
  329. ShowBuff(starLv);
  330. }
  331. /// <summary>
  332. /// 星星数
  333. /// </summary>
  334. /// <param name="starLv"></param>
  335. private void ShowPartnerStarUI(int starLv)
  336. {
  337. int starNum = starLv == 0 ? 0 : starLv % PartnersData.MaxStarNum;
  338. if (starLv > 0 && starNum == 0)
  339. starNum = PartnersData.MaxStarNum;
  340. int starStep = PartnersService.Instance.GetStarStep(starLv);
  341. int[] array = Enumerable.Repeat(starStep, starNum).ToArray();
  342. VM.StarRatingList.BindDatas(array);
  343. }
  344. /// <summary>
  345. /// 拥有的星级效果属性描述
  346. /// </summary>
  347. private void ShowStarOwnAttr(int starLv)
  348. {
  349. partnerStarUpTable starTable = partnerStarUpTableRepo.GetPartnerStarTable(
  350. _partnerId,
  351. starLv
  352. );
  353. if (starTable == null)
  354. {
  355. Log.Error($"圣兵升星表tableId:{_partnerId}, starLv:{starLv} 不存在");
  356. return;
  357. }
  358. var attrsArray = starTable.StarOwnAttr;
  359. if (attrsArray?.Length > 0)
  360. {
  361. string desc = string.Empty;
  362. for (int i = 0; i < attrsArray.Length; i += 2)
  363. {
  364. GetAttributeDesc(attrsArray[i], attrsArray[i + 1], ref desc);
  365. if (i + 1 < attrsArray.Length - 1)
  366. {
  367. desc += ",";
  368. }
  369. }
  370. VM.SkillEffectLabel.text = string.Format(StringDefine.partnerStarAttribute, desc);
  371. VM.SkillEffectLabel.visible = true;
  372. }
  373. else
  374. {
  375. VM.SkillEffectLabel.visible = false;
  376. }
  377. }
  378. private void GetAttributeDesc(int attrType, int attrValue, ref string desc)
  379. {
  380. var attributeInfo = AttrDescTableRepo.Get(attrType);
  381. string valStr = attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
  382. desc += $"{attributeInfo?.ShowName}{valStr}%";
  383. }
  384. /// <summary>
  385. /// 升星消耗
  386. /// </summary>
  387. /// <param name="starLv"></param>
  388. private void ShowStarRatingCostUI(int starLv)
  389. {
  390. partnerStarUpTable starTable = partnerStarUpTableRepo.GetPartnerStarTable(
  391. _partnerId,
  392. starLv
  393. );
  394. if (starTable == null)
  395. {
  396. Log.Error($"圣兵升星表tableId:{_partnerId}, starLv:{starLv} 不存在");
  397. return;
  398. }
  399. bool isMaxStar =
  400. partnerStarUpTableRepo.GetPartnerStarTable(_partnerId, starLv + 1) == null;
  401. VM.MaxStarCtrl.selectedIndex = isMaxStar ? 1 : 0;
  402. if (!isMaxStar && starTable?.StarUpCost > 0)
  403. {
  404. long num = ItemData.Instance.GetItemNum(starTable.PetId);
  405. VM.StarCostBar.max = starTable.StarUpCost;
  406. VM.StarCostBar.value = num;
  407. }
  408. }
  409. private void InitPartnerIdList()
  410. {
  411. if (_initView)
  412. return;
  413. var attrs = PartnerTableRepo.GetAll();
  414. foreach (var attr in attrs)
  415. {
  416. _partnerIds.Add(attr.Id);
  417. }
  418. _initView = true;
  419. }
  420. private void OnSelectPartnerOffset(int offset)
  421. {
  422. var index = _partnerIds.IndexOf(_partnerId);
  423. index += offset;
  424. if (index < 0)
  425. {
  426. index += _partnerIds.Count;
  427. }
  428. else if (index >= _partnerIds.Count)
  429. {
  430. index -= _partnerIds.Count;
  431. }
  432. _partnerId = _partnerIds[index];
  433. ShowUI();
  434. }
  435. /// <summary>
  436. /// 上一个|下一个按钮显隐
  437. /// </summary>
  438. private void ShowSwitchState()
  439. {
  440. VM.CanSwitch.selectedIndex = (_partnerIds.Count > 0 && _slotId < 0) ? 1 : 0;
  441. }
  442. /// <summary>
  443. /// 圣器升级基础属性
  444. /// </summary>
  445. /// <param name="partnerTableId"></param>
  446. /// <param name="level"></param>
  447. private void ShowLevelUI()
  448. {
  449. var info = PartnersData.Instance.GetPartnerAttrByTableId(_partnerId);
  450. var lv = info?.Level ?? 1;
  451. var lvTable = partnerLvUpTableRepo.GetPartnerLvUpTable(_partnerId, lv);
  452. if (lvTable == null)
  453. {
  454. Log.Error($"圣兵等级提升表不存在sbId{_partnerId}, lv:{lv}");
  455. return;
  456. }
  457. bool bMaxLv = partnerLvUpTableRepo.GetPartnerLvUpTable(_partnerId, lv + 1) == null;
  458. if (info == null)
  459. {
  460. VM.UpgradeCostItem.Disable();
  461. }
  462. else if (bMaxLv)
  463. {
  464. VM.UpgradeCostItem.Disable();
  465. }
  466. else
  467. {
  468. VM.UpgradeCostItem.Enable(null);
  469. }
  470. VM.LvLabel.text = $"LV.{lv}";
  471. if (lvTable.LvAttr.Length > 0)
  472. {
  473. VM.MaxLvCtrl.selectedIndex = bMaxLv ? 1 : 0;
  474. if (!bMaxLv)
  475. {
  476. if (lvTable?.LevelUpCost?.Length > 0)
  477. {
  478. VM.UpgradeCostItem.Ctrl.ShowCostUI(
  479. lvTable.LevelUpCost[0],
  480. lvTable.LevelUpCost[1]
  481. );
  482. }
  483. }
  484. var atkVal = lvTable.LvAttr[1];
  485. //var attributeInfo = AttrDescTableRepo.Get(attrType);
  486. string desc = atkVal > 0 ? TableUtils.ToRealDouble(atkVal).ToString("F1") : "0";
  487. //VM.AtkLabel.text = $"{attributeInfo?.ShowName}:{desc}";
  488. VM.AtkLabel.text = string.Format(StringDefine.partnerAttack, desc);
  489. if (lvTable.LvAttr.Length > 3)
  490. {
  491. //var attributeInfo = AttrDescTableRepo.Get(attrType);
  492. var atkSpeed = lvTable.LvAttr[3];
  493. string descSpeed =
  494. atkSpeed > 0 ? TableUtils.ToRealDouble(atkSpeed).ToString("F1") : "0";
  495. //VM.AtkSpeedLabel.text = $"{attributeInfo?.ShowName}:{desc}";
  496. VM.AtkSpeedLabel.text = string.Format(StringDefine.partnerAtkSpeed, descSpeed);
  497. }
  498. }
  499. }
  500. /// <summary>
  501. /// 加载圣器的spine
  502. /// </summary>
  503. /// <param name="spineName"></param>
  504. private void LoadPartnerSpine(string spineName)
  505. {
  506. VM.PartnerSpine.LoadSpine(spineName, "idle", true);
  507. }
  508. private void ShowBuff(int starLv)
  509. {
  510. var table = PartnerTableRepo.Get(_partnerId);
  511. if (table == null)
  512. {
  513. Log.Error($"圣兵tableId {_partnerId} 不存在");
  514. return;
  515. }
  516. var starSkillIds = table?.Skill;
  517. var dataList = new List<List<int>>();
  518. if (starSkillIds?.Length > 0)
  519. {
  520. int index = 0;
  521. for (int i = 0; i < starSkillIds.Length; i += 2)
  522. {
  523. // 0星激活的技能效果
  524. if (starSkillIds[i + 1] == 0)
  525. {
  526. ShowSkillBaseInfo(starSkillIds[i]);
  527. }
  528. else
  529. {
  530. var data = new List<int>() { starSkillIds[i], starSkillIds[i + 1], starLv };
  531. dataList.Add(data);
  532. }
  533. index++;
  534. }
  535. }
  536. VM.StarBuffItemList.BindDatas(dataList);
  537. }
  538. /// <summary>
  539. /// 基础技能描述
  540. /// </summary>
  541. /// <param name="skillId"></param>
  542. private void ShowSkillBaseInfo(int skillId)
  543. {
  544. var skillInfo = SkillTableRepo.Get(skillId);
  545. VM.SkillInfoLabel.text = skillInfo == null ? "" : skillInfo.Desc;
  546. }
  547. #endregion
  548. }
  549. }