EquipEquipPanelCtrl.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. ShowUI(intent as EquipItemBase);
  24. }
  25. protected override void OnDisable()
  26. {
  27. _newEquip = null;
  28. _wearEquip = null;
  29. RemoveUIListenres();
  30. }
  31. #region UI事件
  32. private void AddUIListenres()
  33. {
  34. VM.WearBtn.onClick.Add(OnClickWearBtn);
  35. }
  36. private void RemoveUIListenres()
  37. {
  38. VM.WearBtn.onClick.Remove(OnClickWearBtn);
  39. }
  40. #endregion
  41. /// <summary>
  42. /// 穿戴|替换按钮事件
  43. /// </summary>
  44. /// <param name="context"></param>
  45. private void OnClickWearBtn(EventContext context)
  46. {
  47. if (_newEquip == null) return;
  48. EquipData.Instance.BubblingEquipUid = 0;
  49. DragonEggService.Instance.OnChangeEquip(_newEquip.Id);
  50. ClosePanel();
  51. }
  52. private void ClosePanel()
  53. {
  54. Context.ClosePanel();
  55. }
  56. private void ShowUI(EquipItemBase equipBase)
  57. {
  58. if (equipBase == null) return;
  59. _wearEquip = EquipData.Instance.GetWearEquipData(equipBase.EquipType);
  60. if (_wearEquip != null)
  61. {
  62. ShowEquipInfo(_wearEquip);
  63. VM.WearEquipItem.Disable();
  64. }
  65. if (equipBase.Id == 0) // 身上穿戴的装备
  66. {
  67. return;
  68. }
  69. _newEquip = EquipData.Instance.GetBagEquipItem(equipBase.Id);
  70. if (_newEquip == null) return;
  71. bool bShowWear = _wearEquip != null;
  72. if (bShowWear)
  73. {
  74. VM.WearEquipItem.Enable(null);
  75. VM.WearEquipItem.Ctrl.ShowUI(_newEquip, _wearEquip, true);
  76. }
  77. else
  78. {
  79. VM.WearEquipItem.Disable();
  80. }
  81. VM.NewEquipItem.Ctrl.ShowUI(_newEquip, _wearEquip);
  82. ShowBtnUI(bShowWear);
  83. }
  84. private void ShowBtnUI(bool bWear)
  85. {
  86. VM.BtnState.selectedIndex = bWear ? 1 : 2; // 1_替换 2_穿戴
  87. }
  88. private void ShowEquipInfo(EquipAttr equip)
  89. {
  90. // 展示装备属性详情,不显示按钮
  91. VM.BtnState.selectedIndex = 0;
  92. VM.NewEquipItem.Ctrl.ShowUI(equip, equip, true);
  93. }
  94. }
  95. }