PlayerMainPanelCtrl.cs 9.8 KB

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