local UIMoviePanel = UIViewClass() local EventSystem = require('Event/EventSystem') local PATH = "Movie/%s" function UIMoviePanel:OnCreated() self.controller_Movie:SetAndroidOESEnabled(true) self.playTime = 0 self.movieQueue ={} self.controller_Movie:AddFinishCallBack(function() self:Stop(self.curMovie) end, function(name, skip, duration) self:UploadBI(name, skip, duration) end) end function UIMoviePanel:OnOpened(context) self:RegistSystemEvent(EventID.UI_MoviePanel_OpenInit, self.Init) self.noNeedBI = context.noNeedBI self.movieID = context.movieID self:Init(context) end function UIMoviePanel:Init(context) self:StartMovie(context) end function UIMoviePanel:OnClosed() if self.curMovie then self:Stop(self.curMovie) self.curMovie = nil end end function UIMoviePanel:StartMovie(context) local movie = { id = context.movieID, banSkipTime = context.banSkipTime, callback = context.callback, autoPassTime = context.autoPassTime, isFirstPlayCG = context.isFirstPlayCG, } self:Begin(movie) end function UIMoviePanel:Begin(movie) if not self.curMovie then if not NetManager.IsLaunch() then LevelManager.PauseLevel(true) end self.curMovie = movie self:Show(movie,true) else table.insert(self.movieQueue,movie) end end function UIMoviePanel:Show(movie) if movie.autoPassTime == 0 then self:Stop(movie) return end local moviePath = string.format(PATH,movie.id) self.isPause = false self.playTime = 0 self.skipShowTimer = 0 self.banSkipTime = movie.banSkipTime or 0 if self.banSkipTime > 0 then self.state_Skip:SetState(1) self.txt_CantSkipTimer:ResetAndBeginCustomTimer(false, movie.banSkipTime, 0, UIUtils.GetLocalizedTxt(Const_IDS.IDS_Countdown), 1) else self.state_Skip:SetState(0) self.txt_CantSkipTimer:EndTimer() end UIUtils.SetActive(self.btn_ShowSkip.gameObject, true) UIUtils.SetActive(self.group_Skip,false) self.switch_PauseState:SetState(0) UIUtils.SetLabel(self.lab_PauseTip, UIUtils.GetLocalizedTxt(Const_IDS["IDS_Pause"])); self:StartRepeatFunc(self.OnUpdateFun, 1) self.controller_Movie:PlayMovie(moviePath) end function UIMoviePanel:Stop(movie) if not NetManager.IsLaunch() then LevelManager.PauseLevel(false) end self:StopRepeatFunc(self.OnUpdateFun) self.playTime = 0 if movie.callback then movie.callback(movie.id) movie.callback = nil end if movie.isFirstPlayCG then BIManager.DispatchBIClientEvent(BIManager.EventName.EndOpeningMovie) end self.curMovie = table.remove(self.movieQueue,1) if self.curMovie then self:Show(self.curMovie) else self:CloseView() CTL.Sound.OnMovieStop(movie.id) end end function UIMoviePanel:OnButtonClicked(obj) if obj == self.btn_Skip then self.controller_Movie:StopMovie(true) if self.movieID == MDL.Login.GetLoginShowCGPath() or self.context.needPause then CTL.Sound.PlayGameSound("Music_resume") end elseif obj == self.btn_Pause then if self.isPause then self.controller_Movie:ResumeMovie() self.isPause = false self.switch_PauseState:SetState(0) UIUtils.SetLabel(self.lab_PauseTip, UIUtils.GetLocalizedTxt(Const_IDS["IDS_Pause"])); if self.movieID == MDL.Login.GetLoginShowCGPath() or self.context.needPause then CTL.Sound.PlayGameSound("Music_resume") end else self.controller_Movie:PauseMovie() self.isPause = true self.switch_PauseState:SetState(1) UIUtils.SetLabel(self.lab_PauseTip, UIUtils.GetLocalizedTxt(Const_IDS["IDS_Play"])); if self.movieID == MDL.Login.GetLoginShowCGPath() or self.context.needPause then CTL.Sound.PlayGameSound("Music_pause") end end elseif obj==self.btn_ShowSkip then self.skipShowTimer = 4 UIUtils.SetActive(self.btn_ShowSkip.gameObject, false) UIUtils.SetActive(self.group_Skip,true) end end function UIMoviePanel:OnBackButtonPressed() self:OnButtonClicked(self.btn_ShowSkip) self:OnButtonClicked(self.btn_Pause) end function UIMoviePanel:OnUpdateFun(deltaTime, timeSinceUpdate) self.playTime = timeSinceUpdate if not self.isPause then if self.banSkipTime > 0 then self.banSkipTime = self.banSkipTime - deltaTime if self.banSkipTime <= 0 then self.state_Skip:SetState(0) end end if self.skipShowTimer > 0 then self.skipShowTimer = self.skipShowTimer - deltaTime if self.skipShowTimer <= 0 then UIUtils.SetActive(self.btn_ShowSkip.gameObject, true) UIUtils.SetActive(self.group_Skip, false) end end if self.curMovie.autoPassTime > 0 then if timeSinceUpdate > self.curMovie.autoPassTime then self.controller_Movie:StopMovie(false) end end end end function UIMoviePanel:UploadBI(name, skip, duration) if self.noNeedBI then return end CTL.Cutscene.UploadMovieSkipBI(name, skip, self.playTime, duration) end return UIMoviePanel