changhong/lua_probject/extend_project/extend/poker/chuntian/ChunTian_PlayerBackView.lua

440 lines
14 KiB
Lua

---
--- Created by 谌建军.
--- DateTime: 2017/12/25 13:52
---
local PKPlayBackView = require('main.poker.PKPlayBackView')
local ChunTian_PlayerCardInfoView = import('.ChunTian_PlayerPokerInfoView')
local ChunTian_PlayerSelfCardInfoView = import('.ChunTian_PlayerSelfPokerInfoView')
local PlayerInfoView = import('.EXPlayerInfoView')
local ChunTian_RightPanelView = import(".ChunTian_RightPanelView")
local ChunTian_ResultView = import(".ChunTian_ResultView")
local M = {}
local ChunTian_Record_Event = {
Evt_OutCard = 'OutCard',
Evt_Pass = 'pass',
Evt_NewRound = 'newindex',
Evt_result = 'result',
Evt_Result = 'Result'
}
local default_bg = 1
local bg_config = {
{id = 1, url = 'extend/poker/chuntian/bg/bg1', thumb = 'ui://Extend_Poker_ChunTian/table_bg1'},
{id = 2, url = 'extend/poker/chuntian/bg/bg2', thumb = 'ui://Extend_Poker_ChunTian/table_bg2'},
{id = 3, url = 'extend/poker/chuntian/bg/bg3', thumb = 'ui://Extend_Poker_ChunTian/table_bg3'}
}
--- Create a new
function M.new()
setmetatable(M, {__index = PKPlayBackView})
local self = setmetatable({}, {__index = M})
self.class = 'ChunTian_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/chuntian/ui/Extend_Poker_ChunTian')
PKPlayBackView.InitView(self, 'ui://Extend_Poker_ChunTian/ChunTian_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 = ChunTian_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
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[ChunTian_Record_Event.Evt_OutCard] = self.CmdOutCard
self._cmdmap[ChunTian_Record_Event.Evt_Pass] = self.CmdPass
self._cmdmap[ChunTian_Record_Event.Evt_NewRound] = self.CmdNewRound
self._cmdmap[ChunTian_Record_Event.Evt_result] = self.Cmdresult
self._cmdmap[ChunTian_Record_Event.Evt_Result] = self.CmdResult
end
function M:NewPlayerPokerInfoView(view, index)
if index == 1 then
return ChunTian_PlayerSelfCardInfoView.new(view, self)
end
return ChunTian_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
p.out_card_list = step.player_card_data[i].out_card_list
p.hand_left_count = #p.hand_list
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
if step.cmd == ChunTian_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)
end
if step.cmd == ChunTian_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 == ChunTian_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 == ChunTian_Record_Event.Evt_result then
local result = step.result
for i = 1, #result do
local card_info = self._player_card_info[self:GetPos(result[i].seat)]
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()
end
-- head_info:UpdateScore(result[i].score)
card_info:PlayScore(result[i].score, false, step.win_seat == result[i].seat)
end
end
if step.cmd == ChunTian_Record_Event.Evt_Result then
local Result = step.Result
self.result_view = ChunTian_ResultView.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.result = cmd.data.result
data.win_seat = cmd.seat
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
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