PartnerEpiUpListItemCtrl.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 PartnerEpiUpListItemCtrl : UIController<PartnerEpiUpListItemVM>
  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 (EpigraphData.Instance.UpModeSelect > 0)
  42. {
  43. EventSingle.Instance.Notify(EventDefine.EpigraphUpModeSelect, _sbId);
  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 (EpigraphData.Instance.UpModeSelect > 0)
  67. {
  68. EventSingle.Instance.Notify(EventDefine.EpigraphUpModeSelect, _sbId);
  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. return;
  99. PartnersService.Instance.RequestPartnerDown(slotData.SbId);
  100. }
  101. #endregion
  102. #region 属性
  103. private int _slotId;
  104. private int _sbId;
  105. #endregion
  106. public void OnRefresh(int index, int slotId)
  107. {
  108. _slotId = slotId;
  109. var slotData = PartnersData.Instance.CurUsePlan.GetSlot(slotId);
  110. _sbId = slotData?.SbId ?? 0;
  111. VM.IsUp.selectedIndex = _sbId > 0 ? 0 : 1;
  112. VM.PartnerItem.Ctrl.ShowUI(_sbId);
  113. }
  114. }
  115. }