hengyang_client/lua_probject/extend_project/extend/poker/duoduo/EXPlayerBackView.lua

585 lines
19 KiB
Lua
Raw Permalink Normal View History

2025-12-18 20:23:31 +08:00
---
--- Created by 谌建军.
--- DateTime: 2017/12/25 13:52
---
local PKPlayBackView = require('main.poker.PKPlayBackView')
local EXPlayerCardInfoView = import('.EXPlayerPokerInfoView')
local EXPlayerSelfCardInfoView = import('.EXPlayerSelfPokerInfoView')
local PlayerInfoView = import('.EXPlayerInfoView')
local EXRightPanelView = import(".EXRightPanelView")
local EXResultView = import(".EXResultView")
local EXCardCheck = import(".CardCheck")
local M = {}
local EXRecord_Event = {
Evt_OutCard = 'OutCard',
Evt_Pass = 'pass',
Evt_NewRound = 'newindex',
Evt_result = 'result',
Evt_Result = 'Result',
Evt_Opt = 'prompt'
}
local default_bg = 1
local bg_config = {
{ id = 1, url = 'extend/poker/duoduo/bg/bg1', thumb = 'ui://Extend_Poker_DuoDuo/table_bg1' },
{ id = 2, url = 'extend/poker/duoduo/bg/bg2', thumb = 'ui://Extend_Poker_DuoDuo/table_bg2' },
{ id = 3, url = 'extend/poker/duoduo/bg/bg3', thumb = 'ui://Extend_Poker_DuoDuo/table_bg3' }
}
--- Create a new
function M.new()
setmetatable(M, { __index = PKPlayBackView })
local self = setmetatable({}, { __index = M })
self.class = 'EXPlayBackView'
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/duoduo/ui/Extend_Poker_DuoDuo')
PKPlayBackView.InitView(self, "ui://Extend_Poker_DuoDuo/EXMain_New_" .. room.room_config.people_num,
default_bg, bg_config)
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
self._rightPanelView = EXRightPanelView.new(self, rightpanel)
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
for i = 1, #list do
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
self._ctr_inClear = self._view:GetController('Inclear')
self._cardCheck = EXCardCheck:InitFlag()
self._gamectr._cardCheck = self._cardCheck
self._eventmap = {}
self._cmdmap = {}
self._cmdmap[EXRecord_Event.Evt_OutCard] = self.CmdOutCard
self._cmdmap[EXRecord_Event.Evt_Pass] = self.CmdPass
self._cmdmap[EXRecord_Event.Evt_NewRound] = self.CmdNewRound
self._cmdmap[EXRecord_Event.Evt_result] = self.Cmdresult
self._cmdmap[EXRecord_Event.Evt_Opt] = self.CmdOpt
end
function M:NewPlayerPokerInfoView(view, index)
if index == 1 then
return EXPlayerSelfCardInfoView.new(view, self)
end
return EXPlayerCardInfoView.new(view, self)
end
function M:FillRoomData(data)
-- print("hidezhanji 1111")
self._currentStep = 1
local room = DataManager.CurrenRoom
self._room = DataManager.CurrenRoom
local _player_card_info = self._player_card_info
local roominfo_panel = self._view:GetChild('roominfo_panel1')
self._room.pai = 0
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
-- print("hidezhanji 2222")
head_info._view:GetChild('zhanji').visible = false
if room.hpOnOff == 1 or room:checkHpNonnegative() then
head_info._view:GetChild('zhanji').visible = true
head_info._view:GetChild('text_jifen').text = d2ad(p.total_hp)
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
self:UpdateRound(self._room.curren_round)
self:GenerateAllStepData(data)
self:ShowStep(1)
self:Play()
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.destory_win ~= nil then
coroutine.stop(self.destory_win)
end
self.destory_win = nil
if self.result_view then
self.result_view._root_view:RemoveFromParent()
self.result_view:Destroy()
self._ctr_inClear.selectedIndex = 0
end
self.result_view = nil
end
end
function M:ShowStep(index)
local step = self._step[index]
if step == nil then
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
if step.cmd == EXRecord_Event.Evt_Opt and step.seat == p.seat then
info._view:GetController('out_card_option2').selectedIndex = 1
else
info._view:GetController('out_card_option2').selectedIndex = 0
end
if p.seat ~= self._room.self_player.seat then
info:UpdateHandPoker(p.hand_list, false, true)
else
info:InitPoker(p.hand_list, false)
end
info:SetOutCardInfo(nil, false)
end
if step.cmd == EXRecord_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)
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)
))
end
if step.cmd == EXRecord_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 == EXRecord_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 == EXRecord_Event.Evt_result then
local data = step.data
local over = 0
local info = data.win.info
local win_seat = data.win.winseat
local remaincards = {}
-- local energyTab = arg[5]
local otherpoker_list = self._view:GetChild("otherpoker_list")
local card_info = self._player_card_info[self:GetPos(self._room.self_player.seat)]
if self.dismissWin ~= nil then
self.dismissWin:Destroy()
end
self.dismissWin = nil
if self.MypokerList ~= nil then
-- body
card_info:Clear()
card_info:InitPoker(self.MypokerList, false)
self.MypokerList = nil
end
if otherpoker_list ~= nil then
-- body
otherpoker_list:RemoveChildrenToPool()
otherpoker_list.visible = true
end
if self.destory_win ~= nil then
coroutine.stop(self.destory_win)
end
self.destory_win = nil
self.destory_win = coroutine.start(function()
if win_seat == self._room.self_player.seat then
ViewUtil.PlaySound("DuoDuo_PK", "extend/poker/duoduo/sound/end_music.mp3")
else
ViewUtil.PlaySound("DuoDuo_PK", "extend/poker/duoduo/sound/lose_music.mp3")
end
coroutine.stop(self._leftClock_continue)
for i = 1, #self._player_card_info do
local card_info = self._player_card_info[i]
card_info._ctr_time_clock.selectedIndex = 0
self._left_time = 0
end
for i = 1, #info do
local player = info[i]
local p = self._room:GetPlayerBySeat(player.seat)
local head_info = self._player_info[self:GetPos(player.seat)]
head_info:SetBaoDan(false)
head_info._view:GetChild('text_jifen').text = player.score
head_info:PlayScore(player.winscore, win_seat == player.seat)
end
coroutine.wait(2)
self.result_view = EXResultView.new(self, info, self._room.room_id, over, win_seat, 0,
remaincards)
self.result_view:SetDestroryCallback(function()
for i = 1, #self._player_card_info do
local card_info = self._player_card_info[i]
card_info.ctr_outpoker.selectedIndex = 0
if card_info._ctr_resultOut then
card_info._ctr_resultOut.selectedIndex = 0
end
end
end)
self.result_view:Show()
self.result_view._root_view:RemoveFromParent()
self._view:AddChildAt(self.result_view._root_view,
self._view:GetChildIndex(self._view:GetChild('mask_tips')) - 1)
if self.WinItem_view ~= nil then
self.WinItem_view:Dispose()
self.WinItem_view = nil
end
if self.rank_view ~= nil then
self.rank_view:Dispose()
self.rank_view = nil
end
if self._room.self_player.entrust == true then
local btn_confirm = self.result_view._view:GetChild("btn_confirm")
btn_confirm.onClick:Call()
end
ViewUtil.PlaySound("DuoDuo_PK", "extend/poker/duoduo/sound/end_music.mp3")
end)
if over == 1 then
-- body
self:UnmarkSelfTuoguan()
ControllerManager.ChangeController(LoddyController)
end
end
if step.cmd == EXRecord_Event.Evt_Result then
local Result = step.Result
self.result_view = EXResultView.new(self._root_view, Result.info, self._room.room_id, Result.type,
Result.winseat, 0, Result.remaincards)
local num = self._view:GetChildIndex(self._view:GetChild("panel_record"))
self._view:AddChildAt(self.result_view._view, num)
else
-- if self.result_view then
-- self.result_view:Dispose()
-- end
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
function M:Cmdresult(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.data = cmd.data
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:CmdOpt(cmd, index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.seat = cmd.seat
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
function M:UpdateRound(round)
local total_round = self._room.room_config.Times
-- self._text_round.text = string.format("%d / %d 局", round, total_round)
if not self._text_currenRound then
self._text_currenRound = self._view:GetChild('Text_CurrenRound')
end
if not self._text_maxRound then
self._text_maxRound = self._view:GetChild('Text_MaxMaxRound')
end
self._text_currenRound.text = round
self._text_maxRound.text = string.format("/%s局", total_round)
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()
-- if self.result_view then
-- self.result_view:Dispose()
-- self.result_view = nil
-- end
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()
-- if self.result_view then
-- self.result_view:Dispose()
-- self.result_view = nil
-- end
end
function M:_Effect(type1, player)
if type1 == 1 or type1 == 3 or type1 == 7 then
self._popEvent = true
return
end
local info = self._player_card_info[self:GetPos(player.seat)]
info:PlayEffect(type1, function()
self._popEvent = true
end)
end
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
else
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
end
return fileName
end
function M:PlaySound(sex, path)
local sex_path = ViewUtil.Sex_Chat[sex] -- 1 男 2 女
local sound_path = string.format("extend/poker/duoduo/sound/%s/%s.mp3", sex_path, path)
ViewUtil.PlaySound("DuoDuo_PK", sound_path)
end
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
end
end
if passCount == self._room.room_config.people_num - 1 then
return true
else
return false
end
end
function M:GetIsPass(cardlist)
if #cardlist == 0 then
return true
end
if cardlist[1] ~= nil and cardlist[1] == 0 then
return true
end
return false
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