UILuckyEggCtr.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. local UILuckyEggCtr = class("UILuckyEggCtr", require("UICtrBase"))
  2. function UILuckyEggCtr:Init(view)
  3. self.view = view
  4. end
  5. ---@param data integer 默认进入的页面Id,参考SummonCfg配置
  6. function UILuckyEggCtr:SetData(data)
  7. self.asyncIdx = 0
  8. self.data = data
  9. if self.data and type(self.data) == "table" and self.data.actId then
  10. if not self.activityData then
  11. self.activityData = ManagerContainer.DataMgr.ActsDataMgr:GetActivityItemById(self.data.actId)
  12. end
  13. end
  14. self:InitData()
  15. end
  16. function UILuckyEggCtr:GetAsyncIdx()
  17. self.asyncIdx = self.asyncIdx + 1
  18. return self.asyncIdx
  19. end
  20. function UILuckyEggCtr:GetData()
  21. return self.data
  22. end
  23. function UILuckyEggCtr:GetActivityId()
  24. return self.data and type(self.data) == "table" and self.data.actId or nil
  25. end
  26. function UILuckyEggCtr:OnDispose()
  27. self.data = nil
  28. self.view = nil
  29. self.listIdx = nil
  30. self.selectIdx = nil
  31. self.cfgs = nil
  32. self.cfgLength = nil
  33. end
  34. function UILuckyEggCtr:InitData()
  35. local cfgs = {}
  36. local cfgSource = ManagerContainer.CfgMgr:GetLuckyEggCfg()
  37. --LogError("--------------------self.data.actId-- "..Inspect(self.data.actId))
  38. for id, cfg in pairs(cfgSource) do
  39. --LogError("----------------------"..Inspect(cfg))
  40. if cfg.ActivitiesId == self.data.actId then
  41. --LogError("----------------------"..Inspect(cfg))
  42. cfgs[#cfgs+1] = cfg
  43. end
  44. end
  45. table.sort(cfgs, function(a, b)
  46. return a.SortId < b.SortId
  47. end)
  48. local idx = nil
  49. if self.data then
  50. for i = 1, #cfgs do
  51. if cfgs[i].Id == self.data then
  52. idx = i
  53. end
  54. end
  55. end
  56. if not idx then
  57. idx = 1
  58. end
  59. self.selectIdx = idx
  60. self.listIdx = idx - 1
  61. self.cfgs = cfgs
  62. self:CheckTotalRecharge()
  63. end
  64. function UILuckyEggCtr:GetListIdx()
  65. return self.listIdx
  66. end
  67. function UILuckyEggCtr:SetListIdx(listIdx)
  68. if self.listIdx == listIdx then return false end
  69. self.listIdx = listIdx
  70. self.selectIdx = self:GetSelectIdxByListIdx(listIdx)
  71. return true
  72. end
  73. function UILuckyEggCtr:GetSelectIdxByListIdx(listIdx)
  74. return listIdx % self.cfgLength + 1
  75. end
  76. function UILuckyEggCtr:GetSelectIdx()
  77. return self.selectIdx
  78. end
  79. function UILuckyEggCtr:GetCfgByIdx(idx)
  80. return self.cfgs[idx]
  81. end
  82. function UILuckyEggCtr:GetCfgLength()
  83. return self.cfgLength
  84. end
  85. function UILuckyEggCtr:GetCfgLength_cfg()
  86. return #self.cfgs
  87. end
  88. --- 获取额外奖励进度
  89. function UILuckyEggCtr:GetLuckyEggNumByIdx(idx)
  90. local cfg = self:GetCfgByIdx(idx)
  91. return ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggNum(cfg.Id)
  92. end
  93. function UILuckyEggCtr:GetOwnResCountByItemId(cfgId)
  94. return CommonUtil.GetOwnResCountByItemId(cfgId)
  95. end
  96. function UILuckyEggCtr:CheckTotalRecharge()
  97. local payNum = ManagerContainer.PayMgr:GetTotalRecharge() or 0
  98. --- 彩蛋开放最低儲值金额
  99. local needNum = 0
  100. if #self.cfgs == 1 then
  101. needNum = 0
  102. end
  103. self.eggActive = payNum >= needNum
  104. --- 彩蛋儲值金额需要满足条件才能激活
  105. self.cfgLength = self.eggActive and #self.cfgs or #self.cfgs - 1
  106. end
  107. --- 根据当前儲值金额判断是否激活彩蛋
  108. ---@return boolean
  109. function UILuckyEggCtr:GetEggActiveByPay()
  110. if #self.cfgs == 1 then
  111. return true
  112. end
  113. return self.eggActive
  114. end
  115. function UILuckyEggCtr:GetSendLuckyEggReqErrorCode(idx)
  116. local selectIdx = self:GetSelectIdx()
  117. local cfg = self:GetCfgByIdx(selectIdx)
  118. return ManagerContainer.DataMgr.LuckyEggDataMgr:GetSendLuckyEggReqErrorCode(cfg.Id, idx)
  119. end
  120. function UILuckyEggCtr:GetActivityData()
  121. local rank_list = {}
  122. local selectIdx = self:GetSelectIdx()
  123. local cfg = self:GetCfgByIdx(selectIdx)
  124. if cfg then
  125. rank_list = ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggMsgDataByType(cfg.Type) or {}
  126. end
  127. return rank_list
  128. end
  129. function UILuckyEggCtr:ReadyData()
  130. ManagerContainer.DataMgr.LuckyEggDataMgr:ClearLuckyEggData()
  131. ManagerContainer.DataMgr.LuckyEggDataMgr:ClearRedPoint()
  132. end
  133. function UILuckyEggCtr:HasNeedShowItem()
  134. local luckyData = ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggData()
  135. if luckyData then
  136. local luckyCfgData = ManagerContainer.CfgMgr:GetLuckyEggCfgByType(luckyData.luckyType)
  137. if luckyCfgData and luckyCfgData.ShowItemType and #luckyCfgData.ShowItemType > 0 then
  138. if luckyData.rewards then
  139. for i = 1, #luckyData.rewards do
  140. local reward = luckyData.rewards[i]
  141. if reward then
  142. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(reward.cfgId)
  143. if CommonUtil.EleInTable(itemCfgData.ResType, luckyCfgData.ShowItemType) then
  144. return true
  145. end
  146. end
  147. end
  148. end
  149. end
  150. end
  151. return false
  152. end
  153. function UILuckyEggCtr:SendLuckyEggReq(summonNum)
  154. local selectIdx = self:GetSelectIdx()
  155. local cfg = self:GetCfgByIdx(selectIdx)
  156. if not ManagerContainer.DataMgr.LuckyEggDataMgr:SendLuckyEggReq(cfg.ActivitiesId,summonNum,cfg.Type) then
  157. return 100007
  158. end
  159. return 0
  160. end
  161. function UILuckyEggCtr:SendLuckyEggRecordReq()
  162. local selectIdx = self:GetSelectIdx()
  163. local cfg = self:GetCfgByIdx(selectIdx)
  164. if cfg then
  165. ManagerContainer.DataMgr.LuckyEggDataMgr:SendLuckyEggRecordReq(cfg.ActivitiesId,cfg.Type)
  166. end
  167. return 0
  168. end
  169. return UILuckyEggCtr