local UIFunctionUpdateNotice = UIViewClass() local Movie_Scale_Y = 1 local Video_Width = 930 local Video_Height = 466 local OFFSET_TIME = 0.1 function UIFunctionUpdateNotice:OnOpened(context) self:RegistSystemEvent(EventID.FunctionUpdateNotice_RewardUpdate, self.RefreshRewardBox) self:RefreshTime() Movie_Scale_Y = UNITY_ANDROID and 1 or -1 self.cellHasAddMovieCall = {} self.loopScroll_Activity:ReloadAll(MDL.FunctionUpdateNotice.GetFunctionUpdateModeIDs()) self.curSelectTabIndex = CTL.FunctionUpdateNotice.GetLastTabIndex() self.loopScroll_Activity:SelectIndex(self.curSelectTabIndex-1) end function UIFunctionUpdateNotice:RefreshTime() local dayStr = string.FormatByIdsId(Const_IDS["IDS_FunctionUpdateNotice_Hint_2"], UIUtils.GetLocalizedTxt(Const_IDS["IDS_DirectGift_TimeHint_1"])) local hourStr = string.FormatByIdsId(Const_IDS["IDS_FunctionUpdateNotice_Hint_2"], UIUtils.GetLocalizedTxt(Const_IDS["IDS_DirectGift_TimeHint_2"])) local minStr = string.FormatByIdsId(Const_IDS["IDS_FunctionUpdateNotice_Hint_2"], UIUtils.GetLocalizedTxt(Const_IDS["IDS_DirectGift_TimeHint_3"])) local secStr = string.FormatByIdsId(Const_IDS["IDS_FunctionUpdateNotice_Hint_2"], UIUtils.GetLocalizedTxt(Const_IDS["IDS_DirectGift_TimeHint_4"])) self.txt_CountDown:SetDHMSStr(dayStr, hourStr, minStr, secStr) self.txt_CountDown:ResetAndBeginCustomTimer(false, MDL.FunctionUpdateNotice.GetRemineTime(), 0, nil) end function UIFunctionUpdateNotice:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_Activity then local cfg = DataSheetManager.FunctionUpdateNoticeMode:GetDataByModeID(data) UIUtils.SetLabelText(cellTable.txt_Name, Const_IDS[cfg.ModeName]) UIUtils.SetLabelText(cellTable.txt_Desc, Const_IDS[cfg.ModeDes]) UIUtils.SetImageByAssetBundle(cellTable.img_QualityHead, cfg.ModePicture) cellTable.btn_Click:SetRedPoint(not MDL.FunctionUpdateNotice.IsRewardReceived(index+1)) elseif scrollRect == self.loop_Function then if data.ChildType == MDL.FunctionUpdateNotice.ModeChildType.Image then UIUtils.SetTextureByAssetBundle(cellTable.img_FunctionImage, data.Picture) else self:RefreshVideoCell(cellTable, index, data) end elseif scrollRect == self.Loop_Content then self:RefreshNewThingCell(cellTable,index,data) end end function UIFunctionUpdateNotice:RefreshVideoCell(cellTable, index, cfg) local cellIndex = index + 1 if not self.moviesData[cellIndex] then UIUtils.SetActive(cellTable.AVProVideouGUI.gameObject, false) self.moviesData[cellIndex] = {} self.movieCell = cellTable if not self.cellHasAddMovieCall[cellTable] then self.cellHasAddMovieCall[cellTable] = true cellTable.controller_Movie:SetAndroidOESEnabled(true) cellTable.controller_Movie:AddStartCallBack(function() self:OnMovieStart() end) cellTable.controller_Movie:AddFinishCallBack(function() self:OnMovieStop() end) end self.moviesData[cellIndex].movieCurTime = 0 cellTable.img_Schedule.fillAmount = 0 cellTable.state_Video:SetState(2) cellTable.state_Suspend:SetState(1) cellTable.txt_Time.text = "00:00/00:00" if cellIndex == self.curSelectToggleIndex then local volume = CTL.Setting.GetSoundVolume() cellTable.controller_Movie:PlayMovie(cfg.Movie, volume) end end if cellIndex ~= self.curSelectToggleIndex and cellIndex == self.curPlayingIndex and self.isPlaying then self:PauseVideo(cellTable) end if self.isPlaying and self.moviesData[cellIndex] then local lastProgress = cellTable.img_Schedule.fillAmount local progress = self.moviesData[cellIndex].movieCurTime / self.moviesData[cellIndex].movieTotalTime if progress >= lastProgress then cellTable.img_Schedule.fillAmount = progress local timeStr = UTL.Time.FormatTimeSeconds(self.moviesData[cellIndex].movieCurTime) cellTable.txt_Time.text = timeStr .. "/" .. self.moviesData[cellIndex].movieTotalTimeStr end end end function UIFunctionUpdateNotice:RefreshNewThingCell(cellTable, index, cfg) if cfg.ChildType == MDL.ItemSources.SourceType.HeroAppearance then cellTable.state_Tpye:SetState(1) UIUtils.SetImageByAssetBundle(cellTable.img_Appearance, cfg.Picture) cellTable.img_Appearance.transform:SetAnchoredPosition(cfg.OffsetX, cfg.OffsetY) local scale = cfg.Size cellTable.img_Appearance.transform:SetLocalScale(scale, scale, scale) elseif cfg.ChildType == MDL.ItemSources.SourceType.HeroLightEffect then cellTable.state_Tpye:SetState(2) UIUtils.SetImageByAssetBundle(cellTable.img_Effect, cfg.Picture) cellTable.img_Effect.transform:SetAnchoredPosition(cfg.OffsetX, cfg.OffsetY) local scale = cfg.Size cellTable.img_Effect.transform:SetLocalScale(scale, scale, scale) else cellTable.state_Tpye:SetState(0) cellTable.img_Common.transform:SetAnchoredPosition(cfg.OffsetX, cfg.OffsetY) local scale = cfg.Size cellTable.img_Common.transform:SetLocalScale(scale, scale, scale) UIUtils.SetImageByAssetBundle(cellTable.img_Common, cfg.Picture) cellTable.img_Common:SetNativeSize() end UIUtils.SetLabelText(cellTable.txt_ContentName, Const_IDS[cfg.Text]) UIUtils.SetLabelText(cellTable.txt_Obtain, Const_IDS[cfg.GetText]) UIUtils.SetLabelText(cellTable.txt_Tpye, Const_IDS[cfg.Title]) UTL.Color.SetQualityImageByType(cellTable.img_Quality, cfg.QualityColor, UTL.Color.QualityType.FunctionUpdateNoticeFrame) end function UIFunctionUpdateNotice:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.loopScroll_Activity then self.curSelectTabIndex = index + 1 self.curSelectToggleIndex = 1 self:RefreshRightPart() end end function UIFunctionUpdateNotice:RefreshRightPart() self.videoImgState = false self.moviesData = {} self:StopRepeatFunc(self.OnUpdateFun) self:OperateBgSound(false) self.isPlaying = false local curFunctionUpdateModeCfg = MDL.FunctionUpdateNotice.GetFunctionUpdateData(self.curSelectTabIndex) UIUtils.SetTextureByAssetBundle(self.img_ActivityBg, curFunctionUpdateModeCfg.ModeBackgroundPicture) UIUtils.SetLabelText(self.txt_ActivityName, Const_IDS[curFunctionUpdateModeCfg.ModeName]) UIUtils.SetActive(self.btn_Go, curFunctionUpdateModeCfg.ItemSourceID > 0) self.curPageCfgs = MDL.FunctionUpdateNotice.GetFunctionUpdatePageCfgs(self.curSelectTabIndex) if curFunctionUpdateModeCfg.ModeType == MDL.FunctionUpdateNotice.ModeType.General then self.loop_Function:ClearCells() for _, v in ipairs(self.curPageCfgs) do if v.ChildType == MDL.FunctionUpdateNotice.ModeChildType.Image then self.loop_Function:AddData(v, 0) else self.loop_Function:AddData(v, 1) end end local curPageCfgsCount = #self.curPageCfgs for i = 1, 5 do self.toggle_Bottom:SetToggleActive(i, i<=curPageCfgsCount) end self.state_Function:SetState(0) AuxUtil.InitEnhanceScroll(self.loop_Function.transform, 0) self.toggle_Bottom:SelectIndex(0) if curPageCfgsCount == 1 then self.loop_Function:SetMovementType(3) else self.loop_Function:SetMovementType(0) end else self.Loop_Content:ReloadAll(self.curPageCfgs) self.state_Function:SetState(1) end self:RefreshRewardBox() end function UIFunctionUpdateNotice:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_Function then if target == cellTable.btn_Suspend or target == cellTable.btn_Video then --视频播放/暂停 self:PlayOrPauseVideo(index+1, cellTable) end elseif scrollRect == self.Loop_Content then if target == cellTable.Btn_Goto then CTL.FunctionUpdateNotice.SetLastTabIndex(self.curSelectTabIndex) CTL.ItemSources.ExecuteSourceFunctionById(data.ChildType, data.GotoID) end end end function UIFunctionUpdateNotice:PlayOrPauseVideo(index, cellTable) if not self.moviesData[index] then return end self.isPlaying = not self.isPlaying if self.isPlaying then cellTable.state_Suspend:SetState(1) cellTable.state_Video:SetState(2) if self.moviesData[index].movieCurTime >= self.moviesData[index].movieTotalTime then cellTable.img_Schedule.fillAmount = 0 local timeStr = UTL.Time.FormatTimeSeconds(0) cellTable.txt_Time.text = timeStr .. "/" .. self.moviesData[index].movieTotalTimeStr cellTable.controller_Movie:ReplayMovie() else cellTable.controller_Movie:ResumeMovie() end else self:PauseVideo(cellTable) end end function UIFunctionUpdateNotice:PauseVideo(cellTable) self:OperateBgSound(false) self.isPlaying = false cellTable.state_Suspend:SetState(0) cellTable.controller_Movie:PauseMovie() cellTable.state_Video:SetState(0) self:StopRepeatFunc(self.OnUpdateFun) end function UIFunctionUpdateNotice:OnCellMoveCenter(scrollRect, index, cellTable, data) if scrollRect == self.loop_Function then if self.curSelectToggleIndex ~= index + 1 then self.toggle_Bottom:SelectIndex(index) end end end function UIFunctionUpdateNotice:OnValueChanged(comp, value) if comp == self.toggle_Bottom then self.curSelectToggleIndex = value + 1 self:RefreshPage() self:RefreshArrow() end end function UIFunctionUpdateNotice:RefreshPage() self.loop_Function:UpdateIndex(self.curSelectToggleIndex-1) AuxUtil.SetCenterChildIndex(self.loop_Function.transform, self.curSelectToggleIndex-1) local id = MDL.FunctionUpdateNotice.GetFunctionUpdateModeIDs()[self.curSelectTabIndex] local cfg = DataSheetManager.FunctionUpdateNoticeChild:GetDataByModeID_ChildID(id, self.curSelectToggleIndex) UIUtils.SetLabelText(self.txt_ActivityInfo, Const_IDS[cfg.Text]) end function UIFunctionUpdateNotice:RefreshRewardBox() if MDL.FunctionUpdateNotice.IsRewardReceived(self.curSelectTabIndex) then self.btn_Box:SetRedPoint(false) self.state_box:SetState(0) self.loopScroll_Activity:UpdateIndex(self.curSelectTabIndex-1) else self.btn_Box:SetRedPoint(true) self.state_box:SetState(1) end end function UIFunctionUpdateNotice:OnUpdateFun(deltaTime, timeSinceUpdate) if self.isPlaying and self.curPlayingIndex >= 1 then local data = self.moviesData[self.curPlayingIndex] self.moviesData[self.curPlayingIndex].movieCurTime = data.movieCurTime + deltaTime if data.movieCurTime < data.movieTotalTime then self.loop_Function:UpdateIndex(self.curPlayingIndex - 1) end --加个延时显示,设置视频大小 if not self.videoImgState and timeSinceUpdate >= OFFSET_TIME then self.videoImgState = true UIUtils.SetActive(self.movieCell.AVProVideouGUI.gameObject, true) end self:SetAVProVideouGUISizeDelta() else self:PauseVideo(self.movieCell) end end function UIFunctionUpdateNotice:SetAVProVideouGUISizeDelta() local width = self.movieCell.AVProVideouGUI.transform:GetSizeDelta() if width ~= Video_Width then self.movieCell.AVProVideouGUI.transform:SetSizeDelta(Video_Width, Video_Height) end end --视频暂停后恢复或者开始播放都会执行 function UIFunctionUpdateNotice:OnMovieStart() self:OperateBgSound(true) local movieTotalTime = self.movieCell.controller_Movie:GetDurationTime() self.moviesData[self.curSelectToggleIndex].movieTotalTimeStr = UTL.Time.FormatTimeSeconds(movieTotalTime) self.moviesData[self.curSelectToggleIndex].movieTotalTime = movieTotalTime self.moviesData[self.curSelectToggleIndex].movieCurTime = self.movieCell.controller_Movie:GetCurrentTime() self.isPlaying = true self.curPlayingIndex = self.curSelectToggleIndex self:StartRepeatFunc(self.OnUpdateFun, 0) end --视频播完回调(暂停不会) function UIFunctionUpdateNotice:OnMovieStop() self:OperateBgSound(false) self.isPlaying = false self.curPlayingIndex = -1 self.moviesData[self.curSelectToggleIndex].movieCurTime = self.movieCell.controller_Movie:GetCurrentTime() self.movieCell.img_Schedule.fillAmount = self.moviesData[self.curSelectToggleIndex].movieCurTime / self.moviesData[self.curSelectToggleIndex].movieTotalTime local timeStr = UTL.Time.FormatTimeSeconds(self.moviesData[self.curSelectToggleIndex].movieCurTime) self.movieCell.txt_Time.text = timeStr .. "/" .. self.moviesData[self.curSelectToggleIndex].movieTotalTimeStr self.movieCell.state_Suspend:SetState(0) self.movieCell.controller_Movie:PauseMovie() self.movieCell.state_Video:SetState(1) self:StopRepeatFunc(self.OnUpdateFun) end function UIFunctionUpdateNotice:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIFunctionUpdateNotice:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() CTL.FunctionUpdateNotice.SetLastTabIndex(1) elseif comp == self.btn_Box then if not MDL.FunctionUpdateNotice.IsRewardReceived(self.curSelectTabIndex) then MDL.FunctionUpdateNotice.GetRewardReq(self.curSelectTabIndex) else CTL.Tips.AddTipsMsg(Const_IDS.IDS_FunctionUpdateNotice_Hint_3) end elseif comp == self.btn_ArrowR then self.curSelectToggleIndex = self.curSelectToggleIndex + 1 self.toggle_Bottom:SelectIndex(self.curSelectToggleIndex - 1) elseif comp == self.btn_ArrowL then self.curSelectToggleIndex = self.curSelectToggleIndex -1 self.toggle_Bottom:SelectIndex(self.curSelectToggleIndex -1) elseif comp == self.btn_Go then local curFunctionUpdateModeCfg = MDL.FunctionUpdateNotice.GetFunctionUpdateData(self.curSelectTabIndex) CTL.ItemSources.ExecuteSourceFunctionById(curFunctionUpdateModeCfg.ItemSourceID) end end function UIFunctionUpdateNotice:RefreshArrow() if #self.curPageCfgs == 1 then self.arrow_State:SetState(0) elseif self.curSelectToggleIndex == #self.curPageCfgs then self.arrow_State:SetState(1) elseif self.curSelectToggleIndex == 1 then self.arrow_State:SetState(2) else self.arrow_State:SetState(3) end end function UIFunctionUpdateNotice:OperateBgSound(isMute) if isMute then CTL.Sound.LowPass() CTL.Sound.PlayGameSound("MUSiC_empty") else CTL.Sound.ResumeLevelSound() CTL.Sound.HighPass() end end function UIFunctionUpdateNotice:OnClosed() if self.isPlaying then self:OperateBgSound(false) end end return UIFunctionUpdateNotice