EquipEquipPanelCtrl.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using FairyGUI;
  7. using FL.Data.Items;
  8. using FL.Data;
  9. using XGame.Framework.UI;
  10. namespace FL.FGUI
  11. {
  12. /// <summary>
  13. /// UI逻辑处理类
  14. /// </summary>
  15. /// <typeparam name=""></typeparam>
  16. public partial class EquipEquipPanelCtrl : UIController<EquipEquipPanelVM>
  17. {
  18. private EquipAttr _newEquip;
  19. private EquipAttr _wearEquip;
  20. protected override void OnEnable(object intent)
  21. {
  22. AddUIListenres();
  23. if (intent != null)
  24. {
  25. if (intent is EquipAttr)
  26. ShowUI(intent as EquipAttr);
  27. else
  28. ShowUI(EquipData.Instance.GetBagEquipItem(long.Parse(intent.ToString())));
  29. }
  30. }
  31. protected override void OnDisable()
  32. {
  33. _newEquip = null;
  34. _wearEquip = null;
  35. RemoveUIListenres();
  36. }
  37. #region UI事件
  38. private void AddUIListenres()
  39. {
  40. VM.WearBtn.onClick.Add(OnClickWearBtn);
  41. }
  42. private void RemoveUIListenres()
  43. {
  44. VM.WearBtn.onClick.Remove(OnClickWearBtn);
  45. }
  46. #endregion
  47. /// <summary>
  48. /// 穿戴|替换按钮事件
  49. /// </summary>
  50. /// <param name="context"></param>
  51. private void OnClickWearBtn(EventContext context)
  52. {
  53. if (_newEquip == null) return;
  54. EquipData.Instance.BubblingEquipUid = 0;
  55. DragonEggService.Instance.OnChangeEquip(_newEquip.Id);
  56. ClosePanel();
  57. }
  58. private void ClosePanel()
  59. {
  60. Context.ClosePanel();
  61. }
  62. private void ShowUI(EquipAttr equipBase)
  63. {
  64. if (equipBase == null) return;
  65. _wearEquip = EquipData.Instance.GetWearEquipData(equipBase.EquipType);
  66. if (_wearEquip != null)
  67. {
  68. ShowEquipInfo(_wearEquip);
  69. VM.WearEquipItem.Disable();
  70. }
  71. if (equipBase.Id == 0) // 身上穿戴的装备
  72. {
  73. return;
  74. }
  75. _newEquip = EquipData.Instance.GetBagEquipItem(equipBase.Id);
  76. if (_newEquip == null) return;
  77. bool bShowWear = _wearEquip != null;
  78. if (bShowWear)
  79. {
  80. VM.WearEquipItem.Enable(null);
  81. VM.WearEquipItem.Ctrl.ShowUI(_newEquip, _wearEquip, true);
  82. }
  83. else
  84. {
  85. VM.WearEquipItem.Disable();
  86. }
  87. VM.NewEquipItem.Ctrl.ShowUI(_newEquip, _wearEquip);
  88. ShowBtnUI(bShowWear);
  89. }
  90. private void ShowBtnUI(bool bWear)
  91. {
  92. VM.BtnState.selectedIndex = bWear ? 1 : 2; // 1_替换 2_穿戴
  93. }
  94. private void ShowEquipInfo(EquipAttr equip)
  95. {
  96. // 展示装备属性详情,不显示按钮
  97. VM.BtnState.selectedIndex = 0;
  98. VM.NewEquipItem.Ctrl.ShowUI(equip, equip, true);
  99. }
  100. }
  101. }