KLDailyAddRechargePanel.lua 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. ---@class KLDailyAddRechargePanel:UIKmlLuaPanelBase
  2. ---@field view KLDailyAddRechargePanelView
  3. local KLDailyAddRechargePanel = class(UIKmlLuaPanelBase)
  4. local this =KLDailyAddRechargePanel
  5. function this:AsyncLoadUI()
  6. end
  7. ---创建时调用一次
  8. function this:Init()
  9. self.showList = {}
  10. GUI:DataListInitData(self.view.showItemInfoList, function()
  11. return self:GetAllShowItems()
  12. end,function()
  13. end,function()
  14. end, function(realIndex)
  15. self:ItemUpdateFun(realIndex)
  16. end)
  17. end
  18. function this:GetAllShowItems()
  19. return table.count(self.showList)
  20. end
  21. function this:ItemUpdateFun(realIndex)
  22. local data = self.showList[realIndex+1]
  23. local txt_taskDes = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_taskDes')
  24. local txt_process = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_process')
  25. local showItems = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'showItems')
  26. local btn_get = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'btn_get')
  27. local btn_nav = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'btn_nav')
  28. local txt_get = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_get')
  29. --任务描述
  30. GUI:Text_setString(txt_taskDes, data.dailyCfgData.taskDes)
  31. --任务进度
  32. local todayMoney = InfoManager.dailyAddRechargeInfo.roleTodayAllMoney
  33. local color = todayMoney >= data.dailyCfgData.goal and EColor[EGradColor.green] or EColor[EGradColor.red]
  34. local str = string.format("<color=%s>%s/%s</color>", color, todayMoney, data.dailyCfgData.goal)
  35. GUI:Text_setString(txt_process, str)
  36. --展示奖励
  37. local showRewards = data.dailyCfgData.reward
  38. GUI:HideAllChilds(showItems)
  39. for i = 1, table.count(showRewards) do
  40. local itemId = showRewards[i][1]
  41. local item = GUI:Item_Create(showItems, {
  42. width = "70",
  43. height = "70",
  44. itemid = itemId,
  45. mfixsize = "80,80",
  46. tips = "1",
  47. itemcustomcount = showRewards[i][2]
  48. })
  49. GUI:AddOnClickEvent(item, self, function()
  50. SL:OpenTips(nil, itemId)
  51. end)
  52. end
  53. --任务状态
  54. GUI:SetActive(btn_get,false)
  55. GUI:SetActive(btn_nav,false)
  56. GUI:SetActive(txt_get,false)
  57. if data.giftState == E_RechargeState.CanGet then
  58. GUI:SetActive(btn_get,true)
  59. GUI:AddOnClickEvent(btn_get,self,self.GetOnClick,{cfgId = data.dailyCfgData.id})
  60. elseif data.giftState == E_RechargeState.NotComplete then
  61. GUI:SetActive(btn_nav,true)
  62. GUI:AddOnClickEvent(btn_nav,self,self.GoOnClick)
  63. elseif data.giftState == E_RechargeState.AlreadyGet then
  64. GUI:SetActive(txt_get,true)
  65. end
  66. end
  67. function this:GetOnClick(_,data)
  68. if data.cfgId then
  69. --请求领奖
  70. SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE_ACTION, {type = 11, action = "reward" ,id = data.cfgId})
  71. end
  72. end
  73. function this:GoOnClick()
  74. GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel")
  75. -- --跳转到每日礼包页签
  76. -- local navId = SL:GetConfig("cfg_global",20001).value
  77. -- GUI:UIPanel_Open("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel",_,_,{mainRechargeId = navId})
  78. --跳转到充值界面
  79. GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel",nil,nil,{2})
  80. end
  81. ---注册UI事件和服务器消息
  82. function this:RegistEvents()
  83. SL:RegisterLUAEvent(LUA_DAILYADD_RECHARGE_CHANGE, self.RefreshPanelData, self)
  84. end
  85. ---界面显示时调用一次
  86. function this:Show()
  87. end
  88. ---创建或者刷新界面数据时调用
  89. function this:Refresh()
  90. self:RefreshPanelData()
  91. end
  92. function this:ClearDJHFunc()
  93. if self.sectimer then
  94. SL:UnSchedule(self.sectimer)
  95. self.sectimer = nil
  96. end
  97. end
  98. function this:ShowDJHFunc()
  99. self:ClearDJHFunc()
  100. local time = math.floor(Time.GetServerTime()/1000) + 86400 --秒
  101. local endTime = self:GetTodayZeroTime(time) --今日零点时间
  102. local nowTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) --当前时间
  103. local countdown = endTime - nowTime/1000
  104. countdown = math.floor(countdown) --秒
  105. self.sectimer = SL:Schedule(self.sectimer, 0, 1, countdown, function()
  106. countdown = countdown - 1
  107. if countdown > 0 then
  108. GUI:SetActive(self.view.txt_showTime,true)
  109. GUI:Text_setString(self.view.txt_showTime, GUIUtil.FormatTimeDHM(countdown))
  110. else
  111. GUI:SetActive(self.view.txt_showTime,false)
  112. self:ClearDJHFunc()
  113. GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel")
  114. end
  115. end)
  116. end
  117. function this:RefreshPanelData()
  118. --倒计时
  119. self:ShowDJHFunc()
  120. self.showList = {}
  121. self.showList = InfoManager.dailyAddRechargeInfo.dailyAddRechargeDataTbl
  122. table.sort(self.showList,function(a,b)
  123. if a.giftState == b.giftState then
  124. return a.dailyCfgData.goal < b.dailyCfgData.goal
  125. else
  126. return a.giftState < b.giftState
  127. end
  128. end)
  129. GUI:DataListUpdateData(self.view.showItemInfoList)
  130. end
  131. --获取今日0点时间戳
  132. function this:GetTodayZeroTime(time)
  133. return time - (time + (8 * 3600)) % (24 * 3600) --8 * 3600东八区 时区时间差
  134. end
  135. function this:Close()
  136. self:ClearDJHFunc()
  137. end
  138. return this