RechargeActivityInfo.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ---@class RechargeActivityInfo
  2. RechargeActivityInfo = class()
  3. local this = RechargeActivityInfo
  4. this.timeLimitGiftData = {} --限时礼包
  5. function this:ctor()
  6. end
  7. function this:Reset()
  8. this.timeLimitGiftData = {}
  9. end
  10. function this:Init()
  11. self:InitData()
  12. self:RegistMessages()
  13. end
  14. function this:InitData()
  15. self:InitTimeLimitData()
  16. end
  17. function this:RegistMessages()
  18. --限时礼包
  19. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_ALL_TIME_LIMIT_GIFT,self.RES_ALL_TIME_LIMIT_GIFT,self)
  20. SL:RegisterLuaNetMsg(LuaMessageIdToClient.RES_TIME_LIMIT_GIFT,self.RES_TIME_LIMIT_GIFT,self)
  21. --
  22. end
  23. --region 限时礼包
  24. function this:InitTimeLimitData()
  25. this.timeLimitGiftData = {}
  26. self.timeLimitGift_giftCfg = {}
  27. local giftCfgs = SL:GetConfigTable("cfg_timelLimitGift_gift")
  28. for key, value in pairs(giftCfgs) do
  29. if not self.timeLimitGift_giftCfg[value.group] then
  30. self.timeLimitGift_giftCfg[value.group] = {}
  31. end
  32. self.timeLimitGift_giftCfg[value.group][value.sort] = value
  33. end
  34. end
  35. function this:RES_ALL_TIME_LIMIT_GIFT(id, message)
  36. this.timeLimitGiftData = {}
  37. if message then
  38. for i,msg in pairs(message) do
  39. self:RefreshSingleTimeLimitGiftData(msg)
  40. end
  41. end
  42. self:CalculateTimeLimitGiftEndTime()
  43. self:RefreshTimeLimitGiftUI(message.isNew)
  44. end
  45. function this:RES_TIME_LIMIT_GIFT(id, message)
  46. if not message then
  47. this.timeLimitGiftData = {}
  48. else
  49. self:RefreshSingleTimeLimitGiftData(message)
  50. end
  51. self:CalculateTimeLimitGiftEndTime()
  52. self:RefreshTimeLimitGiftUI(message.isNew)
  53. end
  54. function this:RefreshSingleTimeLimitGiftData(msg)
  55. if not msg then
  56. return
  57. end
  58. --msg: group=cfg_timelLimitGift_all 表id, endTime=结束时间, timeLimitGiftInfo={索引=cfg_timelLimit_gift 表id ...已购买的}
  59. local msgData = {}
  60. msgData.group = tonumber(msg.group)
  61. msgData.endTime = tonumber(msg.endTime)
  62. msgData.timeLimitGiftInfo = {}
  63. for i,v in pairs(msg.timeLimitGiftInfo) do
  64. msgData.timeLimitGiftInfo[i] = tonumber(v)
  65. end
  66. this.timeLimitGiftData[msgData.group] = msgData
  67. end
  68. function this:RefreshTimeLimitGiftUI(isNew)
  69. --刷新主界面按钮(显示、红点、倒计时)
  70. local mainPanel = GUI:GetUI("dev/ui/MainUI/Panel/KLUISystemTop/KLUISystemTopPanel")
  71. if mainPanel then
  72. mainPanel:RefreshSystemMenu()
  73. end
  74. --如果开着限时礼包主面板,刷新面板
  75. local TimeLimitGift = GUI:GetUI("dev/outui/Recharge/Panel/KLRechargeActivity/KLRechargeActivityPanel")
  76. if TimeLimitGift then
  77. TimeLimitGift:Refresh()
  78. elseif isNew then
  79. --else
  80. --SL:onLUAEvent(LUA_EVENT_FORGE_GROUP_PANEL_CLOSE)
  81. GUI:CloseAllUIWithoutMainUI()
  82. GUI:UIPanel_Open("dev/outui/Recharge/Panel/KLRechargeActivity/KLRechargeActivityPanel")
  83. SL.HideMainPanel()
  84. end
  85. end
  86. function this:GetMaxTimeLimitGiftEndTime()
  87. --返回最大的 没买全的 没过期的 endTime
  88. local maxEndTime = nil
  89. for group,msg in pairs(this.timeLimitGiftData) do
  90. if msg.endTime - Time.GetServerTime() > 0 and table.count(msg.timeLimitGiftInfo) < table.count(self.timeLimitGift_giftCfg[group]) then
  91. if not maxEndTime then
  92. maxEndTime = msg.endTime
  93. else
  94. if msg.endTime > maxEndTime then
  95. maxEndTime = msg.endTime
  96. end
  97. end
  98. end
  99. end
  100. if not maxEndTime then
  101. return 0
  102. end
  103. return (maxEndTime - Time.GetServerTime()) // 1000
  104. end
  105. function this:CalculateTimeLimitGiftEndTime()
  106. --返回最小的 没买全的 没过期的 endTime
  107. local minEndTime = nil
  108. local minGroup = nil
  109. for group,msg in pairs(this.timeLimitGiftData) do
  110. if msg.endTime - Time.GetServerTime() > 0 and table.count(msg.timeLimitGiftInfo) < table.count(self.timeLimitGift_giftCfg[group]) then
  111. if not minEndTime then
  112. minEndTime = msg.endTime
  113. minGroup = group
  114. else
  115. if msg.endTime < minEndTime then
  116. minEndTime = msg.endTime
  117. minGroup = group
  118. end
  119. end
  120. end
  121. end
  122. self.TimeLimitGiftEndTime = minEndTime
  123. self.TimeLimitGiftNextEndGroup = minGroup
  124. end
  125. function this:GetTimeLimitGiftEndTime()
  126. --if not self.TimeLimitGiftEndTime or (self.TimeLimitGiftEndTime - Time.GetServerTime()) <= 0 then
  127. self:CalculateTimeLimitGiftEndTime()
  128. --end
  129. return self.TimeLimitGiftEndTime,self.TimeLimitGiftNextEndGroup
  130. end
  131. function this:IsShowTimeLimitGiftBtn()
  132. for group,msg in pairs(this.timeLimitGiftData) do
  133. --有 没过期的 没购买的
  134. if msg.endTime - Time.GetServerTime() > 0 then
  135. if self.timeLimitGift_giftCfg and self.timeLimitGift_giftCfg[group] then
  136. for sort,cfg in pairs(self.timeLimitGift_giftCfg[group]) do
  137. if not table.contains(msg.timeLimitGiftInfo,cfg.id) then
  138. return true
  139. end
  140. end
  141. end
  142. end
  143. end
  144. return false
  145. end
  146. function this:IsShowTimeLimitGiftRedDot() --TODO:主界面按钮红点刷新?
  147. local res = {}
  148. local needRedPoint = false
  149. for group,msg in pairs(this.timeLimitGiftData) do
  150. --没过期的 没购买的、免费的、上一个已购买
  151. if msg.endTime - Time.GetServerTime() > 0 then
  152. if self.timeLimitGift_giftCfg and self.timeLimitGift_giftCfg[group] then
  153. for sort,cfg in pairs(self.timeLimitGift_giftCfg[group]) do
  154. if not table.contains(msg.timeLimitGiftInfo,cfg.id)
  155. and table.count(cfg.cost) == 0
  156. and self.timeLimitGift_giftCfg[group][sort-1]
  157. and table.contains(msg.timeLimitGiftInfo,self.timeLimitGift_giftCfg[group][sort-1].id)
  158. then
  159. needRedPoint = true
  160. if not res[group] then
  161. res[group] = {}
  162. end
  163. table.insert(res[group],sort)
  164. end
  165. end
  166. end
  167. end
  168. end
  169. return needRedPoint,res
  170. end
  171. --endregion 限时礼包