KLEarningsPanel.lua 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. ---@class KLOpenServerPanel:UIKmlLuaPanelBase
  2. ---@field view KLOpenServerPanelView
  3. local KLEarningsPanel = class(UIKmlLuaPanelBase)
  4. local this =KLEarningsPanel
  5. ---创建时调用一次
  6. function this:Init()
  7. self.receiveTimestamp = 0 ---点击领取时间戳
  8. self.leftTime = 0 ---未领取剩余时间秒
  9. self.gettime = 0 ---已领取时间秒
  10. SL.HideMainPanel()
  11. end
  12. ---时间的选项(单位:小时,-1为领取所有剩余三倍收益时间)
  13. function this:GetInfoData()
  14. local Info2 = {}
  15. local consumeCfg = string.split(SL:GetConfig("cfg_global",5003).value,'#')
  16. for i, v in ipairs(consumeCfg) do
  17. local num = tonumber(v)
  18. if num < 0 then num = 0 end
  19. local str ="领取".."<color=#1add1f>".."所有".."</color>".."三倍收益时间"
  20. if num > 0 then
  21. str = "领取".."<color=#1add1f>"..GUIUtil.ToNumberString(num).."小时".."</color>".."三倍收益时间"
  22. end
  23. local data = {
  24. des = str,
  25. hourtime = num
  26. }
  27. table.insert(Info2,data)
  28. end
  29. return Info2
  30. end
  31. function this:DataListItemGetFunc(realIndex)
  32. local item = GUI:UIPanel_Open("dev/outui/ThreeEarnings/Item/KLEarnings/KLEarningsItem", self.view.EarData_list, self, nil, true)
  33. if not self.earningsItems then
  34. self.earningsItems = {}
  35. end
  36. local kmlCtrl = item.view.root
  37. self.earningsItems[kmlCtrl] = item
  38. return kmlCtrl
  39. end
  40. function this:DataListItemInitFunc(realIndex, kmlcontrol)
  41. end
  42. function this:DataListItemUpdateFunc(realIndex, kmlcontrol)
  43. local item = self.earningsItems[kmlcontrol]
  44. local luaIndex = realIndex + 1
  45. local info = self.Info[luaIndex]
  46. local minute = math.modf(self.leftTime / 60)
  47. item:UpdateUI(info,minute)
  48. end
  49. ---创建或者刷新界面数据时调用
  50. function this:Refresh()
  51. local isfirstbug = InfoManager.monthCardInfo.IsGetMonthCard --是否首次购买月卡
  52. local monthallTime = InfoManager.monthCardInfo.MonthCardTimeTotal-SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) --月卡剩余时间
  53. local cardHour = tonumber(SL:GetConfig("cfg_global",5004).value)
  54. self.maxNum = tonumber(SL:GetConfig("cfg_global",5001).value) --最多可以继承多少时间(单位:小时)
  55. SL:SendLuaNetMsg(LuaMessageIdToSever.TRIPLE_INCOME_PANEL) --请求三倍收益信息
  56. if not InfoManager.monthCardInfo.IsEarningFirst then
  57. if monthallTime < 24 then
  58. self:LoginFirstTipClick()
  59. InfoManager.monthCardInfo.IsEarningFirst = true
  60. end
  61. end
  62. if not isfirstbug then
  63. GUI:Text_setString(self.view.time_tip, "首充购买月卡赠送"..cardHour.."小时三倍收益时间")
  64. end
  65. GUI:setVisible(self.view.time_tip,not isfirstbug)
  66. GUI:Text_setString(self.view.time_text, "剩余三倍收益时间")
  67. ---领取时间列表数据
  68. self.Info = self:GetInfoData()
  69. GUI:DataListInitData(self.view.EarData_list, function()
  70. return table.count(self.Info)
  71. end, function(realIndex)
  72. return self:DataListItemGetFunc(realIndex)
  73. end, function(realIndex, kmlcontrol)
  74. return self:DataListItemInitFunc(realIndex, kmlcontrol)
  75. end, function(realIndex, kmlcontrol)
  76. return self:DataListItemUpdateFunc(realIndex, kmlcontrol)
  77. end)
  78. ---归还状态,倒计时
  79. self:SetChillingState()
  80. end
  81. ---刷新两个时间
  82. function this:RefreshTimeText()
  83. if self.leftTime == 0 then
  84. GUI:Text_setString(self.view.time_show, "00f00f00")
  85. else
  86. local strtime = GUIUtil.FormatTimeHMAndDW(self.leftTime)
  87. --local strtime = GUIUtil.FormatTimeHM(self.leftTime)
  88. GUI:Text_setString(self.view.time_show, strtime)
  89. end
  90. if self.gettime <= 0 then
  91. if self.gettimer then
  92. SL:UnSchedule(self.gettimer)
  93. self.gettimer = nil
  94. end
  95. GUI:Text_setString(self.view.des_time, "00:00:00")
  96. else
  97. self:SetGetTimeSchedule() --倒计时
  98. end
  99. self:SetBtnGivebackState()
  100. GUI:DataListUpdateData(self.view.EarData_list)
  101. end
  102. ---注册UI事件和服务器消息
  103. function this:RegistEvents()
  104. GUI:AddOnClickEvent(self.view.CloseButton,self,self.CloseBtnClick)
  105. GUI:AddOnClickEvent(self.view.btnTip,self,self.btnTipClick)
  106. GUI:AddOnClickEvent(self.view.btnGiveback,self,self.btnGivebackClick)
  107. SL:RegisterLuaNetMsg(LuaMessageIdToClient.TRIPLE_INCOME_INFO, self.ResTripleIncomeInfo, self)
  108. end
  109. ---响应三倍收益信息
  110. function this:ResTripleIncomeInfo(id,data)
  111. if data then
  112. self.receiveTimestamp = data.receiveTimestamp
  113. self.leftTime = data.remainSec
  114. self.gettime = data.effectSec
  115. end
  116. self:RefreshCountdown() ---刷新冷却
  117. self:RefreshTimeText() ---刷新时间
  118. end
  119. ---点击领取,刷新冷却时间
  120. function this:RefreshCountdown()
  121. local chiltime = tonumber(SL:GetConfig("cfg_global",5002).value) --分钟
  122. local endTimestamp = self.receiveTimestamp + chiltime*60*1000
  123. self.countdown = (endTimestamp - Time.GetServerTime()) /1000
  124. self:SetChillingState()
  125. end
  126. ---关闭
  127. function this:CloseBtnClick()
  128. GUI:UIPanel_Close("dev/outui/ThreeEarnings/Panel/KLEarnings/KLEarningsPanel")
  129. GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionToggleList/KLUnionToggleListPanel")
  130. SL.ShowMainPanel()
  131. end
  132. ---帮助提示
  133. function this:btnTipClick()
  134. local helpCfg = SL:FindConfigs("cfg_rule_text","id",5)
  135. if helpCfg and helpCfg[1] then
  136. SL:CommonStrTipsMessage({title = helpCfg[1].menutxt,str = helpCfg[1].location})
  137. end
  138. end
  139. ---登陆后首次打开UI 且 月卡时间小于24小时
  140. function this:LoginFirstTipClick()
  141. SL:CommonTipsMessage({stringTblID=224,
  142. ui = self,
  143. sureBtnText = "确定",
  144. cancelBtnText = "取消",
  145. callback = function()
  146. --跳转月卡界面
  147. GUI:UIPanel_Close("dev/outui/ThreeEarnings/Panel/KLEarnings/KLEarningsPanel")
  148. GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel",_,_,{JumpType = 1})
  149. end,
  150. })
  151. end
  152. ---归还按钮
  153. function this:btnGivebackClick()
  154. if not self.ischilling and self.gettime > 0 then
  155. SL:SendLuaNetMsg(LuaMessageIdToSever.TRIPLE_INCOME_RETURN)
  156. end
  157. end
  158. ---领取时间倒计时
  159. function this:SetGetTimeSchedule()
  160. local getcountdown = self.gettime
  161. self.gettimer = SL:Schedule( self.gettimer,0,1,getcountdown,function()
  162. getcountdown =getcountdown - 1
  163. if getcountdown > 0 then
  164. GUI:Text_setString(self.view.des_time,GUIUtil.FormatTimeHMS(getcountdown))
  165. else
  166. GUI:Text_setString(self.view.des_time, "00:00:00")
  167. end
  168. end)
  169. end
  170. ---冷却倒计时
  171. function this:SetChillingState()
  172. if self.countdown and self.countdown > 0 then
  173. self.timer = SL:Schedule( self.timer,0,1,self.countdown,function()
  174. self.countdown = self.countdown - 1
  175. if self.countdown > 0 then
  176. self.ischilling = true
  177. self:SetBtnGivebackState()
  178. GUI:Text_setString(self.view.desGiveback,"归还冷却时间:"..GUIUtil.FormatTimeMS(self.countdown))
  179. else
  180. self.ischilling = false
  181. self:SetBtnGivebackState()
  182. GUI:Text_setString(self.view.desGiveback,"")
  183. end
  184. end)
  185. else
  186. self.ischilling = false
  187. self:SetBtnGivebackState()
  188. GUI:Text_setString(self.view.desGiveback,"")
  189. end
  190. end
  191. ---归还按钮置灰: 已领取三倍收益时间为0时 ; 处于归还冷却时间内
  192. function this:SetBtnGivebackState()
  193. GUI:Button_setGrey(self.view.btnGiveback, self.ischilling or self.gettime==0)
  194. end
  195. function this:Close()
  196. SL:ShowMainPanel()
  197. if self.timer then
  198. SL:UnSchedule(self.timer)
  199. self.timer = nil
  200. end
  201. if self.gettimer then
  202. SL:UnSchedule(self.gettimer)
  203. self.gettimer = nil
  204. end
  205. end
  206. return this