local UIReplayControlPanel = UIViewClass() local PLAY_RATE = {"1.0x","2.0x", "4.0x", "8.0x",} local PLAY_RATE_DIC = {1,2, 4, 8,} function UIReplayControlPanel:OnCreated() end function UIReplayControlPanel:OnOpened(content) self:RegistSystemEvent(EventID.Level_SwitchHero, self.SetPlayerInfo) self:RegistSystemEvent(EventID.Level_UpdateServerFrame, self.UpdateServerFrame) self:RegistSystemEvent(EventID.Cheat_ShowOrHideReplayUI, self.ShowOrHide) self:RegistSystemEvent(EventID.Cheat_ReplaySwitchPlayer, self.SwitchHero) self:SetPlayerInfo() self:InitPlayRateInfo() self:StartRepeatFunc(self.OnUpdateFun, 1) self.skillView = self.skillRoot:OpenView(GetViewClass(Const_UI_Lua.UIEnum.UIBattleAttackPanel), nil, "Replay/UIReplayBattleAttackPanel") self.isPlaying = true UIUtils.SetActive(self.group_playCtl.img_Play, not self.isPlaying) UIUtils.SetActive(self.group_playCtl.img_Stop, self.isPlaying) self.selectRateActive = false UIUtils.SetActive(self.group_playCtl.img_ArrowDOWN, true) UIUtils.SetActive(self.group_playCtl.img_ArrowUP, false) self.group_playCtl.dropdown_playSpd:SetText("1.0x") self.group_playCtl.slider_progress.value = 0 local maxTime = MDL.Replay.GetCurBattleFightTime() -- 帧 self.maxTimeStr = UTL.Time.FormatTimeSeconds(maxTime) self.maxFrames = maxTime > 0 and maxTime * 20 or 1 if LevelManager.IsBossChallenge() then UIUtils.SetActive(self.btn_switch, false) UIUtils.SetActive(self.group_playerInfo.img_SwitchBG, false) else UIUtils.SetActive(self.btn_switch, true) UIUtils.SetActive(self.group_playerInfo.img_SwitchBG, true) end self:OnUpdateFun() local rate = CTL.Replay.GetPlayRate() for i, v in ipairs(PLAY_RATE_DIC) do if rate == v then self.group_playCtl.dropdown_playSpd:SetText(PLAY_RATE[i]) break end end end -- 更新进度条和进度数字 function UIReplayControlPanel:OnUpdateFun(deltaTime, timeSineUpdate) -- 更新进度条 local curFrame = BattleDataGetter.GetCurFrameIndex() if curFrame > self.maxFrames then curFrame = self.maxFrames end if BattleDataGetter.HadStopLevel() then self:StopRepeatFunc(self.OnUpdateFun) end local progress = curFrame / self.maxFrames self.group_playCtl.slider_progress.value = progress --设置时间 local curSecond = UTL.Time.FormatTimeByFrameCount(curFrame) -- 加5的目的是为了防止出现最后播放完毕时显示的是 self.group_playCtl.lab_progress.text = curSecond .. "/" .. self.maxTimeStr end --更新总帧数据 function UIReplayControlPanel:UpdateServerFrame(frame) self.maxTimeStr = UTL.Time.FormatTimeByFrameCount(frame) self.maxFrames = frame end -- 设置玩家头像 function UIReplayControlPanel:SetPlayerInfo() local myEntity = BattleDataGetter.GetCurEntity() local heroId = BattleDataGetter.GetMainPlayerCharacterID() local heroName = myEntity and myEntity._logicInitData.Name or "" UTL.Item.SetHeroIconByHeroId(self.group_playerInfo.texture_HeadImg, heroId, BattleDataGetter.GetHeroIsAwaken(BattleDataGetter.GetCurPlayerID(), heroId)) self.group_playerInfo.labLocal_name.text = heroName end --region 四个按钮功能 function UIReplayControlPanel:OnButtonClicked(comp) if comp == self.btn_switch then -- 切换人 self:SwitchHero() elseif comp == self.btn_exit then -- 退出 UTL.MessageBox.ShowOKCancelBox(nil, Const_IDS.IDS_FairPlayReplay_ConfirmQuitTips, function() CTL.Replay.Exit() end) if not self.isPlaying then -- 暂停时,则取消暂停,防止UI底层问题导致的卡住。 self:OnButtonClicked(self.group_playCtl.btn_playOrStop) end elseif comp == self.group_playCtl.btn_playOrStop then -- 播放和暂停 self.isPlaying = not self.isPlaying CTL.Replay.PauseReplayBattle( not self.isPlaying) UIUtils.SetActive(self.group_playCtl.img_Play, not self.isPlaying) UIUtils.SetActive(self.group_playCtl.img_Stop, self.isPlaying) CTL.Sound.PlayGameSound("UI_sound_Close") if self.isPlaying then self:StartRepeatFunc(self.OnUpdateFun, 1) else self:StopRepeatFunc(self.OnUpdateFun) end elseif comp == self.group_playCtl.btn_playFromZero then -- 重新播放 if not self.isPlaying then self.isPlaying = true CTL.Replay.PauseReplayBattle( not self.isPlaying) end if CTL.Replay.IsReplayFromMyRecords() then CTL.Replay.ReplayAgainMyRecords() else MDL.Replay.ReplayAgain() end elseif comp == self.group_playCtl.dropdown_playSpd then -- 速率 self.selectRateActive = not self.selectRateActive UIUtils.SetActive(self.group_playCtl.img_ArrowDOWN, not self.selectRateActive) UIUtils.SetActive(self.group_playCtl.img_ArrowUP, self.selectRateActive) UIUtils.SetActive(self.group_playCtl.loop_Choose01, self.selectRateActive) if self.selectRateActive then CTL.Sound.PlayGameSound("UI_expand") else CTL.Sound.PlayGameSound("UI_fold") end end end --endregion --region 播放速率 function UIReplayControlPanel:InitPlayRateInfo() for i,v in ipairs(PLAY_RATE) do self.group_playCtl.loop_Choose01:AddData(v, 0) end end function UIReplayControlPanel:OnCellInit(scrollRect, index, cellTable, data) if self.group_playCtl.loop_Choose01 == scrollRect then cellTable.txt_Choose01.text = PLAY_RATE[index+1] end end function UIReplayControlPanel:OnCellClicked(scrollRect, index, cellTable, target, data) if self.group_playCtl.loop_Choose01 == scrollRect then CTL.Replay.SetPlayRate(PLAY_RATE_DIC[index+1], self.isPlaying) self.selectRateActive = false UIUtils.SetActive(self.group_playCtl.img_ArrowDOWN, not self.selectRateActive) UIUtils.SetActive(self.group_playCtl.img_ArrowUP, self.selectRateActive) UIUtils.SetActive(self.group_playCtl.loop_Choose01, self.selectRateActive) self.group_playCtl.dropdown_playSpd:SetText(PLAY_RATE[index+1]) CTL.Sound.PlayGameSound("UI_fold") end end --endregion function UIReplayControlPanel:SwitchHero(useLast) CTL.Replay.SwitchPlayer(useLast) self:SetPlayerInfo() end --region cheat logic function UIReplayControlPanel:ShowOrHide() UIUtils.SetActive(self.Bottom,not self.Bottom.gameObject.activeSelf) if not self.Bottom.gameObject.activeSelf then UIManager.OpenView(Const_UI_Lua.UIEnum.UIBattleAttackPanel) else UIManager.CloseView(Const_UI_Lua.UIEnum.UIBattleAttackPanel) end end --endregion return UIReplayControlPanel