PlayerMainPanelCtrl.cs 9.8 KB

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