PartnerReplacePartnerListItemCtrl.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. 
  2. /// #pkgName FGUI包名
  3. /// #panelName UIPanel名字
  4. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  5. /// 该脚本由模板创建
  6. /// created by cb 2024
  7. using FairyGUI;
  8. using FL.Data;
  9. using XGame;
  10. using XGame.Database;
  11. using XGame.Framework.UI;
  12. namespace FL.FGUI
  13. {
  14. public interface IPartnerReplacePanelCtrl
  15. {
  16. int PlanId { get; }
  17. int SlotId { get; }
  18. int CurSelectId { get; }
  19. }
  20. public class PartnerReplacePartnerListItemCtrlParam
  21. {
  22. public int PartnerId;
  23. public IPartnerReplacePanelCtrl Ctrl;
  24. }
  25. /// <summary>
  26. /// UI逻辑处理类
  27. /// </summary>
  28. /// <typeparam name=""></typeparam>
  29. public partial class PartnerReplacePartnerListItemCtrl
  30. : UIController<PartnerReplacePartnerListItemVM>
  31. {
  32. private int _partnerId; // 圣兵的uid
  33. private int _planId; //方案id
  34. private int _slotId;
  35. private int _curSelectedId;
  36. protected override void OnEnable(object intent)
  37. {
  38. AddUIListenres();
  39. }
  40. protected override void OnDisable()
  41. {
  42. RemoveUIListenres();
  43. }
  44. #region UI事件
  45. private void AddUIListenres()
  46. {
  47. VM.PanelEvent.Add(OnClickClickBtn);
  48. }
  49. private void RemoveUIListenres()
  50. {
  51. VM.PanelEvent.Remove(OnClickClickBtn);
  52. }
  53. private void OnClickClickBtn(EventContext context)
  54. {
  55. EventSingle.Instance.Notify(EventDefine.PartnerSelectReplace, _partnerId);
  56. }
  57. #endregion
  58. public void OnRefresh(int index, PartnerReplacePartnerListItemCtrlParam param)
  59. {
  60. _partnerId = param.PartnerId;
  61. _planId = param.Ctrl.PlanId;
  62. _slotId = param.Ctrl.SlotId;
  63. _curSelectedId = param.Ctrl.CurSelectId;
  64. var info = PartnersData.Instance.GetPartnerAttrByTableId(param.PartnerId);
  65. if (info == null)
  66. {
  67. Log.Error($"圣兵数据不存在id:{param.PartnerId}");
  68. return;
  69. }
  70. ShowSelectState();
  71. var plan = PartnersData.Instance.GetPlanById(param.Ctrl.PlanId);
  72. if (plan == null)
  73. {
  74. Log.Error($"方案信息不存在,方案id:{param.Ctrl.PlanId}");
  75. return;
  76. }
  77. var isUp = false;
  78. foreach (var slot in plan.Slots)
  79. {
  80. if (slot.SbId == _partnerId)
  81. {
  82. isUp = true;
  83. break;
  84. }
  85. }
  86. VM.StateCtrl.selectedIndex = isUp ? 1 : 0;
  87. var parterInfo = PartnerTableRepo.Get(param.PartnerId);
  88. VM.NameLabel.text = parterInfo?.Name ?? "";
  89. VM.PartnerItem.Ctrl.ShowUI(_partnerId);
  90. }
  91. public void ShowSelectState()
  92. {
  93. VM.Selected.selectedIndex = _curSelectedId == _partnerId ? 1 : 0;
  94. }
  95. }
  96. }