PlayerPassiveSkillListItemCtrl.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using System;
  8. using XGame.Database;
  9. using XGame.Framework.UI;
  10. namespace FL.FGUI
  11. {
  12. /// <summary>
  13. /// UI逻辑处理类
  14. /// </summary>
  15. /// <typeparam name=""></typeparam>
  16. public partial class PlayerPassiveSkillListItemCtrl : UIController<PlayerPassiveSkillListItemVM>
  17. {
  18. private int _index;
  19. private int _passiveSkillId;
  20. private Action<int, int> _callback;//点击被动技能图标的回调函数
  21. protected override void OnEnable(object intent)
  22. {
  23. AddUIListenres();
  24. }
  25. protected override void OnDisable()
  26. {
  27. RemoveUIListenres();
  28. _callback = null;
  29. _passiveSkillId = 0;
  30. }
  31. #region UI事件
  32. private void AddUIListenres()
  33. {
  34. VM.PassiveSkillBtn.onClick.Add(OnClickBtn);
  35. }
  36. private void RemoveUIListenres()
  37. {
  38. VM.PassiveSkillBtn.onClick.Remove(OnClickBtn);
  39. }
  40. private void OnClickBtn(EventContext context)
  41. {
  42. if (_callback != null)
  43. {
  44. _callback(_passiveSkillId,_index);
  45. }
  46. }
  47. #endregion
  48. public void OnRefresh(int index, JobSkillParam skillParam)
  49. {
  50. _index = index;
  51. //使用默认值来判断结构体是否被初始化
  52. bool bEmpty = skillParam.Equals(default(JobSkillParam));
  53. VM.Ctrl.selectedIndex = bEmpty ? 0 : 1;
  54. if (bEmpty)
  55. {
  56. _callback = null;
  57. _passiveSkillId = 0;
  58. return;
  59. }
  60. _passiveSkillId = skillParam.skillId;
  61. _callback = skillParam.onclickSkillIcon;
  62. var skillInfo = SkillTableRepo.Get(skillParam.skillId);
  63. if (skillInfo != null)
  64. {
  65. VM.PassiveSkillBtn.icon = skillInfo.Icon;
  66. }
  67. }
  68. }
  69. }