PartnerEpiBookDetailPanelCtrl.cs 2.9 KB

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