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.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. }
  107. #endregion
  108. private void AddEventListener()
  109. {
  110. EventSingle.Instance.AddListener(EventDefine.OnChangeEquip, OnChangeEquip);
  111. EventSingle.Instance.AddListener(EventDefine.PlayerExpAdd, AddPlayerExp);
  112. EventSingle.Instance.AddListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI);
  113. EventSingle.Instance.AddListener(EventDefine.TransferSucess, TransferSucess);
  114. EventSingle.Instance.AddListener(EventDefine.ResetJobSucess, ResetJobSucess);
  115. }
  116. private void RemoveEventListener()
  117. {
  118. EventSingle.Instance.RemoveListener(EventDefine.OnChangeEquip, OnChangeEquip);
  119. EventSingle.Instance.RemoveListener(EventDefine.PlayerExpAdd, AddPlayerExp);
  120. EventSingle.Instance.RemoveListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI);
  121. EventSingle.Instance.RemoveListener(EventDefine.TransferSucess, TransferSucess);
  122. EventSingle.Instance.RemoveListener(EventDefine.ResetJobSucess, ResetJobSucess);
  123. }
  124. private void Init()
  125. {
  126. if (_equipItemList == null)
  127. {
  128. _equipItemList = new List<CommonItemBaseView>()
  129. {
  130. VM.Weapon,VM.Helmet,VM.Clothes,VM.Hand,VM.Pants,VM.Boots
  131. };
  132. }
  133. _bHideSkillInfo = true;
  134. VM.JokSkillNested.Ctrl.Init((bool bHideSkillInfo) =>
  135. {
  136. _bHideSkillInfo = bHideSkillInfo;
  137. });
  138. PlayerService.Instance.SendToEquipInto();
  139. }
  140. private void ShowUI()
  141. {
  142. ShowEquipUI();
  143. ShowTitleIcon(PlayerData.Instance.Title);
  144. ShowAttributeUI();
  145. //ShowContractSkills(201711);
  146. LoadPlayerSpine("info_job_1001_1_SkeletonData");
  147. VM.JokSkillNested.Ctrl.ShowJobUI();
  148. }
  149. /// <summary>
  150. /// 加载主角的spine
  151. /// </summary>
  152. /// <param name="spineName"></param>
  153. private void LoadPlayerSpine(string spineName)
  154. {
  155. VM.PlayerSpine.LoadSpine(spineName, "stand", true);
  156. }
  157. /// <summary>
  158. /// 角色称号
  159. /// </summary>
  160. /// <param name="title"></param>
  161. private void ShowTitleIcon(string title)
  162. {
  163. VM.TitleIcon.url = title;
  164. }
  165. #region 装备UI
  166. /// <summary>
  167. /// 显示装备UI
  168. /// </summary>
  169. private void ShowEquipUI()
  170. {
  171. UiParam _uiParam = new UiParam();
  172. _uiParam.bShowBtn = true;
  173. _uiParam.bShowLevel = true;
  174. int index = 1;
  175. _equipItemList.ForEach((item) =>
  176. {
  177. EquipItem equipData = EquipData.Instance.GetWearEquipData((EEquipType)index);
  178. if (equipData != null)
  179. {
  180. item.Ctrl.ShowUI(equipData, _uiParam);
  181. }
  182. else
  183. {
  184. item.Ctrl.ShowEmptyUI();
  185. }
  186. index++;
  187. });
  188. }
  189. /// <summary>
  190. /// 更换装备
  191. /// </summary>
  192. /// <param name="type"></param>
  193. /// <param name="id"></param>
  194. private void OnChangeEquip(int eventId, object args)
  195. {
  196. if (args == null)
  197. {
  198. return;
  199. }
  200. var changeEquipPartList = args as List<EEquipType>;
  201. if (changeEquipPartList?.Count > 0)
  202. {
  203. foreach (var equipPart in changeEquipPartList)
  204. {
  205. CommonItemBaseView equipItem = _equipItemList[(int)equipPart - 1];
  206. if (equipItem != null)
  207. {
  208. UiParam _uiParam = new UiParam();
  209. _uiParam.bShowBtn = true;
  210. _uiParam.bShowLevel = true;
  211. equipItem.Ctrl.ShowUI(EquipData.Instance.GetWearEquipData(equipPart), _uiParam);
  212. }
  213. }
  214. }
  215. }
  216. /// <summary>
  217. /// 刷新身上穿戴的装备信息
  218. /// </summary>
  219. /// <param name="eventId"></param>
  220. /// <param name="args"></param>
  221. private void RefreshWearEquipUI(int eventId, object args)
  222. {
  223. XGame.Log.Info("刷新身上穿戴的装备信息");
  224. ShowEquipUI();
  225. }
  226. #endregion
  227. #region 角色属性信息
  228. private void ShowAttributeUI()
  229. {
  230. VM.NameLabel.text = PlayerData.Instance.Name;
  231. ShowPlayerLevel();
  232. ShowExp(false);
  233. VM.JokSkillNested.Ctrl.ShowAttributeUI();
  234. }
  235. private void ShowPlayerLevel()
  236. {
  237. VM.LvLabl.text = $"LV.{PlayerData.Instance.Level}";
  238. }
  239. private void ShowExp(bool bShowAni = true)
  240. {
  241. var expInfo = LevelTableRepo.Get(PlayerData.Instance.Level + 1);
  242. if (expInfo == null)
  243. {
  244. // 等级上限
  245. expInfo = LevelTableRepo.Get(PlayerData.Instance.Level);
  246. }
  247. VM.ExpBar.max = expInfo.Exp;
  248. if (bShowAni)
  249. VM.ExpBar.TweenValue(PlayerData.Instance.Exp, 0.5f);
  250. else
  251. VM.ExpBar.value = PlayerData.Instance.Exp;
  252. }
  253. /// <summary>
  254. /// 角色经验值增加
  255. /// </summary>
  256. /// <param name="eventId"></param>
  257. /// <param name="args"></param>
  258. private void AddPlayerExp(int eventId, object args)
  259. {
  260. ShowExp();
  261. }
  262. #endregion
  263. /// <summary>
  264. /// 转职成功
  265. /// </summary>
  266. /// <param name="eventId"></param>
  267. /// <param name="args"></param>
  268. private void TransferSucess(int eventId, object args)
  269. {
  270. Context.UI.OpenAsync(UIKeys.PlayerTransferSucessPanel);
  271. VM.JokSkillNested.Ctrl.ShowJobUI();
  272. }
  273. /// <summary>
  274. /// 重置职业成功
  275. /// </summary>
  276. /// <param name="eventId"></param>
  277. /// <param name="args"></param>
  278. private void ResetJobSucess(int eventId, object args)
  279. {
  280. Context.UI.OpenAsync(UIKeys.PlayerTransferPanel, true);
  281. VM.JokSkillNested.Ctrl.ShowJobUI();
  282. }
  283. }
  284. }