local ZPPlayBackView = require('main.zipai.ZPPlayBackView') local PlayerSelfCardInfoView = import('.PlayerSelfCardInfoView') local PlayerCardInfoView = import('.PlayerCardInfoView') local RunBeard_ResultView = import('.RunBeard_ResultView') local M = {} local Record_Event = { Evt_OutCard = 'OutCard', Evt_GetCard = 'GetCard', Evt_Action = 'Action', Evt_ThrowCard = 'ThrowCard', Evt_AddCard = 'AddCard', Evt_ChangePaiXing = 'ChangePaiXing', Evt_Win = 'Win', Evt_result = 'result' } local function tableSortNumber(a, b) return a.card_code_number > b.card_code_number end --- Create a new function M.new() setmetatable(M, {__index = PlayBackView}) local self = setmetatable({}, {__index = M}) self.class = 'PlayBackView' self:init() return self end function M:InitView(url) local room = self._room self._gamectr = ControllerManager.GetController(GameController) UIPackage.AddPackage('base/main_zipai/ui/Main_RunBeard') UIPackage.AddPackage('extend/zipai/changdepaohuzi/ui/Extend_Poker_ChangdeWHZ') ZPPlayBackView.InitView(self, 'ui://Main_RunBeard/Main_' .. room.room_config.people_num) UpdateBeat:Add(self.OnUpdate, self) local user_id = DataManager.SelfUser.account_id local json_data = Utils.LoadLocalFile(user_id .. room.game_id) if json_data ~= nil then local _data = json.decode(json_data) local typeface = _data['game_typeface'] if typeface == 1 then room.change_card_display = '2_' else room.change_card_display = '1_' end end 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') self.btn_setting = rightpanel:GetChild('btn_setting') self.btn_setting.visible = false self.tex_time = rightpanel:GetChild('tex_time') self.tex_time.visible = false self.gcm_xinhao = rightpanel:GetChild('gcm_xinhao') self.gcm_xinhao.visible = false self.pb_batteryLevel = rightpanel:GetChild('pb_batteryLevel') self.pb_batteryLevel.visible = false local tex_round_item = rightpanel:GetChild('tex_round') if tex_round_item ~= nil then tex_round_item.text = '第 ' .. room.curren_round .. ' 局' end local btn_rule = rightpanel:GetChild('btn_log') if btn_rule ~= nil then btn_rule.onClick:Set( function() if self.RuleView == nil or self.RuleView._is_destroy then self.RuleView = RoomInfoView.new(self._room) end self.RuleView:Show() end ) end local tex_roomid = rightpanel:GetChild('tex_roomid') tex_roomid.text = room.room_id rightpanel:GetChild('tex_gametype').text = room.room_config:GetGameName() self._tex_round = self._view:GetChild('tex_round') self._tex_LeftCard = self._view:GetChild('remaining_card') self._eventmap = {} self._cmdmap = {} self._cmdmap[Record_Event.Evt_OutCard] = self.CmdOutCard self._cmdmap[Record_Event.Evt_GetCard] = self.CmdGetCard self._cmdmap[Record_Event.Evt_Action] = self.CmdAction self._cmdmap[Record_Event.Evt_ThrowCard] = self.CmdThrowCard self._cmdmap[Record_Event.Evt_AddCard] = self.CmdAddCard self._cmdmap[Record_Event.Evt_Win] = self.CmdWin self._cmdmap[Record_Event.Evt_ChangePaiXing] = self.CmdChangePaiXing self._cmdmap[Record_Event.Evt_result] = self.onResult end function M:NewPlayerPokerInfoView(view, index) if index == 1 then return PlayerSelfCardInfoView.new(view, self) end return PlayerCardInfoView.new(view, self) end function M:FillRoomData(data) if self._win_pic then self._win_pic:Dispose() end self._currentStep = 0 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 = room.room_id 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)] card_info:Clear() card_info:SetPlayer(p) if p.seat == room.self_player.seat then card_info:UpdateIsOnClick(false) end local infoHand = self._player_info[self:GetPos(p.seat)] infoHand._view:GetController('huxi').selectedIndex = 1 infoHand._view:GetChild('huxi').text = p.hu_xi if p.total_hp then infoHand._view:GetController('zhanji').selectedIndex = 0 if room.hpOnOff == 1 or room:checkHpNonnegative() then infoHand._view:GetController('zhanji').selectedIndex = 1 infoHand._view:GetChild('tex_jifen').text = d2ad(p.total_hp) end infoHand:UpdateScore() end end self.CheckServerErrorList={} self:UpdateRound(self._room.curren_round) self:GenerateAllStepData(data) self:ShowStep(1) self:UpdateStep(1) end function M:ShowStep(index) local step = self._step[index + 1] self:UpdateStep(index + 1) self:UpdateLeftCard(step.left_card) for i = 1, #step.player_card_data do local p = self._room:GetPlayerBySeat(i) local info = self._player_card_info[self:GetPos(i)] p.card_list = step.player_card_data[i].card_list p.outcard_list = step.player_card_data[i].outcard_list p.fz_list = step.player_card_data[i].fz_list p.hu_xi = step.player_card_data[i].hu_xi p.hand_left_count = #p.card_list if index == 1 then info:Clear() if p.total_hp then local avHand = self._player_info[self:GetPos(p.seat)] local room = DataManager.CurrenRoom avHand._view:GetController('zhanji').selectedIndex = 0 if room.hpOnOff == 1 or room:checkHpNonnegative() then avHand._view:GetController('zhanji').selectedIndex = 1 avHand._view:GetChild('tex_jifen').text = d2ad(p.total_hp) end avHand:UpdateScore() end end if p.hu_xi ~= nil then local infoHand = self._player_info[self:GetPos(p.seat)] infoHand._view:GetChild('huxi').text = p.hu_xi end if step.cmd == Record_Event.Evt_Action then if p.fz_list ~= nil and #p.fz_list > 0 then info:UpdateFzList(p.fz_list) end end if index>1 then for k,v in pairs(self.CheckServerErrorList) do --printlog("k===>>>",k) --printlog("v===>>>",v) --printlog(k,index) --pt(p.card_list) if tonumber(index+1)>tonumber(k) then list_remove(p.card_list,v) end end end if p.seat ~= self._room.self_player.seat then info:InitHandCard(p.card_list) else self._room.self_player.handcard_list = p.card_list info:InitHandCard(false) end --if p.seat == self._room.self_player.seat then --[[if step.cmd == Record_Event.Evt_ChangePaiXing then local _card_list = {} for i = 1, #step.card_list do local data = {} data.card_item = step.card_list[i].card data.index_X = step.card_list[i].X data.index_Y = step.card_list[i].Y _card_list[#_card_list + 1] = data end local info = self._player_card_info[self:GetPos(step.seat)] if step.card_list[1].card ~= nil then info:UpdateHandCards(_card_list) else info:UpdateHandCards(step.card_list) end end--]] --end if step.cmd == Record_Event.Evt_OutCard or step.cmd == Record_Event.Evt_GetCard then if step.DiceCard ~= nil and step.DiceCard ~= 0 then if p.seat == step.seat then info:UpdateOutCardList(step.DiceCard) coroutine.start( function() coroutine.wait(1.5) info:ClearOutCard() end ) end end end if p.outcard_list ~= nil then info:UpdateQiPai(p.outcard_list) end end -- print("step.cmd ",step.cmdm,Record_Event.Evt_Win) if step.cmd == Record_Event.Evt_result then local _room = DataManager.CurrenRoom local result = step.result self._win_pic = UIPackage.CreateObjectFromURL('ui://Main_RunBeard/胡') local info = self._player_card_info[self:GetPos(step.win)] info._mask_liangpai:AddChild(self._win_pic) self._win_pic:Center() if result ~= nil then if self._clearingView == nil then self._clearingView = RunBeard_ResultView.new(self._view) coroutine.start( function() coroutine.wait(0.5) self._clearingView:Show() end ) end local data = result.data.info_list self._clearingView:InitData( 0, _room, result.data, nil, function(...) for i = 1, #data do local p = _room:GetPlayerBySeat(data[i].seat) p.total_score = data[i].total_score -- p.cur_hp = data[i]['cur_hp'] or 0 -- if data[i]['hp_info'] then -- p.cur_hp = data[i].hp_info.cur_hp -- end local card_info = self._player_card_info[self:GetPos(p.seat)] local info = self._player_info[self:GetPos(p.seat)] card_info:Clear() if data[i]['hp_info'] then p.total_score = d2ad(data[i].hp_info.cur_hp) local stotal_hp = data[i].hp_info.total_hp info._view:GetController('zhanji').selectedIndex = 0 if _room.hpOnOff == 1 or _room:checkHpNonnegative() then info._view:GetController('zhanji').selectedIndex = 1 info._view:GetChild('tex_jifen').text = d2ad(stotal_hp) end end info:UpdateScore(p.total_score) end self._clearingView = nil end ) end else if self._win_pic then self._win_pic:Dispose() end end end function M:GenerateAllStepData(data) local cmdList = self.cmdList --pt(cmdList) self._step = {} local step = {} local info = data.info --pt(info) step.cmd = '' step.left_card = info.left_card 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.card_list = p.hand_card u.hand_left_count = #u.card_list u.fz_list = {} u.outcard_list = {} u.hu_xi = 0 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] list_remove(u.card_list, cmd.data.card) data.seat = cmd.seat data.DiceCard = cmd.data.card end function M:CmdGetCard(cmd, index) local data = self:CopyLastStep(index) data.cmd = cmd.cmd data.left_card = cmd.data.left_count local u = data.player_card_data[cmd.seat] data.seat = cmd.seat data.DiceCard = cmd.data.card end function M:CmdThrowCard(cmd, index) local data = self:CopyLastStep(index) data.cmd = cmd.cmd data.seat = cmd.seat data.current_seat = cmd.seat local u = data.player_card_data[cmd.seat] data.out_card_list = cmd.data.card u.outcard_list[#u.outcard_list + 1] = cmd.data.card end function M:CmdAddCard(cmd, index) --printlog("CmdAddCard======>>>",index,cmd.data.card) local data = self:CopyLastStep(index) data.cmd = cmd.cmd local _room = self._room local u = data.player_card_data[cmd.seat] u.card_list[#u.card_list + 1] = cmd.data.card --pt(u.card_list) end function M:onResult(cmd, index) local data = self:CopyLastStep(index) data.cmd = cmd.cmd data.result = cmd.result end function M:CmdChangePaiXing(cmd, index) local data = self:CopyLastStep(index) data.cmd = cmd.cmd data.seat = cmd.seat data.card_list = cmd.data.card_list end function M:CmdAction(cmd, index) local data = self:CopyLastStep(index) data.cmd = cmd.cmd data.seat = cmd.seat local p = data.player_card_data[cmd.seat] local fz = {} p.hu_xi = cmd.data.hu_xi fz.type = cmd.data.type fz.card = cmd.data.card fz.active_card = cmd.data.card fz.opcard = cmd.data.opcard local opcard = fz.opcard local ftype = fz.type local card = fz.card local remove_num = #opcard if ftype == RB_FZType.Chi then p.fz_list[#p.fz_list + 1] = fz for i = 1, remove_num do list_remove(p.card_list, opcard[i]) end elseif ftype == RB_FZType.Bi then p.fz_list[#p.fz_list + 1] = fz for i = 1, remove_num do list_remove(p.card_list, opcard[i]) end list_remove(p.card_list, fz.card) elseif ftype == RB_FZType.Peng then p.fz_list[#p.fz_list + 1] = fz for i = 1, remove_num do list_remove(p.card_list, opcard[i]) end elseif ftype == RB_FZType.Kan then local _room = self._room if #opcard == 2 then p.card_list[#p.card_list + 1] = card end elseif ftype == RB_FZType.ChouWei then p.fz_list[#p.fz_list + 1] = fz for i = 1, 2 do list_remove(p.card_list, opcard[i]) end elseif ftype == RB_FZType.Wei then p.fz_list[#p.fz_list + 1] = fz for i = 1, remove_num do list_remove(p.card_list, opcard[i]) end elseif ftype == RB_FZType.Pao then local num = 0 for i = 1, #p.card_list do if card == p.card_list[i] then num = num + 1 end end local isAddTi = false for i = 1, #p.fz_list do if p.fz_list[i].card == card then p.fz_list[i].type = RB_FZType.Pao isAddTi = true end end if num > 0 then for i = 1, num do list_remove(p.card_list, card) end if isAddTi == false then p.fz_list[#p.fz_list + 1] = fz end end elseif ftype == RB_FZType.Ti then local num = 0 for i = 1, #p.card_list do if card == p.card_list[i] then num = num + 1 end end --table.insert(self.CheckServerErrorList,card) if self.CheckServerErrorList==nil then self.CheckServerErrorList={} end self.CheckServerErrorList[index]=card local isAddTi = false for i = 1, #p.fz_list do if p.fz_list[i].card == card then p.fz_list[i].type = RB_FZType.Ti isAddTi = true end end if num > 0 then for i = 1, num do list_remove(p.card_list, card) end if isAddTi == false then p.fz_list[#p.fz_list + 1] = fz end end end end function M:CmdWin(cmd, index) local data = self:CopyLastStep(index) data.cmd = cmd.cmd data.win = cmd.seat end function M:UpdateLeftCard(num) self._tex_LeftCard.text = '剩余 ' .. num .. ' 张牌' end function M:UpdateRound(round) self._tex_round.text = '第 ' .. round .. '/' .. self._room.room_config.round .. ' 局' end function M:CopyLastStep(index) local step = {} local last_step = self._step[index] step = self:deepcopy(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].card_list = self:deepcopy(last_step.player_card_data[i].card_list) card_data[i].outcard_list = self:deepcopy(last_step.player_card_data[i].outcard_list) card_data[i].fz_list = self:deepcopy(last_step.player_card_data[i].fz_list) card_data[i].hand_left_count = #card_data[i].card_list card_data[i].hu_xi = self:deepcopy(last_step.player_card_data[i].hu_xi) end --pt(card_data) self._step[#self._step + 1] = step return step end -- lua table 深拷贝 function M:deepcopy(object) local lookup_table = {} local function _copy(object) if type(object) ~= 'table' then return object elseif lookup_table[object] then return lookup_table[object] end local new_table = {} lookup_table[object] = new_table for index, value in pairs(object) do new_table[_copy(index)] = _copy(value) end return setmetatable(new_table, getmetatable(object)) end return _copy(object) end function M:NextRecordPlay() printlog("NextRecordPlay") 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() printlog("LastRecordPlay") 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: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 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:Destroy() UpdateBeat:Remove(self.OnUpdate, self) PlayBackView.Destroy(self) end function M:UpdateStep(step) self._record:GetChild('tex_step').text = '第 ' .. step .. ' / ' .. #self._step .. '步' end return M