PlayerJokSkillNestedCtrl.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. Context.UI.OpenAsync(UIKeys.PlayerJobCareerPreviewPanel);
  83. }
  84. private void OnClickSkillBtn(EventContext context)
  85. {
  86. if (_skillId > 0)
  87. {
  88. OnClickSkillIcon(_skillId, -1);
  89. }
  90. }
  91. /// <summary>
  92. /// 觉醒按钮
  93. /// </summary>
  94. /// <param name="context"></param>
  95. private void OnClickWakeUpBtn(EventContext context)
  96. {
  97. Context.UI.OpenAsync(UIKeys.PlayerAwakePanel);
  98. }
  99. /// <summary>
  100. /// 转职按钮
  101. /// </summary>
  102. /// <param name="context"></param>
  103. private void OnClickTransferBtn(EventContext context)
  104. {
  105. // 分条件满足和不满足的(相当于展示下阶职业的预览ui)显示
  106. // 当前是否最高级职业
  107. if (_jobInfo.Job_change?.Length > 0)
  108. {
  109. Context.UI.OpenAsync(UIKeys.PlayerTransferPanel, false);
  110. }
  111. else
  112. {
  113. OnClickJobBtn(null);
  114. }
  115. }
  116. #endregion
  117. private void AddEventListener()
  118. {
  119. EventSingle.Instance.AddListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
  120. }
  121. private void RemoveEventListener()
  122. {
  123. EventSingle.Instance.RemoveListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
  124. }
  125. public void Init(Action<bool> clickSkillIcon)
  126. {
  127. _clickSkillIconCallback = clickSkillIcon;
  128. if (_attributeDescMap == null)
  129. {
  130. _attributeDescMap = new Dictionary<EAttributeType, string>()
  131. {
  132. {EAttributeType.AtkTotal, GetAttributeDesc(EAttributeType.AtkTotal)},
  133. {EAttributeType.HpTotal, GetAttributeDesc(EAttributeType.HpTotal)},
  134. {EAttributeType.DefTotal, GetAttributeDesc(EAttributeType.DefTotal)},
  135. { EAttributeType.AtkSpeedTotal, GetAttributeDesc(EAttributeType.AtkSpeedTotal)}
  136. };
  137. }
  138. InitPassiveSkillDataList();
  139. ShowSkillInfoGroup(false);
  140. }
  141. public void ShowAttributeUI()
  142. {
  143. ShowAtrributeVal(VM.AtkLabel, EAttributeType.AtkTotal);
  144. ShowAtrributeVal(VM.HpLabel, EAttributeType.HpTotal);
  145. ShowAtrributeVal(VM.DefLabel, EAttributeType.DefTotal);
  146. ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeedTotal, true);
  147. }
  148. private string GetAttributeDesc(EAttributeType attrType)
  149. {
  150. var attrInfo = AttrDescTableRepo.Get((int)attrType);
  151. return attrInfo?.ShowName ?? string.Empty;
  152. }
  153. /// <summary>
  154. /// 角色属性变化
  155. /// </summary>
  156. /// <param name="eventId"></param>
  157. /// <param name="args"></param>
  158. private void OnChangeAttribute(int eventId, object args)
  159. {
  160. //EAttributeType attrType = (EAttributeType)args;
  161. //if (attrType == EAttributeType.AtkTotal)
  162. //{
  163. // ShowAtrributeVal(VM.AtkLabel, EAttributeType.AtkTotal);
  164. //}
  165. //else if (attrType == EAttributeType.HpTotal)
  166. //{
  167. // ShowAtrributeVal(VM.HpLabel, EAttributeType.HpTotal);
  168. //}
  169. //else if (attrType == EAttributeType.DefTotal)
  170. //{
  171. // ShowAtrributeVal(VM.DefLabel, EAttributeType.DefTotal);
  172. //}
  173. //else if (attrType == EAttributeType.AtkSpeedTotal)
  174. //{
  175. // ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeedTotal, true);
  176. //}
  177. ShowAttributeUI();
  178. }
  179. private void ShowAtrributeVal(GTextField attrLabel, EAttributeType attrType, bool bAtkSpeed = false)
  180. {
  181. var attrVal = PlayerData.Instance.Attr.GetValue(attrType);
  182. attrLabel.text = $"{_attributeDescMap[attrType]}:{(bAtkSpeed ? TableUtils.ToRealDouble(attrVal).ToString("F1") : attrVal.ToString())}";
  183. }
  184. public void ShowJobUI()
  185. {
  186. _jobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
  187. if (_jobInfo == null) return;
  188. int playerLv = PlayerData.Instance.Level;
  189. VM.JobNameLabel.text = _jobInfo.Name;
  190. VM.TransfersCountLabel.text = _jobInfo.Change_times.ToString(); // 转职次数
  191. // 当前是否最高级职业
  192. bool bSuperlative = _jobInfo.Job_change.Length == 0;
  193. if (!bSuperlative)
  194. {
  195. var advanceInfo = careerTableRepo.Get(_jobInfo.Job_change[0]);
  196. if (advanceInfo == null)
  197. {
  198. bSuperlative = true;
  199. }
  200. else
  201. {
  202. VM.UnlockLabel.text = string.Format(StringDefine.UnlockAdvanceJob, playerLv, advanceInfo.Unlock);
  203. }
  204. }
  205. VM.SuperlativeCtrl.selectedIndex = bSuperlative ? 1 : 0;
  206. ShowJobSkillUI(_jobInfo.Skill);
  207. ShowJobPassiveSkillUI(_jobInfo.Passive_skill);
  208. ShowWakeUpBtn(_jobInfo?.Passive_imprint.Length > 4); // (转职需要觉醒印记)显示|隐藏觉醒按钮
  209. }
  210. /// <summary>
  211. /// 是否显示觉醒按钮
  212. /// </summary>
  213. /// <param name="bShow"></param>
  214. private void ShowWakeUpBtn(bool bShow)
  215. {
  216. VM.WakeUpBtn.visible = bShow;
  217. }
  218. /// <summary>
  219. /// 点击技能图标
  220. /// </summary>
  221. /// <param name="skillId"></param>
  222. private void OnClickSkillIcon(int skillId, int index)
  223. {
  224. var skillInfo = SkillTableRepo.Get(skillId);
  225. if (skillInfo == null) return;
  226. if (_clickSkillIconCallback != null) _clickSkillIconCallback(false);
  227. ShowSkillInfoGroup(true, index, skillInfo);
  228. //Log.Info($"OnClickSkillIcon.点击技能图标id:{skillId}");
  229. }
  230. /// <summary>
  231. /// 显示技能弹窗信息UI
  232. /// </summary>
  233. /// <param name="Show"></param>
  234. /// <param name="bPassive"></param>
  235. public void ShowSkillInfoGroup(bool bShow, int index = 0, SkillTable skillInfo = null)
  236. {
  237. Log.Debug($"ShowSkillInfoGroup bShow:{bShow} info:{skillInfo != null} Frame:{Time.frameCount}");
  238. if (bShow && skillInfo != null)
  239. {
  240. var skillParam = new SkillInfoParam()
  241. {
  242. bShowRightBubble = index > 1,
  243. skillInfo = skillInfo
  244. };
  245. if (VM.SkillInfoNested.Active)
  246. VM.SkillInfoNested.Ctrl.ShowSkillInfo(skillParam);
  247. else
  248. VM.SkillInfoNested.Enable(skillParam);
  249. VM.SkillInfoTipCtrl.selectedIndex = index == -1 ? 0 : (index + 1);
  250. }
  251. else if (VM.SkillInfoNested.Active)
  252. {
  253. VM.SkillInfoNested.Disable();
  254. }
  255. }
  256. /// <summary>
  257. /// 职业主动技能UI(解锁等级|技能id|技能等级)
  258. /// </summary>
  259. private void ShowJobSkillUI(int[] skillIds)
  260. {
  261. if (skillIds.Length > 1)
  262. {
  263. _skillId = skillIds[1];
  264. var skillInfo = SkillTableRepo.Get(skillIds[1]);
  265. if (skillInfo != null)
  266. {
  267. VM.JobSkillLabel.text = skillInfo.Name;
  268. VM.SkillBtn.icon = skillInfo.Icon;
  269. }
  270. }
  271. else
  272. {
  273. _skillId = 0;
  274. }
  275. }
  276. private void InitPassiveSkillDataList()
  277. {
  278. if (_passiveSkillDataArray == null || _passiveSkillDataArray.Length == 0)
  279. {
  280. _passiveSkillDataArray = new JobSkillParam[5];
  281. }
  282. }
  283. /// <summary>
  284. /// 职业被动技能UI
  285. /// </summary>
  286. private void ShowJobPassiveSkillUI(int[] skillIds)
  287. {
  288. int index = 0;
  289. for (int i = 0; i < skillIds.Length; i += 2)
  290. {
  291. _passiveSkillDataArray[index] = new JobSkillParam()
  292. {
  293. unlockLv = skillIds[i],
  294. skillId = skillIds[i + 1],
  295. onclickSkillIcon = OnClickSkillIcon
  296. };
  297. index++;
  298. }
  299. VM.PassiveSkillList.BindDatas(_passiveSkillDataArray);
  300. }
  301. }
  302. }