changhong/lua_probject/extend_project/extend/poker/mushi/MuShi_PlayerBackView.lua

544 lines
17 KiB
Lua

---
--- Created by 谌建军.
--- DateTime: 2017/12/25 13:52
---
local PKPlayBackView = require('main.poker.PKPlayBackView')
local MuShi_PlayerCardInfoView = import('.MuShi_PlayerPokerInfoView')
local MuShi_PlayerSelfCardInfoView = import('.MuShi_PlayerSelfPokerInfoView')
local PlayerInfoView = import('.EXPlayerInfoView')
local MuShi_RightPanelView = import(".MuShi_RightPanelView")
local MuShi_ResultView = import(".MuShi_ResultView")
local M = {}
local MuShi_Record_Event = {
Evt_alertQiangZhuang = 'alertQiangZhuang',
Evt_userQiangZhuang = 'userQiangZhuang',
Evt_zhuangInfo = 'zhuangInfo',
Evt_alertXiaZhu = 'alertXiaZhu',
Evt_userXiaZhu = 'userXiaZhu',
Evt_alertBuPai = 'alertBuPai',
Evt_playerBuPai = 'playerBuPai',
Evt_playerSendCards = 'playerSendCards',
Evt_result = 'result',
Evt_OutCard = 'OutCard',
Evt_Pass = 'pass',
Evt_NewRound = 'newindex',
Evt_Result = 'Result'
}
local default_bg = 1
local bg_config = {
{id = 1, url = 'extend/poker/mushi/bg/bg1', thumb = 'ui://Extend_Poker_MuShi/table_bg1'},
{id = 2, url = 'extend/poker/mushi/bg/bg1', thumb = 'ui://Extend_Poker_MuShi/table_bg1'},
{id = 3, url = 'extend/poker/mushi/bg/bg1', thumb = 'ui://Extend_Poker_MuShi/table_bg1'}
}
--- Create a new
function M.new()
setmetatable(M, {__index = PKPlayBackView})
local self = setmetatable({}, {__index = M})
self.class = 'MuShi_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/mushi/ui/Extend_Poker_MuShi')
PKPlayBackView.InitView(self, 'ui://Extend_Poker_MuShi/MuShi_Main_' .. self._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 = MuShi_RightPanelView.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
self.btnstar = self._view:GetChild("btnstar")
self.btn_ready1 = self._view:GetChild("btn_ready1")
self.btn_ready1.visible = false
self.btnstar.visible = false
-- 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._eventmap = {}
self._cmdmap = {}
self._cmdmap[MuShi_Record_Event.Evt_alertQiangZhuang] = self.CmdAlertQiangZhuang
self._cmdmap[MuShi_Record_Event.Evt_userQiangZhuang] = self.CmdUserQiangZhuang
self._cmdmap[MuShi_Record_Event.Evt_zhuangInfo] = self.CmdZhuangInfo
self._cmdmap[MuShi_Record_Event.Evt_alertXiaZhu] = self.CmdAlertXiaZhu
self._cmdmap[MuShi_Record_Event.Evt_userXiaZhu] = self.CmdUserXiaZhu
self._cmdmap[MuShi_Record_Event.Evt_alertBuPai] = self.CmdAlertBuPai
self._cmdmap[MuShi_Record_Event.Evt_playerBuPai] = self.CmdPlayerBuPai
self._cmdmap[MuShi_Record_Event.Evt_playerSendCards] = self.CmdPlayerSendCards
self._cmdmap[MuShi_Record_Event.Evt_result] = self.CmdResult
self._cmdmap[MuShi_Record_Event.Evt_OutCard] = self.Wuyong
self._cmdmap[MuShi_Record_Event.Evt_Pass] = self.Wuyong
self._cmdmap[MuShi_Record_Event.Evt_NewRound] = self.Wuyong
self._cmdmap[MuShi_Record_Event.Evt_Result] = self.Wuyong
self:CuoPai()
end
function M:CuoPai()
self.cuopai = self._view:GetChild("cuopai")
self.cuopai.visible = false
-- print("self.btnY ",self.btnY)
end
function M:Wuyong()
end
function M:NewPlayerPokerInfoView(view, index)
if index == 1 then
return MuShi_PlayerSelfCardInfoView.new(view, self)
end
return MuShi_PlayerCardInfoView.new(view, self)
end
function M:FillRoomData(data)
--print("hidezhanji 1111")
self._currentStep = 1
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
-- 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:GenerateAllStepData(data)
self:ShowStep(1)
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
-- info:InitPoker(p.hand_list, false)
-- end
-- Evt_alertQiangZhuang = 'alertQiangZhuang',
-- Evt_userQiangZhuang = 'userQiangZhuang',
-- Evt_zhuangInfo = 'zhuangInfo',
-- Evt_alertXiaZhu = 'alertXiaZhu',
-- Evt_userXiaZhu = 'userXiaZhu',
-- Evt_alertBuPai = 'alertBuPai',
-- Evt_playerBuPai = 'playerBuPai'
if step.cmd == MuShi_Record_Event.Evt_alertQiangZhuang then
for _, player in ipairs(self._room.player_list) do
local player_head = self._player_info[self:GetPos(player.seat)]
player_head:MarkBank(false)
player_head:UpdateFen(-1,0)
end
self._player_card_info[1]:StarQiangZhuang(1)
end
if step.cmd == MuShi_Record_Event.Evt_userQiangZhuang then
local seat = step.seat
local index = step.index
if (seat == self._room.self_player.seat) then
self._player_card_info[1]:StarQiangZhuang(0)
end
local head_info = self._player_info[self:GetPos(seat)]
head_info:UpdateFen(0,index)
end
if step.cmd == MuShi_Record_Event.Evt_zhuangInfo then
local seat = step.seat
local score = step.score
local head_info = self._player_info[self:GetPos(seat)]
for _, player in ipairs(self._room.player_list) do
local player_head = self._player_info[self:GetPos(player.seat)]
player_head:MarkBank(false)
end
head_info:UpdateFen(1,score)
head_info:MarkBank(true)
end
if step.cmd == MuShi_Record_Event.Evt_alertXiaZhu then
local seat = step.seat
if (seat ~= self._room.self_player.seat) then
self._player_card_info[1]:StarBet(1)
end
end
if step.cmd == MuShi_Record_Event.Evt_userXiaZhu then
local seat = step.seat
local index = step.index
local head_info = self._player_info[self:GetPos(seat)]
head_info:UpdateFen(2,index)
if (seat == self._room.self_player.seat) then
self._player_card_info[1]:StarBet(0)
end
end
if step.cmd == MuShi_Record_Event.Evt_alertBuPai then
local seat = step.seat
if(seat == self._room.self_player.seat) then
self._player_card_info[1]:ChangeCtrBuPai(1)
end
end
if step.cmd == MuShi_Record_Event.Evt_playerBuPai then
local seat = step.seat
local bupai = step.bupai
local card = step.card
--printlog("补牌================",bupai,card)
if (bupai == 1) then
local card_info = self._player_card_info[self:GetPos(seat)]
card_info:AddPoker(card,1)
end
if self._room.self_player.seat == seat then
local player_card_info = self._player_card_info[1]
player_card_info:ChangeCtrBuPai(0)
end
end
if step.cmd == MuShi_Record_Event.Evt_alertBuPai then
local seat = step.seat
if(seat == self._room.self_player.seat) then
self._player_card_info[1]:ChangeCtrBuPai(1)
end
end
if step.cmd == MuShi_Record_Event.Evt_playerSendCards then
local seat = step.seat
local cards = step.cards
local info = self._player_card_info[self:GetPos(seat)]
info:InitPoker1(cards)
end
if step.cmd == MuShi_Record_Event.Evt_result then
local result = step.result
for i = 1,#result do
local seat = result[i].seat
local cardType = result[i].cardType
local cardPoint = result[i].cardPoint
local card_info = self._player_card_info[self:GetPos(seat)]
card_info:SetCarType(cardType,cardPoint)
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:CmdAlertQiangZhuang(cmd,index) --通知抢庄
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
end
function M:CmdUserQiangZhuang(cmd,index) --玩家抢庄
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.seat = cmd.data.seat
data.index = cmd.data.index
data.score = cmd.data.score
end
function M:CmdZhuangInfo(cmd,index) --定庄
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.seat = cmd.data.seat
data.index = cmd.data.index
data.score = cmd.data.score
end
function M:CmdAlertXiaZhu(cmd,index) --通知下注
local data = self:CopyLastStep(index)
data.cmd = cmd.data.cmd
data.seat = cmd.data.seat
end
function M:CmdUserXiaZhu(cmd,index) --玩家下注
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.seat = cmd.data.seat
data.index = cmd.data.index
end
function M:CmdAlertBuPai(cmd,index) --通知补牌
local data = self:CopyLastStep(index)
data.cmd = cmd.data.cmd
data.seat = cmd.data.seat
end
function M:CmdPlayerBuPai(cmd,index) --玩家补牌
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.bupai = cmd.data.bupai
data.card = cmd.data.card
end
function M:CmdPlayerSendCards(cmd,index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.seat = cmd.data.seat
data.cards = cmd.data.cards
end
function M:CmdResult(cmd,index)
local data = self:CopyLastStep(index)
data.cmd = cmd.cmd
data.result = cmd.data.result
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()
local round = self._room.curren_round
self._tex_round.text = string.format('第 %d 局', 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: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 + 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