local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef") local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions") local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound") local ZPWanFa=ZPFramework.ImportWanFa("luaScript.SubGameDefine.ZiPai.ZPWanFa") local PokerUtil = require("zp_doushisi.luaScript.Views.Room.doushisiPokerUtil") local douishisiRoomXiaoJuView = class("douishisiRoomXiaoJuView", cc.UIView) function douishisiRoomXiaoJuView:ctor(nextCallBackFun,isRecontect) douishisiRoomXiaoJuView.super.ctor(self); self.isRecontect = isRecontect self.nextCallBack = nextCallBackFun self.xiaojuData = app.room.roomInfo.playList self.isShow = false if self.isRecontect then self.xiaojuData = app.room.roomInfo.arrayTableInfo end self.allNode = {} self.showHu = {} end function douishisiRoomXiaoJuView:loadUI() local ui = loadUI("zp_doushisi/res/ui/ui_fangjian/doushisi_ui_xiaoju.ui"); self.ui = ui; self:addChild(ui); end function douishisiRoomXiaoJuView:onEnter() douishisiRoomXiaoJuView.super.onEnter(self) self:loadUI() -- 下一局 self.ui.Items.Button_Next:registerClick(handler(self , self.onClickNext)) --显示总结算 self.ui.Items.Button_All:registerClick(handler(self , self.onClickZongJieSuan)) --self.ui.Items.Button_ChaPai:setVisible(false) --查牌 self.ui.Items.Button_ChaPai:registerClick(handler(self , self.onClickChaPai)) --胡牌类型item,复制用 --显示结束 if app.room.roomInfo.isGameOver == 1 then self.ui.Items.Button_Next:setVisible(false) self.ui.Items.Button_All:setVisible(true) else self.ui.Items.Button_All:setVisible(false) end --组合牌第一个点的坐标 self.huweaveCardPos = cc.p(100,85) self.handcardPos = cc.p(100,85) self.weaveCardPos = cc.p(100,30) if app.room.roomInfo.playerNum == 2 or app.room:getActualPlayerNum() == 2 then self.ui.Items.Layout_Player_4:setVisible(false) self.ui.Items.Layout_Player_3:setVisible(false) self.ui.Items.Layout_Player:doLayout() self.ui.Items.Layout_Player:requestDoLayout() elseif app.room.roomInfo.playerNum == 3 or app.room:getActualPlayerNum() == 3 then self.ui.Items.Layout_Player_4:setVisible(false) self.ui.Items.Layout_Player:doLayout() self.ui.Items.Layout_Player:requestDoLayout() end --初始化人物信息 self:initPlayerView() self:initOtherData() self:updatePlayerInfo() end function douishisiRoomXiaoJuView:initPlayerView() for i=1,4 do local head = "ImageView_head_"..i local name = "Text_Name_"..i local id = "Text_ID_"..i local winScore = "TextBMFont_WinScore_"..i local loseScore = "TextBMFont_LoseScore_"..i local layout = "Layout_Hand_"..i --local loseBg = "ImageView_pt_bg_"..i local layoutHuinfo = "Layout_HuInfo_"..i local fangPao = "ImageView_FangPao_"..i local layoutHuTypes = "Layout_huTypes_"..i local textFanshu = "Text_fanshu_"..i local toujia = "ImageView_toujia_"..i local xiaojia = "ImageView_xiaojia_"..i local piao = "ImageView_piao_"..i local textLeixing = "Text_leixing_"..i local fengding = "ImageView_fengding_"..i self.allNode[i] = {} self.allNode[i].nodeHead = self.ui.Items[head] self.allNode[i].nodeName = self.ui.Items[name] self.allNode[i].nodeID = self.ui.Items[id] self.allNode[i].nodewinScore = self.ui.Items[winScore] self.allNode[i].nodeloseScore = self.ui.Items[loseScore] self.allNode[i].nodeLayout = self.ui.Items[layout] --self.allNode[i].nodeloseBg = self.ui.Items[loseBg] self.allNode[i].nodelayoutHuinfo = self.ui.Items[layoutHuinfo] self.allNode[i].nodefangPao = self.ui.Items[fangPao] self.allNode[i].nodelayoutHuTypes = self.ui.Items[layoutHuTypes] self.allNode[i].nodefanshu = self.ui.Items[textFanshu] self.allNode[i].nodetoujia = self.ui.Items[toujia] self.allNode[i].nodexiaojia = self.ui.Items[xiaojia] self.allNode[i].nodepiao = self.ui.Items[piao] self.allNode[i].nodeleixing = self.ui.Items[textLeixing] self.allNode[i].nodefengding = self.ui.Items[fengding] end end --是否是小家uid function douishisiRoomXiaoJuView:isLittleUid(uid) --[[ if not uid then return false end local viewId = app.room:getViewIdByUserId(uid) if not viewId then return false end local seatId = app.room:getSeatIdByViewId(viewId) if not seatId then return false end if app.room.roomInfo.xiaoSeatId and app.room.roomInfo.xiaoSeatId == seatId then return true else return false end--]] return false end --获取最大得分 function douishisiRoomXiaoJuView:getMaxTurnScore(t) local score = 0 for i,j in pairs(t) do j.nTurnScore = tonumber(j.nTurnScore) if j.nTurnScore > score then score = j.nTurnScore end end return score end function douishisiRoomXiaoJuView:updatePlayerInfo() self.isHaveUse = {} local indexPlayer = 2 local maxTurnScore = self:getMaxTurnScore(self.xiaojuData) --按要求赢家要摆在第一个位置 for k,v in pairsByKeys(self.xiaojuData) do if app.room:checkUserIDIsInTable(v.nUserId) then v.nTurnScore = tonumber(v.nTurnScore) local i = indexPlayer local myuid = app.room:getMyUserId() if app.room.roomInfo.stopFlag ~= ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL and table.nums(app.room.roomInfo.hupaiInfo) == 0 then --如果不是正常结算并且没有胡牌信息第一排显示自己 if v.nUserId == myuid then i = 1 else indexPlayer = indexPlayer + 1 end else if (v.nTurnScore == maxTurnScore and not self.isHaveUse[1] and (not self:isLittleUid(v.nUserId))) then i = 1 elseif self:isLittleUid(v.nUserId) then i = 4 else indexPlayer = indexPlayer + 1 end end if i== 4 and (not self:isLittleUid(v.nUserId)) then for tt=1,4 do if not self.isHaveUse[tt] then i = tt end end self.isHaveUse[i] = true elseif not self.isHaveUse[i] then self.isHaveUse[i] = true else for tt=1,4 do if not self.isHaveUse[tt] then i = tt end end self.isHaveUse[i] = true end local roomInfo = app.room.roomInfo local userInfo = app.room:getUserInfo(v.nUserId) local viewId = app.room:getViewIdByUserId(v.nUserId) local nWinerId = app.room.roomInfo.winUserId local dianPaoUserId = app.room.roomInfo.dianPaoUserId local bankerId = app.room:getUserIdBySeatId(app.room.roomInfo.nBankSeatId) local stopFlag = app.room.roomInfo.stopFlag local baoPeiUserId = app.room.roomInfo.baopeiUserid local xiaojiaid = self:getXiaojiaUid() if stopFlag ~= 0 then self.allNode[i].nodefanshu:setVisible(false) self.allNode[i].nodelayoutHuTypes:setVisible(false) end self.allNode[i].nodefengding:setVisible(false) if i == 1 then self.ui.Items.Text_mingTang:setVisible(false) end if v.nTurnScore > 0 then self.allNode[i].nodewinScore:setText(tostring("+"..v.nTurnScore)) self.allNode[i].nodeloseScore:setVisible(false) else self.allNode[i].nodeloseScore:setText(v.nTurnScore) self.allNode[i].nodewinScore:setVisible(false) end self.allNode[i].nodelayoutHuinfo:setVisible(false) --先设置默认头像 local width = self.allNode[i].nodeHead:getContentSize().width local nickname = "" if userInfo and userInfo.nickname then nickname = getSubStringNickname(userInfo.nickname) self:updateUserHead(self.allNode[i].nodeHead,v.nUserId, userInfo.sex, userInfo.headimgurl); end --名称 self.allNode[i].nodeName:setText(nickname) --ID self.allNode[i].nodeID:setText(tostring("ID:"..v.nUserId)) --庄家 if bankerId == v.nUserId then self.allNode[i].nodetoujia:setVisible(true) else self.allNode[i].nodetoujia:setVisible(false) end self.allNode[i].nodeID:setVisible(false) self.allNode[i].nodeleixing:setVisible(false) --小家 if xiaojiaid == v.nUserId then self.allNode[i].nodexiaojia:setVisible(true) else self.allNode[i].nodexiaojia:setVisible(false) end --报叫 if v.nBaoPaiStatus == 2 then self.allNode[i].nodepiao:setVisible(true) else self.allNode[i].nodepiao:setVisible(false) end self.allNode[i].nodefangPao:setVisible(false) --组合牌展示 local data = self.xiaojuData[v.nUserId] if not data then return end local isHuUid = false--是否是赢牌者uid for huk,huv in pairs(roomInfo.hupaiInfo) do if huv.huPaiUid == v.nUserId then isHuUid = true app.room.roomInfo.huCard = huv.huCard self.allNode[i].nodefangPao:setVisible(true) self.allNode[i].nodelayoutHuinfo:setVisible(false) if getNumBand(huv.huTypes,ZPDef.HuType.TIAN_HU) > 0 then self.allNode[i].nodefangPao:loadTexture("zp_doushisi/res/ui/zy_fangjian/jiesuan/tianhu.png") elseif getNumBand(huv.huTypes,ZPDef.HuType.DI_HU) > 0 then self.allNode[i].nodefangPao:loadTexture("zp_doushisi/res/ui/zy_fangjian/jiesuan/dihu.png") else self.allNode[i].nodefangPao:loadTexture("zp_doushisi/res/ui/zy_fangjian/jiesuan/hu.png") end if getNumBand(huv.huTypes,ZPDef.HuType.FENGDING) > 0 then self.allNode[i].nodefengding:setVisible(true) end end if huv.huPaiUid == v.nUserId then self.allNode[i].nodefanshu:setVisible(true) self.allNode[i].nodefanshu:setText(huv.huPaiHuShu.."番") --local hustr = self:getHuTypesStr(huv.huPaiUid,huv.huTypes) --self.allNode[i].nodelayoutHuTypes:setVisible(true) else self.allNode[i].nodefanshu:setVisible(false) --self.allNode[i].nodelayoutHuTypes:setVisible(false) end end local tempTxt = "" if v.nBaoPaiStatus == 2 and not isHuUid and app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL then tempTxt = tempTxt.."被杀报".." " self.allNode[i].nodeleixing:setText(tempTxt) self.allNode[i].nodeleixing:setVisible(true) end --点炮 包赔玩家 if dianPaoUserId == v.nUserId then tempTxt = tempTxt.."点炮".." " self.allNode[i].nodeleixing:setText(tempTxt) self.allNode[i].nodeleixing:setVisible(true) end if baoPeiUserId == v.nUserId then tempTxt = tempTxt.."包赔".." " self.allNode[i].nodeleixing:setText(tempTxt) self.allNode[i].nodeleixing:setVisible(true) end if isHuUid then local mingTangTxt = "" if v.nBaoPaiStatus == 2 then mingTangTxt = mingTangTxt.."报叫".." " end if app.room.roomInfo.threeNormolNum and app.room.roomInfo.threeNormolNum > 0 then local num = app.room.roomInfo.threeNormolNum mingTangTxt = mingTangTxt.."三张x"..num.." " end if app.room.roomInfo.fourNormolNum and app.room.roomInfo.fourNormolNum > 0 then local num = app.room.roomInfo.fourNormolNum mingTangTxt = mingTangTxt.."巴牌x"..num.." " end if xiaojiaid == v.nUserId then mingTangTxt = mingTangTxt.."小家" end self.ui.Items.Text_mingTang:setVisible(true) self.ui.Items.Text_mingTang:setText(mingTangTxt) end if i == 1 then isHuUid = true end local index = 0 self.allNode[i].nodeLayout:setVisible(true) --只显示一次胡变为opCard local findHuCard = false local showOneTime = true for key,value in pairs(data.tableWeaveCard) do local list = {} list = value.card local optype = value.type if list then local lens = table.nums(list) for j = 1,lens do self:createWeaveCard(list[j],index,self.allNode[i].nodeLayout,isHuUid) index = index + 1 end end index = index + 1 end local temphandcardList = {} for k,value in pairs(data.handCard) do local card = value.opcard local list = value.card for _,v in pairs(list or {}) do table.insert(temphandcardList,v) end end local handcardList = {} handcardList = app.room:rankHandCard(temphandcardList) local handlens = table.nums(handcardList) local hulieshu = 0 for k,v in pairs(handcardList) do if v == app.room.roomInfo.huCard and not findHuCard and isHuUid then findHuCard = true hulieshu = k end if findHuCard then break end end if hulieshu > 0 then local list = table.remove(handcardList,hulieshu) end self.handcardPos.x = self.huweaveCardPos.x + index * 30 local isHuCard = false local huindex = 0 local resultHandcardlist = app.room:rankHandCard(handcardList) for k,v in pairs(resultHandcardlist) do if isHuUid then self:createHandCard(v,huindex,self.allNode[i].nodeLayout,isHuUid) huindex = huindex + 1 else self:createWeaveCard(v,index,self.allNode[i].nodeLayout,isHuUid) end index = index + 1 end --本局结束 if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL then if #roomInfo.hupaiInfo > 0 then if v.nTurnScore > 0 then if v.nUserId == app.user.loginInfo.uid then ZPSound.PlayWinGame() end else if v.nUserId == app.user.loginInfo.uid then ZPSound.PlayLoseGame() end end end end if isHuUid and true == isHuUid and app.room.roomInfo.huCard and app.room.roomInfo.huCard > 0 then self:createHandCard(app.room.roomInfo.huCard,huindex,self.allNode[i].nodeLayout,isHuUid,true) end end end end function douishisiRoomXiaoJuView:getHuTypeAndBeiShuStr(huType,beishu) local strRul = "" return strRul end --判断是否是赢家uid function douishisiRoomXiaoJuView:getIsWinUid(uid) for huk,huv in pairs(app.room.roomInfo.hupaiInfo) do if huv.huPaiUid == uid then return true end end return false end function douishisiRoomXiaoJuView:createWeaveCard(value,index,node,isHuUid,isHuCard) local ui = self.ui.Items.Layout_HuCard:getCopied() ui.Items = getUIItems(ui); ui:setVisible(true) local fileName = PokerUtil.pokerPng(value,ZPDef.CardType.CARD_TYPE_HU) ui.Items.ImageView_HuCard:loadTextureFromPlist(fileName) if isHuUid then ui:setPosition(cc.p(self.huweaveCardPos.x + index * 30,self.huweaveCardPos.y)) else ui:setPosition(cc.p(self.weaveCardPos.x + index * 30,self.weaveCardPos.y)) end node:addChild(ui) end function douishisiRoomXiaoJuView:createHandCard(value,index,node,isHuUid,isHuCard) local ui = self.ui.Items.Layout_HandCard:getCopied() ui.Items = getUIItems(ui); ui:setVisible(true) local fileName = PokerUtil.pokerPng(value,ZPDef.CardType.CARD_TYPE_HAND) ui.Items.ImageView_HandCard:loadTextureFromPlist(fileName) ui.Items.ImageView_Hu_Icon:setVisible(false) local tempX = 0 if isHuCard then --只有一列的情况 tempX = 20 ui.Items.ImageView_Hu_Icon:setVisible(true) end if isHuUid then ui:setPosition(cc.p(self.handcardPos.x + index * 66 + tempX,self.huweaveCardPos.y)) else ui:setPosition(cc.p(self.weaveCardPos.x + index * 66 + tempX,self.weaveCardPos.y)) end node:addChild(ui) end --在胡牌的那张牌上面显示胡字 --[[function xichongRoomXiaoJuView:showHuCardBox(node,hucard) if not node then return end local cardUI = node:getChildren() if cardUI and type(cardUI) == 'table' then local endPos = cardUI[#cardUI]:getPosition() for i = #cardUI ,1,-1 do local tui = cardUI[i] for k = 1,4 do local name = "ImageView_Card_"..k local hu = "ImageView_card_hu_"..k if tui.Items[name] and tui.Items[name]:isVisible() and tui.Items[name].cardValue == hucard then --把带胡字的那一列放到最后去 tui.Items[hu]:setVisible(true) local pos1 = tui:getPosition() tui:setPosition(endPos) cardUI[#cardUI]:setPosition(pos1) return end end end end end--]] --[[ 获取组合类型文件 ]] function douishisiRoomXiaoJuView:getWeaveTypeFile(sendCardType) if sendCardType == ZPDef.SendCardType.TWO_SEVEN_TEN or sendCardType == ZPDef.SendCardType.ONE_FIVE_TEN or sendCardType == ZPDef.SendCardType.ONE_TWO_THREE or sendCardType == ZPDef.SendCardType.DA_ZI_TWO_AND_ONE or sendCardType == ZPDef.SendCardType.SHUN_ZI then return ZPDef.XiaoJuWeaveCardType.CHI elseif sendCardType == ZPDef.SendCardType.DUI_THREE_SAME then return ZPDef.XiaoJuWeaveCardType.PENG elseif sendCardType == ZPDef.SendCardType.KAN_THREE_SAME or sendCardType == ZPDef.SendCardType.DIRTY_THREE_SAME then return ZPDef.XiaoJuWeaveCardType.WEI elseif sendCardType == ZPDef.SendCardType.KUAI_SHUI_FOUR_SAME or sendCardType == ZPDef.SendCardType.CHI_PAI_PENG_PAO or sendCardType == ZPDef.SendCardType.CHI_PAI_SHAO_PAO then return ZPDef.XiaoJuWeaveCardType.ZHAO elseif sendCardType == ZPDef.SendCardType.GUN_ZI_FOUR_SAME or sendCardType == ZPDef.SendCardType.CHI_PAI_TI then return ZPDef.XiaoJuWeaveCardType.LONG elseif sendCardType == ZPDef.SendCardType.ZHUANG_ZI then return ZPDef.XiaoJuWeaveCardType.JIANG elseif sendCardType == ZPDef.SendCardType.KANPAI_LOCAL then return ZPDef.XiaoJuWeaveCardType.KAN else local txt = string.format("发牌类型为:"..sendCardType) --showTooltip(txt) return "" end end function douishisiRoomXiaoJuView:initOtherData() local roomInfo = app.room.roomInfo local winUserId = app.room.roomInfo.winUserId --规则 self.ui.Items.Text_Rule:setText(ZPWanFa.getRuleInfo(roomInfo.strGameInfo)) --时间 self.ui.Items.Text_Time:setText(getTimeString()) --房号 self.ui.Items.Text_RoomNum:setText("房号:"..tostring(app.room.roomInfo.nShowTableId)) end function douishisiRoomXiaoJuView:updateUserHead(nodeHead,nUserId, sex, headimgurl) setPlayerHeadImage(nUserId, headimgurl, nodeHead); end -- 查牌 function douishisiRoomXiaoJuView:onClickChaPai() playBtnEffect() self:setVisible(false) end -- 下一局 function douishisiRoomXiaoJuView:onClickNext() playBtnEffect() self.ui:sendMsg(app.room, "callReadyRequest"); if self.nextCallBack then self.nextCallBack() end end function douishisiRoomXiaoJuView:onClickZongJieSuan() playBtnEffect() if self.nextCallBack then self.nextCallBack() end end function douishisiRoomXiaoJuView:getAHutypeTextUi(text) local hutext = cc.Text:createNode() hutext:setDefaults() local config = hutext:getFontConfig() config.fontSize = 22 config.texColor = cc.c3b(255,240,179)--cc.c4b(251,213,130,255) hutext:setFontConfig(config) hutext:setText(tostring(text)) return hutext end function douishisiRoomXiaoJuView:getXiaojiaUid() return app.room:getUserIdBySeatId(app.room.roomInfo.xiaoSeatId) end --显示胡牌类型 --[[function xichongRoomXiaoJuView:getHuTypesStr(huUid,huType) local strSpec = "" if huType > 0 then local ret = getNumBand(huType,ZPDef.HuType.TIAN_HU) if ret > 0 then strSpec = strSpec.."天胡x2 " end local ret = getNumBand(huType,ZPDef.HuType.LONG_HU) if ret > 0 then strSpec = strSpec.."龙胡x1 " end local ret = getNumBand(huType,ZPDef.HuType.TUO_HONG_HU) if ret > 0 then if huUid == self:getXiaojiaUid() then strSpec = strSpec.."坨坨红x1 " else strSpec = strSpec.."坨坨红x3 " end end local ret = getNumBand(huType,ZPDef.HuType.HEI_LONG_HU) if ret > 0 then strSpec = strSpec.."黑龙x1 " end local ret = getNumBand(huType,ZPDef.HuType.CHI_PIAO) if ret > 0 then strSpec = strSpec.."吃飘x1 " end local ret = getNumBand(huType,ZPDef.HuType.XIAO_HU) if ret > 0 then strSpec = strSpec.."小胡 " end local ret = getNumBand(huType,ZPDef.HuType.TUO_HEI_HU) if ret > 0 then if huUid == self:getXiaojiaUid() then strSpec = strSpec.."坨坨黑x1 " else strSpec = strSpec.."坨坨黑x3 " end end local ret = getNumBand(huType,ZPDef.HuType.BAO_HU) if ret > 0 then strSpec = strSpec.."报叫x1 " end end --另加番 if app.room.roomInfo.fourHongNum > 0 or app.room.roomInfo.fourNormolNum > 0 then local num = app.room.roomInfo.fourHongNum + app.room.roomInfo.fourNormolNum strSpec = strSpec.."四张x"..num.." " end if app.room.roomInfo.threeHongNum > 0 or app.room.roomInfo.fourHongNum > 0 then local num = app.room.roomInfo.fourHongNum + app.room.roomInfo.threeHongNum strSpec = strSpec.."冲番牌x"..num.." " end return strSpec end--]] return douishisiRoomXiaoJuView