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

209 lines
5.4 KiB
Lua
Raw Normal View History

2025-04-01 10:48:36 +08:00
local MJPlayerCardInfoView = import(".MJPlayerCardInfoView")
local MJPlayerSelfCardInfoView = import(".MJPlayerSelfCardInfoView")
local TableBG = import('Game.Data.TableBG')
2025-06-24 21:48:34 +08:00
---
2025-04-01 10:48:36 +08:00
local M = {}
2025-06-24 21:48:34 +08:00
setmetatable(M, { __index = PlayBackView })
2025-04-01 10:48:36 +08:00
local bg_config = {
2025-06-24 21:48:34 +08:00
{ id = 1, url = "base/main_majiang/bg/bg1", thumb = "ui://Main_Majiang/b01" }
2025-04-01 10:48:36 +08:00
}
function M:InitView(url)
UIPackage.AddPackage("base/main_majiang/ui/Main_Majiang")
2025-06-24 21:48:34 +08:00
PlayBackView.InitView(self, url)
2025-04-01 10:48:36 +08:00
local _view = self._view
self._cursor = UIPackage.CreateObjectFromURL("ui://Main_Majiang/Ani_play_bj")
2025-06-24 21:48:34 +08:00
TableBG.LoadTableBG(1, nil, self._root_view, bg_config)
2025-04-01 10:48:36 +08:00
2025-06-24 21:48:34 +08:00
UpdateBeat:Add(self.OnUpdate, self)
2025-04-01 10:48:36 +08:00
end
function M:FillRoomData()
local _room = self._room
2025-06-24 21:48:34 +08:00
if self._player_card_info == nil or #self._player_card_info == 0 then
2025-04-01 10:48:36 +08:00
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)
2025-06-24 21:48:34 +08:00
_player_card_info[i] = self:NewMJPlayerCardInfoView(tem, i)
2025-04-01 10:48:36 +08:00
end
end
local list = _room.player_list
2025-06-24 21:48:34 +08:00
for i = 1, #list do
2025-04-01 10:48:36 +08:00
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
2025-06-24 21:48:34 +08:00
for i = 1, #list do
2025-04-01 10:48:36 +08:00
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()
2025-06-24 21:48:34 +08:00
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
2025-04-01 10:48:36 +08:00
end
2025-06-24 21:48:34 +08:00
function M:NewMJPlayerCardInfoView(view, index)
2025-06-25 22:49:44 +08:00
return MJPlayerCardInfoView.new(view, self, 1)
2025-04-01 10:48:36 +08:00
end
function M:NextRecordPlay()
self:RemoveCursor()
local result = PlayBackView.NextRecordPlay(self)
if not result then return end
2025-06-24 22:24:56 +08:00
self:ChangePlayState(true)
2025-04-01 10:48:36 +08:00
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
2025-06-24 22:24:56 +08:00
self:ChangePlayState(true)
2025-04-01 10:48:36 +08:00
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
end
2025-06-24 21:48:34 +08:00
function M:RestartRecordPlay()
self:ChangeAlpha()
self._currentStep = 0
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
self:ChangePlayState(true)
end
2025-04-01 10:48:36 +08:00
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()
2025-06-24 21:48:34 +08:00
-- 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
self._record:GetChild('tex_speed').text = self._speed
2025-04-01 10:48:36 +08:00
end
function M:CmdLeftArrows()
self:ChangeAlpha()
self:ChangePlayState(true)
if not self._playFoward then
2025-06-24 21:48:34 +08:00
if self._speed < 5 then
self._speed = self._speed + 1
2025-04-01 10:48:36 +08:00
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
2025-06-24 21:48:34 +08:00
if self._speed < 5 then
self._speed = self._speed + 1
2025-04-01 10:48:36 +08:00
else
self._speed = 1
end
self:ChangeTextSpeed()
else
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
end
end
2025-06-24 21:48:34 +08:00
function M:MaxSpeedArriws()
self:ChangeAlpha()
self:ChangePlayState(true)
self._speed = 30
end
2025-04-01 10:48:36 +08:00
function M:OnUpdate()
if self._play then
if (self._currentStep == #self.cmdList and self._playFoward) then
self:ChangePlayState(false)
2025-06-24 21:48:34 +08:00
ViewUtil.ErrorTip(nil, "当前已是录像结尾了,再次点击播放按钮可重新播放")
2025-04-01 10:48:36 +08:00
return
elseif (self._currentStep == 0 and not self._playFoward) then
self:ChangePlayState(false)
2025-06-24 21:48:34 +08:00
ViewUtil.ErrorTip(nil, "当前已是录像开头了,再次点击播放按钮可重新播放")
2025-04-01 10:48:36 +08:00
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
2025-06-24 21:48:34 +08:00
function M:RemoveCursor()
-- if self._cursor.parent then
-- self._cursor.parent:GetController("color").selectedIndex = 0
-- end
self._cursor:RemoveFromParent()
2025-04-01 10:48:36 +08:00
end
function M:GetPrefix()
2025-06-24 21:48:34 +08:00
return get_majiang_prefix(DataManager.CurrenRoom.game_id)
2025-04-01 10:48:36 +08:00
end
function M:Destroy()
if self._cursor then self._cursor:Dispose() end
2025-06-24 21:48:34 +08:00
UpdateBeat:Remove(self.OnUpdate, self)
2025-04-01 10:48:36 +08:00
PlayBackView.Destroy(self)
end
2025-06-24 21:48:34 +08:00
return M