PlayerJokSkillNestedCtrl.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data;
  8. using System;
  9. using System.Collections.Generic;
  10. using UnityEngine;
  11. using XGame;
  12. using XGame.Database;
  13. using XGame.Framework.UI;
  14. namespace FL.FGUI
  15. {
  16. /// <summary>
  17. /// 职业(主|被)技能
  18. /// </summary>
  19. public struct JobSkillParam
  20. {
  21. public int unlockLv;
  22. public int skillId;
  23. public Action<int, int> onclickSkillIcon;
  24. }
  25. /// <summary>
  26. /// UI逻辑处理类
  27. /// </summary>
  28. /// <typeparam name=""></typeparam>
  29. public partial class PlayerJokSkillNestedCtrl : UIController<PlayerJokSkillNestedVM>
  30. {
  31. private int _skillId; // 当前主动技能id
  32. private careerTable _jobInfo; // 当前职业信息
  33. private JobSkillParam[] _passiveSkillDataArray; // 被动技能数据列表
  34. private Dictionary<EAttributeType, string> _attributeDescMap;
  35. private Action<bool> _clickSkillIconCallback;
  36. protected override void OnEnable(object intent)
  37. {
  38. AddUIListenres();
  39. AddEventListener();
  40. }
  41. protected override void OnDisable()
  42. {
  43. RemoveUIListenres();
  44. RemoveEventListener();
  45. ShowSkillInfoGroup(false);
  46. if (_attributeDescMap != null)
  47. {
  48. _attributeDescMap.Clear();
  49. _attributeDescMap = null;
  50. }
  51. _jobInfo = null;
  52. if (_passiveSkillDataArray != null) _passiveSkillDataArray = null;
  53. }
  54. #region UI事件
  55. private void AddUIListenres()
  56. {
  57. VM.AttrInfoBtn.onClick.Add(OnClickAttrInfoBtn);
  58. VM.JobBtn.onClick.Add(OnClickJobBtn);
  59. VM.SkillBtn.onClick.Add(OnClickSkillBtn);
  60. VM.WakeUpBtn.onClick.Add(OnClickWakeUpBtn);
  61. VM.TransferBtn.onClick.Add(OnClickTransferBtn);
  62. }
  63. private void RemoveUIListenres()
  64. {
  65. VM.AttrInfoBtn.onClick.Remove(OnClickAttrInfoBtn);
  66. VM.JobBtn.onClick.Remove(OnClickJobBtn);
  67. VM.SkillBtn.onClick.Remove(OnClickSkillBtn);
  68. VM.WakeUpBtn.onClick.Remove(OnClickWakeUpBtn);
  69. VM.TransferBtn.onClick.Remove(OnClickTransferBtn);
  70. }
  71. private void OnClickAttrInfoBtn(EventContext context)
  72. {
  73. Context.UI.OpenAsync(UIKeys.PlayerDetailsAttribute);
  74. }
  75. /// <summary>
  76. /// 职业(整个线路图)预览
  77. /// </summary>
  78. /// <param name="context"></param>
  79. private void OnClickJobBtn(EventContext context)
  80. {
  81. Context.ShowTips("职业(整个线路图)预览");
  82. }
  83. private void OnClickSkillBtn(EventContext context)
  84. {
  85. if (_skillId > 0)
  86. {
  87. OnClickSkillIcon(_skillId, -1);
  88. }
  89. }
  90. /// <summary>
  91. /// 觉醒按钮
  92. /// </summary>
  93. /// <param name="context"></param>
  94. private void OnClickWakeUpBtn(EventContext context)
  95. {
  96. Context.UI.OpenAsync(UIKeys.PlayerAwakePanel);
  97. }
  98. /// <summary>
  99. /// 转职按钮
  100. /// </summary>
  101. /// <param name="context"></param>
  102. private void OnClickTransferBtn(EventContext context)
  103. {
  104. // 分条件满足和不满足的(相当于展示下阶职业的预览ui)显示
  105. // 当前是否最高级职业
  106. if (_jobInfo.Job_change?.Length > 0)
  107. {
  108. Context.UI.OpenAsync(UIKeys.PlayerTransferPanel, false);
  109. }
  110. else
  111. {
  112. OnClickJobBtn(null);
  113. }
  114. }
  115. #endregion
  116. private void AddEventListener()
  117. {
  118. EventSingle.Instance.AddListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
  119. }
  120. private void RemoveEventListener()
  121. {
  122. EventSingle.Instance.RemoveListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
  123. }
  124. public void Init(Action<bool> clickSkillIcon)
  125. {
  126. _clickSkillIconCallback = clickSkillIcon;
  127. if (_attributeDescMap == null)
  128. {
  129. _attributeDescMap = new Dictionary<EAttributeType, string>()
  130. {
  131. {EAttributeType.Atk, GetAttributeDesc(EAttributeType.Atk)},
  132. {EAttributeType.Hp, GetAttributeDesc(EAttributeType.Hp)},
  133. {EAttributeType.Def, GetAttributeDesc(EAttributeType.Def)},
  134. { EAttributeType.AtkSpeed, GetAttributeDesc(EAttributeType.AtkSpeed)}
  135. };
  136. }
  137. InitPassiveSkillDataList();
  138. ShowSkillInfoGroup(false);
  139. }
  140. public void ShowAttributeUI()
  141. {
  142. ShowAtrributeVal(VM.AtkLabel, EAttributeType.Atk);
  143. ShowAtrributeVal(VM.HpLabel, EAttributeType.Hp);
  144. ShowAtrributeVal(VM.DefLabel, EAttributeType.Def);
  145. ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeed, true);
  146. }
  147. private string GetAttributeDesc(EAttributeType attrType)
  148. {
  149. var attrInfo = AttrDescTableRepo.Get((int)attrType);
  150. return attrInfo?.ShowName ?? string.Empty;
  151. }
  152. /// <summary>
  153. /// 角色属性变化
  154. /// </summary>
  155. /// <param name="eventId"></param>
  156. /// <param name="args"></param>
  157. private void OnChangeAttribute(int eventId, object args)
  158. {
  159. EAttributeType attrType = (EAttributeType)args;
  160. if (attrType == EAttributeType.Atk)
  161. {
  162. ShowAtrributeVal(VM.AtkLabel, EAttributeType.Atk);
  163. }
  164. else if (attrType == EAttributeType.Hp)
  165. {
  166. ShowAtrributeVal(VM.HpLabel, EAttributeType.Hp);
  167. }
  168. else if (attrType == EAttributeType.Def)
  169. {
  170. ShowAtrributeVal(VM.DefLabel, EAttributeType.Def);
  171. }
  172. else if (attrType == EAttributeType.AtkSpeed)
  173. {
  174. ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeed, true);
  175. }
  176. }
  177. private void ShowAtrributeVal(GTextField attrLabel, EAttributeType attrType, bool bAtkSpeed = false)
  178. {
  179. var attrVal = PlayerData.Instance.Attr.GetValue(attrType);
  180. attrLabel.text = $"{_attributeDescMap[attrType]}:{(bAtkSpeed ? TableUtils.ToRealDouble(attrVal).ToString("F1") : attrVal.ToString())}";
  181. }
  182. public void ShowJobUI()
  183. {
  184. _jobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
  185. if (_jobInfo == null) return;
  186. int playerLv = PlayerData.Instance.Level;
  187. VM.JobNameLabel.text = _jobInfo.Name;
  188. VM.TransfersCountLabel.text = _jobInfo.Change_times.ToString(); // 转职次数
  189. // 当前是否最高级职业
  190. bool bSuperlative = _jobInfo.Job_change.Length == 0;
  191. if (!bSuperlative)
  192. {
  193. var advanceInfo = careerTableRepo.Get(_jobInfo.Job_change[0]);
  194. if (advanceInfo == null)
  195. {
  196. bSuperlative = true;
  197. }
  198. else
  199. {
  200. VM.UnlockLabel.text = string.Format(StringDefine.UnlockAdvanceJob, playerLv, advanceInfo.Unlock);
  201. }
  202. }
  203. VM.SuperlativeCtrl.selectedIndex = bSuperlative ? 1 : 0;
  204. ShowJobSkillUI(_jobInfo.Skill);
  205. ShowJobPassiveSkillUI(_jobInfo.Passive_skill);
  206. ShowWakeUpBtn(_jobInfo.Change_times > 4); // 若角色转职未达到五阶段,将隐藏觉醒按钮
  207. }
  208. /// <summary>
  209. /// 是否显示觉醒按钮
  210. /// </summary>
  211. /// <param name="bShow"></param>
  212. private void ShowWakeUpBtn(bool bShow)
  213. {
  214. VM.WakeUpBtn.visible = bShow;
  215. }
  216. /// <summary>
  217. /// 点击技能图标
  218. /// </summary>
  219. /// <param name="skillId"></param>
  220. private void OnClickSkillIcon(int skillId, int index)
  221. {
  222. var skillInfo = SkillTableRepo.Get(skillId);
  223. if (skillInfo == null) return;
  224. if (_clickSkillIconCallback != null) _clickSkillIconCallback(false);
  225. ShowSkillInfoGroup(true, index, skillInfo);
  226. //Log.Info($"OnClickSkillIcon.点击技能图标id:{skillId}");
  227. }
  228. /// <summary>
  229. /// 显示技能弹窗信息UI
  230. /// </summary>
  231. /// <param name="Show"></param>
  232. /// <param name="bPassive"></param>
  233. public void ShowSkillInfoGroup(bool bShow, int index = 0, SkillTable skillInfo = null)
  234. {
  235. Log.Debug($"ShowSkillInfoGroup bShow:{bShow} info:{skillInfo != null} Frame:{Time.frameCount}");
  236. if (bShow && skillInfo != null)
  237. {
  238. var skillParam = new SkillInfoParam()
  239. {
  240. bShowRightBubble = index > 1,
  241. skillInfo = skillInfo
  242. };
  243. if (VM.SkillInfoNested.Active)
  244. VM.SkillInfoNested.Ctrl.ShowSkillInfo(skillParam);
  245. else
  246. VM.SkillInfoNested.Enable(skillParam);
  247. VM.SkillInfoTipCtrl.selectedIndex = index == -1 ? 0 : (index + 1);
  248. }
  249. else if (VM.SkillInfoNested.Active)
  250. {
  251. VM.SkillInfoNested.Disable();
  252. }
  253. }
  254. /// <summary>
  255. /// 职业主动技能UI(解锁等级|技能id|技能等级)
  256. /// </summary>
  257. private void ShowJobSkillUI(int[] skillIds)
  258. {
  259. if (skillIds.Length > 1)
  260. {
  261. _skillId = skillIds[1];
  262. var skillInfo = SkillTableRepo.Get(skillIds[1]);
  263. if (skillInfo != null)
  264. {
  265. VM.JobSkillLabel.text = skillInfo.Name;
  266. VM.SkillBtn.icon = skillInfo.Icon;
  267. }
  268. }
  269. else
  270. {
  271. _skillId = 0;
  272. }
  273. }
  274. private void InitPassiveSkillDataList()
  275. {
  276. if (_passiveSkillDataArray == null || _passiveSkillDataArray.Length == 0)
  277. {
  278. _passiveSkillDataArray = new JobSkillParam[5];
  279. }
  280. }
  281. /// <summary>
  282. /// 职业被动技能UI
  283. /// </summary>
  284. private void ShowJobPassiveSkillUI(int[] skillIds)
  285. {
  286. int index = 0;
  287. for (int i = 0; i < skillIds.Length; i += 2)
  288. {
  289. _passiveSkillDataArray[index] = new JobSkillParam()
  290. {
  291. unlockLv = skillIds[i],
  292. skillId = skillIds[i + 1],
  293. onclickSkillIcon = OnClickSkillIcon
  294. };
  295. index++;
  296. }
  297. VM.PassiveSkillList.BindDatas(_passiveSkillDataArray);
  298. }
  299. }
  300. }