PartnerPartnerUpListItemCtrl.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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.PanelEvent.Add(OnClickClickBtn);
  30. VM.DownBtn.onClick.Add(OnClickDownBtn);
  31. VM.PartnerItem.VM.EpiSetBase.VM.PanelEvent.Add(OnClickEpiSet);
  32. }
  33. private void RemoveUIListenres()
  34. {
  35. VM.PartnerItem.VM.PartnerBase.VM.PanelEvent.Remove(OnClickClickBtn);
  36. VM.DownBtn.onClick.Remove(OnClickDownBtn);
  37. VM.PartnerItem.VM.EpiSetBase.VM.PanelEvent.Remove(OnClickEpiSet);
  38. }
  39. private void OnClickEpiSet(EventContext eventContext)
  40. {
  41. if (PartnersData.Instance.UpModeSelect > 0)
  42. {
  43. EventSingle.Instance.Notify(EventDefine.PartnerUpModeSelect, _slotId);
  44. }
  45. else
  46. {
  47. var partnerInfo = PartnersData.Instance.GetPartnerAttrByTableId(_sbId);
  48. if (partnerInfo == null)
  49. {
  50. Log.Error($"圣兵数据不存在,id:{_sbId}");
  51. return;
  52. }
  53. Context.UI.OpenAsync(
  54. UIKeys.PartnerEpiChangePanel,
  55. new PartnerEpiChangePanelCtrlParam()
  56. {
  57. PlanId = PartnersData.Instance.UsePlanId,
  58. SlotId = -1,
  59. SbId = _sbId,
  60. }
  61. );
  62. }
  63. }
  64. private void OnClickClickBtn(EventContext context)
  65. {
  66. if (PartnersData.Instance.UpModeSelect > 0)
  67. {
  68. EventSingle.Instance.Notify(EventDefine.PartnerUpModeSelect, _slotId);
  69. }
  70. else if (_sbId > 0)
  71. {
  72. Context.UI.OpenAsync(
  73. UIKeys.PartnerDetailsPanel,
  74. new PartnerDetailsPanelParam()
  75. {
  76. PlanId = PartnersData.Instance.UsePlanId,
  77. SlotId = -1,
  78. PartnerId = _sbId,
  79. }
  80. );
  81. }
  82. else
  83. {
  84. Context.UI.OpenAsync(
  85. UIKeys.PartnerReplacePartnerPanel,
  86. new PartnerReplacePartnerPanelCtrlParam()
  87. {
  88. PlanId = PartnersData.Instance.UsePlanId,
  89. SlotId = _slotId,
  90. }
  91. );
  92. }
  93. }
  94. private void OnClickDownBtn(EventContext context)
  95. {
  96. var slotData = PartnersData.Instance.CurUsePlan.GetSlot(_slotId);
  97. if (slotData.SbId <= 0)
  98. {
  99. Context.ShowTips(StringDefine.PartnerCurSlotNoSbTips);
  100. return;
  101. }
  102. PartnersService.Instance.RequestPartnerDown(slotData.SbId);
  103. }
  104. #endregion
  105. #region 属性
  106. private int _slotId;
  107. private int _sbId;
  108. #endregion
  109. public void OnRefresh(int index, int slotId)
  110. {
  111. _slotId = slotId;
  112. var slotData = PartnersData.Instance.CurUsePlan.GetSlot(slotId);
  113. _sbId = slotData?.SbId ?? 0;
  114. VM.IsUp.selectedIndex = _sbId > 0 ? 0 : 1;
  115. VM.PartnerItem.Ctrl.ShowUI(_sbId);
  116. }
  117. }
  118. }