changhong/lua_probject/extend_project/extend/poker/runfast/RunFast_PlayerBackView.lua

518 lines
16 KiB
Lua
Raw Normal View History

2025-05-24 14:29:14 +08:00
---
--- Created by 谌建军.
--- DateTime: 2017/12/25 13:52
---
local PKPlayBackView = require('main.poker.PKPlayBackView')
local RunFast_PlayerCardInfoView = import('.RunFast_PlayerPokerInfoView')
local RunFast_PlayerSelfCardInfoView = import('.RunFast_PlayerSelfPokerInfoView')
local PlayerInfoView = import('.EXPlayerInfoView')
local RunFast_RightPanelView = import(".RunFast_RightPanelView")
local RunFast_ResultView = import(".RunFast_ResultView")
2026-02-04 15:07:37 +08:00
local RunFast_CardCheck = import(".CardCheck")
2025-05-24 14:29:14 +08:00
local M = {}
local RunFast_Record_Event = {
Evt_OutCard = 'OutCard',
Evt_Pass = 'pass',
Evt_NewRound = 'newindex',
Evt_result = 'result',
2026-02-07 20:42:59 +08:00
Evt_Result = 'Result'
2025-05-24 14:29:14 +08:00
}
local default_bg = 1
local bg_config = {
2025-06-04 17:50:55 +08:00
{ id = 1, url = 'extend/poker/runfast/bg/bg1', thumb = 'ui://Extend_Poker_RunFastNew/table_bg1' },
{ id = 2, url = 'extend/poker/runfast/bg/bg2', thumb = 'ui://Extend_Poker_RunFastNew/table_bg2' },
{ id = 3, url = 'extend/poker/runfast/bg/bg3', thumb = 'ui://Extend_Poker_RunFastNew/table_bg3' }
2025-05-24 14:29:14 +08:00
}
--- Create a new
function M.new()
2025-06-04 17:50:55 +08:00
setmetatable(M, { __index = PKPlayBackView })
local self = setmetatable({}, { __index = M })
2025-05-24 14:29:14 +08:00
self.class = 'RunFast_PlayBackView'
self:init()
return self
end
function M:InitView(url)
local room = self._room
if not room.self_player then
room.self_player = room:GetPlayerBySeat(1)
end
self._gamectr = ControllerManager.GetController(GameController)
UIPackage.AddPackage('extend/poker/runfast/ui/Extend_Poker_RunFastNew')
2026-02-04 15:07:37 +08:00
PKPlayBackView.InitView(self, "ui://Extend_Poker_RunFastNew/RunFast_Main_New_" .. room.room_config.people_num,
2025-06-04 17:50:55 +08:00
default_bg, bg_config)
2026-02-04 15:07:37 +08:00
2025-05-24 14:29:14 +08:00
self._tex_round = self._view:GetChild('round')
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)
self._player_card_info[i] = self:NewPlayerPokerInfoView(tem, i)
end
local rightpanel = self._view:GetChild("right_panel")
if self._rightPanelView ~= nil then
self._rightPanelView:Destroy()
end
2025-06-04 17:50:55 +08:00
self._rightPanelView = RunFast_RightPanelView.new(self, rightpanel)
2025-05-24 14:29:14 +08:00
rightpanel:GetChild("btn_setting").onClick:Clear()
self._player_info = {}
local _player_info = self._player_info
for i = 1, self._room.room_config.people_num do
local tem = self._view:GetChild('player_info' .. i)
_player_info[i] = PlayerInfoView.new(tem, self)
end
local list = self._room.player_list
2025-06-04 17:50:55 +08:00
for i = 1, #list do
2025-05-24 14:29:14 +08:00
local p = list[i]
local info = _player_info[self:GetPos(p.seat)]
info._view.visible = true
info:FillData(p)
end
if self._room.hpOnOff == 1 and self._room.score_times ~= 1 then
-- body
self._view:GetChild('roominfo_panel1'):GetChild('tex_beishu').text = self._room.score_times .. ''
else
self._view:GetChild('roominfo_panel1'):GetChild('tex_beishu').text = ''
end
2026-02-04 15:07:37 +08:00
self._cardCheck = RunFast_CardCheck:InitFlag()
self._gamectr._cardCheck = self._cardCheck
2025-05-24 14:29:14 +08:00
self._eventmap = {}
self._cmdmap = {}
self._cmdmap[RunFast_Record_Event.Evt_OutCard] = self.CmdOutCard
self._cmdmap[RunFast_Record_Event.Evt_Pass] = self.CmdPass
self._cmdmap[RunFast_Record_Event.Evt_NewRound] = self.CmdNewRound
self._cmdmap[RunFast_Record_Event.Evt_result] = self.Cmdresult
2026-02-07 20:42:59 +08:00
self._cmdmap[RunFast_Record_Event.Evt_Result] = self.CmdResult
2025-05-24 14:29:14 +08:00
end
function M:NewPlayerPokerInfoView(view, index)
if index == 1 then
return RunFast_PlayerSelfCardInfoView.new(view, self)
end
return RunFast_PlayerCardInfoView.new(view, self)
end
function M:FillRoomData(data)
2026-02-04 15:07:37 +08:00
-- print("hidezhanji 1111")
2025-05-24 14:29:14 +08:00
self._currentStep = 1
2026-02-07 20:42:59 +08:00
DataManager.CurrenRoom.pai = 0
2025-05-24 14:29:14 +08:00
local room = DataManager.CurrenRoom
local _player_card_info = self._player_card_info
local roominfo_panel = self._view:GetChild('roominfo_panel1')
roominfo_panel:GetChild('tex_roomid').text = data.info.roomid
roominfo_panel:GetChild('tex_gametype').text = room.room_config:GetGameName()
for i = 1, #room.player_list do
local p = room.player_list[i]
local card_info = _player_card_info[self:GetPos(p.seat)]
local head_info = self._player_info[self:GetPos(p.seat)]
if p.total_hp then
2026-02-04 15:07:37 +08:00
-- print("hidezhanji 2222")
2025-05-24 14:29:14 +08:00
2025-06-04 17:50:55 +08:00
head_info._view:GetChild('zhanji').visible = false
2025-05-24 14:29:14 +08:00
if room.hpOnOff == 1 or room:checkHpNonnegative() then
2025-06-04 17:50:55 +08:00
head_info._view:GetChild('zhanji').visible = true
2026-02-07 20:42:59 +08:00
head_info._view:GetChild('text_jifen').text = d2ad(p.total_hp)
2025-05-24 14:29:14 +08:00
end
end
head_info:FillData(p)
head_info:UnmarkTuoguan()
head_info:UpdateScore()
if p.seat ~= room.self_player.seat then
card_info:UpdateHandPoker(p.hand_list, false, true)
end
head_info:UpdatePiao(p.piao)
end
2026-02-07 20:42:59 +08:00
self:UpdateRound()
2025-06-04 17:50:55 +08:00
2025-05-24 14:29:14 +08:00
self:GenerateAllStepData(data)
self:ShowStep(1)
end
function M:ShowStep(index)
local step = self._step[index]
2025-06-04 17:50:55 +08:00
if step == nil then
2025-05-24 14:29:14 +08:00
return
end
for i = 1, #step.player_card_data do
local p = self._room:GetPlayerBySeat(i)
local info = self._player_card_info[self:GetPos(i)]
p.hand_list = step.player_card_data[i].hand_list
p.out_card_list = step.player_card_data[i].out_card_list
p.hand_left_count = #p.hand_list
2025-06-04 17:50:55 +08:00
2025-05-24 14:29:14 +08:00
if p.seat ~= self._room.self_player.seat then
info:UpdateHandPoker(p.hand_list, false, true)
else
info:InitPoker(p.hand_list, false)
end
end
2026-02-07 20:42:59 +08:00
2025-05-24 14:29:14 +08:00
if step.cmd == RunFast_Record_Event.Evt_OutCard then
local seat = step.current_out_seat
local p = self._room:GetPlayerBySeat(seat)
local info = self._player_card_info[self:GetPos(seat)]
local card = step.out_card_list
local card_list = self._gamectr:ChangeCodeByFrom(card, true)
info:SetOutCardInfo(card_list, false)
self:ClearNextSeatOutCard(seat)
2026-02-04 15:07:37 +08:00
self._cardCheck:InitLastCard(card_list)
self:_Effect(self._cardCheck.type, p)
self:PlaySound(p.self_user.sex,
self:GetSoundFileName(self._cardCheck.type, num, self:GetIsNewBout(seat)
))
2025-05-24 14:29:14 +08:00
end
if step.cmd == RunFast_Record_Event.Evt_Pass then
local seat = step.current_out_seat
local p = self._room:GetPlayerBySeat(seat)
local info = self._player_card_info[self:GetPos(seat)]
info:SetOutCardInfo(nil, true)
self:ClearNextSeatOutCard(seat)
end
if step.cmd == RunFast_Record_Event.Evt_NewRound then
for i = 1, #self._room.player_list do
local p = self._room:GetPlayerBySeat(i)
local card_info = self._player_card_info[self:GetPos(p.seat)]
card_info:SetOutCardInfo(nil, false)
end
end
if step.cmd == RunFast_Record_Event.Evt_result then
2026-02-07 20:42:59 +08:00
local result = step.result
for i = 1, #result do
local card_info = self._player_card_info[self:GetPos(result[i].seat)]
2026-02-04 15:07:37 +08:00
2026-02-07 20:42:59 +08:00
if result[i].entrust ~= nil and result[i].entrust == true then
local head_info = self._player_info[self:GetPos(result[i].seat)]
head_info:MarkTuoguan()
2026-02-04 15:07:37 +08:00
end
2026-02-07 20:42:59 +08:00
-- head_info:UpdateScore(result[i].score)
card_info:PlayScore(result[i].score, false, step.win_seat == result[i].seat)
2025-05-24 14:29:14 +08:00
end
end
if step.cmd == RunFast_Record_Event.Evt_Result then
local Result = step.Result
2025-06-04 17:50:55 +08:00
self.result_view = RunFast_ResultView.new(self._root_view, Result.info, self._room.room_id, Result.type,
Result.winseat, 0, Result.remaincards)
2025-05-24 14:29:14 +08:00
local num = self._view:GetChildIndex(self._view:GetChild("panel_record"))
self._view:AddChildAt(self.result_view._view, num)
else
2026-02-07 20:42:59 +08:00
if self.result_view then
self.result_view:Dispose()
end
2025-05-24 14:29:14 +08:00
end
end
function M:GenerateAllStepData(data)
local cmdList = self.cmdList
self._step = {}
local step = {}
local info = data.info
step.cmd = ''
step.win = 0
step.player_card_data = {}
for i = 1, #self._room.player_list do
local p = info.playerData[i]
local u = {}
u.seat = p.seat
u.hand_list = p.hand_card
u.hand_count = #u.hand_list
u.out_card_list = {}
step.player_card_data[u.seat] = u
end
self._step[#self._step + 1] = step
for i = 1, #cmdList do
local tem = cmdList[i]
self._cmdmap[tem.cmd](self, tem, i)
end
end
function M:CmdOutCard(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.current_out_seat = cmd.seat
local u = data.player_card_data[cmd.seat]
u.card_list = cmd.data.card
data.out_card_list = cmd.data.card_list
for i = 1, #data.out_card_list do
local out_card = data.out_card_list[i]
for j = 1, #u.hand_list do
if u.hand_list[j] == out_card then
list_remove(u.hand_list, out_card)
break
end
end
end
end
function M:CmdNewRound(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
end
function M:CmdPass(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.current_out_seat = cmd.seat
end
2025-06-04 17:50:55 +08:00
2025-05-24 14:29:14 +08:00
function M:Cmdresult(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
2026-02-07 20:42:59 +08:00
data.result = cmd.data.result
data.win_seat = cmd.seat
2025-05-24 14:29:14 +08:00
end
function M:CmdResult(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.Result = cmd.data
for i = 1, #data.Result.info do
local p = data.Result.info[i]
p.nick = self._room:GetPlayerBySeat(p.seat).self_user.nick_name
end
end
function M:CopyLastStep(index)
local step = {}
local last_step = self._step[index]
step = membe_clone(last_step)
step.player_card_data = {}
local card_data = step.player_card_data
for i = 1, #last_step.player_card_data do
card_data[i] = {}
card_data[i].hand_list = membe_clone(last_step.player_card_data[i].hand_list)
card_data[i].out_card_list = membe_clone(last_step.player_card_data[i].out_card_list)
end
step.Result = nil
self._step[#self._step + 1] = step
return step
end
function M:ClearNextSeatOutCard(currenOutCardSeat)
local people_num = self._room.room_config.people_num
local next_seat = currenOutCardSeat + 1
if next_seat > people_num then
next_seat = next_seat - people_num
end
local p = self._room:GetPlayerBySeat(next_seat)
local card_info = self._player_card_info[self:GetPos(p.seat)]
card_info:SetOutCardInfo(nil, false)
end
2026-02-07 20:42:59 +08:00
function M:UpdateRound()
local round = self._room.curren_round
self._tex_round.text = string.format('第 %d 局', round)
2025-05-24 14:29:14 +08:00
end
function M:NextRecordPlay()
self._totalRound = tonumber(self._totalRound)
local result = PlayBackView.NextRecordPlay(self)
if not result then
return
end
self:ChangePlayState(false)
self._speed = 1
self._playFoward = true
self:ChangeTextSpeed()
2026-02-07 20:42:59 +08:00
if self.result_view then
self.result_view:Dispose()
self.result_view = nil
end
2025-05-24 14:29:14 +08:00
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()
2026-02-07 20:42:59 +08:00
if self.result_view then
self.result_view:Dispose()
self.result_view = nil
end
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: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
2025-05-24 14:29:14 +08:00
end
2026-02-04 15:07:37 +08:00
function M:_Effect(type1, player)
if type1 == 1 or type1 == 3 or type1 == 7 then
self._popEvent = true
2025-05-24 14:29:14 +08:00
return
end
2026-02-04 15:07:37 +08:00
local info = self._player_card_info[self:GetPos(player.seat)]
info:PlayEffect(type1, function()
self._popEvent = true
end)
2025-05-24 14:29:14 +08:00
end
2026-02-04 15:07:37 +08:00
function M:GetSoundFileName(type, num, isNewBout)
local fileName
if type == 1 or type == 3 or type == 7 then
local num = self._cardCheck.lastMinCard
if type == 1 then
fileName = string.format("1_%d", num)
elseif type == 3 then
fileName = string.format("2_%d", num)
elseif type == 7 then
fileName = string.format("3_%d", num)
end
2025-05-24 14:29:14 +08:00
else
2026-02-04 15:07:37 +08:00
if not isNewBout and type ~= 6 then
local r = math.random(1, 3)
fileName = "dani_" .. r
else
if type == 8 or type == 12 then
fileName = 5
else
fileName = type
end
end
2025-05-24 14:29:14 +08:00
end
2026-02-04 15:07:37 +08:00
return fileName
2025-05-24 14:29:14 +08:00
end
2026-02-04 15:07:37 +08:00
function M:PlaySound(sex, path)
local sex_path = ViewUtil.Sex_Chat[sex] -- 1 男 2 女
local sound_path = string.format("extend/poker/runfast/sound/%s/%s.mp3", sex_path, path)
ViewUtil.PlaySound("RunFastNew_PK", sound_path)
2025-05-24 14:29:14 +08:00
end
2026-02-04 15:07:37 +08:00
function M:GetIsNewBout(seat)
local passCount = 0
for i = 1, #self._room.player_list do
local player = self._room.player_list[i]
if seat ~= player.seat then
local isPass = self:GetIsPass(player.out_card_list)
if isPass then
passCount = passCount + 1
end
2025-05-24 14:29:14 +08:00
end
2026-02-04 15:07:37 +08:00
end
if passCount == self._room.room_config.people_num - 1 then
return true
2025-05-24 14:29:14 +08:00
else
2026-02-04 15:07:37 +08:00
return false
2025-05-24 14:29:14 +08:00
end
end
2026-02-04 15:07:37 +08:00
function M:GetIsPass(cardlist)
if #cardlist == 0 then
return true
end
if cardlist[1] ~= nil and cardlist[1] == 0 then
return true
2025-05-24 14:29:14 +08:00
end
2026-02-04 15:07:37 +08:00
return false
2025-05-24 14:29:14 +08:00
end
function M:OnUpdate()
if self._play then
if (self._currentStep == #self.cmdList + 1 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
if self._currentStep > 0 then
self:ShowStep(self._currentStep)
end
end
end
end
function M:Destroy()
UpdateBeat:Remove(self.OnUpdate, self)
PlayBackView.Destroy(self)
end
return M