PartnerEpiBookDetailPanelCtrl.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 FL.Data;
  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 PartnerEpiBookDetailPanelCtrl : UIController<PartnerEpiBookDetailPanelVM>
  18. {
  19. protected override void OnEnable(object intent)
  20. {
  21. _curId = (int)intent;
  22. AddUIListenres();
  23. InitView();
  24. UpView();
  25. }
  26. protected override void OnDisable()
  27. {
  28. RemoveUIListenres();
  29. }
  30. #region UI事件
  31. private void AddUIListenres()
  32. {
  33. VM.LeftBtn.onClick.Add(OnClickLeftBtn);
  34. VM.RightBtn.onClick.Add(OnClickRightBtn);
  35. VM.GetBtn.onClick.Add(OnClickGetBtn);
  36. Context.AddListener(EventDefine.PartnerJibanRwdGet, OnRwdGet);
  37. Context.AddListener(EventDefine.PartnerJibanRwdGetAll, OnRwdGet);
  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. Context.RemoveListener(EventDefine.PartnerJibanRwdGet, OnRwdGet);
  45. Context.RemoveListener(EventDefine.PartnerJibanRwdGetAll, OnRwdGet);
  46. }
  47. private void OnRwdGet(int eventId, object args)
  48. {
  49. UpdateList();
  50. }
  51. private void OnClickLeftBtn(EventContext context)
  52. {
  53. SelectOffset(-1);
  54. }
  55. private void OnClickRightBtn(EventContext context)
  56. {
  57. SelectOffset(1);
  58. }
  59. private void OnClickGetBtn(EventContext context)
  60. {
  61. var collectTable = collectTableRepo.Get(_curId);
  62. var starLv = 0;
  63. foreach (var id in collectTable.Param)
  64. {
  65. if (EpigraphData.Instance.TryGetEpigraphAttrByTableId(id, out var epi))
  66. {
  67. starLv += epi.StarLv;
  68. }
  69. }
  70. var rwdList = collect_rewardTableRepo.GetCollectRwdList(_curId);
  71. var canGet = false;
  72. foreach (var item in rwdList)
  73. {
  74. if (
  75. starLv > item.Unlock
  76. && !EpigraphData.Instance.GetJibaIsActive(item.CollectId, item.Level)
  77. )
  78. {
  79. canGet = true;
  80. break;
  81. }
  82. }
  83. if (canGet)
  84. {
  85. EpigraphService.Instance.RequestJibanRwdGetAll(_curId);
  86. }
  87. else
  88. {
  89. Context.ShowTips(StringDefine.PartnerJiBanNoActivatable);
  90. }
  91. }
  92. #endregion
  93. private bool _initView = false;
  94. private int _curId;
  95. private List<int> _list;
  96. private void InitView()
  97. {
  98. if (_initView)
  99. return;
  100. _initView = true;
  101. VM.List.ListType = EGListType.None;
  102. VM.RwdList.ListType = EGListType.Virtual;
  103. var tableList = collectTableRepo.GetAllEpiCollectList();
  104. var list = new List<int>();
  105. foreach (var item in tableList)
  106. {
  107. list.Add(item.Id);
  108. }
  109. _list = list;
  110. }
  111. private void UpView()
  112. {
  113. var table = collectTableRepo.Get(_curId);
  114. XGame.Framework.Assert.IsNotNull(table, $"羁绊表不存在,id:{_curId}");
  115. VM.List.BindDatas(table.Param);
  116. VM.NameLabel.text = table.Name;
  117. UpdateList();
  118. }
  119. private void UpdateList()
  120. {
  121. var list = collect_rewardTableRepo.GetCollectRwdList(_curId);
  122. VM.RwdList.BindDatas(list);
  123. }
  124. private void SelectOffset(int offset)
  125. {
  126. var index = _list.IndexOf(offset);
  127. index += offset;
  128. if (index < 0)
  129. {
  130. index += _list.Count;
  131. }
  132. else if (index >= _list.Count)
  133. {
  134. index -= _list.Count;
  135. }
  136. _curId = _list[index];
  137. UpView();
  138. }
  139. }
  140. }