hengyang_client/lua_probject/main_project/main/majiang/MJPlayBackView.lua

191 lines
5.1 KiB
Lua

local MJPlayerCardInfoView = import(".MJPlayerCardInfoView")
local MJPlayerSelfCardInfoView = import(".MJPlayerSelfCardInfoView")
local TableBG = import('Game.Data.TableBG')
---
local M = {}
setmetatable(M,{__index = PlayBackView})
local bg_config = {
{id = 1, url = "base/main_majiang/bg/bg1", thumb = "ui://Main_Majiang/b01"}
}
function M:InitView(url)
UIPackage.AddPackage("base/main_majiang/ui/Main_Majiang")
PlayBackView.InitView(self,url)
local _view = self._view
self._cursor = UIPackage.CreateObjectFromURL("ui://Main_Majiang/Ani_play_bj")
TableBG.LoadTableBG(1, nil, self._root_view,bg_config)
UpdateBeat:Add(self.OnUpdate,self)
end
function M:FillRoomData()
local _room = self._room
if self._player_card_info == nil or #self._player_card_info == 0 then
self._player_card_info = {}
local _player_card_info = self._player_card_info
for i = 1, _room.room_config.people_num do
local tem = self._view:GetChild("player_card_info" .. i)
_player_card_info[i] = self:NewMJPlayerCardInfoView(tem,i)
end
end
local list = _room.player_list
for i=1,#list do
local p = list[i]
local info = self._player_card_info[self:GetPos(p.seat)]
info:SetPlayer(p)
info:FillData()
end
self:SetCardBoxPosition()
local list = _room.player_list
for i=1,#list do
local p = list[i]
local info = self._player_info[self:GetPos(p.seat)]
info._view.visible = true
info:FillData(p)
end
end
function M:SetCardBoxPosition()
local _room = self._room
for i = 1, _room.room_config.people_num do
local tex = self._view:GetChild("cardbox"):GetChild("direction"..i)
local index = _room.self_player.seat + i - 1
index = index > 4 and index - 4 or index
tex.text = self._gamectr:GetPosString(index)
end
end
function M:NewMJPlayerCardInfoView(view,index)
return MJPlayerCardInfoView.new(view,self)
end
function M:NextRecordPlay()
self:RemoveCursor()
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()
self:RemoveCursor()
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:RemoveCursor()
if self._cursor.parent then
self._cursor.parent:GetController("color").selectedIndex = 0
end
self._cursor:RemoveFromParent()
end
function M:GetPrefix()
return get_majiang_prefix(DataManager.CurrenRoom.game_id)
end
function M:Destroy()
if self._cursor then self._cursor:Dispose() end
UpdateBeat:Remove(self.OnUpdate,self)
PlayBackView.Destroy(self)
end
return M