|
- 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 ZPRoomCard=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomCard")
-
- local ZPRoomXiaoJuChaPaiView = class("ZPRoomXiaoJuChaPaiView", cc.UIView)
-
- function ZPRoomXiaoJuChaPaiView:ctor(nextCallBackFun)
- ZPRoomXiaoJuChaPaiView.super.ctor(self);
- self.lieShuMax = 15
- self.littleCardScale = 1
- self.nextCallBack = nextCallBackFun
- end
-
-
- function ZPRoomXiaoJuChaPaiView:loadUI()
- local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_xiaoju_chapai.ui");
- self.ui = ui;
- self:addChild(ui);
- end
-
- function ZPRoomXiaoJuChaPaiView:onEnter()
- ZPRoomXiaoJuChaPaiView.super.onEnter(self)
- self:loadUI()
-
- --查牌
- self.ui.Items.Button_QueDing:registerClick(handler(self , self.onClickQueDing))
-
- self:initLiangPaiPos()
- end
-
- function ZPRoomXiaoJuChaPaiView:onClickQueDing()
- if self.nextCallBack then
- self.nextCallBack()
- end
- end
-
- function ZPRoomXiaoJuChaPaiView:PlayHuangZhuangAni(bShowAni)
- local nodeDipai = self.ui.Items.Layout_XiaoJu_LiangPai
- --黄庄不显示结算,增加黄庄动画
- local tip = cc.ImageView:createNode();
- tip:setAnchorPoint(cc.p(0.5,0.5));
- tip:loadTextureFromPlist("zp_room_chapai_huangzhuang.png");
- tip:setPosition(cc.p(nodeDipai:getContentSize().width / 2,nodeDipai:getContentSize().height / 2))
- tip:setTag(1000)
- nodeDipai:addChild(tip);
- if bShowAni then
- tip:setScale(5.0)
- local seq = cc.Sequence:create(cc.ScaleTo:create(0.2,0.8),cc.ScaleTo:create(0.15,1.2),cc.ScaleTo:create(0.1,1))
- tip:runAction(seq)
- end
- end
-
- function ZPRoomXiaoJuChaPaiView:liangShouPai(isRecontect)
-
- --胡牌类型
- local huType = ZPDef.ReconnectHuType.NO_HU
- --房间信息
- local roomInfo = app.room.roomInfo
-
- --正常结束取值
- local tt = roomInfo.playList
- --重连取值
- if isRecontect then
- tt = roomInfo.arrayTableInfo
- end
-
- if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL then
- --胡的牌
- local huCard = roomInfo.huCard
-
- --出牌者ID或者点炮的ID,自摸这个是nil,有人点炮这个是有值的
- local showViewId = nil
-
- local dianPaoViewId = app.room:getViewIdByUserId(roomInfo.dianPaoUserId)
-
- --重连
- if isRecontect then
- showViewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
- else
- --小局结算
- showViewId = dianPaoViewId
- end
- for k,v in pairs(roomInfo.hupaiInfo) do
- local nUserId = v.huPaiUid
- local viewId = app.room:getViewIdByUserId(nUserId)
-
- --显示胡的那个牌
- if isRecontect then
- --[[if roomInfo.dianPaoUserId == -1 and showViewId then
- if huCard ~= 0 then
- self:playMoPaiAni(table.nums(roomInfo.dipaiList),huCard,showViewId,0,1,nil,true)
- end
- else
- self:setOutCardVisible(true,showViewId,huCard,false,nil,true)
- end--]]
- if self.showHuCardCallBack then
- self.showHuCardCallBack(showViewId,huCard)
- end
- end
-
- --赢家手牌
- local cardList = {}
-
- cardList = roomInfo.memberList[nUserId].cardList
-
- --判断赢家是否吃胡
- local isHandHaveHuCard = false
- local isFindChi = false
- for key,list in pairs(cardList) do
- for i = 1,3 do
- if list[i] == huCard then
- isHandHaveHuCard = true
- isFindChi = true
- break
- end
- end
- if isFindChi then
- break
- end
- end
- --是否是跑胡或提胡
- local paoTiHU = false
-
- --如果是吃胡
- if isHandHaveHuCard then
- huType = ZPDef.ReconnectHuType.CHI_HU
- --吃胡操作,去掉手里胡的那张
- local isFind = false
- if table.nums(cardList) > 0 then
- for i = 1,self.lieShuMax do
- local cardColList = cardList[i] or {}
- for idx,value in pairs(cardColList) do
- if value == huCard then
- table.remove(cardColList,idx)
- isFind = true
- break
- end
- end
- if isFind then
- break
- end
- end
- end
- else
- for k,v in pairs(tt) do
- if k == nUserId then
- for key,value in pairs(v.tableWeaveCard) do
- local list,operationType = ZPFuc.getZPCardList(value.card,value.type)
- if operationType == ZPDef.OpType.OP_TYPE_MINGWEI and huCard == value.card
- or operationType == ZPDef.OpType.OP_TYPE_ANWEI and huCard == value.card then
- huType = ZPDef.ReconnectHuType.WEI_HU
- elseif operationType == ZPDef.OpType.OP_TYPE_PENG and huCard == value.card then
- huType = ZPDef.ReconnectHuType.PENG_HU
- elseif operationType == ZPDef.OpType.OP_TYPE_PAO and huCard == value.card then
- if value.type == ZPDef.SendCardType.CHI_PAI_SHAO_PAO then --x
- huType = ZPDef.ReconnectHuType.WEI_PAO_HU
- elseif value.type == ZPDef.SendCardType.CHI_PAI_PENG_PAO then
- huType = ZPDef.ReconnectHuType.PENG_PAO_HU
- elseif value.type == ZPDef.SendCardType.KUAI_SHUI_FOUR_SAME then
- huType = ZPDef.ReconnectHuType.KAN_PAO_HU
- end
- paoTiHU = true
- elseif operationType == ZPDef.OpType.OP_TYPE_TI and huCard == value.card then
- if value.type == ZPDef.SendCardType.CHI_PAI_TI then
- huType = ZPDef.ReconnectHuType.WEI_TI_HU
- elseif value.type == ZPDef.SendCardType.GUN_ZI_FOUR_SAME then
- huType = ZPDef.ReconnectHuType.KAN_TI_HU
- end
- paoTiHU = true
- elseif operationType == ZPDef.OpType.OP_TYPE_CHONG_PAO and huCard == value.card then
- paoTiHU = true
- end
- end
- end
- end
- end
- --添加2个牌
- if huType == ZPDef.ReconnectHuType.WEI_HU or huType == ZPDef.ReconnectHuType.PENG_HU then
- local tt = {huCard,huCard}
- table.insert(cardList,tt)
- elseif huType == ZPDef.ReconnectHuType.KAN_TI_HU or huType == ZPDef.ReconnectHuType.KAN_PAO_HU
- or (true == paoTiHU) then
- local tt = {huCard,huCard,huCard}
- table.insert(cardList,tt)
- end
- end
- end
-
-
- for k,v in pairsByKeys(tt) do
- local myUserID = app.room:getMyUserId()
- local nUserId = v.nUserId
-
- if myUserID ~= nUserId then
- local cardList = roomInfo.memberList[nUserId].cardList
- logE("cardList:"..table.tostring(cardList))
- self:createHandCard(nUserId)
- end
- end
-
- app.room.roomInfo.huCardType = huType
-
- return huType
- end
-
- --[[
- 游戏结束或者重连,展示其余玩家手牌
- ]]
- function ZPRoomXiaoJuChaPaiView:createHandCard(nUserId)
- logE("====================RoomView:createHandCard()===================");
-
- local cardList = app.room.roomInfo.memberList[nUserId].cardList
-
- --过滤手牌为空的情况
- if not cardList or table.nums(cardList) <= 0 then
- return
- end
-
- local viewId = app.room:getViewIdByUserId(nUserId)
-
- --不管有无数据,默认创建10列数据
- if viewId == 1 then
- for i = 1,self.lieShuMax do
- local value = cardList[i] or {}
- local isKan = self:getCurrentColIsKan(value)
- local card = ZPRoomCard:new(value,ZPDef.CardType.CARD_TYPE_TABLE,i,isKan,true)
- local pos = self.boxPosList1[i]
- card.ui:setPosition(pos)
- self.ui.Items.Layout_HandCard:addChild(card.ui,1)
- end
- elseif viewId == 2 then
- for i = 1,self.lieShuMax do
- local value = cardList[i] or {}
- local isKan = self:getCurrentColIsKan(value)
- local card = ZPRoomCard:new(value,ZPDef.CardType.CARD_TYPE_TABLE,i,isKan,true)
- local pos = self.boxPosList2[i]
- card.ui:setPosition(pos)
- self.ui.Items.Layout_HandCard:addChild(card.ui,1)
- end
- elseif viewId == 3 then
- for i = 1,self.lieShuMax do
- local value = cardList[i] or {}
- local isKan = self:getCurrentColIsKan(value)
- local card = ZPRoomCard:new(value,ZPDef.CardType.CARD_TYPE_TABLE,i,isKan,true)
- local pos = self.boxPosList3[i]
- card.ui:setPosition(pos)
- self.ui.Items.Layout_HandCard:addChild(card.ui,1)
- end
- end
-
- end
-
- --判断列数是否是砍牌
- function ZPRoomXiaoJuChaPaiView:getCurrentColIsKan(list)
- local isKan = false
- if list[1] and list[2] and list[3] then
- if list[1] == list[2] and list[2] == list[3] then
- isKan = true
- end
- end
- return isKan
- end
-
- function ZPRoomXiaoJuChaPaiView:showDiPai()
- local roomInfo = app.room.roomInfo
- self.ui.Items.Layout_dipai:removeAllChildren()
- --显示剩余底牌
- local jiantouImg = cc.ImageView:createNode();
- jiantouImg:setAnchorPoint(cc.p(0,0));
- jiantouImg:loadTextureFromPlist("zipai_arrow.png");
-
- local dipaiSize = table.nums(roomInfo.dipaiList);
- local nodeDipai = self.ui.Items.Layout_dipai
- --没有底牌不显示底牌背景
- if dipaiSize <= 0 then
- self.ui.Items.ImageView_DiPai:setVisible(false)
- else
- self.ui.Items.ImageView_DiPai:setVisible(true)
- end
- local scale = 1--self.littleCardScale + 0.03
- local tmp = {}
- local max = table.nums(roomInfo.dipaiList)
- for i = max,1,-1 do
- local card = roomInfo.dipaiList[i]
- table.insert(tmp,card)
- end
- for dipaiK,dipaiV in pairsByKeys(tmp) do
- local cardImg = cc.ImageView:createNode();
- cardImg:setAnchorPoint(cc.p(0,0));
- local fileName = ZPFuc.getZPCardImgByValue(dipaiV.chessCards,ZPDef.CardType.CARD_TYPE_TABLE)
- cardImg:loadTextureFromPlist(fileName);
- cardImg:setScale(scale)
- local showColNum = 20
- local getHeightCount = function (count)
- if count >= showColNum then
- return math.floor(count/showColNum)
- else
- return 0
- end
- end
- local x = (dipaiK - 1) % showColNum
- local width = cardImg:getContentSize().width * scale;
- local height = cardImg:getContentSize().height * scale;
- local adjustPos = cc.p(width * x,height * getHeightCount(dipaiK - 1))
- local tarPos = cc.p(width * (showColNum - 1) - adjustPos.x,0 + adjustPos.y)
- cardImg:setPosition(tarPos);
- nodeDipai:addChild(cardImg);
- if dipaiK == dipaiSize then
- local x = (dipaiK) % showColNum
- local adjustPos = cc.p(width * x,height * getHeightCount(dipaiK))
- local tarPos = cc.p(width * (showColNum - 1) - adjustPos.x,0 + adjustPos.y)
- jiantouImg:setPosition(tarPos)
- if dipaiK == showColNum or dipaiK == showColNum * 2 then
- x = (dipaiK - 1) % showColNum
- adjustPos = cc.p(width * x,height * getHeightCount(dipaiK - 1))
- tarPos = cc.p(width * (showColNum - 1) - adjustPos.x - width,0 + adjustPos.y)
- jiantouImg:setPosition(tarPos)
- end
- nodeDipai:addChild(jiantouImg);
- end
- end
- end
-
- function ZPRoomXiaoJuChaPaiView:clearView()
- self.ui.Items.Layout_HandCard:removeAllChildren()
- self.ui.Items.Layout_dipai:removeAllChildren()
- --移除黄庄
- self.ui.Items.Layout_XiaoJu_LiangPai:removeChildByTag(1000)
- end
-
- --初始化小局查牌界面亮手牌的位置
- function ZPRoomXiaoJuChaPaiView:initLiangPaiPos()
- self.boxPosList1 = {}
- local weaveCardPos1 = self.ui.Items.Layout_LiangPai_1:getPosition()
- for i = 1, self.lieShuMax do
- --矩形3
- self.boxPosList1[i] = cc.p(weaveCardPos1.x - 36 * (i - 1),weaveCardPos1.y)
- end
-
- self.boxPosList2 = {}
- local weaveCardPos2 = self.ui.Items.Layout_LiangPai_2:getPosition()
- for i = 1, self.lieShuMax do
- --矩形3
- self.boxPosList2[i] = cc.p(weaveCardPos2.x + 36 * (i - 1),weaveCardPos2.y)
- end
-
- self.boxPosList3 = {}
- local weaveCardPos3 = self.ui.Items.Layout_LiangPai_3:getPosition()
- for i = 1, self.lieShuMax do
- --矩形3
- self.boxPosList3[i] = cc.p(weaveCardPos3.x + 36 * (i - 1),weaveCardPos3.y)
- end
- end
-
- --设置确定回调
- function ZPRoomXiaoJuChaPaiView:setQueDingCallBack(cback)
- self.nextCallBack = cback
- end
-
- --显示胡牌回调
- function ZPRoomXiaoJuChaPaiView:showHuCardCallBack(cback)
- self.showHuCardCallBack = cback
- end
-
- return ZPRoomXiaoJuChaPaiView;
|