PartnerDetailsPanelCtrl.cs 19 KB

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