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 ZPRoomXiaoJuView = class("ZPRoomXiaoJuView", cc.UIView) function ZPRoomXiaoJuView:ctor(nextCallBackFun,isRecontect) ZPRoomXiaoJuView.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 ZPRoomXiaoJuView:loadUI() local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_xiaoju.ui"); self.ui = ui; self:addChild(ui); end function ZPRoomXiaoJuView:onEnter() ZPRoomXiaoJuView.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:registerClick(handler(self , self.onClickChaPai)) --胡牌类型item,复制用 self.ui.Items.Layout_hutypes:setVisible(false) --显示结束 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.ui.Items.ImageView_DiCard_1:setVisible(false) --组合牌第一个点的坐标 self.weaveCardPos = cc.p(200,50) self.leftCardPos = self.ui.Items.ImageView_DiCard_1:getPosition() 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 ZPRoomXiaoJuView:initPlayerView() self.ui.Items.Layout_WeaveCard_Item:setVisible(false) for i=1,4 do local head = "ImageView_head_"..i local name = "Text_Name_"..i local id = "Text_ID_"..i local banker = "ImageView_Zhuang_"..i local winScore = "TextBMFont_WinScore_"..i local loseScore = "TextBMFont_LoseScore_"..i local layout = "Layout_Hand_"..i local winBg = "ImageView_ying_bg_"..i --local loseBg = "ImageView_pt_bg_"..i local layoutHuinfo = "Layout_HuInfo_"..i local fangPao = "ImageView_FangPao_"..i local layoutHuTypes = "Layout_huTypes_"..i local huType = "ImageView_HuType_"..i local textHuInfo = "Text_Hu_Info_"..i local textHushu = "Text_hushu_"..i local textBeishu = "Text_beishu_"..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].nodeBanker = self.ui.Items[banker] 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].nodewinBg = self.ui.Items[winBg] --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].nodehutype = self.ui.Items[huType] self.allNode[i].nodelayoutHuTypes = self.ui.Items[layoutHuTypes] self.allNode[i].nodehuinfo = self.ui.Items[textHuInfo] self.allNode[i].nodeHushu = self.ui.Items[textHushu] self.allNode[i].nodeBeishu = self.ui.Items[textBeishu] end end --是否是小家uid function ZPRoomXiaoJuView: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 end --获取最大得分 function ZPRoomXiaoJuView: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 ZPRoomXiaoJuView:updatePlayerInfo() self.isHaveUse = {} local indexPlayer = 2 local maxTurnScore = self:getMaxTurnScore(self.xiaojuData) --按要求赢家要摆在第一个位置 for k,v in pairsByKeys(self.xiaojuData) do v.nTurnScore = tonumber(v.nTurnScore) if app.room:checkUserIDIsInTable(v.nUserId) then local i = indexPlayer 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 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 --[[if app.room:getActualPlayerNum() == 4 then i = app.room:getViewIdByUserId(v.nUserId)--indexPlayer if i == 2 then i = 4 elseif i == 4 then i = 3 elseif i == 3 then i = 2 end else i = indexPlayer 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 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) self.allNode[i].nodewinBg:setVisible(false) end self.allNode[i].nodelayoutHuinfo:setVisible(false) self.allNode[i].nodehutype: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)) --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq -- begin local ClubDefine = require("luaScript.Protocol.Club.ClubDefine") if app.club_php.clubID and app.club_php.clubID ~= 0 then if app.club_php:getCestIsOpen(app.club_php.clubID) then --隐私数据 local clubInfo = app.club_php.clubList[app.club_php.clubID] self.cliext = clubInfo.groupext and clubInfo.groupext.cliext if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then self.allNode[i].nodeID:setVisible(true) else self.allNode[i].nodeID:setVisible(false) end end end end if v.nUserId == tonumber(app.user.loginInfo.uid) then self.allNode[i].nodeID:setVisible(true) end -- end --庄家 if bankerId == v.nUserId then self.allNode[i].nodeBanker:setVisible(true) else self.allNode[i].nodeBanker:setVisible(false) end --点炮玩家 if dianPaoUserId == v.nUserId then self.allNode[i].nodefangPao:setVisible(false) --更换显示方式 local ui = self:getAHutypeUi(0,"zp_mt_dianpao.png") self.allNode[i].nodelayoutHuTypes:addChild(ui) else self.allNode[i].nodefangPao:setVisible(false) end --组合牌展示 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].nodelayoutHuinfo:setVisible(true) --显示胡牌 self.allNode[i].nodeHushu:setText(huv.huPaiHuShu) self.allNode[i].nodeBeishu:setText(huv.multiNum) local huDes = { [1] = "十",[2] = "二十",[3] = "三十",[4] = "四十",[5] = "五十",[6] = "六十",[7] = "七十",[8] = "八十", [9] = "九十",[10] = "一百",[20] = "二百",[30] = "三百", } --查叫 if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then local ui = self:getAHutypeUi(0,"zp_mt_chajiao.png") self.allNode[i].nodelayoutHuTypes:addChild(ui) end --非自摸 非点炮 显示堂出 if huv.dianPaoUid <= 0 and not ZPFuc.isZiMo(huv.huTypes) then local ui = self:getAHutypeUi(0,"zp_mt_tangchu.png") self.allNode[i].nodelayoutHuTypes:addChild(ui) end local huDNum = math.floor(huv.huPaiHuShu/10) if huv.huPaiHuShu == 0 then self.allNode[i].nodehuinfo:setText("乱胡")--显示无胡 local ui = self:getAHutypeUi(0) self.allNode[i].nodelayoutHuTypes:addChild(ui) elseif huDNum > 0 then if huv.huPaiHuShu%10 == 0 then self.allNode[i].nodehuinfo:setText("恰"..huDes[huDNum].."胡")--显示梗 local ui = self:getAHutypeUi(0,"zp_mt_geng.png") self.allNode[i].nodelayoutHuTypes:addChild(ui) else self.allNode[i].nodehuinfo:setText(huDes[huDNum].."多胡") end else self.allNode[i].nodehuinfo:setText(huv.huPaiHuShu.."胡") end if huv.guiNum and huv.guiNum > 0 then local gui = string.format("zp_mt_gui%d.png",huv.guiNum) local ui = self:getAHutypeUi(0,gui) self.allNode[i].nodelayoutHuTypes:addChild(ui) end self:showHuTypes(self.allNode[i].nodelayoutHuTypes,huv.huTypes) end end local index = 0 for key,value in pairs(data.tableWeaveCard) do local list,operationType = ZPFuc.getZPCardList(value.card,value.type) local card = value.opcard list = ZPFuc.getOpCardFirstList(operationType,list,card) --上面吃或不吃不要用if else因为还可能都不成立 if list then self:createWeaveCard(value,list,index,false,self.allNode[i].nodeLayout,v.nUserId) end index = index + 1 end --只显示一次胡变为opCard local showOneTime = true for k,value in pairs(data.handCard) do local list,operationType = ZPFuc.getZPCardList(value.card,value.type) local card = value.opcard --判断组合牌里是否有胡的那张 local haveHuCard = false for t = 1,3 do if app.room.roomInfo.huCard == list[t] then haveHuCard = true break end end --如果是吃胡,并且手里的这次的组合牌里还有胡的那张 if showOneTime and haveHuCard and app.room.roomInfo.huCardType and app.room.roomInfo.huCardType == ZPDef.ReconnectHuType.CHI_HU then card = app.room.roomInfo.huCard showOneTime = false end list = ZPFuc.getOpCardFirstList(operationType,list,card) if value.type == ZPDef.SendCardType.KAN_THREE_SAME then value.type = ZPDef.SendCardType.KANPAI_LOCAL end --上面吃或不吃不要用if else因为还可能都不成立 if list then self:createWeaveCard(value,list,index,true,self.allNode[i].nodeLayout,v.nUserId) 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 --indexPlayer = indexPlayer + 1 if isHuUid and true == isHuUid then self:showHuCardBox(self.allNode[i].nodeLayout,app.room.roomInfo.huCard) end end end self:showDiPai() end function ZPRoomXiaoJuView:showDiPai() local dipaiSize = table.nums(app.room.roomInfo.dipaiList); if dipaiSize <= 0 then self.ui.Items.Layout_Bottom_1:setVisible(false) else self.ui.Items.Layout_Bottom_1:setVisible(true) end --[[if app.room:getActualPlayerNum() == 2 then local y = self.ui.Items.Layout_Bottom_1:getPositionY() self.ui.Items.Layout_Bottom_1:setPositionY(y+40) end--]] local tIndex = 0 for dipaiK,dipaiV in pairsByKeys(app.room.roomInfo.dipaiList) do local mLayout = cc.Layout:createNode() mLayout:setAnchorPoint(cc.p(0.5,0.5)) mLayout:setSize(cc.size(30,30)) local cardImg = cc.ImageView:createNode(); cardImg:setAnchorPoint(cc.p(0.5,0.5)); cardImg:setScale(0.8) local fileName = ZPFuc.getZPCardImgByValue(dipaiV.chessCards,ZPDef.CardType.CARD_TYPE_TABLE) cardImg:loadTextureFromPlist(fileName); local row = math.floor(tIndex/22) --cardImg:setPosition(self.leftCardPos.x + (tIndex%25)*45,self.leftCardPos.y-row*60) cardImg:setPosition(cc.p(15,15)) mLayout:addChild(cardImg) self.ui.Items.Layout_dipai:addChild(mLayout); tIndex = tIndex + 1; end end function ZPRoomXiaoJuView:getHuTypeAndBeiShuStr(huType,beishu) local strRul = "" return strRul end --判断是否是赢家uid function ZPRoomXiaoJuView: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 ZPRoomXiaoJuView:createWeaveCard(value,list,index,isHand,node,userID) local sendCardType = value.type local huxi = value.hushu local opCard = value.opcard local ui = self.ui.Items.Layout_WeaveCard_Item:getCopied() ui.Items = getUIItems(ui); ui:setVisible(true) local max = table.nums(list) local idx = max for i = 1,4 do local name = "ImageView_Card_"..i local hu = "ImageView_card_hu_"..i ui.Items[hu]:setVisible(false) if i > max then ui.Items[name]:setVisible(false) else if list[idx] == app.room.roomInfo.huCard and not self.isShow then --[[--吃胡一定是手牌 if app.room.roomInfo.huCardType and app.room.roomInfo.huCardType == ZPDef.ReconnectHuType.CHI_HU and isHand then self.isShow = true --其他类型的胡牌在组合牌上 elseif app.room.roomInfo.huCardType and app.room.roomInfo.huCardType ~= ZPDef.ReconnectHuType.CHI_HU and not isHand then self.isShow = true elseif app.room.roomInfo.huCardType and app.room.roomInfo.huCardType == 0 and isHand then--叫牌的时候 self.isShow = true end--]] if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then if true == isHand or #list == 4 or (#list == 3 and list[1]==list[2] and list[2]==list[3]) then self.isShow = true end else if app.room.roomInfo.huCardType == ZPDef.ReconnectHuType.CHI_HU and not isHand then else self.isShow = true end end end local fileName = ZPFuc.getZPCardImgByValue(list[idx],ZPDef.CardType.CARD_TYPE_TABLE) ui.Items[name]:loadTextureFromPlist(fileName) ui.Items[name].cardValue = list[idx] idx = idx - 1 --[[if self.isShow == true then --ui.Items[name]:setColor(cc.c3b(248,193,103)) if not self.showHu[userID] then self.isShow = false self.showHu[userID] = true if self:getIsWinUid(userID) then ui.Items[hu]:setVisible(true) end end self.isShow = false end--]] end end --不管是不是手牌都要显示 if self:getWeaveTypeFile(sendCardType) ~= "" then--and (not isHand) ui.Items.ImageView_tip:loadTextureFromPlist(self:getWeaveTypeFile(sendCardType)) else ui.Items.ImageView_tip:setVisible(false) end ui.Items.TextBMFont_youshu:setText(huxi) ui:setPosition(cc.p(self.weaveCardPos.x + index * 40,self.weaveCardPos.y)) --self.ui.Items.Layout_1:addChild(ui) node:addChild(ui) end --在胡牌的那张牌上面显示胡字 function ZPRoomXiaoJuView:showHuCardBox(node,hucard) if not node then return end local cardUI = node:getChildren() if cardUI and type(cardUI) == 'table' then 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) return end end end end end --[[ 获取组合类型文件 ]] function ZPRoomXiaoJuView: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 ZPRoomXiaoJuView: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 ZPRoomXiaoJuView:updateUserHead(nodeHead,nUserId, sex, headimgurl) setPlayerHeadImage(nUserId, headimgurl, nodeHead); end -- 查牌 function ZPRoomXiaoJuView:onClickChaPai() playBtnEffect() self:setVisible(false) end -- 下一局 function ZPRoomXiaoJuView:onClickNext() playBtnEffect() self.ui:sendMsg(app.room, "callReadyRequest"); if self.nextCallBack then self.nextCallBack() end end function ZPRoomXiaoJuView:onClickZongJieSuan() playBtnEffect() if self.nextCallBack then self.nextCallBack() end end function ZPRoomXiaoJuView:getAHutypeUi(ht,filename) local ui = self.ui.Items.Layout_hutypes:getCopied() ui.Items = getUIItems(ui); ui:setVisible(true) if not ht then ht = 0 end local name = string.format(ZPDef.TipFile.HU,ht) if filename then name = filename end ui.Items.ImageView_hutype:loadTextureFromPlist(name) return ui end --显示胡牌类型 function ZPRoomXiaoJuView:showHuTypes(node,huType) --[[local initPos = cc.p(100,115) local scale = 0.4 local offsetY = 30--]] if huType > 0 then local strSpec = "" local ret = getNumBand(huType,ZPDef.HuType.TIAN_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.TIAN_HU) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.DI_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.DI_HU) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.HAI_DI_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.HAI_DI_HU) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.ZI_MO_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.ZI_MO_HU) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.SHUI_SHANG_PIAO) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.SHUI_SHANG_PIAO) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.HEI_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.HEI_HU) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.HONG_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.HONG_HU) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.BAO_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.BAO_HU) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.KUN_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.KUN_HU) node:addChild(ui) end local ret = getNumBand(huType,ZPDef.HuType.SHA_BAO_HU) if ret > 0 then local ui = self:getAHutypeUi(ZPDef.HuType.SHA_BAO_HU) node:addChild(ui) end end end return ZPRoomXiaoJuView;