123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- ---@class KLDailyAddRechargePanel:UIKmlLuaPanelBase
- ---@field view KLDailyAddRechargePanelView
- local KLDailyAddRechargePanel = class(UIKmlLuaPanelBase)
- local this =KLDailyAddRechargePanel
- function this:AsyncLoadUI()
- end
- ---创建时调用一次
- function this:Init()
- self.showList = {}
- GUI:DataListInitData(self.view.showItemInfoList, function()
- return self:GetAllShowItems()
- end,function()
- end,function()
- end, function(realIndex)
- self:ItemUpdateFun(realIndex)
- end)
- end
- function this:GetAllShowItems()
- return table.count(self.showList)
- end
- function this:ItemUpdateFun(realIndex)
- local data = self.showList[realIndex+1]
- local txt_taskDes = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_taskDes')
- local txt_process = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_process')
- local showItems = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'showItems')
- local btn_get = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'btn_get')
- local btn_nav = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'btn_nav')
- local txt_get = GUI:GetChildControl(self.view.showItemInfoList, realIndex, 'txt_get')
- --任务描述
- GUI:Text_setString(txt_taskDes, data.dailyCfgData.taskDes)
- --任务进度
- local todayMoney = InfoManager.dailyAddRechargeInfo.roleTodayAllMoney
- local color = todayMoney >= data.dailyCfgData.goal and EColor[EGradColor.green] or EColor[EGradColor.red]
- local str = string.format("<color=%s>%s/%s</color>", color, todayMoney, data.dailyCfgData.goal)
- GUI:Text_setString(txt_process, str)
- --展示奖励
- local showRewards = data.dailyCfgData.reward
- GUI:HideAllChilds(showItems)
- for i = 1, table.count(showRewards) do
- local itemId = showRewards[i][1]
- local item = GUI:Item_Create(showItems, {
- width = "70",
- height = "70",
- itemid = itemId,
- mfixsize = "80,80",
- tips = "1",
- itemcustomcount = showRewards[i][2]
- })
- GUI:AddOnClickEvent(item, self, function()
- SL:OpenTips(nil, itemId)
- end)
- end
- --任务状态
- GUI:SetActive(btn_get,false)
- GUI:SetActive(btn_nav,false)
- GUI:SetActive(txt_get,false)
- if data.giftState == E_RechargeState.CanGet then
- GUI:SetActive(btn_get,true)
- GUI:AddOnClickEvent(btn_get,self,self.GetOnClick,{cfgId = data.dailyCfgData.id})
- elseif data.giftState == E_RechargeState.NotComplete then
- GUI:SetActive(btn_nav,true)
- GUI:AddOnClickEvent(btn_nav,self,self.GoOnClick)
- elseif data.giftState == E_RechargeState.AlreadyGet then
- GUI:SetActive(txt_get,true)
- end
- end
- function this:GetOnClick(_,data)
- if data.cfgId then
- --请求领奖
- SL:SendLuaNetMsg(LuaMessageIdToSever.REQ_RECHARGE_ACTION, {type = 11, action = "reward" ,id = data.cfgId})
- end
- end
- function this:GoOnClick()
- GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel")
- -- --跳转到每日礼包页签
- -- local navId = SL:GetConfig("cfg_global",20001).value
- -- GUI:UIPanel_Open("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel",_,_,{mainRechargeId = navId})
-
- --跳转到充值界面
- GUI:UIPanel_Open("dev/outui/ShopMain/Panel/KLShopMain/KLShopMainPanel",nil,nil,{2})
- end
- ---注册UI事件和服务器消息
- function this:RegistEvents()
- SL:RegisterLUAEvent(LUA_DAILYADD_RECHARGE_CHANGE, self.RefreshPanelData, self)
- end
- ---界面显示时调用一次
- function this:Show()
- end
- ---创建或者刷新界面数据时调用
- function this:Refresh()
- self:RefreshPanelData()
- end
- function this:ClearDJHFunc()
- if self.sectimer then
- SL:UnSchedule(self.sectimer)
- self.sectimer = nil
- end
- end
- function this:ShowDJHFunc()
- self:ClearDJHFunc()
- local time = math.floor(Time.GetServerTime()/1000) + 86400 --秒
- local endTime = self:GetTodayZeroTime(time) --今日零点时间
- local nowTime = SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) --当前时间
- local countdown = endTime - nowTime/1000
- countdown = math.floor(countdown) --秒
- self.sectimer = SL:Schedule(self.sectimer, 0, 1, countdown, function()
- countdown = countdown - 1
- if countdown > 0 then
- GUI:SetActive(self.view.txt_showTime,true)
- GUI:Text_setString(self.view.txt_showTime, GUIUtil.FormatTimeDHM(countdown))
- else
- GUI:SetActive(self.view.txt_showTime,false)
- self:ClearDJHFunc()
- GUI:UIPanel_Close("dev/outui/MainRecharge/Panel/KLMainRecharge/KLMainRechargePanel")
- end
- end)
- end
- function this:RefreshPanelData()
- --倒计时
- self:ShowDJHFunc()
- self.showList = {}
- self.showList = InfoManager.dailyAddRechargeInfo.dailyAddRechargeDataTbl
- table.sort(self.showList,function(a,b)
- if a.giftState == b.giftState then
- return a.dailyCfgData.goal < b.dailyCfgData.goal
- else
- return a.giftState < b.giftState
- end
- end)
- GUI:DataListUpdateData(self.view.showItemInfoList)
- end
- --获取今日0点时间戳
- function this:GetTodayZeroTime(time)
- return time - (time + (8 * 3600)) % (24 * 3600) --8 * 3600东八区 时区时间差
- end
- function this:Close()
- self:ClearDJHFunc()
- end
- return this
|