PlayerMainPanelCtrl.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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 List<CommonItemBaseView> _equipItemList;
  21. private Dictionary<EAttributeType, string> _attributeDescMap;
  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. if (_attributeDescMap != null)
  39. {
  40. _attributeDescMap.Clear();
  41. _attributeDescMap = null;
  42. }
  43. VM.PlayerSpine.url = string.Empty;
  44. }
  45. #region UI事件
  46. private void AddUIListenres()
  47. {
  48. VM.AttrInfoBtn.onClick.Add(OnClickAttrInfoBtn);
  49. VM.SkillBtn.onClick.Add(OnClickSkillBtn);
  50. VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
  51. VM.MountBtn.onClick.Add(OnClickMountBtn);
  52. VM.ArtifactBtn.onClick.Add(OnClickArtifactBtn);
  53. VM.ContractBtn.onClick.Add(OnClickContractBtn);
  54. VM.JewelryBtn.onClick.Add(OnClickJewelryBtn);
  55. VM.NotOpenBtn1.onClick.Add(OnClickNotOpenBtn1);
  56. VM.NotOpenBtn2.onClick.Add(OnClickNotOpenBtn2);
  57. }
  58. private void RemoveUIListenres()
  59. {
  60. VM.AttrInfoBtn.onClick.Remove(OnClickAttrInfoBtn);
  61. VM.SkillBtn.onClick.Remove(OnClickSkillBtn);
  62. VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
  63. VM.MountBtn.onClick.Remove(OnClickMountBtn);
  64. VM.ArtifactBtn.onClick.Remove(OnClickArtifactBtn);
  65. VM.ContractBtn.onClick.Remove(OnClickContractBtn);
  66. VM.JewelryBtn.onClick.Remove(OnClickJewelryBtn);
  67. VM.NotOpenBtn1.onClick.Remove(OnClickNotOpenBtn1);
  68. VM.NotOpenBtn2.onClick.Remove(OnClickNotOpenBtn2);
  69. }
  70. private void OnClickAttrInfoBtn(EventContext context)
  71. {
  72. Context.UI.OpenAsync(UIKeys.PlayerDetailsAttribute);
  73. }
  74. private void OnClickSkillBtn(EventContext context)
  75. {
  76. EventSingle.Instance.Notify(EventDefine.ShowTips, "显示技能详情界面");
  77. }
  78. private void OnClickChangeBtn(EventContext context)
  79. {
  80. EventSingle.Instance.Notify(EventDefine.ShowTips, "更换契约技能");
  81. }
  82. private void OnClickMountBtn(EventContext context)
  83. {
  84. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开坐骑界面");
  85. }
  86. private void OnClickArtifactBtn(EventContext context)
  87. {
  88. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开神器界面");
  89. }
  90. private void OnClickContractBtn(EventContext context)
  91. {
  92. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开锲约界面");
  93. }
  94. private void OnClickJewelryBtn(EventContext context)
  95. {
  96. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开饰品装扮界面");
  97. }
  98. private void OnClickNotOpenBtn1(EventContext context)
  99. {
  100. EventSingle.Instance.Notify(EventDefine.ShowTips, StringDefine.notOpen);
  101. }
  102. private void OnClickNotOpenBtn2(EventContext context)
  103. {
  104. EventSingle.Instance.Notify(EventDefine.ShowTips, StringDefine.notOpen);
  105. }
  106. #endregion
  107. private void AddEventListener()
  108. {
  109. EventSingle.Instance.AddListener(EventDefine.OnChangeEquip, OnChangeEquip);
  110. EventSingle.Instance.AddListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
  111. EventSingle.Instance.AddListener(EventDefine.PlayerExpAdd, AddPlayerExp);
  112. EventSingle.Instance.AddListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI);
  113. }
  114. private void RemoveEventListener()
  115. {
  116. EventSingle.Instance.RemoveListener(EventDefine.OnChangeEquip, OnChangeEquip);
  117. EventSingle.Instance.RemoveListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
  118. EventSingle.Instance.RemoveListener(EventDefine.PlayerExpAdd, AddPlayerExp);
  119. EventSingle.Instance.RemoveListener(EventDefine.RefreshWearEquipUI, RefreshWearEquipUI);
  120. }
  121. private void Init()
  122. {
  123. if (_equipItemList == null)
  124. {
  125. _equipItemList = new List<CommonItemBaseView>()
  126. {
  127. VM.Weapon,VM.Helmet,VM.Clothes,VM.Hand,VM.Pants,VM.Boots
  128. };
  129. }
  130. if (_attributeDescMap == null)
  131. {
  132. _attributeDescMap = new Dictionary<EAttributeType, string>()
  133. {
  134. {EAttributeType.Atk, GetAttributeDesc(EAttributeType.Atk)},
  135. {EAttributeType.Hp, GetAttributeDesc(EAttributeType.Hp)},
  136. {EAttributeType.Def, GetAttributeDesc(EAttributeType.Def)},
  137. { EAttributeType.AtkSpeed, GetAttributeDesc(EAttributeType.AtkSpeed)}
  138. };
  139. }
  140. PlayerService.Instance.SendToEquipInto();
  141. }
  142. private void ShowUI()
  143. {
  144. ShowEquipUI();
  145. ShowTitleIcon(PlayerData.Instance.Title);
  146. ShowAttributeUI();
  147. ShowContractSkills(201711);
  148. LoadPlayerSpine("info_job_1001_1_SkeletonData");
  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. /// <summary>
  167. /// 锲约的技能
  168. /// </summary>
  169. /// <param name="skillName"></param>
  170. private void ShowContractSkills(int skillId)
  171. {
  172. var skillInfo = SkillTableRepo.Get(skillId);
  173. if (skillInfo == null) return;
  174. VM.SkillNameLabl.text = skillInfo.Name;
  175. VM.SkillDescLabl.text = skillInfo.Desc;
  176. (VM.SkillBtn.GetChild("bg") as GLoader).url = AddressableDefine.ItemFrame((EQualityLevel)skillInfo.Quality);
  177. VM.SkillBtn.icon = $"skillicon_{skillInfo.Icon}";
  178. }
  179. #region 装备UI
  180. /// <summary>
  181. /// 显示装备UI
  182. /// </summary>
  183. private void ShowEquipUI()
  184. {
  185. UiParam _uiParam = new UiParam();
  186. _uiParam.bShowBtn = true;
  187. _uiParam.bShowLevel = true;
  188. int index = 1;
  189. _equipItemList.ForEach((item) =>
  190. {
  191. EquipItem equipData = EquipData.Instance.GetWearEquipData((EEquipType)index);
  192. if (equipData != null)
  193. {
  194. item.Ctrl.ShowUI(equipData, _uiParam);
  195. }
  196. index++;
  197. });
  198. }
  199. /// <summary>
  200. /// 更换装备
  201. /// </summary>
  202. /// <param name="type"></param>
  203. /// <param name="id"></param>
  204. private void OnChangeEquip(int eventId, object args)
  205. {
  206. if (args == null)
  207. {
  208. return;
  209. }
  210. var changeEquipPartList = args as List<EEquipType>;
  211. if (changeEquipPartList?.Count > 0)
  212. {
  213. foreach (var equipPart in changeEquipPartList)
  214. {
  215. CommonItemBaseView equipItem = _equipItemList[(int)equipPart - 1];
  216. if (equipItem != null)
  217. {
  218. UiParam _uiParam = new UiParam();
  219. _uiParam.bShowBtn = true;
  220. _uiParam.bShowLevel = true;
  221. equipItem.Ctrl.ShowUI(EquipData.Instance.GetWearEquipData(equipPart), _uiParam);
  222. }
  223. }
  224. }
  225. }
  226. /// <summary>
  227. /// 刷新身上穿戴的装备信息
  228. /// </summary>
  229. /// <param name="eventId"></param>
  230. /// <param name="args"></param>
  231. private void RefreshWearEquipUI(int eventId, object args)
  232. {
  233. XGame.Log.Info("刷新身上穿戴的装备信息");
  234. ShowEquipUI();
  235. }
  236. #endregion
  237. #region 角色属性信息
  238. private void ShowAttributeUI()
  239. {
  240. VM.NameLabel.text = PlayerData.Instance.Name;
  241. ShowPlayerLevel();
  242. ShowExp(false);
  243. ShowAtrributeVal(VM.AtkLabel, EAttributeType.Atk);
  244. ShowAtrributeVal(VM.HpLabel, EAttributeType.Hp);
  245. ShowAtrributeVal(VM.DefLabel, EAttributeType.Def);
  246. ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeed);
  247. }
  248. private void ShowPlayerLevel()
  249. {
  250. VM.LvLabl.text = $"LV.{PlayerData.Instance.Level}";
  251. }
  252. private void ShowExp(bool bShowAni = true)
  253. {
  254. var expInfo = LevelTableRepo.Get(PlayerData.Instance.Level + 1);
  255. if (expInfo == null)
  256. {
  257. // 等级上限
  258. expInfo = LevelTableRepo.Get(PlayerData.Instance.Level);
  259. }
  260. VM.ExpBar.max = expInfo.Exp;
  261. if (bShowAni)
  262. VM.ExpBar.TweenValue(PlayerData.Instance.Exp, 0.5f);
  263. else
  264. VM.ExpBar.value = PlayerData.Instance.Exp;
  265. }
  266. /// <summary>
  267. /// 角色经验值增加
  268. /// </summary>
  269. /// <param name="eventId"></param>
  270. /// <param name="args"></param>
  271. private void AddPlayerExp(int eventId, object args)
  272. {
  273. ShowExp();
  274. }
  275. private string GetAttributeDesc(EAttributeType attrType)
  276. {
  277. var attrInfo = AttrDescTableRepo.Get((int)attrType);
  278. return attrInfo?.ShowName ?? string.Empty;
  279. }
  280. /// <summary>
  281. /// 角色属性变化
  282. /// </summary>
  283. /// <param name="eventId"></param>
  284. /// <param name="args"></param>
  285. private void OnChangeAttribute(int eventId, object args)
  286. {
  287. EAttributeType attrType = (EAttributeType)args;
  288. if (attrType == EAttributeType.Atk)
  289. {
  290. ShowAtrributeVal(VM.AtkLabel, EAttributeType.Atk);
  291. }
  292. else if (attrType == EAttributeType.Hp)
  293. {
  294. ShowAtrributeVal(VM.HpLabel, EAttributeType.Hp);
  295. }
  296. else if (attrType == EAttributeType.Def)
  297. {
  298. ShowAtrributeVal(VM.DefLabel, EAttributeType.Def);
  299. }
  300. else if (attrType == EAttributeType.AtkSpeed)
  301. {
  302. ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeed);
  303. }
  304. }
  305. private void ShowAtrributeVal(GTextField attrLabel, EAttributeType attrType)
  306. {
  307. attrLabel.text = $"{_attributeDescMap[attrType]}:{PlayerData.Instance.Attr.GetValue(attrType)}";
  308. }
  309. #endregion
  310. }
  311. }