PlayerJobCareerPreviewPanelCtrl.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 FL.FGUI;
  9. using System.Collections.Generic;
  10. using XGame.Database;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUIP
  13. {
  14. /// <summary>
  15. /// UI逻辑处理类
  16. /// </summary>
  17. /// <typeparam name=""></typeparam>
  18. public partial class PlayerJobCareerPreviewPanelCtrl : UIController<PlayerJobCareerPreviewPanelVM>
  19. {
  20. private ScrollPane _scrollPanel;
  21. protected override void OnEnable(object intent)
  22. {
  23. _scrollPanel = VM.JobCareerScrollNested.VM.Scroll;
  24. AddUIListenres();
  25. ShowUI();
  26. }
  27. protected override void OnDisable()
  28. {
  29. RemoveUIListenres();
  30. }
  31. #region UI事件
  32. private void AddUIListenres()
  33. {
  34. VM.BackBtn.onClick.Add(OnClickBackBtn);
  35. VM.ResetBtn.onClick.Add(OnClickResetBtn);
  36. _scrollPanel.onScroll.Add(OnScrollPaneScroll);
  37. }
  38. private void RemoveUIListenres()
  39. {
  40. VM.BackBtn.onClick.Remove(OnClickBackBtn);
  41. VM.ResetBtn.onClick.Remove(OnClickResetBtn);
  42. _scrollPanel.onScroll.Remove(OnScrollPaneScroll);
  43. }
  44. private void OnClickBackBtn(EventContext context)
  45. {
  46. Context.ClosePanel();
  47. }
  48. private void OnClickResetBtn(EventContext context)
  49. {
  50. ConfirmationBoxParam dialogParam = new ConfirmationBoxParam()
  51. {
  52. cnt = StringDefine.resetCareer,
  53. onPromiseCallback = ()=>
  54. {
  55. PlayerService.Instance.SendToResetJob();
  56. Context.ClosePanel();
  57. }
  58. };
  59. Context.UI.OpenAsync(UIKeys.CommonConfirmationBox, dialogParam);
  60. }
  61. #endregion
  62. private void ShowUI()
  63. {
  64. var curJobInfo = careerTableRepo.Get(PlayerData.Instance.JobId);
  65. if (curJobInfo != null)
  66. {
  67. var lvList = new HashSet<int>();
  68. var dataList = careerTableRepo.GetAll();
  69. var preDataList = new List<careerTable>(); // 前置数据(初始职业和10级转职数据)
  70. var soldierDataMap = new Dictionary<eAdvanceType, List<careerTable>>();
  71. var shooterDataMap = new Dictionary<eAdvanceType, List<careerTable>>();
  72. var magicianDataMap = new Dictionary<eAdvanceType, List<careerTable>>();
  73. foreach (var item in dataList)
  74. {
  75. lvList.Add(item.Unlock);
  76. if (item.Change_times < 2)
  77. {
  78. preDataList.Add(item);
  79. }
  80. else
  81. {
  82. eAdvanceType advanceType = (eAdvanceType)item.Type;
  83. if (item.Careertype == (int)eCareerType.Soldier)
  84. {
  85. if (soldierDataMap.ContainsKey(advanceType))
  86. {
  87. soldierDataMap[advanceType].Add(item);
  88. }
  89. else
  90. {
  91. soldierDataMap.Add(advanceType, new List<careerTable>() { item });
  92. }
  93. }
  94. else if (item.Careertype == (int)eCareerType.Shooter)
  95. {
  96. if (shooterDataMap.ContainsKey(advanceType))
  97. {
  98. shooterDataMap[advanceType].Add(item);
  99. }
  100. else
  101. {
  102. shooterDataMap.Add(advanceType, new List<careerTable>() { item });
  103. }
  104. }
  105. else if (item.Careertype == (int)eCareerType.Magician)
  106. {
  107. if (magicianDataMap.ContainsKey(advanceType))
  108. {
  109. magicianDataMap[advanceType].Add(item);
  110. }
  111. else
  112. {
  113. magicianDataMap.Add(advanceType, new List<careerTable>() { item });
  114. }
  115. }
  116. }
  117. }
  118. ShowLvTitle(curJobInfo.Unlock, lvList);
  119. VM.JobCareerScrollNested.Ctrl.ShowUI(curJobInfo, preDataList, soldierDataMap, shooterDataMap, magicianDataMap);
  120. _scrollPanel.SetPercX(0,false);
  121. _scrollPanel.SetPercY(0, false);
  122. }
  123. }
  124. /// <summary>
  125. /// 等级阶段
  126. /// </summary>
  127. private void ShowLvTitle(int jobLv, HashSet<int> lvList)
  128. {
  129. var jobLvParamList = new List<JobLvParam>();
  130. foreach (var item in lvList)
  131. {
  132. jobLvParamList.Add(new JobLvParam()
  133. {
  134. lv = item,
  135. curJobLv = jobLv
  136. });
  137. }
  138. VM.LvList.BindDatas(jobLvParamList);
  139. }
  140. /// <summary>
  141. /// 职业阶段等级UI滚动
  142. /// </summary>
  143. private void OnScrollPaneScroll()
  144. {
  145. // 获取当前滚动位置
  146. if (VM.LvList.scrollPane.percX != _scrollPanel.percX)
  147. VM.LvList.scrollPane.percX = _scrollPanel.percX;
  148. }
  149. }
  150. }