PartnerPartnerBookDetailPanelCtrl.cs 4.4 KB

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