PlayerMainPanelCtrl.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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.Data.Items;
  9. using System;
  10. using System.Collections.Generic;
  11. using XGame;
  12. using XGame.Database;
  13. using XGame.Framework.UI;
  14. namespace FL.FGUI
  15. {
  16. /// <summary>
  17. /// UI逻辑处理类
  18. /// </summary>
  19. /// <typeparam name=""></typeparam>
  20. public partial class PlayerMainPanelCtrl : UIController<PlayerMainPanelVM>
  21. {
  22. private bool _bHideSkillInfo; // 是否需要隐藏技能信息气泡
  23. private List<CommonItemBaseView> _equipItemList;
  24. protected override void OnEnable(object intent)
  25. {
  26. AddUIListenres();
  27. AddEventListener();
  28. Init();
  29. ShowUI();
  30. }
  31. protected override void OnDisable()
  32. {
  33. RemoveUIListenres();
  34. RemoveEventListener();
  35. if (_equipItemList != null)
  36. {
  37. _equipItemList.Clear();
  38. _equipItemList = null;
  39. }
  40. VM.PlayerSpine.url = string.Empty;
  41. }
  42. #region UI事件
  43. private void AddUIListenres()
  44. {
  45. VM.MountBtn.onClick.Add(OnClickMountBtn);
  46. VM.ArtifactBtn.onClick.Add(OnClickArtifactBtn);
  47. VM.ContractBtn.onClick.Add(OnClickContractBtn);
  48. VM.JewelryBtn.onClick.Add(OnClickJewelryBtn);
  49. VM.NotOpenBtn1.onClick.Add(OnClickNotOpenBtn1);
  50. VM.NotOpenBtn2.onClick.Add(OnClickNotOpenBtn2);
  51. VM.UpgradeLvBtn.onClick.Add(OnClickUpgradeLvBtn);
  52. VM.PanelEvent.Add(OnCllickPanel);
  53. }
  54. private void RemoveUIListenres()
  55. {
  56. VM.MountBtn.onClick.Remove(OnClickMountBtn);
  57. VM.ArtifactBtn.onClick.Remove(OnClickArtifactBtn);
  58. VM.ContractBtn.onClick.Remove(OnClickContractBtn);
  59. VM.JewelryBtn.onClick.Remove(OnClickJewelryBtn);
  60. VM.NotOpenBtn1.onClick.Remove(OnClickNotOpenBtn1);
  61. VM.NotOpenBtn2.onClick.Remove(OnClickNotOpenBtn2);
  62. VM.UpgradeLvBtn.onClick.Remove(OnClickUpgradeLvBtn);
  63. VM.PanelEvent.Remove(OnCllickPanel);
  64. }
  65. /// <summary>
  66. /// 隐藏技能信息气泡弹窗
  67. /// </summary>
  68. /// <param name="context"></param>
  69. private void OnCllickPanel(EventContext context)
  70. {
  71. if (_bHideSkillInfo)
  72. {
  73. VM.JokSkillNested.Ctrl.ShowSkillInfoGroup(false);
  74. }
  75. _bHideSkillInfo = true;
  76. }
  77. private void OnClickUpgradeLvBtn(EventContext context)
  78. {
  79. Context.ShowTips("一键使用经验道具进行升级事件");
  80. }
  81. private void OnClickChangeBtn(EventContext context)
  82. {
  83. Context.ShowTips("更换契约技能");
  84. }
  85. private void OnClickMountBtn(EventContext context)
  86. {
  87. Context.ShowTips("打开坐骑界面");
  88. }
  89. private void OnClickArtifactBtn(EventContext context)
  90. {
  91. Context.ShowTips("打开神器界面");
  92. }
  93. private void OnClickContractBtn(EventContext context)
  94. {
  95. Context.ShowTips("打开锲约界面");
  96. }
  97. private void OnClickJewelryBtn(EventContext context)
  98. {
  99. Context.ShowTips("打开饰品装扮界面");
  100. }
  101. private void OnClickNotOpenBtn1(EventContext context)
  102. {
  103. Context.ShowTips(StringDefine.notOpen);
  104. }
  105. private void OnClickNotOpenBtn2(EventContext context)
  106. {
  107. Context.ShowTips(StringDefine.notOpen);
  108. Context.UI.OpenAsync(UIKeys.PlayerJobInformationPanel);
  109. }
  110. #endregion
  111. private void AddEventListener()
  112. {
  113. EventSingle.Instance.AddListener(EventDefine.OnChangeEquip, OnChangeEquip);
  114. EventSingle.Instance.AddListener(EventDefine.PlayerExpAdd, AddPlayerExp);
  115. EventSingle.Instance.AddListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI);
  116. EventSingle.Instance.AddListener(EventDefine.TransferSucess, TransferSucess);
  117. EventSingle.Instance.AddListener(EventDefine.ResetJobSucess, ResetJobSucess);
  118. }
  119. private void RemoveEventListener()
  120. {
  121. EventSingle.Instance.RemoveListener(EventDefine.OnChangeEquip, OnChangeEquip);
  122. EventSingle.Instance.RemoveListener(EventDefine.PlayerExpAdd, AddPlayerExp);
  123. EventSingle.Instance.RemoveListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI);
  124. EventSingle.Instance.RemoveListener(EventDefine.TransferSucess, TransferSucess);
  125. EventSingle.Instance.RemoveListener(EventDefine.ResetJobSucess, ResetJobSucess);
  126. }
  127. private void Init()
  128. {
  129. if (_equipItemList == null)
  130. {
  131. _equipItemList = new List<CommonItemBaseView>()
  132. {
  133. VM.Weapon,VM.Helmet,VM.Clothes,VM.Hand,VM.Pants,VM.Boots
  134. };
  135. }
  136. _bHideSkillInfo = true;
  137. VM.JokSkillNested.Ctrl.Init((bool bHideSkillInfo) =>
  138. {
  139. _bHideSkillInfo = bHideSkillInfo;
  140. });
  141. PlayerService.Instance.SendToEquipInto();
  142. }
  143. private void ShowUI()
  144. {
  145. ShowEquipUI();
  146. ShowTitleIcon(PlayerData.Instance.Title);
  147. ShowAttributeUI();
  148. //ShowContractSkills(201711);
  149. LoadPlayerSpine("info_job_1001_1_SkeletonData");
  150. VM.JokSkillNested.Ctrl.ShowJobUI();
  151. }
  152. /// <summary>
  153. /// 加载主角的spine
  154. /// </summary>
  155. /// <param name="spineName"></param>
  156. private void LoadPlayerSpine(string spineName)
  157. {
  158. VM.PlayerSpine.LoadSpine(spineName, "stand", true);
  159. }
  160. /// <summary>
  161. /// 角色称号
  162. /// </summary>
  163. /// <param name="title"></param>
  164. private void ShowTitleIcon(string title)
  165. {
  166. VM.TitleIcon.url = title;
  167. }
  168. #region 装备UI
  169. /// <summary>
  170. /// 显示装备UI
  171. /// </summary>
  172. private void ShowEquipUI()
  173. {
  174. UiParam _uiParam = new UiParam();
  175. _uiParam.bShowBtn = true;
  176. _uiParam.bShowLevel = true;
  177. int index = 1;
  178. _equipItemList.ForEach((item) =>
  179. {
  180. EquipItem equipData = EquipData.Instance.GetWearEquipData((EEquipType)index);
  181. if (equipData != null)
  182. {
  183. item.Ctrl.ShowUI(equipData, _uiParam);
  184. }
  185. index++;
  186. });
  187. }
  188. /// <summary>
  189. /// 更换装备
  190. /// </summary>
  191. /// <param name="type"></param>
  192. /// <param name="id"></param>
  193. private void OnChangeEquip(int eventId, object args)
  194. {
  195. if (args == null)
  196. {
  197. return;
  198. }
  199. var changeEquipPartList = args as List<EEquipType>;
  200. if (changeEquipPartList?.Count > 0)
  201. {
  202. foreach (var equipPart in changeEquipPartList)
  203. {
  204. CommonItemBaseView equipItem = _equipItemList[(int)equipPart - 1];
  205. if (equipItem != null)
  206. {
  207. UiParam _uiParam = new UiParam();
  208. _uiParam.bShowBtn = true;
  209. _uiParam.bShowLevel = true;
  210. equipItem.Ctrl.ShowUI(EquipData.Instance.GetWearEquipData(equipPart), _uiParam);
  211. }
  212. }
  213. }
  214. }
  215. /// <summary>
  216. /// 刷新身上穿戴的装备信息
  217. /// </summary>
  218. /// <param name="eventId"></param>
  219. /// <param name="args"></param>
  220. private void RefreshWearEquipUI(int eventId, object args)
  221. {
  222. XGame.Log.Info("刷新身上穿戴的装备信息");
  223. ShowEquipUI();
  224. }
  225. #endregion
  226. #region 角色属性信息
  227. private void ShowAttributeUI()
  228. {
  229. VM.NameLabel.text = PlayerData.Instance.Name;
  230. ShowPlayerLevel();
  231. ShowExp(false);
  232. VM.JokSkillNested.Ctrl.ShowAttributeUI();
  233. }
  234. private void ShowPlayerLevel()
  235. {
  236. VM.LvLabl.text = $"LV.{PlayerData.Instance.Level}";
  237. }
  238. private void ShowExp(bool bShowAni = true)
  239. {
  240. var expInfo = LevelTableRepo.Get(PlayerData.Instance.Level + 1);
  241. if (expInfo == null)
  242. {
  243. // 等级上限
  244. expInfo = LevelTableRepo.Get(PlayerData.Instance.Level);
  245. }
  246. VM.ExpBar.max = expInfo.Exp;
  247. if (bShowAni)
  248. VM.ExpBar.TweenValue(PlayerData.Instance.Exp, 0.5f);
  249. else
  250. VM.ExpBar.value = PlayerData.Instance.Exp;
  251. }
  252. /// <summary>
  253. /// 角色经验值增加
  254. /// </summary>
  255. /// <param name="eventId"></param>
  256. /// <param name="args"></param>
  257. private void AddPlayerExp(int eventId, object args)
  258. {
  259. ShowExp();
  260. }
  261. #endregion
  262. /// <summary>
  263. /// 转职成功
  264. /// </summary>
  265. /// <param name="eventId"></param>
  266. /// <param name="args"></param>
  267. private void TransferSucess(int eventId, object args)
  268. {
  269. Context.UI.OpenAsync(UIKeys.PlayerTransferSucessPanel);
  270. VM.JokSkillNested.Ctrl.ShowJobUI();
  271. }
  272. /// <summary>
  273. /// 重置职业成功
  274. /// </summary>
  275. /// <param name="eventId"></param>
  276. /// <param name="args"></param>
  277. private void ResetJobSucess(int eventId, object args)
  278. {
  279. Context.UI.OpenAsync(UIKeys.PlayerTransferPanel, true);
  280. VM.JokSkillNested.Ctrl.ShowJobUI();
  281. }
  282. }
  283. }