PartnerEpiDetailInfoCtrl.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using FairyGUI;
  8. using FL.Data;
  9. using XGame;
  10. using XGame.Database;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUI
  13. {
  14. /// <summary>
  15. /// UI逻辑处理类
  16. /// </summary>
  17. /// <typeparam name=""></typeparam>
  18. public partial class PartnerEpiDetailInfoCtrl : UIController<PartnerEpiDetailInfoVM>
  19. {
  20. protected override void OnEnable(object intent)
  21. {
  22. _mwId = (int)intent;
  23. AddUIListenres();
  24. UpView();
  25. }
  26. protected override void OnDisable()
  27. {
  28. RemoveUIListenres();
  29. }
  30. #region UI事件
  31. private void AddUIListenres()
  32. {
  33. VM.UpBtn.onClick.Add(OnClickUpBtn);
  34. VM.DownBtn.onClick.Add(OnClickDownBtn);
  35. VM.GotoBtn.onClick.Add(OnClickGotoBtn);
  36. VM.RankUpBtn.onClick.Add(OnClickRankUpBtn);
  37. EventSingle.Instance.AddListener(EventDefine.EpigraphUpStar, OnEpiUpdate);
  38. EventSingle.Instance.AddListener(EventDefine.PartnerBinding, UpdateUpDownBtn);
  39. EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnItemUpdate);
  40. }
  41. private void RemoveUIListenres()
  42. {
  43. VM.UpBtn.onClick.Remove(OnClickUpBtn);
  44. VM.DownBtn.onClick.Remove(OnClickDownBtn);
  45. VM.GotoBtn.onClick.Remove(OnClickGotoBtn);
  46. VM.RankUpBtn.onClick.Remove(OnClickRankUpBtn);
  47. EventSingle.Instance.RemoveListener(EventDefine.EpigraphUpStar, OnEpiUpdate);
  48. EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, UpdateUpDownBtn);
  49. EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnItemUpdate);
  50. }
  51. private void OnItemUpdate(int eventId, object args)
  52. {
  53. UpProgressInfo();
  54. }
  55. private void OnEpiUpdate(int eventId, object args)
  56. {
  57. UpProgressInfo();
  58. UpSkillList();
  59. }
  60. private void OnClickDownBtn(EventContext eventContext)
  61. {
  62. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  63. if (info == null)
  64. {
  65. Log.Error($"铭文数据不存在tableId:{_mwId}");
  66. return;
  67. }
  68. EpigraphService.Instance.RequestEpiInset(info.PartnerId, 0);
  69. Context.ClosePanel();
  70. }
  71. private void OnClickUpBtn(EventContext context)
  72. {
  73. if (!EpigraphData.Instance.TryGetEpigraphAttrByTableId(_mwId, out var attr))
  74. {
  75. Context.ShowTips(StringDefine.EpigraphEmptyTips);
  76. return;
  77. }
  78. if (attr.PartnerId > 0)
  79. {
  80. Context.ShowTips(StringDefine.EpigraphAlreadyUpTips);
  81. return;
  82. }
  83. EpigraphService.Instance.OpenUpMode(_mwId);
  84. Context.ClosePanel();
  85. }
  86. private void OnClickGotoBtn(EventContext context) { }
  87. private void OnClickRankUpBtn(EventContext context)
  88. {
  89. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  90. if (info == null)
  91. {
  92. Log.Error($"铭文数据不存在tableId:{_mwId}");
  93. return;
  94. }
  95. var table = epigraphUpTableRepo.GetEpiragphUp(_mwId, info.StarLv);
  96. if (table == null)
  97. {
  98. Log.Error($"铭文升星表不存在id:{_mwId}, starLv{info.StarLv}");
  99. return;
  100. }
  101. if (table.LevelUpCost > ItemData.Instance.GetItemNum(_mwId))
  102. {
  103. Context.ShowTips(StringDefine.epigraphUpUnenough);
  104. return;
  105. }
  106. EpigraphService.Instance.RequestEpiStarUp(_mwId);
  107. }
  108. #endregion
  109. #region 属性
  110. private int _mwId;
  111. #endregion
  112. #region 页面
  113. private void UpView()
  114. {
  115. UpDescInfo();
  116. UpProgressInfo();
  117. UpSkillList();
  118. }
  119. private void UpdateUpDownBtn(int eventId, object args)
  120. {
  121. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  122. VM.Up.selectedIndex = info?.PartnerId > 0 ? 1 : 0;
  123. }
  124. private void UpDescInfo()
  125. {
  126. var table = EpigraphTableRepo.Get(_mwId);
  127. if (table == null)
  128. {
  129. Log.Error($"铭文表不存在id:{_mwId}");
  130. }
  131. VM.EpiLabel.Ctrl.SetEpiIcon(_mwId, true);
  132. var initSkillId = table.Skill[0];
  133. var skillTable = SkillTableRepo.Get(initSkillId);
  134. if (skillTable == null)
  135. {
  136. Log.Error($"技能表不能存在,技能ID:{initSkillId}");
  137. return;
  138. }
  139. VM.DescLabel.text = skillTable.Desc;
  140. VM.NameLabel.text = table.Name;
  141. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  142. if (info != null)
  143. {
  144. VM.Up.selectedIndex = info.PartnerId > 0 ? 1 : 0;
  145. int nextLv = info.StarLv + 1;
  146. var nextUpTable = epigraphUpTableRepo.GetEpiragphUp(_mwId, nextLv);
  147. VM.HaveState.selectedIndex = nextUpTable != null ? 1 : 2;
  148. }
  149. else
  150. {
  151. VM.HaveState.selectedIndex = 0;
  152. }
  153. if (table.Element > 0)
  154. {
  155. VM.AttrIcon.visible = true;
  156. VM.AttrIcon.url = AddressableDefine.PartnerElementType(((int)table.Element));
  157. }
  158. else
  159. {
  160. VM.AttrIcon.visible = false;
  161. }
  162. VM.HaveAtrr.selectedIndex = table.Own_attr.Length > 0 ? 0 : 1;
  163. if (table.Own_attr.Length > 0)
  164. {
  165. string str = "";
  166. for (int i = 0; i < table.Own_attr.Length; i += 2)
  167. {
  168. var attrTable = AttrDescTableRepo.Get(table.Own_attr[i]);
  169. if (attrTable == null)
  170. continue;
  171. var attrValue = table.Own_attr[i + 1];
  172. var val =
  173. attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
  174. if (i > 0)
  175. str += ",";
  176. str += $"{attrTable.ShowName}{val}%";
  177. }
  178. VM.AttrLabel.SetVar("attr", str).FlushVars();
  179. }
  180. }
  181. private void UpProgressInfo()
  182. {
  183. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  184. var curlv = info != null ? info.StarLv : 0;
  185. var table = epigraphUpTableRepo.GetEpiragphUp(_mwId, curlv);
  186. if (table == null)
  187. {
  188. Log.Error($"铭文升星表不存在id:{_mwId}, starLv:{curlv}");
  189. return;
  190. }
  191. VM.ChipPbar.max = table.LevelUpCost;
  192. VM.ChipPbar.value = ItemData.Instance.GetItemNum(table.PetId);
  193. }
  194. private void UpSkillList()
  195. {
  196. var list = new List<EpigraphSkillLimit>();
  197. var epiTable = EpigraphTableRepo.Get(_mwId);
  198. if (epiTable == null)
  199. {
  200. Log.Error($"铭文表不存在id:{_mwId}");
  201. return;
  202. }
  203. for (var i = 2; i < epiTable.Skill.Length; i = i + 2)
  204. {
  205. var skill = epiTable.Skill[i];
  206. var limit = epiTable.Skill[i + 1];
  207. var skillLimit = new EpigraphSkillLimit()
  208. {
  209. epiId = _mwId,
  210. limitLv = limit,
  211. skillId = skill,
  212. };
  213. list.Add(skillLimit);
  214. }
  215. VM.EffectList.BindDatas(list);
  216. }
  217. #endregion
  218. }
  219. }