UILuckyEggCtr.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. ManagerContainer.DataMgr.LuckyEggDataMgr.curActID = self.data.actId
  38. --LogError("--------------------self.data.actId-- "..Inspect(self.data.actId))
  39. for id, cfg in pairs(cfgSource) do
  40. --LogError("----------------------"..Inspect(cfg))
  41. if cfg.ActivitiesId == self.data.actId then
  42. --LogError("----------------------"..Inspect(cfg))
  43. cfgs[#cfgs+1] = cfg
  44. end
  45. end
  46. table.sort(cfgs, function(a, b)
  47. return a.SortId < b.SortId
  48. end)
  49. local idx = nil
  50. if self.data then
  51. for i = 1, #cfgs do
  52. if cfgs[i].Id == self.data then
  53. idx = i
  54. end
  55. end
  56. end
  57. if not idx then
  58. idx = 1
  59. end
  60. self.selectIdx = idx
  61. self.listIdx = idx - 1
  62. self.cfgs = cfgs
  63. self:CheckTotalRecharge()
  64. end
  65. function UILuckyEggCtr:GetListIdx()
  66. return self.listIdx
  67. end
  68. function UILuckyEggCtr:SetListIdx(listIdx)
  69. if self.listIdx == listIdx then return false end
  70. self.listIdx = listIdx
  71. self.selectIdx = self:GetSelectIdxByListIdx(listIdx)
  72. return true
  73. end
  74. function UILuckyEggCtr:GetSelectIdxByListIdx(listIdx)
  75. return listIdx % self.cfgLength + 1
  76. end
  77. function UILuckyEggCtr:GetSelectIdx()
  78. return self.selectIdx
  79. end
  80. function UILuckyEggCtr:GetCfgByIdx(idx)
  81. return self.cfgs[idx]
  82. end
  83. function UILuckyEggCtr:GetCfgLength()
  84. return self.cfgLength
  85. end
  86. function UILuckyEggCtr:GetCfgLength_cfg()
  87. return #self.cfgs
  88. end
  89. --- 获取额外奖励进度
  90. function UILuckyEggCtr:GetLuckyEggNumByIdx(idx)
  91. local cfg = self:GetCfgByIdx(idx)
  92. return ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggNum(cfg.Id)
  93. end
  94. function UILuckyEggCtr:GetOwnResCountByItemId(cfgId)
  95. return CommonUtil.GetOwnResCountByItemId(cfgId)
  96. end
  97. function UILuckyEggCtr:CheckTotalRecharge()
  98. local payNum = ManagerContainer.PayMgr:GetTotalRecharge() or 0
  99. --- 彩蛋开放最低儲值金额
  100. local needNum = 0
  101. if #self.cfgs == 1 then
  102. needNum = 0
  103. end
  104. self.eggActive = payNum >= needNum
  105. --- 彩蛋儲值金额需要满足条件才能激活
  106. self.cfgLength = self.eggActive and #self.cfgs or #self.cfgs - 1
  107. end
  108. --- 根据当前儲值金额判断是否激活彩蛋
  109. ---@return boolean
  110. function UILuckyEggCtr:GetEggActiveByPay()
  111. if #self.cfgs == 1 then
  112. return true
  113. end
  114. return self.eggActive
  115. end
  116. function UILuckyEggCtr:GetSendLuckyEggReqErrorCode(idx)
  117. local selectIdx = self:GetSelectIdx()
  118. local cfg = self:GetCfgByIdx(selectIdx)
  119. return ManagerContainer.DataMgr.LuckyEggDataMgr:GetSendLuckyEggReqErrorCode(cfg.Id, idx)
  120. end
  121. function UILuckyEggCtr:GetActivityData()
  122. local rank_list = {}
  123. local selectIdx = self:GetSelectIdx()
  124. local cfg = self:GetCfgByIdx(selectIdx)
  125. if cfg then
  126. rank_list = ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggMsgDataByType(cfg.Type) or {}
  127. end
  128. return rank_list
  129. end
  130. function UILuckyEggCtr:ReadyData()
  131. ManagerContainer.DataMgr.LuckyEggDataMgr:ClearLuckyEggData()
  132. ManagerContainer.DataMgr.LuckyEggDataMgr:ClearRedPoint()
  133. end
  134. function UILuckyEggCtr:HasNeedShowItem()
  135. local luckyData = ManagerContainer.DataMgr.LuckyEggDataMgr:GetLuckyEggData()
  136. if luckyData then
  137. local luckyCfgData = ManagerContainer.CfgMgr:GetLuckyEggCfgByTypeAndActid(luckyData.luckyType,self.data.actId)
  138. if luckyCfgData and luckyCfgData.ShowItemType and #luckyCfgData.ShowItemType > 0 then
  139. if luckyData.rewards then
  140. for i = 1, #luckyData.rewards do
  141. local reward = luckyData.rewards[i]
  142. if reward then
  143. local itemCfgData = ManagerContainer.CfgMgr:GetItemById(reward.cfgId)
  144. if CommonUtil.EleInTable(itemCfgData.ResType, luckyCfgData.ShowItemType) then
  145. return true
  146. end
  147. end
  148. end
  149. end
  150. end
  151. end
  152. return false
  153. end
  154. function UILuckyEggCtr:SendLuckyEggReq(summonNum)
  155. local selectIdx = self:GetSelectIdx()
  156. local cfg = self:GetCfgByIdx(selectIdx)
  157. if not ManagerContainer.DataMgr.LuckyEggDataMgr:SendLuckyEggReq(cfg.ActivitiesId,summonNum,cfg.Type) then
  158. return 100007
  159. end
  160. return 0
  161. end
  162. function UILuckyEggCtr:SendLuckyEggRecordReq()
  163. local selectIdx = self:GetSelectIdx()
  164. local cfg = self:GetCfgByIdx(selectIdx)
  165. if cfg then
  166. ManagerContainer.DataMgr.LuckyEggDataMgr:SendLuckyEggRecordReq(cfg.ActivitiesId,cfg.Type)
  167. end
  168. return 0
  169. end
  170. return UILuckyEggCtr