PartnerInfoListItemCtrl.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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.Database;
  9. using XGame.Framework.UI;
  10. namespace FL.FGUI
  11. {
  12. public partial class PartnerInfoListItemCtrl : UIController<PartnerInfoListItemVM>
  13. {
  14. #region 属性
  15. /// <summary>
  16. /// 圣兵id
  17. /// </summary>
  18. private int _id;
  19. #endregion
  20. protected override void OnEnable(object intent)
  21. {
  22. AddUIListenres();
  23. }
  24. protected override void OnDisable()
  25. {
  26. RemoveUIListenres();
  27. }
  28. #region UI事件
  29. private void AddUIListenres()
  30. {
  31. VM.DownBtn.onClick.Add(OnClickDownBtn);
  32. VM.UpBtn.onClick.Add(OnClickUpBtn);
  33. VM.PartnerItem.VM.PartnerBase.VM.PanelEvent.Add(OnClickBtn);
  34. VM.PartnerItem.VM.EpiSetBase.VM.PanelEvent.Add(OnClickEpiSet);
  35. }
  36. private void RemoveUIListenres()
  37. {
  38. VM.DownBtn.onClick.Remove(OnClickDownBtn);
  39. VM.UpBtn.onClick.Remove(OnClickUpBtn);
  40. VM.PartnerItem.VM.PartnerBase.VM.PanelEvent.Remove(OnClickBtn);
  41. VM.PartnerItem.VM.EpiSetBase.VM.PanelEvent.Remove(OnClickEpiSet);
  42. }
  43. private void OnClickEpiSet(EventContext eventContext)
  44. {
  45. var partnerInfo = PartnersData.Instance.GetPartnerAttrByTableId(_id);
  46. if (partnerInfo == null)
  47. return;
  48. var curUsePlan = PartnersData.Instance.CurUsePlan;
  49. Context.UI.OpenAsync(
  50. UIKeys.PartnerEpiChangePanel,
  51. new PartnerEpiChangePanelCtrlParam()
  52. {
  53. PlanId = PartnersData.Instance.UsePlanId,
  54. SlotId = -1,
  55. SbId = _id,
  56. }
  57. );
  58. }
  59. private void OnClickDownBtn(EventContext context)
  60. {
  61. PartnersService.Instance.RequestPartnerDown(_id);
  62. }
  63. private void OnClickUpBtn(EventContext context)
  64. {
  65. //PartnersService.Instance.RequestPartnerUp(_data.uid);
  66. //Context.UI.OpenAsync(UIKeys.PartnerDetailsPanel, _id);
  67. if (PartnersData.Instance.GetPartnerAttrByTableId(_id) == null)
  68. return;
  69. PartnersService.Instance.OpenPartnerMode(_id);
  70. }
  71. private void OnClickBtn(EventContext context)
  72. {
  73. Context.UI.OpenAsync(
  74. UIKeys.PartnerDetailsPanel,
  75. new PartnerDetailsPanelParam()
  76. {
  77. PlanId = PartnersData.Instance.UsePlanId,
  78. SlotId = -1,
  79. PartnerId = _id,
  80. }
  81. );
  82. }
  83. #endregion
  84. public void OnRefresh(int index, int id)
  85. {
  86. _id = id;
  87. VM.PartnerItem.Ctrl.ShowUI(id);
  88. var table = PartnerTableRepo.Get(id);
  89. var partnerInfo = PartnersData.Instance.GetPartnerAttrByTableId(table.Id);
  90. var have = partnerInfo != null;
  91. var upPos = PartnersData.Instance.GetPartnerUpPosById(table.Id);
  92. var isUp = upPos >= 0;
  93. if (have)
  94. {
  95. VM.UpBtn.touchable = true;
  96. VM.StateCtrl.selectedIndex = isUp ? 2 : 1;
  97. }
  98. else
  99. {
  100. VM.UpBtn.touchable = false;
  101. VM.StateCtrl.selectedIndex = 0;
  102. }
  103. }
  104. }
  105. }