PartnerPartnerBookDetailPanelCtrl.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /// #pkgName FGUI包名
  2. /// #panelName UIPanel名字
  3. /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
  4. /// 该脚本由模板创建
  5. /// created by cb 2024
  6. using System.Collections.Generic;
  7. using FairyGUI;
  8. using XGame;
  9. using XGame.Database;
  10. using XGame.Framework.UI;
  11. namespace FL.FGUI
  12. {
  13. /// <summary>
  14. /// UI逻辑处理类
  15. /// </summary>
  16. /// <typeparam name=""></typeparam>
  17. public partial class PartnerPartnerBookDetailPanelCtrl
  18. : UIController<PartnerPartnerBookDetailPanelVM>
  19. {
  20. private bool _initView = false;
  21. private int _curId;
  22. private List<int> _list;
  23. protected override void OnEnable(object intent)
  24. {
  25. _curId = (int)intent;
  26. AddUIListenres();
  27. UpView();
  28. }
  29. protected override void OnDisable()
  30. {
  31. RemoveUIListenres();
  32. }
  33. #region UI事件
  34. private void AddUIListenres()
  35. {
  36. VM.LeftBtn.onClick.Add(OnClickLeftBtn);
  37. VM.RightBtn.onClick.Add(OnClickRightBtn);
  38. VM.GetBtn.onClick.Add(OnClickGetBtn);
  39. }
  40. private void RemoveUIListenres()
  41. {
  42. VM.LeftBtn.onClick.Remove(OnClickLeftBtn);
  43. VM.RightBtn.onClick.Remove(OnClickRightBtn);
  44. VM.GetBtn.onClick.Remove(OnClickGetBtn);
  45. }
  46. private void OnClickLeftBtn(EventContext context)
  47. {
  48. SelectOffset(-1);
  49. }
  50. private void OnClickRightBtn(EventContext context)
  51. {
  52. SelectOffset(1);
  53. }
  54. private void OnClickGetBtn(EventContext context) { }
  55. #endregion
  56. private void InitView()
  57. {
  58. if (_initView)
  59. return;
  60. _initView = true;
  61. VM.List.ListType = EGListType.None;
  62. VM.RwdList.ListType = EGListType.Virtual;
  63. var tableList = collectTableRepo.GetAllPartnerCollectList();
  64. var list = new List<int>();
  65. foreach (var item in tableList)
  66. {
  67. list.Add(item.Id);
  68. }
  69. _list = list;
  70. }
  71. private void UpView()
  72. {
  73. var table = collectTableRepo.Get(_curId);
  74. if (table == null)
  75. {
  76. Log.Error($"羁绊表不存在,id:{_curId}");
  77. return;
  78. }
  79. VM.List.BindDatas(table.Param);
  80. VM.NameLabel.text = table.Name;
  81. var list = collect_rewardTableRepo.GetCollectRwdList(_curId);
  82. VM.RwdList.BindDatas(list);
  83. }
  84. private void SelectOffset(int offset)
  85. {
  86. var index = _list.IndexOf(offset);
  87. index += offset;
  88. if (index < 0)
  89. {
  90. index += _list.Count;
  91. }
  92. else if (index >= _list.Count)
  93. {
  94. index -= _list.Count;
  95. }
  96. _curId = _list[index];
  97. UpView();
  98. }
  99. }
  100. }