hengyang_client/lua_probject/main_project/main/poker/PKPlayBackView.lua

135 lines
3.7 KiB
Lua

local TableBG = import('Game.Data.TableBG')
local M = {}
setmetatable(M,{__index = PlayBackView})
local pk_default_bg = 1
local pk_bg_config = {
{id = 1, url = "base/main_poker/bg/bg1", thumb = "ui://Main_Poker/bg1"},
{id = 2, url = "base/main_poker/bg/bg2", thumb = "ui://Main_Poker/bg2"},
{id = 3, url = "base/main_poker/bg/bg3", thumb = "ui://Main_Poker/bg3"},
}
function M:InitView(url, ex_defaultbg, ex_bgconfig)
UIPackage.AddPackage("base/main_poker/ui/Main_Poker")
PlayBackView.InitView(self,url)
local _view = self._view
local default_bg = ex_defaultbg or pk_default_bg
local bg_config = ex_bgconfig or pk_bg_config
TableBG.LoadTableBG(default_bg, self._room.game_id, self._root_view, bg_config)
UpdateBeat:Add(self.OnUpdate,self)
end
function M:NextRecordPlay()
local result = PlayBackView.NextRecordPlay(self)
if not result then return end
self:ChangePlayState(false)
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
end
function M:LastRecordPlay()
local result = PlayBackView.LastRecordPlay(self)
if not result then return end
self:ChangePlayState(false)
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
end
function M:Play()
self:ChangeAlpha()
self:ChangePlayState(not self._play)
if not self._play then return end
if (self._currentStep == #self.cmdList and self._playFoward) or (self._currentStep == 0 and not self._playFoward) then
self._currentStep = 0
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
end
end
function M:ChangePlayState(state)
self._play = state
self:ChangeTextSpeed()
local btn_play = self._view:GetChild("panel_record"):GetChild("btn_play")
if self._play then
btn_play:GetController("state").selectedIndex = 1
else
btn_play:GetController("state").selectedIndex = 0
end
end
function M:ChangeTextSpeed()
local str1 = self._play and self._speed or ""
self._view:GetChild("panel_record"):GetChild("tex_speed").text = str1
local str2 = not self._play and (self._playFoward and "播放暂停" or "回退暂停") or self._playFoward and (self._speed == 1 and "播放" or "快进") or (self._speed == 1 and "回退" or "快退")
self._view:GetChild("panel_record"):GetChild("tex_2").text = str2
local str3 = self._play and "倍速度" or ""
self._view:GetChild("panel_record"):GetChild("tex_1").text = str3
end
function M:CmdLeftArrows()
self:ChangeAlpha()
self:ChangePlayState(true)
if not self._playFoward then
if self._speed < 16 then
self._speed = self._speed * 2
else
self._speed = 1
end
self:ChangeTextSpeed()
else
self._speed = 1
self._playFoward = false
self:ChangeTextSpeed()
end
end
function M:CmdRightArrows()
self:ChangeAlpha()
self:ChangePlayState(true)
if self._playFoward then
if self._speed < 16 then
self._speed = self._speed * 2
else
self._speed = 1
end
self:ChangeTextSpeed()
else
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
end
end
function M:OnUpdate()
if self._play then
if (self._currentStep == #self.cmdList and self._playFoward) then
self:ChangePlayState(false)
ViewUtil.ErrorTip(nil,"当前已是录像结尾了,再次点击播放按钮可重新播放")
return
elseif (self._currentStep == 0 and not self._playFoward) then
self:ChangePlayState(false)
ViewUtil.ErrorTip(nil,"当前已是录像开头了,再次点击播放按钮可重新播放")
return
end
self._timer = self._timer + Time.deltaTime
if self._timer >= 1 / self._speed then
self._timer = 0
local step = self._playFoward and 1 or -1
self._currentStep = self._currentStep + step
self:ShowStep(self._currentStep)
end
end
end
function M:Destroy()
UpdateBeat:Remove(self.OnUpdate,self)
PlayBackView.Destroy(self)
end
return M