PartnerPartnerUpListItemCtrl.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 XGame;
  9. using XGame.Framework.UI;
  10. namespace FL.FGUI
  11. {
  12. /// <summary>
  13. /// UI逻辑处理类
  14. /// </summary>
  15. /// <typeparam name=""></typeparam>
  16. public partial class PartnerPartnerUpListItemCtrl : UIController<PartnerPartnerUpListItemVM>
  17. {
  18. protected override void OnEnable(object intent)
  19. {
  20. AddUIListenres();
  21. }
  22. protected override void OnDisable()
  23. {
  24. RemoveUIListenres();
  25. }
  26. #region UI事件
  27. private void AddUIListenres()
  28. {
  29. VM.PartnerItem.VM.PartnerBase.VM.ClickBtn.onClick.Add(OnClickClickBtn);
  30. VM.DownBtn.onClick.Add(OnClickDownBtn);
  31. VM.UpBtn.onClick.Add(OnClickUpBtn);
  32. VM.PartnerItem.VM.EpiSetBase.VM.ClickBtn.onClick.Add(OnClickEpiSet);
  33. }
  34. private void RemoveUIListenres()
  35. {
  36. VM.PartnerItem.VM.PartnerBase.VM.ClickBtn.onClick.Remove(OnClickClickBtn);
  37. VM.DownBtn.onClick.Remove(OnClickDownBtn);
  38. VM.UpBtn.onClick.Remove(OnClickUpBtn);
  39. VM.PartnerItem.VM.EpiSetBase.VM.ClickBtn.onClick.Remove(OnClickEpiSet);
  40. }
  41. private void OnClickEpiSet(EventContext eventContext)
  42. {
  43. if (PartnersData.Instance.UpModeSelect > 0)
  44. {
  45. EventSingle.Instance.Notify(EventDefine.PartnerUpModeSelect, _slotId);
  46. }
  47. else
  48. {
  49. var partnerInfo = PartnersData.Instance.GetPartnerAttrByTableId(_sbId);
  50. if (partnerInfo == null)
  51. {
  52. Log.Error($"圣兵数据不存在,id:{_sbId}");
  53. return;
  54. }
  55. Context.UI.OpenAsync(
  56. UIKeys.PartnerEpiChangePanel,
  57. new PartnerEpiChangePanelCtrlParam()
  58. {
  59. PlanId = PartnersData.Instance.UsePlanId,
  60. SlotId = -1,
  61. SbId = _sbId,
  62. }
  63. );
  64. }
  65. }
  66. private void OnClickClickBtn(EventContext context)
  67. {
  68. if (PartnersData.Instance.UpModeSelect > 0)
  69. {
  70. EventSingle.Instance.Notify(EventDefine.PartnerUpModeSelect, _slotId);
  71. }
  72. else if (_sbId > 0)
  73. {
  74. Context.UI.OpenAsync(UIKeys.PartnerDetailsPanel, _sbId);
  75. }
  76. else
  77. {
  78. Context.UI.OpenAsync(
  79. UIKeys.PartnerReplacePartnerPanel,
  80. new PartnerReplacePartnerPanelCtrlParam()
  81. {
  82. PlanId = PartnersData.Instance.UsePlanId,
  83. SlotId = _slotId,
  84. }
  85. );
  86. }
  87. }
  88. private void OnClickDownBtn(EventContext context)
  89. {
  90. var slotData = PartnersData.Instance.CurUsePlan.GetSlot(_slotId);
  91. if (slotData.SbId <= 0)
  92. {
  93. Context.ShowTips(StringDefine.PartnerCurSlotNoSbTips);
  94. return;
  95. }
  96. PartnersService.Instance.RequestPartnerDown(slotData.SbId);
  97. }
  98. private void OnClickUpBtn(EventContext context) { }
  99. #endregion
  100. #region 属性
  101. private int _slotId;
  102. private int _sbId;
  103. #endregion
  104. public void OnRefresh(int index, int slotId)
  105. {
  106. _slotId = slotId;
  107. var slotData = PartnersData.Instance.CurUsePlan.GetSlot(slotId);
  108. _sbId = slotData?.SbId ?? 0;
  109. VM.IsUp.selectedIndex = _sbId > 0 ? 0 : 1;
  110. VM.PartnerItem.Ctrl.ShowUI(_sbId);
  111. }
  112. }
  113. }