PartnerDetailsPanelCtrl.cs 20 KB

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