PartnerDetailsPanelCtrl.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. 
  2. /// #pkgName FGUI包名
  3. /// #panelName UIPanel名字
  4. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  5. /// 该脚本由模板创建
  6. /// created by cb 2024
  7. using FairyGUI;
  8. using FL.Data;
  9. using System.Collections.Generic;
  10. using System.Linq;
  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 long _partnerId;
  22. private int _state; /// 1:已获取未上阵 2:已上阵
  23. private int _curIndex;
  24. private List<long> _partnerIdList; // 拥有的全部伙伴(圣兵)id列表
  25. protected override void OnEnable(object intent)
  26. {
  27. AddUIListenres();
  28. AddEventListener();
  29. InitUI(intent as PartnerListItemData);
  30. ShowUI();
  31. }
  32. protected override void OnDisable()
  33. {
  34. RemoveUIListenres();
  35. RemoveEventListener();
  36. }
  37. private void OnClosePanel()
  38. {
  39. Context.ClosePanel();
  40. }
  41. #region UI事件
  42. private void AddUIListenres()
  43. {
  44. VM.PreviousBtn.onClick.Add(OnClickPreviousBtn);
  45. VM.NextBtn.onClick.Add(OnClickNextBtn);
  46. VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
  47. VM.UpgradeBtn.onClick.Add(OnClickUpgradeBtn);
  48. VM.GoIntoBattleBtn.onClick.Add(OnClickGoIntoBattleBtn);
  49. VM.TakeDownBtn.onClick.Add(OnclickTakeDownBtn);
  50. VM.RisingStarBtn.onClick.Add(OnClickRisingStarBtn);
  51. VM.BackBtn.onClick.Add(OnClickBackBtn);
  52. }
  53. private void RemoveUIListenres()
  54. {
  55. VM.PreviousBtn.onClick.Remove(OnClickPreviousBtn);
  56. VM.NextBtn.onClick.Remove(OnClickNextBtn);
  57. VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
  58. VM.UpgradeBtn.onClick.Remove(OnClickUpgradeBtn);
  59. VM.GoIntoBattleBtn.onClick.Remove(OnClickGoIntoBattleBtn);
  60. VM.TakeDownBtn.onClick.Remove(OnclickTakeDownBtn);
  61. VM.RisingStarBtn.onClick.Remove(OnClickRisingStarBtn);
  62. VM.BackBtn.onClick.Remove(OnClickBackBtn);
  63. }
  64. private void OnClickPreviousBtn(EventContext context)
  65. {
  66. OnSelectPartner(_curIndex-1);
  67. }
  68. private void OnClickNextBtn(EventContext context)
  69. {
  70. OnSelectPartner(_curIndex+1);
  71. }
  72. private void OnClickChangeBtn(EventContext context)
  73. {
  74. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开铭文替换界面");
  75. }
  76. private void OnClickUpgradeBtn(EventContext context)
  77. {
  78. EventSingle.Instance.Notify(EventDefine.ShowTips, "升级按钮事件");
  79. }
  80. private void OnClickGoIntoBattleBtn(EventContext context)
  81. {
  82. EventSingle.Instance.Notify(EventDefine.ShowTips, "上阵按钮事件");
  83. //if (PartnersData.Instance.IsReachedLimit)
  84. //{
  85. // //Context.UI.OpenAsync(UIKeys.PartnerReplacePartnerPanel, new PartnerParam()
  86. // //{
  87. // // partnerId = _partnerId,
  88. // // lineupPlanIndex = PartnersData.Instance.usePlanIndex
  89. // //});
  90. // EventSingle.Instance.Notify(EventDefine.WaitForDownPartner,true);
  91. //}
  92. //else
  93. //{
  94. // PartnersService.Instance.RequestPartnerUp(_partnerId);
  95. //}
  96. EventSingle.Instance.Notify(EventDefine.WaitForDownPartner, true);
  97. OnClosePanel();
  98. }
  99. /// <summary>
  100. /// 下阵按钮事件
  101. /// </summary>
  102. /// <param name="context"></param>
  103. private void OnclickTakeDownBtn(EventContext context)
  104. {
  105. //PartnersData.Instance.GoneUpMap.ContainsKey(_partnerId)
  106. //PartnersService.Instance.RequestPartnerDown(_partnerId);
  107. OnClosePanel();
  108. }
  109. private void OnClickRisingStarBtn(EventContext context)
  110. {
  111. EventSingle.Instance.Notify(EventDefine.ShowTips, "升星按钮事件");
  112. }
  113. private void OnClickBackBtn(EventContext context)
  114. {
  115. OnClosePanel();
  116. }
  117. #endregion
  118. private void AddEventListener()
  119. {
  120. EventSingle.Instance.AddListener(EventDefine.UpgradePartnerLevel, UpgradePartnerLevel);
  121. EventSingle.Instance.AddListener(EventDefine.UpgradePartnerStar, UpgradePartnerStar);
  122. }
  123. private void RemoveEventListener()
  124. {
  125. EventSingle.Instance.RemoveListener(EventDefine.UpgradePartnerLevel, UpgradePartnerLevel);
  126. EventSingle.Instance.RemoveListener(EventDefine.UpgradePartnerStar, UpgradePartnerStar);
  127. }
  128. private void InitUI(PartnerListItemData data)
  129. {
  130. if (data != null)
  131. {
  132. _partnerId = data.tableId;
  133. //_state = data.state;
  134. }
  135. }
  136. private void ShowUI()
  137. {
  138. InitPartnerIdList();
  139. _curIndex = _partnerIdList.IndexOf(_partnerId);
  140. XGame.Log.Info($"_partnerId:{_partnerId}所处的索引:{_curIndex}");
  141. ShowPartnerUI();
  142. ShowBtnState();
  143. }
  144. private void ShowPartnerUI()
  145. {
  146. if (PartnersData.Instance.PartnersMap.TryGetValue(_partnerId, out var partnerData))
  147. {
  148. var partnerInfo = PartnerTableRepo.Get(partnerData.TableId);
  149. if (partnerInfo != null)
  150. {
  151. EQualityLevel qualityLv = (EQualityLevel)partnerInfo.Quality;
  152. VM.PartnerIcon.icon = partnerInfo.Icon;
  153. //LoadPartnerSpine(partnerInfo?.Model);
  154. VM.QualityIcon.icon = AddressableDefine.ItemFrame(qualityLv);
  155. VM.SacredVesselsIcon.icon = partnerInfo.Icon;
  156. VM.AttrTypeIcon.icon = AddressableDefine.PartnerElementType((int)partnerInfo.Element);
  157. VM.NameLabel.text = partnerInfo.Name;
  158. VM.TypeLabel.text = StringDefine.partnerTypeList[partnerInfo.Type - 1];
  159. ShowUpgradeUI(partnerData.TableId, partnerData.Level);
  160. ShowStarRatingUI(partnerData.RisingStarLv, partnerData.TableId);
  161. ShowBuff(partnerInfo.Skill, partnerData.RisingStarLv);
  162. }
  163. }
  164. }
  165. /// <summary>
  166. /// 星星数
  167. /// </summary>
  168. /// <param name="starLv"></param>
  169. private void ShowPartnerStarUI(int starLv)
  170. {
  171. int starNum = starLv == 0 ? 0 : starLv % PartnersData.MaxStarNum;
  172. if (starLv > 0 && starNum == 0)starNum = PartnersData.MaxStarNum;
  173. int starStep = PartnersData.Instance.GetStarStep(starLv);
  174. int[] array = Enumerable.Repeat(starStep, starNum).ToArray();
  175. VM.StarRatingList.BindDatas(array);
  176. //XGame.Log.Info($"星级starLv:{starLv}对应的星阶starStep:{starStep}");
  177. }
  178. /// <summary>
  179. /// 升级消耗
  180. /// </summary>
  181. /// <param name="starLv"></param>
  182. private void ShowUpgradeCostUI(partnerLvUpTable partnerInfo)
  183. {
  184. if (partnerInfo == null) return;
  185. bool bMaxLv = partnerLvUpTableRepo.Get(partnerInfo.Id + 1) == null;
  186. VM.MaxLvCtrl.selectedIndex = bMaxLv ? 1 : 0;
  187. if (!bMaxLv)
  188. {
  189. if (partnerInfo?.LevelUpCost?.Length > 0)
  190. {
  191. VM.UpgradeCostItem.Ctrl.ShowCostUI(partnerInfo.LevelUpCost[0], partnerInfo.LevelUpCost[1]);
  192. }
  193. }
  194. }
  195. /// <summary>
  196. /// 升星相关UI
  197. /// </summary>
  198. /// <param name="starLv"></param>
  199. /// <param name="partnerTableId"></param>
  200. private void ShowStarRatingUI(int starLv, int partnerTableId)
  201. {
  202. ShowPartnerStarUI(starLv);
  203. partnerStarUpTable partnerStarInfo = partnerStarUpTableRepo.Get(partnerTableId * 1000 + starLv);
  204. ShowStarRatingCostUI(starLv, partnerStarInfo);
  205. ShowStarOwnAttr(partnerStarInfo?.StarOwnAttr);
  206. }
  207. /// <summary>
  208. /// 拥有的星级效果属性描述
  209. /// </summary>
  210. private void ShowStarOwnAttr(int[] attrsArray)
  211. {
  212. string desc = string.Empty;
  213. if (attrsArray?.Length > 0)
  214. {
  215. for (int i = 0; i < attrsArray.Length; i+=2)
  216. {
  217. GetAttributeDesc(attrsArray[i], attrsArray[i + 1], ref desc);
  218. if (i+1 < attrsArray.Length-1)
  219. {
  220. desc += ",";
  221. }
  222. }
  223. }
  224. VM.SkillEffectLabel.text = string.Format(StringDefine.partnerStarAttribute, desc);
  225. }
  226. private void GetAttributeDesc(int attrType, int attrValue,ref string desc)
  227. {
  228. var attributeInfo = AttrDescTableRepo.Get(attrType);
  229. string valStr = attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
  230. desc += $"{attributeInfo?.ShowName}{valStr}%";
  231. }
  232. /// <summary>
  233. /// 升星消耗
  234. /// </summary>
  235. /// <param name="starLv"></param>
  236. private void ShowStarRatingCostUI(int starLv, partnerStarUpTable partnerStarInfo)
  237. {
  238. bool bMaxStar = starLv >= PartnersData.MaxStarNum * PartnersData.MaxStarStep;
  239. VM.MaxStarCtrl.selectedIndex = bMaxStar ? 1 : 0;
  240. if (!bMaxStar && partnerStarInfo?.StarUpCost > 0)
  241. {
  242. long num = ItemData.Instance.GetItemNum(partnerStarInfo.PetId);
  243. VM.StarCostBar.max = partnerStarInfo.StarUpCost;
  244. VM.StarCostBar.value = num;
  245. }
  246. }
  247. private void InitPartnerIdList()
  248. {
  249. if (_partnerIdList == null)
  250. _partnerIdList = new List<long>();
  251. else
  252. _partnerIdList.Clear();
  253. var partnersMap = PartnersData.Instance.PartnersMap;
  254. if (partnersMap != null)
  255. {
  256. foreach (var key in partnersMap.Keys)
  257. {
  258. _partnerIdList.Add(key);
  259. }
  260. }
  261. }
  262. private void OnSelectPartner(int selectIndex)
  263. {
  264. if (selectIndex < 0 || selectIndex >= _partnerIdList?.Count) return;
  265. _curIndex = selectIndex;
  266. _partnerId = _partnerIdList[selectIndex];
  267. _state = PartnersData.Instance.GoneUpMap.ContainsKey(_partnerId) ? 2 : 1;
  268. ShowPartnerUI();
  269. ShowBtnState();
  270. }
  271. /// <summary>
  272. /// 上一个|下一个按钮显隐
  273. /// </summary>
  274. private void ShowBtnState()
  275. {
  276. VM.PreviousBtn.visible = _curIndex > 0;
  277. VM.NextBtn.visible = _curIndex < _partnerIdList.Count - 1;
  278. // 2_已上阵的圣器
  279. VM.ShowBtnCtrl.selectedIndex = _state == 2 ? 1 : 0;
  280. }
  281. /// <summary>
  282. /// 圣器升级基础属性
  283. /// </summary>
  284. /// <param name="partnerTableId"></param>
  285. /// <param name="level"></param>
  286. private void ShowUpgradeUI(int partnerTableId, int level)
  287. {
  288. VM.LvLabel.text = $"LV.{level}";
  289. partnerLvUpTable partnerLvInfo = partnerLvUpTableRepo.Get(partnerTableId * 1000 + level);
  290. ShowUpgradeCostUI(partnerLvInfo);
  291. if (partnerLvInfo?.LvAttr?.Length > 0)
  292. {
  293. ShowAttack(partnerLvInfo.LvAttr[0], partnerLvInfo.LvAttr[1]);
  294. if (partnerLvInfo.LvAttr.Length > 3)
  295. {
  296. ShowAtkSpeed(partnerLvInfo.LvAttr[2], partnerLvInfo.LvAttr[3]);
  297. }
  298. }
  299. }
  300. /// <summary>
  301. /// 攻速描述
  302. /// </summary>
  303. /// <param name="atkSpeedVal"></param>
  304. private void ShowAtkSpeed(int attrType, long atkSpeedVal)
  305. {
  306. //var attributeInfo = AttrDescTableRepo.Get(attrType);
  307. string desc = atkSpeedVal > 0 ? TableUtils.ToRealDouble(atkSpeedVal).ToString("F1") : "0";
  308. //VM.AtkSpeedLabel.text = $"{attributeInfo?.ShowName}:{desc}";
  309. VM.AtkSpeedLabel.text = string.Format(StringDefine.partnerAtkSpeed, desc);
  310. }
  311. /// <summary>
  312. /// 攻击伤害
  313. /// </summary>
  314. /// <param name="attrType"></param>
  315. /// <param name="attackVal"></param>
  316. private void ShowAttack(int attrType,long attackVal)
  317. {
  318. //var attributeInfo = AttrDescTableRepo.Get(attrType);
  319. string desc = attackVal > 0 ? TableUtils.ToRealDouble(attackVal).ToString("F1") : "0";
  320. //VM.AtkLabel.text = $"{attributeInfo?.ShowName}:{desc}";
  321. VM.AtkLabel.text = string.Format(StringDefine.partnerAttack, desc);
  322. }
  323. /// <summary>
  324. /// 加载圣器的spine
  325. /// </summary>
  326. /// <param name="spineName"></param>
  327. private void LoadPartnerSpine(string spineName)
  328. {
  329. VM.PartnerSpine.LoadSpine(spineName, "idle", true);
  330. }
  331. private void ShowBuff(int[] starSkillIds, int risingStarLv)
  332. {
  333. var dataList = new List<List<int>>();
  334. if (starSkillIds?.Length > 0)
  335. {
  336. int index = 0;
  337. for (int i = 0; i < starSkillIds.Length; i += 2)
  338. {
  339. // 0星激活的技能效果
  340. if (starSkillIds[i + 1] == 0)
  341. {
  342. ShowSkillBaseInfo(starSkillIds[i]);
  343. }
  344. else
  345. {
  346. var data = new List<int>()
  347. {
  348. starSkillIds[i],
  349. starSkillIds[i + 1],
  350. risingStarLv
  351. };
  352. dataList.Add(data);
  353. }
  354. index++;
  355. }
  356. }
  357. VM.StarBuffItemList.BindDatas(dataList);
  358. }
  359. /// <summary>
  360. /// 基础技能描述
  361. /// </summary>
  362. /// <param name="skillId"></param>
  363. private void ShowSkillBaseInfo(int skillId)
  364. {
  365. var skillInfo = SkillTableRepo.Get(skillId);
  366. VM.SkillInfoLabel.text = skillInfo == null ? "" : skillInfo.Desc;
  367. }
  368. /// <summary>
  369. /// 圣兵升级监听事件
  370. /// </summary>
  371. /// <param name="eventId"></param>
  372. /// <param name="args"></param>
  373. private void UpgradePartnerLevel(int eventId, object args)
  374. {
  375. }
  376. /// <summary>
  377. /// 圣兵升星监听事件
  378. /// </summary>
  379. /// <param name="eventId"></param>
  380. /// <param name="args"></param>
  381. private void UpgradePartnerStar(int eventId, object args)
  382. {
  383. }
  384. }
  385. }