AdvertisementView = AdvertisementView or BaseClass(BaseView)
|
|
local AdvertisementView = AdvertisementView
|
|
|
|
function AdvertisementView:__init()
|
|
self.base_file = "advertisement"
|
|
self.layout_file = "AdvertisementView"
|
|
self.layer_name = "Activity"
|
|
self.destroy_imm = true
|
|
self.use_background = true
|
|
self.hide_maincancas = true --全屏界面需要放开隐藏主UI
|
|
self.change_scene_close = false
|
|
self.append_to_ctl_queue = false --是否要添加进界面堆栈
|
|
self.need_show_money = false --是否要显示顶部的金钱栏
|
|
self.ad_type = ad_type
|
|
|
|
self.model = AdvertisementModel:getInstance()
|
|
|
|
self.load_callback = function ()
|
|
self:LoadSuccess()
|
|
self:AddEvent()
|
|
end
|
|
self.open_callback = function ( )
|
|
self:OpenSuccess()
|
|
end
|
|
self.switch_callback = function(index)
|
|
self:SwitchTab(index)
|
|
end
|
|
self.destroy_callback = function ( )
|
|
self:DestroySuccess()
|
|
end
|
|
end
|
|
|
|
function AdvertisementView:Open( sub_type )
|
|
self.data = self.model:GetAdvertisementData(sub_type)
|
|
self.sub_type = sub_type
|
|
BaseView.Open(self)
|
|
end
|
|
|
|
function AdvertisementView:LoadSuccess()
|
|
local nodes = {
|
|
"goBtn:obj:img", "closeTipTxt:obj:txt", "goBtn/goTxt:obj:txt", "bg:obj:raw", "closeBtn:obj",
|
|
-- 不再toggle
|
|
"Toggle:obj", "Toggle/tipTxt:obj:txt", "Toggle/toggleBtn:obj", "Toggle/checkbox:obj",
|
|
}
|
|
self:GetChildren(nodes)
|
|
self:UpdateBaseView( )
|
|
end
|
|
|
|
function AdvertisementView:UpdateBaseView( )
|
|
self.goTxt_txt.text = "前往获取"
|
|
self.closeTipTxt_txt.text = ""
|
|
self.closeBtn_obj:SetActive(true) -- 默认有关闭
|
|
self.tipTxt_txt.text = "今日登陆不再提示"
|
|
self.today_not_show = false
|
|
self.checkbox_obj:SetActive(false)
|
|
end
|
|
|
|
function AdvertisementView:AddEvent()
|
|
local on_click = function ( click_obj )
|
|
if self.goBtn_obj == click_obj then
|
|
if self.data and self.data.ad_tpye == AdvertisementModel.AD_TYPE.LOGIN then
|
|
OpenFun.Open(self.data.module_data[1], self.data.module_data[2])
|
|
self:Close()
|
|
end
|
|
elseif self.closeBtn_obj == click_obj then
|
|
self:Close()
|
|
elseif self.toggleBtn_obj == click_obj then
|
|
self:SetToggle( not self.today_not_show )
|
|
end
|
|
end
|
|
AddClickEvent(self.goBtn_obj, on_click)
|
|
AddClickEvent(self.closeBtn_obj, on_click)
|
|
AddClickEvent(self.toggleBtn_obj, on_click)
|
|
end
|
|
|
|
function AdvertisementView:OpenSuccess()
|
|
self:UpdateView()
|
|
end
|
|
|
|
function AdvertisementView:SetToggle( bool )
|
|
self.today_not_show = bool
|
|
self.checkbox_obj:SetActive(bool)
|
|
end
|
|
|
|
function AdvertisementView:UpdateView()
|
|
lua_resM:setOutsideRawImage(self, self.bg_raw, GameResPath.GetAdBigBg(self.data.ad_pic))
|
|
if self.data.ad_tpye == AdvertisementModel.AD_TYPE.LOGIN then
|
|
self.goBtn_obj:SetActive(true)
|
|
self.Toggle_obj:SetActive(true)
|
|
--self.closeBtn_obj:SetActive(false)
|
|
elseif self.data.ad_tpye == AdvertisementModel.AD_TYPE.INSIDE then
|
|
self.goBtn_obj:SetActive(false)
|
|
self.Toggle_obj:SetActive(false)
|
|
self:AddCloseTimer()
|
|
--self.closeBtn_obj:SetActive(true)
|
|
else
|
|
-- logWarn('=======Msh:AdvertisementView.lua[72]==ad_type error=====', self.data.ad_tpye)
|
|
end
|
|
end
|
|
|
|
function AdvertisementView:AddCloseTimer( )
|
|
self.time = 6
|
|
local function clockFun()
|
|
self.time = self.time - 1
|
|
if self.time > 0 then
|
|
self.closeTipTxt_txt.text = HtmlColorTxt( tostring(self.time) .. " 秒后自动关闭" , '#63ED80')
|
|
else
|
|
self:Close()
|
|
end
|
|
end
|
|
clockFun()
|
|
self.close_time_id = self.close_time_id or GlobalTimerQuest:AddPeriodQuest(clockFun, 1, -1)
|
|
end
|
|
|
|
function AdvertisementView:SwitchTab( index )
|
|
|
|
end
|
|
|
|
function AdvertisementView:DestroySuccess( )
|
|
-- 处理一下不再弹出的cookie
|
|
if self.data and self.data.ad_tpye == AdvertisementModel.AD_TYPE.LOGIN and self.today_not_show then
|
|
self.model:SetSubTypeCookie(self.sub_type, false)
|
|
end
|
|
|
|
if self.close_time_id then
|
|
GlobalTimerQuest:CancelQuest(self.close_time_id)
|
|
self.close_time_id = nil
|
|
end
|
|
end
|