PartnerEpiDetailInfoCtrl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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. public class PartnerEpiDetailInfoParam
  15. {
  16. public int PlanId;
  17. /// <summary>
  18. /// 槽位id,-1为非更换界面打开的详情
  19. /// </summary>
  20. public int SlotId;
  21. public int EpigraphId;
  22. public int PartnerId;
  23. }
  24. /// <summary>
  25. /// UI逻辑处理类
  26. /// </summary>
  27. /// <typeparam name=""></typeparam>
  28. public partial class PartnerEpiDetailInfoCtrl : UIController<PartnerEpiDetailInfoVM>
  29. {
  30. #region 属性
  31. private int _mwId;
  32. private int _planId;
  33. private int _slotId;
  34. private int _partnerId;
  35. #endregion
  36. protected override void OnEnable(object intent)
  37. {
  38. var param = intent as PartnerEpiDetailInfoParam;
  39. _mwId = param.EpigraphId;
  40. _planId = param.PlanId;
  41. _slotId = param.SlotId;
  42. _partnerId = param.PartnerId;
  43. AddUIListenres();
  44. UpView();
  45. }
  46. protected override void OnDisable()
  47. {
  48. RemoveUIListenres();
  49. }
  50. #region UI事件
  51. private void AddUIListenres()
  52. {
  53. VM.UpBtn.onClick.Add(OnClickUpBtn);
  54. VM.DownBtn.onClick.Add(OnClickDownBtn);
  55. VM.GotoBtn.onClick.Add(OnClickGotoBtn);
  56. VM.RankUpBtn.onClick.Add(OnClickRankUpBtn);
  57. EventSingle.Instance.AddListener(EventDefine.EpigraphUpStar, OnEpiUpdate);
  58. EventSingle.Instance.AddListener(EventDefine.PartnerBinding, UpdateUpDownBtn);
  59. EventSingle.Instance.AddListener(EventDefine.UpdataItemData, OnItemUpdate);
  60. }
  61. private void RemoveUIListenres()
  62. {
  63. VM.UpBtn.onClick.Remove(OnClickUpBtn);
  64. VM.DownBtn.onClick.Remove(OnClickDownBtn);
  65. VM.GotoBtn.onClick.Remove(OnClickGotoBtn);
  66. VM.RankUpBtn.onClick.Remove(OnClickRankUpBtn);
  67. EventSingle.Instance.RemoveListener(EventDefine.EpigraphUpStar, OnEpiUpdate);
  68. EventSingle.Instance.RemoveListener(EventDefine.PartnerBinding, UpdateUpDownBtn);
  69. EventSingle.Instance.RemoveListener(EventDefine.UpdataItemData, OnItemUpdate);
  70. }
  71. private void OnItemUpdate(int eventId, object args)
  72. {
  73. UpProgressInfo();
  74. }
  75. private void OnEpiUpdate(int eventId, object args)
  76. {
  77. UpProgressInfo();
  78. UpSkillList();
  79. }
  80. private void OnClickDownBtn(EventContext eventContext)
  81. {
  82. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  83. if (info == null)
  84. {
  85. Log.Error($"铭文数据不存在tableId:{_mwId}");
  86. return;
  87. }
  88. if (PartnersData.Instance.UsePlanId == _planId)
  89. {
  90. EpigraphService.Instance.RequestEpiInset(info.PartnerId, 0);
  91. }
  92. else
  93. {
  94. if (!PartnersData.Instance.TryGetPlan(_planId, out var plan))
  95. {
  96. Context.ShowTips(StringDefine.PartnerPlanEmptyTips);
  97. return;
  98. }
  99. var caoId = -1;
  100. var sbId = 0;
  101. foreach (var slot in plan.Slots)
  102. {
  103. if (slot.MwId == _mwId)
  104. {
  105. caoId = slot.CaoId;
  106. sbId = slot.SbId;
  107. break;
  108. }
  109. }
  110. if (sbId == 0 || caoId < 0)
  111. {
  112. Context.ShowTips(StringDefine.EpigraphNotInPlanTips);
  113. return;
  114. }
  115. PartnersService.Instance.RequestUpdatePlanMw(_planId, caoId, sbId, 0);
  116. }
  117. Context.ClosePanel();
  118. }
  119. private void OnClickUpBtn(EventContext context)
  120. {
  121. if (_planId == PartnersData.Instance.UsePlanId)
  122. {
  123. if (!EpigraphData.Instance.TryGetEpigraphAttrByTableId(_mwId, out var attr))
  124. {
  125. Context.ShowTips(StringDefine.EpigraphEmptyTips);
  126. return;
  127. }
  128. if (attr.PartnerId > 0)
  129. {
  130. Context.ShowTips(StringDefine.EpigraphAlreadyUpTips);
  131. return;
  132. }
  133. if (_partnerId > 0)
  134. {
  135. if (
  136. !PartnersData.Instance.TryGetPartnerAttrByTableId(
  137. _partnerId,
  138. out var partnerAttr
  139. )
  140. )
  141. {
  142. Context.ShowTips(StringDefine.PartnerEmptyTips);
  143. return;
  144. }
  145. EpigraphService.Instance.RequestEpiInset(_partnerId, _mwId);
  146. }
  147. else
  148. {
  149. EpigraphService.Instance.OpenUpMode(_mwId);
  150. }
  151. }
  152. else
  153. {
  154. if (!PartnersData.Instance.TryGetPlan(_planId, out var plan))
  155. {
  156. Context.ShowTips(StringDefine.PartnerPlanEmptyTips);
  157. return;
  158. }
  159. PartnerPlanSlot curSlot = null;
  160. foreach (var slot in plan.Slots)
  161. {
  162. if (slot.MwId == _mwId)
  163. {
  164. curSlot = slot;
  165. break;
  166. }
  167. }
  168. if (curSlot != null)
  169. {
  170. Context.ShowTips(StringDefine.EpigraphAlreadyUpTips);
  171. return;
  172. }
  173. var targetSlot = PartnersData.Instance.GetPlanSlot(_planId, _slotId);
  174. if (targetSlot == null || targetSlot.SbId == 0)
  175. {
  176. Context.ShowTips(StringDefine.PartnerCurSlotNoSbTips);
  177. return;
  178. }
  179. PartnersService.Instance.RequestUpdatePlanMw(
  180. _planId,
  181. _slotId,
  182. targetSlot.SbId,
  183. _mwId
  184. );
  185. }
  186. Context.ClosePanel();
  187. }
  188. private void OnClickGotoBtn(EventContext context) { }
  189. private void OnClickRankUpBtn(EventContext context)
  190. {
  191. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  192. if (info == null)
  193. {
  194. Log.Error($"铭文数据不存在tableId:{_mwId}");
  195. return;
  196. }
  197. var table = epigraphUpTableRepo.GetEpiragphUp(_mwId, info.StarLv);
  198. if (table == null)
  199. {
  200. Log.Error($"铭文升星表不存在id:{_mwId}, starLv{info.StarLv}");
  201. return;
  202. }
  203. if (table.LevelUpCost > ItemData.Instance.GetItemNum(_mwId))
  204. {
  205. Context.ShowTips(StringDefine.epigraphUpUnenough);
  206. return;
  207. }
  208. EpigraphService.Instance.RequestEpiStarUp(_mwId);
  209. }
  210. #endregion
  211. #region 页面
  212. private void UpView()
  213. {
  214. UpDescInfo();
  215. UpProgressInfo();
  216. UpSkillList();
  217. }
  218. private void UpdateUpDownBtn(int eventId, object args)
  219. {
  220. ShowUpDownBtn();
  221. }
  222. private void ShowUpDownBtn()
  223. {
  224. if (_planId == PartnersData.Instance.UsePlanId)
  225. {
  226. if (!EpigraphData.Instance.TryGetEpigraphAttrByTableId(_mwId, out var epi))
  227. {
  228. Log.Error($"铭文数据不存在,id:{_mwId}");
  229. return;
  230. }
  231. VM.Up.selectedIndex = epi.PartnerId > 0 ? 1 : 0;
  232. }
  233. else
  234. {
  235. if (!PartnersData.Instance.TryGetPlan(_planId, out var plan))
  236. {
  237. Log.Error($"方案信息不存在,planId:{_planId}");
  238. return;
  239. }
  240. var isFind = false;
  241. foreach (var slot in plan.Slots)
  242. {
  243. if (slot.MwId == _mwId)
  244. {
  245. isFind = true;
  246. break;
  247. }
  248. }
  249. VM.Up.selectedIndex = isFind ? 1 : 0;
  250. }
  251. }
  252. private void UpDescInfo()
  253. {
  254. var table = EpigraphTableRepo.Get(_mwId);
  255. if (table == null)
  256. {
  257. Log.Error($"铭文表不存在id:{_mwId}");
  258. }
  259. VM.EpiLabel.Ctrl.SetEpiIcon(_mwId, true);
  260. var initSkillId = table.Skill[0];
  261. var skillTable = SkillTableRepo.Get(initSkillId);
  262. if (skillTable == null)
  263. {
  264. Log.Error($"技能表不能存在,技能ID:{initSkillId}");
  265. return;
  266. }
  267. VM.DescLabel.text = skillTable.Desc;
  268. VM.NameLabel.text = table.Name;
  269. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  270. if (info != null)
  271. {
  272. ShowUpDownBtn();
  273. int nextLv = info.StarLv + 1;
  274. var nextUpTable = epigraphUpTableRepo.GetEpiragphUp(_mwId, nextLv);
  275. VM.HaveState.selectedIndex = nextUpTable != null ? 1 : 2;
  276. }
  277. else
  278. {
  279. VM.HaveState.selectedIndex = 0;
  280. }
  281. if (table.Element > 0)
  282. {
  283. VM.AttrIcon.visible = true;
  284. VM.AttrIcon.url = AddressableDefine.PartnerElementType(((int)table.Element));
  285. }
  286. else
  287. {
  288. VM.AttrIcon.visible = false;
  289. }
  290. VM.HaveAtrr.selectedIndex = table.Own_attr.Length > 0 ? 0 : 1;
  291. if (table.Own_attr.Length > 0)
  292. {
  293. string str = "";
  294. for (int i = 0; i < table.Own_attr.Length; i += 2)
  295. {
  296. var attrTable = AttrDescTableRepo.Get(table.Own_attr[i]);
  297. if (attrTable == null)
  298. continue;
  299. var attrValue = table.Own_attr[i + 1];
  300. var val =
  301. attrValue > 0 ? TableUtils.ToRealDouble(attrValue).ToString("F2") : "0";
  302. if (i > 0)
  303. str += ",";
  304. str += $"{attrTable.ShowName}{val}%";
  305. }
  306. VM.AttrLabel.SetVar("attr", str).FlushVars();
  307. }
  308. }
  309. private void UpProgressInfo()
  310. {
  311. var info = EpigraphData.Instance.GetEpigraphAttrByTableId(_mwId);
  312. var curlv = info != null ? info.StarLv : 1;
  313. var table = epigraphUpTableRepo.GetEpiragphUp(_mwId, curlv);
  314. if (table == null)
  315. {
  316. Log.Error($"铭文升星表不存在id:{_mwId}, starLv:{curlv}");
  317. return;
  318. }
  319. VM.ChipPbar.max = table.LevelUpCost;
  320. VM.ChipPbar.value = ItemData.Instance.GetItemNum(table.PetId);
  321. }
  322. private void UpSkillList()
  323. {
  324. var list = new List<EpigraphSkillLimit>();
  325. var epiTable = EpigraphTableRepo.Get(_mwId);
  326. if (epiTable == null)
  327. {
  328. Log.Error($"铭文表不存在id:{_mwId}");
  329. return;
  330. }
  331. for (var i = 2; i < epiTable.Skill.Length; i = i + 2)
  332. {
  333. var skill = epiTable.Skill[i];
  334. var limit = epiTable.Skill[i + 1];
  335. var skillLimit = new EpigraphSkillLimit()
  336. {
  337. epiId = _mwId,
  338. limitLv = limit,
  339. skillId = skill,
  340. };
  341. list.Add(skillLimit);
  342. }
  343. VM.EffectList.BindDatas(list);
  344. }
  345. #endregion
  346. }
  347. }