|
|
- ExitTimeTip = ExitTimeTip or BaseClass(BaseView)
- local ExitTimeTip = ExitTimeTip
-
- --[[
- 使用范例
- local data = {
- time = time,--倒计时时间
- use_action = 15,--最后几秒使用闪烁
- -------------------------
- call_back = function() --时间到期回调函数
- self.model:Fire(BeachConst.REQ_QUIT_SCENE)
- end,
- exit_desc = "%s 自动退出",--不同退出提示
- time_str = "秒后",--需要放大的时间链接字符串<size=130%><#ffffff>10秒后</color></size>击败小怪解除
- }
- GlobalEventSystem:Fire(EventName.OPEN_EXIT_TIME_TIP,data)
- --]]
-
- function ExitTimeTip:__init()
- self.base_file = "common"
- self.layout_file = "ExitTimeTip"
- self.layer_name = "Main"
- self.destroy_imm = true
- self.change_scene_close = true
- self.append_to_ctl_queue = false --是否要添加进界面堆栈
- self.need_show_money = false --是否要显示顶部的金钱栏
- -- self.is_set_zdepth = true
- self.click_bg_toClose = false
- ------------------------
- -- 一级全屏界面:
- self.hide_maincancas = false --隐藏主界面
- self.use_background = false --不一定显示遮罩
- ------------------------
-
- CommonController.Instance:Fire(EventName.CLOSE_SPECIALTIPVIEW)--防止重叠
- self.load_callback = function ()
- self:LoadSuccess()
- end
- self.open_callback = function ( )
- self:OpenSuccess()
- end
- self.close_win_callback = function ( )
- self:Close()
- end
- self.destroy_callback = function ( )
- self:DestroySuccess()
- end
- end
-
- function ExitTimeTip:Open( data )
- data.time = data.time or 10
- self.data = data
- self.data.end_time = data.time + TimeUtil:getServerTime() --把时间段转为时间戳,兼容计时器帧率不稳定的问题
- self.data.exit_desc = data.exit_desc or "自动退出"
- self.data.time_str = data.time_str or "秒后"
- BaseView.Open(self)
- end
-
- function ExitTimeTip:LoadSuccess()
- local nodes = {
- "container/exitTimeText:tmp", "container:obj", "container/exitTimeBg:raw",
- }
- self:GetChildren(nodes)
- lua_resM:setOutsideRawImage(self, self.exitTimeBg_raw, GameResPath.GetViewBigBg("special_tip_di_3"), false)
-
- self:AddEvent()
- -------------------------
- SetSizeDelta(self.transform, ScreenWidth, ScreenHeight)
- SetAnchoredPosition(self.transform, 0, 0)
- end
-
- function ExitTimeTip:AddEvent()
-
- end
-
- function ExitTimeTip:OpenSuccess()
- self:UpdateView()
- end
-
- function ExitTimeTip:UpdateView()
- self.clock_time = self.data.end_time - TimeUtil:getServerTime()
- local use_action = self.data and self.data.use_action or 0
- local call_back = self.data and self.data.call_back
- SetVisibleByRotate( self.container.transform, self.clock_time > 0 )
-
- -------------------------
- local function clockFun()
- self.clock_time = self.data.end_time - TimeUtil:getServerTime()
- if self.clock_time >= 0 then
- self.exitTimeText_tmp.text = string.format("<size=130%%><#ffffff>%s%s</color></size>%s",self.clock_time,self.data.time_str,self.data.exit_desc)
- -------------------------
- if (not self.is_action) and (self.clock_time <= use_action) then
- self:StartExitAction()
- end
- else
- if call_back then
- call_back()
- end
- self:Close()
- end
- end
- clockFun()
- self.close_time_id = self.close_time_id or GlobalTimerQuest:AddPeriodQuest(clockFun, 0.5, -1)
- end
-
- --开始退出按钮闪烁动画
- function ExitTimeTip:StartExitAction( )
- self.is_action = true
- if not self.container_canvas then
- self.container_canvas = self.container:GetComponent("CanvasGroup")
- end
- self.container_canvas.alpha = 0
-
- local function show_icon_func( percent )
- self.container_canvas.alpha = percent
- end
- local show_update = cc.CustomUpdate.New(0.5,show_icon_func)
-
- local function hide_icon_func( percent )
- self.container_canvas.alpha = 1 - percent
- end
- local hide_update = cc.CustomUpdate.New(0.5,hide_icon_func)
- local action = cc.Sequence.New(show_update,hide_update)
- self:AddAction(cc.RepeatForever.New(action), self.container)
- end
-
- function ExitTimeTip:DestroySuccess( )
- if self.close_time_id then
- GlobalTimerQuest:CancelQuest(self.close_time_id)
- self.close_time_id = nil
- end
- end
|