PlayerTransferPanelCtrl.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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.Collections.Generic;
  9. using XGame.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. /// <summary>
  14. /// UI逻辑处理类
  15. /// </summary>
  16. /// <typeparam name=""></typeparam>
  17. public partial class PlayerTransferPanelCtrl : UIController<PlayerTransferPanelVM>
  18. {
  19. private int _selectJobId; // 当前选择的职业id
  20. private bool _bNovice; // 是否新手(还未转过职)
  21. private bool _bResetJob; // 是否职业重置
  22. private careerTable _jobInfo;
  23. private Dictionary<int, List<int> > _jobTypeMap;//重置后可选择的职业分支选择
  24. protected override void OnEnable(object intent)
  25. {
  26. AddUIListenres();
  27. _bResetJob = intent == null ? false : (bool)intent;
  28. ShowUI();
  29. }
  30. protected override void OnDisable()
  31. {
  32. RemoveUIListenres();
  33. if (_jobTypeMap != null ) _jobTypeMap.Clear();
  34. }
  35. #region UI事件
  36. private void AddUIListenres()
  37. {
  38. VM.TransferBtn.onClick.Add(OnClickTransferBtn);
  39. VM.SoldierBtn.onClick.Add(OnClickSoldierBtn);
  40. VM.ScoutsBtn.onClick.Add(OnClickScoutsBtn);
  41. VM.MagicBtn.onClick.Add(OnClickMagicBtn);
  42. VM.BackBtn.onClick.Add(OnClickBackBtn);
  43. VM.JobList.ItemClickEvent += onClickJobItem;
  44. }
  45. private void RemoveUIListenres()
  46. {
  47. VM.TransferBtn.onClick.Remove(OnClickTransferBtn);
  48. VM.SoldierBtn.onClick.Remove(OnClickSoldierBtn);
  49. VM.ScoutsBtn.onClick.Remove(OnClickScoutsBtn);
  50. VM.MagicBtn.onClick.Remove(OnClickMagicBtn);
  51. VM.BackBtn.onClick.Remove(OnClickBackBtn);
  52. VM.JobList.ItemClickEvent -= onClickJobItem;
  53. }
  54. /// <summary>
  55. /// 转职按钮事件
  56. /// </summary>
  57. /// <param name="context"></param>
  58. private void OnClickTransferBtn(EventContext context)
  59. {
  60. if (IsNeedAwakeRune())
  61. {
  62. Context.UI.OpenAsync(UIKeys.PlayerAwakePanel);
  63. Context.ClosePanel();
  64. return;
  65. }
  66. else if (_selectJobId == 0)
  67. {
  68. Context.ShowTips(StringDefine.TransferNoSelect);
  69. return;
  70. }
  71. PlayerService.Instance.SendToTransfer(_selectJobId);
  72. Context.ClosePanel();
  73. }
  74. /// <summary>
  75. /// 是否觉醒符文后才能转职
  76. /// </summary>
  77. /// <returns></returns>
  78. private bool IsNeedAwakeRune()
  79. {
  80. var jobIofo = careerTableRepo.Get(PlayerData.Instance.JobId);
  81. if (jobIofo?.Passive_imprint?.Length > 0 )
  82. {
  83. var runePlanData = PlayerData.Instance.RunePlanMap[PlayerData.Instance.CurPlanIndex];
  84. if (runePlanData.slot == null || runePlanData.slot.Count == 0) return true;
  85. int num = jobIofo.Passive_imprint.Length / 2;
  86. for ( int i = 0;i < num; i++)
  87. {
  88. if (runePlanData.slot[i] == null)
  89. {
  90. return true;
  91. }
  92. else if (runePlanData.slot[i].runeId == 0)
  93. {
  94. return true;
  95. }
  96. }
  97. }
  98. return false;
  99. }
  100. /// <summary>
  101. /// 武师分支选择
  102. /// </summary>
  103. /// <param name="context"></param>
  104. private void OnClickSoldierBtn(EventContext context)
  105. {
  106. ShowChoices(1);
  107. }
  108. /// <summary>
  109. /// 斥候分支选择
  110. /// </summary>
  111. /// <param name="context"></param>
  112. private void OnClickScoutsBtn(EventContext context)
  113. {
  114. ShowChoices(2);
  115. }
  116. /// <summary>
  117. /// 卜师分支选择
  118. /// </summary>
  119. /// <param name="context"></param>
  120. private void OnClickMagicBtn(EventContext context)
  121. {
  122. ShowChoices(3);
  123. }
  124. private void OnClickBackBtn(EventContext context)
  125. {
  126. Context.ClosePanel();
  127. }
  128. private void onClickJobItem(int index)
  129. {
  130. var jobItemList = VM.JobList.GetChildren();
  131. for (int i = 0; i < jobItemList.Length; i++)
  132. {
  133. if (i == index)
  134. {
  135. jobItemList[i].SetScale(1.08f, 1.08f);
  136. _selectJobId = _jobInfo.Job_change[i];
  137. }
  138. else
  139. {
  140. jobItemList[i].SetScale(1f, 1f);
  141. }
  142. }
  143. ShowTransferBtn();
  144. }
  145. #endregion
  146. private void ShowUI()
  147. {
  148. _selectJobId = 0;
  149. _jobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
  150. _bNovice = !_bResetJob && _jobInfo.Front_job == 0;
  151. VM.JobCtrl.selectedIndex = _bResetJob ? 2 : (_bNovice ? 0 : 1); // 0_新手 1_职业提升 2_职业重置
  152. if (!_bNovice && !_bResetJob) _selectJobId = _jobInfo.Job_change[0]; // 进阶职业id
  153. VM.JobList.BindDatas(_jobInfo.Job_change);
  154. ShowTransferBtn();
  155. var advanceJobInfo = careerTableRepo.Get(_jobInfo.Job_change[0]);
  156. int unlockLv = advanceJobInfo == null ? _jobInfo.Unlock : advanceJobInfo.Unlock;
  157. ShowTransferBtnName(unlockLv);
  158. if (_bResetJob)
  159. {
  160. ShowResetUI();
  161. }
  162. else
  163. ResetSelectJobItemUI();
  164. }
  165. /// <summary>
  166. /// 是否显示转职按钮
  167. /// </summary>
  168. private void ShowTransferBtn()
  169. {
  170. bool bShow = true;
  171. if (_selectJobId == 0 && (_bNovice || _bResetJob))
  172. {
  173. bShow = false;
  174. }
  175. VM.TransferBtn.visible = bShow;
  176. VM.TipLabel.visible = _bNovice &&!bShow;
  177. }
  178. /// <summary>
  179. /// 转职按钮名称
  180. /// </summary>
  181. /// <param name="unlockLv"></param>
  182. private void ShowTransferBtnName(int unlockLv)
  183. {
  184. bool bShowAwakeLabel = false;
  185. bool bLock = unlockLv > PlayerData.Instance.Level;
  186. VM.TransferBtn.enabled = !bLock;
  187. VM.TransferBtn.title = bLock ? string.Format(StringDefine.TransferUnlockLv, unlockLv) : GetTransferBtnName(ref bShowAwakeLabel);
  188. VM.AwakeTipsLabel.visible = bShowAwakeLabel;
  189. }
  190. /// <summary>
  191. /// 转职|觉醒
  192. /// </summary>
  193. /// <returns></returns>
  194. private string GetTransferBtnName(ref bool bShowAwakeLabel)
  195. {
  196. var jobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
  197. bool bNeedAwake = jobInfo?.Passive_imprint?.Length > 0;
  198. string btnName = bNeedAwake ? StringDefine.AwakeBtnName : StringDefine.TransferBtnName;
  199. if (bNeedAwake)
  200. {
  201. if (IsNeedAwakeRune())
  202. {
  203. bShowAwakeLabel = true;
  204. btnName = StringDefine.GoToAwake;
  205. }
  206. }
  207. return btnName;
  208. }
  209. private void ShowResetUI()
  210. {
  211. // 重置会在最接近阶的分支线
  212. var resetJobInfo = careerTableRepo.Get(PlayerData.Instance.ResetJobId);
  213. if (resetJobInfo == null) return;
  214. if (_jobTypeMap == null) _jobTypeMap = new Dictionary<int, List<int>>();
  215. else _jobTypeMap.Clear();
  216. var dataList = careerTableRepo.GetAll();
  217. foreach (var item in dataList)
  218. {
  219. if (item.Change_times == resetJobInfo.Change_times)
  220. {
  221. if (_jobTypeMap.ContainsKey(item.Careertype))
  222. {
  223. _jobTypeMap[item.Careertype].Add(item.Id);
  224. }
  225. else
  226. {
  227. _jobTypeMap.Add(item.Careertype, new List<int>() { item.Id});
  228. }
  229. }
  230. }
  231. ShowChoices(1);
  232. }
  233. /// <summary>
  234. /// 职业分支选择
  235. /// </summary>
  236. private void ShowChoices(int index)
  237. {
  238. VM.JobList.BindDatas(_jobTypeMap[index]);
  239. ResetSelectJobItemUI();
  240. }
  241. private void ResetSelectJobItemUI()
  242. {
  243. if (_selectJobId != 0)_selectJobId = 0;
  244. var jobItemList = VM.JobList.GetChildren();
  245. for (int i = 0; i < jobItemList.Length; i++)
  246. {
  247. jobItemList[i].SetScale(1f, 1f);
  248. }
  249. ShowTransferBtn();
  250. }
  251. }
  252. }