123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- ---@class KLOpenServerPanel:UIKmlLuaPanelBase
- ---@field view KLOpenServerPanelView
- local KLEarningsPanel = class(UIKmlLuaPanelBase)
- local this =KLEarningsPanel
- ---创建时调用一次
- function this:Init()
- self.receiveTimestamp = 0 ---点击领取时间戳
- self.leftTime = 0 ---未领取剩余时间秒
- self.gettime = 0 ---已领取时间秒
- SL.HideMainPanel()
- end
- ---时间的选项(单位:小时,-1为领取所有剩余三倍收益时间)
- function this:GetInfoData()
- local Info2 = {}
- local consumeCfg = string.split(SL:GetConfig("cfg_global",5003).value,'#')
- for i, v in ipairs(consumeCfg) do
- local num = tonumber(v)
- if num < 0 then num = 0 end
- local str ="领取".."<color=#1add1f>".."所有".."</color>".."三倍收益时间"
- if num > 0 then
- str = "领取".."<color=#1add1f>"..GUIUtil.ToNumberString(num).."小时".."</color>".."三倍收益时间"
- end
- local data = {
- des = str,
- hourtime = num
- }
- table.insert(Info2,data)
- end
- return Info2
- end
- function this:DataListItemGetFunc(realIndex)
- local item = GUI:UIPanel_Open("dev/outui/ThreeEarnings/Item/KLEarnings/KLEarningsItem", self.view.EarData_list, self, nil, true)
- if not self.earningsItems then
- self.earningsItems = {}
- end
-
- local kmlCtrl = item.view.root
- self.earningsItems[kmlCtrl] = item
- return kmlCtrl
- end
- function this:DataListItemInitFunc(realIndex, kmlcontrol)
- end
- function this:DataListItemUpdateFunc(realIndex, kmlcontrol)
- local item = self.earningsItems[kmlcontrol]
- local luaIndex = realIndex + 1
- local info = self.Info[luaIndex]
- local minute = math.modf(self.leftTime / 60)
- item:UpdateUI(info,minute)
- end
- ---创建或者刷新界面数据时调用
- function this:Refresh()
- local isfirstbug = InfoManager.monthCardInfo.IsGetMonthCard --是否首次购买月卡
- local monthallTime = InfoManager.monthCardInfo.MonthCardTimeTotal-SL:GetMetaValue(EMetaVarGetKey.SERVER_TIME) --月卡剩余时间
- local cardHour = tonumber(SL:GetConfig("cfg_global",5004).value)
- self.maxNum = tonumber(SL:GetConfig("cfg_global",5001).value) --最多可以继承多少时间(单位:小时)
- SL:SendLuaNetMsg(LuaMessageIdToSever.TRIPLE_INCOME_PANEL) --请求三倍收益信息
- if not InfoManager.monthCardInfo.IsEarningFirst then
- if monthallTime < 24 then
- self:LoginFirstTipClick()
- InfoManager.monthCardInfo.IsEarningFirst = true
- end
- end
- if not isfirstbug then
- GUI:Text_setString(self.view.time_tip, "首充购买月卡赠送"..cardHour.."小时三倍收益时间")
- end
- GUI:setVisible(self.view.time_tip,not isfirstbug)
- GUI:Text_setString(self.view.time_text, "剩余三倍收益时间")
- ---领取时间列表数据
- self.Info = self:GetInfoData()
- GUI:DataListInitData(self.view.EarData_list, function()
- return table.count(self.Info)
- end, function(realIndex)
- return self:DataListItemGetFunc(realIndex)
- end, function(realIndex, kmlcontrol)
- return self:DataListItemInitFunc(realIndex, kmlcontrol)
- end, function(realIndex, kmlcontrol)
- return self:DataListItemUpdateFunc(realIndex, kmlcontrol)
- end)
- ---归还状态,倒计时
- self:SetChillingState()
- end
- ---刷新两个时间
- function this:RefreshTimeText()
- if self.leftTime == 0 then
- GUI:Text_setString(self.view.time_show, "00f00f00")
- else
- local strtime = GUIUtil.FormatTimeHMAndDW(self.leftTime)
- --local strtime = GUIUtil.FormatTimeHM(self.leftTime)
- GUI:Text_setString(self.view.time_show, strtime)
- end
- if self.gettime <= 0 then
- if self.gettimer then
- SL:UnSchedule(self.gettimer)
- self.gettimer = nil
- end
- GUI:Text_setString(self.view.des_time, "00:00:00")
- else
- self:SetGetTimeSchedule() --倒计时
- end
- self:SetBtnGivebackState()
- GUI:DataListUpdateData(self.view.EarData_list)
- end
- ---注册UI事件和服务器消息
- function this:RegistEvents()
- GUI:AddOnClickEvent(self.view.CloseButton,self,self.CloseBtnClick)
- GUI:AddOnClickEvent(self.view.btnTip,self,self.btnTipClick)
- GUI:AddOnClickEvent(self.view.btnGiveback,self,self.btnGivebackClick)
- SL:RegisterLuaNetMsg(LuaMessageIdToClient.TRIPLE_INCOME_INFO, self.ResTripleIncomeInfo, self)
- end
- ---响应三倍收益信息
- function this:ResTripleIncomeInfo(id,data)
- if data then
- self.receiveTimestamp = data.receiveTimestamp
- self.leftTime = data.remainSec
- self.gettime = data.effectSec
- end
- self:RefreshCountdown() ---刷新冷却
- self:RefreshTimeText() ---刷新时间
- end
- ---点击领取,刷新冷却时间
- function this:RefreshCountdown()
- local chiltime = tonumber(SL:GetConfig("cfg_global",5002).value) --分钟
- local endTimestamp = self.receiveTimestamp + chiltime*60*1000
- self.countdown = (endTimestamp - Time.GetServerTime()) /1000
- self:SetChillingState()
- end
- ---关闭
- function this:CloseBtnClick()
- GUI:UIPanel_Close("dev/outui/ThreeEarnings/Panel/KLEarnings/KLEarningsPanel")
- GUI:UIPanel_Close("dev/ui/Union/Panel/KLUnionToggleList/KLUnionToggleListPanel")
- SL.ShowMainPanel()
- end
- ---帮助提示
- function this:btnTipClick()
- local helpCfg = SL:FindConfigs("cfg_rule_text","id",5)
- if helpCfg and helpCfg[1] then
- SL:CommonStrTipsMessage({title = helpCfg[1].menutxt,str = helpCfg[1].location})
- end
- end
- ---登陆后首次打开UI 且 月卡时间小于24小时
- function this:LoginFirstTipClick()
- SL:CommonTipsMessage({stringTblID=224,
- ui = self,
- sureBtnText = "确定",
- cancelBtnText = "取消",
- callback = function()
- --跳转月卡界面
- GUI:UIPanel_Close("dev/outui/ThreeEarnings/Panel/KLEarnings/KLEarningsPanel")
- GUI:UIPanel_Open("dev/outui/MonthCard/Panel/KLUIMonthCardMain/KLUIMonthCardMainPanel",_,_,{JumpType = 1})
- end,
- })
- end
- ---归还按钮
- function this:btnGivebackClick()
- if not self.ischilling and self.gettime > 0 then
- SL:SendLuaNetMsg(LuaMessageIdToSever.TRIPLE_INCOME_RETURN)
- end
- end
- ---领取时间倒计时
- function this:SetGetTimeSchedule()
- local getcountdown = self.gettime
- self.gettimer = SL:Schedule( self.gettimer,0,1,getcountdown,function()
- getcountdown =getcountdown - 1
- if getcountdown > 0 then
- GUI:Text_setString(self.view.des_time,GUIUtil.FormatTimeHMS(getcountdown))
- else
- GUI:Text_setString(self.view.des_time, "00:00:00")
- end
- end)
- end
- ---冷却倒计时
- function this:SetChillingState()
- if self.countdown and self.countdown > 0 then
- self.timer = SL:Schedule( self.timer,0,1,self.countdown,function()
- self.countdown = self.countdown - 1
- if self.countdown > 0 then
- self.ischilling = true
- self:SetBtnGivebackState()
- GUI:Text_setString(self.view.desGiveback,"归还冷却时间:"..GUIUtil.FormatTimeMS(self.countdown))
- else
- self.ischilling = false
- self:SetBtnGivebackState()
- GUI:Text_setString(self.view.desGiveback,"")
- end
- end)
- else
- self.ischilling = false
- self:SetBtnGivebackState()
- GUI:Text_setString(self.view.desGiveback,"")
- end
- end
- ---归还按钮置灰: 已领取三倍收益时间为0时 ; 处于归还冷却时间内
- function this:SetBtnGivebackState()
- GUI:Button_setGrey(self.view.btnGiveback, self.ischilling or self.gettime==0)
- end
- function this:Close()
- SL:ShowMainPanel()
- if self.timer then
- SL:UnSchedule(self.timer)
- self.timer = nil
- end
- if self.gettimer then
- SL:UnSchedule(self.gettimer)
- self.gettimer = nil
- end
- end
- return this
|