PlayerMainPanelCtrl.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  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. EventSingle.Instance.AddListener(EventDefine.OnChangeEquip, OnChangeEquip);
  26. EventSingle.Instance.AddListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
  27. EventSingle.Instance.AddListener(EventDefine.PlayerExpAdd, AddPlayerExp);
  28. Init();
  29. ShowUI();
  30. }
  31. protected override void OnDisable()
  32. {
  33. RemoveUIListenres();
  34. EventSingle.Instance.RemoveListener(EventDefine.OnChangeEquip, OnChangeEquip);
  35. EventSingle.Instance.RemoveListener(EventDefine.AttributeChange, OnChangeAttribute); // 角色属性变化
  36. EventSingle.Instance.RemoveListener(EventDefine.PlayerExpAdd, AddPlayerExp);
  37. if (_equipItemList != null)
  38. {
  39. _equipItemList.Clear();
  40. _equipItemList = null;
  41. }
  42. if (_attributeDescMap != null)
  43. {
  44. _attributeDescMap.Clear();
  45. _attributeDescMap = null;
  46. }
  47. VM.PlayerSpine.url = string.Empty;
  48. }
  49. #region UI事件
  50. private void AddUIListenres()
  51. {
  52. VM.AttrInfoBtn.onClick.Add(OnClickAttrInfoBtn);
  53. VM.SkillBtn.onClick.Add(OnClickSkillBtn);
  54. VM.ChangeBtn.onClick.Add(OnClickChangeBtn);
  55. VM.MountBtn.onClick.Add(OnClickMountBtn);
  56. VM.ArtifactBtn.onClick.Add(OnClickArtifactBtn);
  57. VM.ContractBtn.onClick.Add(OnClickContractBtn);
  58. VM.JewelryBtn.onClick.Add(OnClickJewelryBtn);
  59. VM.NotOpenBtn1.onClick.Add(OnClickNotOpenBtn1);
  60. VM.NotOpenBtn2.onClick.Add(OnClickNotOpenBtn2);
  61. }
  62. private void RemoveUIListenres()
  63. {
  64. VM.AttrInfoBtn.onClick.Remove(OnClickAttrInfoBtn);
  65. VM.SkillBtn.onClick.Remove(OnClickSkillBtn);
  66. VM.ChangeBtn.onClick.Remove(OnClickChangeBtn);
  67. VM.MountBtn.onClick.Remove(OnClickMountBtn);
  68. VM.ArtifactBtn.onClick.Remove(OnClickArtifactBtn);
  69. VM.ContractBtn.onClick.Remove(OnClickContractBtn);
  70. VM.JewelryBtn.onClick.Remove(OnClickJewelryBtn);
  71. VM.NotOpenBtn1.onClick.Remove(OnClickNotOpenBtn1);
  72. VM.NotOpenBtn2.onClick.Remove(OnClickNotOpenBtn2);
  73. }
  74. private void OnClickAttrInfoBtn(EventContext context)
  75. {
  76. Context.UI.OpenAsync(UIKeys.PlayerDetailsAttribute);
  77. }
  78. private void OnClickSkillBtn(EventContext context)
  79. {
  80. EventSingle.Instance.Notify(EventDefine.ShowTips, "显示技能详情界面");
  81. }
  82. private void OnClickChangeBtn(EventContext context)
  83. {
  84. EventSingle.Instance.Notify(EventDefine.ShowTips, "更换契约技能");
  85. }
  86. private void OnClickMountBtn(EventContext context)
  87. {
  88. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开坐骑界面");
  89. }
  90. private void OnClickArtifactBtn(EventContext context)
  91. {
  92. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开神器界面");
  93. }
  94. private void OnClickContractBtn(EventContext context)
  95. {
  96. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开锲约界面");
  97. }
  98. private void OnClickJewelryBtn(EventContext context)
  99. {
  100. EventSingle.Instance.Notify(EventDefine.ShowTips, "打开饰品装扮界面");
  101. }
  102. private void OnClickNotOpenBtn1(EventContext context)
  103. {
  104. EventSingle.Instance.Notify(EventDefine.ShowTips, StringDefine.notOpen);
  105. }
  106. private void OnClickNotOpenBtn2(EventContext context)
  107. {
  108. EventSingle.Instance.Notify(EventDefine.ShowTips, StringDefine.notOpen);
  109. }
  110. #endregion
  111. private void Init()
  112. {
  113. if (_equipItemList == null)
  114. {
  115. _equipItemList = new List<CommonItemBaseView>()
  116. {
  117. VM.Weapon,VM.Helmet,VM.Clothes,VM.Hand,VM.Pants,VM.Boots
  118. };
  119. }
  120. if (_attributeDescMap == null)
  121. {
  122. _attributeDescMap = new Dictionary<EAttributeType, string>()
  123. {
  124. {EAttributeType.Atk, GetAttributeDesc(EAttributeType.Atk)},
  125. {EAttributeType.Hp, GetAttributeDesc(EAttributeType.Hp)},
  126. {EAttributeType.Def, GetAttributeDesc(EAttributeType.Def)},
  127. { EAttributeType.AtkSpeed, GetAttributeDesc(EAttributeType.AtkSpeed)}
  128. };
  129. }
  130. }
  131. private void ShowUI()
  132. {
  133. ShowEquipUI();
  134. ShowTitleIcon(PlayerData.Instance.Title);
  135. ShowAttributeUI();
  136. ShowContractSkills(201711);
  137. LoadPlayerSpine("info_job_1001_1_SkeletonData");
  138. }
  139. /// <summary>
  140. /// 加载主角的spine
  141. /// </summary>
  142. /// <param name="spineName"></param>
  143. private void LoadPlayerSpine(string spineName)
  144. {
  145. VM.PlayerSpine.LoadSpine(spineName, "stand", true);
  146. }
  147. /// <summary>
  148. /// 角色称号
  149. /// </summary>
  150. /// <param name="title"></param>
  151. private void ShowTitleIcon(string title)
  152. {
  153. VM.TitleIcon.url = title;
  154. }
  155. /// <summary>
  156. /// 锲约的技能
  157. /// </summary>
  158. /// <param name="skillName"></param>
  159. private void ShowContractSkills(int skillId)
  160. {
  161. var skillInfo = SkillTableRepo.Get(skillId);
  162. if (skillInfo == null) return;
  163. VM.SkillNameLabl.text = skillInfo.Name;
  164. VM.SkillDescLabl.text = skillInfo.Desc;
  165. (VM.SkillBtn.GetChild("QualityIcon") as GLoader).url = AddressableDefine.ItemFrame((EQualityLevel)skillInfo.Quality);
  166. VM.SkillBtn.icon = $"skillicon_{skillInfo.Icon}";
  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 = ItemData.Instance.GetEquipData((EEquipType)index);
  181. if (equipData != null)
  182. {
  183. item.Ctrl.ShowUI(ItemData.Instance.GetEquipData((EEquipType)index), _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. ChangeEquipParam param = (ChangeEquipParam)args;
  200. CommonItemBaseView equipItem = _equipItemList[(int)param.equipType - 1];
  201. if (equipItem != null)
  202. {
  203. UiParam _uiParam = new UiParam();
  204. _uiParam.bShowBtn = true;
  205. _uiParam.bShowLevel = true;
  206. equipItem.Ctrl.ShowUI(ItemData.Instance.GetEquipData(param.equipType), _uiParam);
  207. }
  208. }
  209. #endregion
  210. #region 角色属性信息
  211. private void ShowAttributeUI()
  212. {
  213. VM.NameLabel.text = PlayerData.Instance.Name;
  214. ShowPlayerLevel();
  215. ShowExp(false);
  216. ShowAtrributeVal(VM.AtkLabel, EAttributeType.Atk);
  217. ShowAtrributeVal(VM.HpLabel, EAttributeType.Hp);
  218. ShowAtrributeVal(VM.DefLabel, EAttributeType.Def);
  219. ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeed);
  220. }
  221. private void ShowPlayerLevel()
  222. {
  223. VM.LvLabl.text = $"LV.{PlayerData.Instance.Level}";
  224. }
  225. private void ShowExp(bool bShowAni = true)
  226. {
  227. var expInfo = LevelTableRepo.Get(PlayerData.Instance.Level + 1);
  228. if (expInfo == null)
  229. {
  230. // 等级上限
  231. expInfo = LevelTableRepo.Get(PlayerData.Instance.Level);
  232. }
  233. VM.ExpBar.max = expInfo.Exp;
  234. if (bShowAni)
  235. VM.ExpBar.TweenValue(PlayerData.Instance.Exp, 0.5f);
  236. else
  237. VM.ExpBar.value = PlayerData.Instance.Exp;
  238. }
  239. /// <summary>
  240. /// 角色经验值增加
  241. /// </summary>
  242. /// <param name="eventId"></param>
  243. /// <param name="args"></param>
  244. private void AddPlayerExp(int eventId, object args)
  245. {
  246. ShowExp();
  247. }
  248. private string GetAttributeDesc(EAttributeType attrType)
  249. {
  250. var attrInfo = AttrDescTableRepo.Get((int)attrType);
  251. return attrInfo?.ShowName ?? string.Empty;
  252. }
  253. /// <summary>
  254. /// 角色属性变化
  255. /// </summary>
  256. /// <param name="eventId"></param>
  257. /// <param name="args"></param>
  258. private void OnChangeAttribute(int eventId, object args)
  259. {
  260. EAttributeType attrType = (EAttributeType)args;
  261. if (attrType == EAttributeType.Atk)
  262. {
  263. ShowAtrributeVal(VM.AtkLabel, EAttributeType.Atk);
  264. }
  265. else if (attrType == EAttributeType.Hp)
  266. {
  267. ShowAtrributeVal(VM.HpLabel, EAttributeType.Hp);
  268. }
  269. else if (attrType == EAttributeType.Def)
  270. {
  271. ShowAtrributeVal(VM.DefLabel, EAttributeType.Def);
  272. }
  273. else if (attrType == EAttributeType.AtkSpeed)
  274. {
  275. ShowAtrributeVal(VM.AtkSpeedLabel, EAttributeType.AtkSpeed);
  276. }
  277. }
  278. private void ShowAtrributeVal(GTextField attrLabel, EAttributeType attrType)
  279. {
  280. attrLabel.text = $"{_attributeDescMap[attrType]}:{PlayerData.Instance.Attr.GetValue(attrType)}";
  281. }
  282. #endregion
  283. }
  284. }