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

290 lines
8.1 KiB
Lua
Raw Normal View History

2025-11-14 23:38:35 +08:00
local MJPlayerCardInfoView = import(".MJPlayerCardInfoView")
local MJPlayerSelfCardInfoView = import(".MJPlayerSelfCardInfoView")
local TableBG = import('Game.Data.TableBG')
local MJMainView = import(".MJMainView")
local HuCardImg = import(".HuCardImg")
---
local M = {}
setmetatable(M, { __index = PlayBackView })
M.HuCardImg = HuCardImg
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")
self._laiziMove = self._view:GetTransition('laiziMove')
self._touxiangMove = self._view:GetTransition('touxiangMove')
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
local config = ExtendManager.GetExtendConfig(_room.game_id)
local mode = config:GetGameInfo()
local gamePlay = mode:LoadConfigToDetailOnlyPlay(json.encode(_room.room_config.config),
json.encode(_room.room_config.config.hpData))
self._view:GetChild('wanfa_text').text = gamePlay
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 MJMainView.NewMJPlayerCardInfoView(self, view, index, 1)
--[[
if index == 1 then
return MJPlayerSelfCardInfoView.new(view, self)
end
return MJPlayerCardInfoView.new(view, self)
]]
end
function M:markOutCards(showTip, data)
MJMainView.markOutCards(self, showTip, data)
-- for i = 1, #self._room.player_list do
-- local p = self._room.player_list[i]
-- local info = self._player_card_info[self:GetPos(p.seat)]
-- -- for j = 1, #p.outcard_list do
-- -- local card = p.outcard_list[j]
-- -- if card == data then
-- -- for k = 1, #p.outcard_list do
-- -- local obj = info:GetOutCardByIndex(k)
-- -- if obj.data == card then
-- -- obj:GetController("gray").selectedIndex = showTip and 1 or 0
-- -- end
-- -- end
-- -- end
-- -- end
-- for j = 1, info._view_outCardList.numItems do
-- local card = p.outcard_list[j]
-- if card == data then
-- for k = 1, info._view_outCardList.numItems do
-- local obj = info:GetOutCardByIndex(k)
-- if obj.data == card then
-- obj:GetController("gray").selectedIndex = showTip and 1 or 0
-- end
-- end
-- end
-- end
-- end
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:RestartRecordPlay()
local list = self._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)
local card_info = self._player_card_info[self:GetPos(p.seat)]
card_info:Clear()
end
self:ChangeAlpha()
self._currentStep = 0
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
self:ChangePlayState(true)
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
--开始时,隐藏显示结算界面
if state then
if self.result then
self.result:Destroy()
self.result = nil
end
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
self._record:GetChild('tex_speed').text = self._speed == 30 and 1 or self._speed
end
function M:CmdLeftArrows()
self:ChangeAlpha()
self:ChangePlayState(true)
if not self._playFoward then
if self._speed < 5 then
self._speed = self._speed + 1
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 < 5 then
self._speed = self._speed + 1
else
self._speed = 1
end
self:ChangeTextSpeed()
else
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
end
end
function M:MaxSpeedArriws()
self:ChangeAlpha()
self:ChangePlayState(true)
self._speed = 30
end
local majiang_asset_path = "base/main_majiang/sound/"
function M:PlayMJSound(path)
ViewUtil.PlaySound(self.asset_group, majiang_asset_path .. path)
end
function M:PlayMJMusic(path)
ViewUtil.PlayMuisc(self.asset_group, majiang_asset_path .. path)
end
function M:PlaySound(group, sex, path)
local sex_path = ViewUtil.Sex_Chat[sex]
local path1 = majiang_asset_path .. string.format("%s/%s.mp3", sex_path, path)
ViewUtil.PlaySound(group, path1)
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