local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ") local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine") local MJGroupFactory=MJFramework.MJImport("mj.luaScript.Views.Game.MJGroupFactory") local huamajiangPositionCompnent = MJFramework.MJImport("mj_huamajiang.luaScript.Views.Compnent.huamajiangPositionCompnent") local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage") local MJHandCardView=MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Game.MJHandCardView") local MJSound = MJFramework.MJImport("mj.luaScript.MJSound") local huamajiangHandCardView = class("huamajiangHandCardView", MJHandCardView) function huamajiangHandCardView:ctor(viewId,desktopType) huamajiangHandCardView.super.ctor(self,viewId,desktopType) self.huCardLayout = {}; end function huamajiangHandCardView:loadUI() local ui = nil if self.desktopType == MJDefine.DesktopType.TwoD or self.desktopType == MJDefine.DesktopType.TwoDGold then ui = loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_hand_card_2d.ui"); else ui = loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_hand_card.ui"); end autoAdapt(ui) self.ui = ui; self:addChild(ui) end function huamajiangHandCardView:initView() if self:isUseNew3D() then self:loadUI() self.ui.Items.Layout_Hand_Card:setVisible(false) self.ui.Items.Layout_OperateItem:setVisible(false) self.ui.Items.Button_Sure:setVisible(false) local MJConfig = MJDefine.MJConfig_2d if self.desktopType == MJDefine.DesktopType.ThreeD then MJConfig = MJDefine.MJConfig_3d end local MahjongHandCard = require(MJConfig.HANDCARD_VIEW) local MahjongOutCardView = require(MJConfig.OUTCARD_VIEW) local MahjongHuCardView = require(MJConfig.HU_CARD_VIEW) self._huCardView = MahjongHuCardView:new(self.viewId) self:addChild(self._huCardView) self._outCardView = MahjongOutCardView:new(self.viewId) self:addChild(self._outCardView) self._handcard = MahjongHandCard:new(self.viewId, self.desktopType) self:addChild(self._handcard) self.ui:setLocalZOrder(10) else self:loadUI() self.ui.Items.Layout_Operate:setVisible(false) self.ui.Items.Button_Sure:setVisible(false) self.ui.Items.Button_Sure:registerClick(function() if not self.touchMJ then showTooltip("请选择要出的麻将!") end self:sendOutCard() end) print("MJHandCardView:"..self.viewId) self.initX=self.ui.Items["ImageView_Start_"..self.viewId]:getPositionX()--MJDefine.MJStartPositions[self.viewId].x self.initY=self.ui.Items["ImageView_Start_"..self.viewId]:getPositionY()--MJDefine.MJStartPositions[self.viewId].y print("手牌起始位置self.initX = "..self.initX.."self.initY"..self.initY) if self.viewId == MJDefine.PlayerViewType.My then self.initX = self.initX + (CONST_WIDTH*g_radio_x-CONST_WIDTH)/2 print("调整过后我的位置self.initX = "..self.initX.."self.initY"..self.initY) else self.initX = self.initX*g_radio_x self.initY = self.initY*g_radio_y print("调整过后其他人位置self.initX = "..self.initX.."self.initY"..self.initY) end self.outX=self.ui.Items["ImageView_Out_"..self.viewId]:getPositionX() self.outY=self.ui.Items["ImageView_Out_"..self.viewId]:getPositionY() print("出牌起始位置self.outX = "..self.outX.."self.outY"..self.outY) self.outX = self.outX*g_radio_x self.outY = self.outY*g_radio_y print("出牌调整后的起始位置self.outX = "..self.outX.."self.outY"..self.outY) --如果是2人房 调整出牌坐标 if app.room.roomInfo.nMaxPlayCount==2 then if self.viewId == MJDefine.PlayerViewType.My then self.outX=self.outX-285 elseif self.viewId == MJDefine.PlayerViewType.Top then self.outX=self.outX+200 end end -- if self.viewId~=MJDefine.MyViewId then self.showCardPostion=self.ui.Items["ImageView_Show_"..self.viewId]:getPosition() -- end print("showCard起始位置self.showCardPostion x = "..self.showCardPostion.x.."y = "..self.showCardPostion.y) self.showCardPostion.x = self.showCardPostion.x*g_radio_x self.showCardPostion.y = self.showCardPostion.y*g_radio_y print("showCard调整后起始位置self.showCardPostion x = "..self.showCardPostion.x.."y = "..self.showCardPostion.y) self.ui.Items.Layout_Hand_Card:removeAllChildren() self:hideOperateItem() self.ui.Items.Layout_OperateItem:setLocalZOrder(1); self.ui.Items.Layout_Operate:setLocalZOrder(1); end end function huamajiangHandCardView:pushTing() if self:isUseNew3D() then self._handcard:pushTing() else local tings = app.room.roomInfo:getTingCards(); if tings then for k,v in pairs(tings) do for _,mj in pairs(self.handCards) do if mj.value==v.outCard then mj:setTing(true) end end end end end end --摸牌 function huamajiangHandCardView:onGetCard(operates,card,isSwap) if self:isUseNew3D() then self.touchMJ = nil self:createHandCards(card, true) if not operates or table.nums(operates) == 0 then self._handcard:setOutCardEnable(true) MJDefine.outCardSendGuo = false else self._handcard:setOutCardEnable(true) MJDefine.outCardSendGuo = true -- self:canOutCard(true) end if self.viewId==MJDefine.MyViewId then MJSound.PlayGetCard() end else self.touchMJ = nil; self:createHandCards(card) if self.viewId==MJDefine.PlayerViewType.Right and not self.isReplay then -- self:resetHandCards() end if isSwap and isSwap == true then return end --如果是换牌阶段,返回 if self.desktopType == MJDefine.DesktopType.ThreeD then if self.viewId == MJDefine.PlayerViewType.Right then local mj = self.handCards[#self.handCards]; local pos = mj:getPosition(); mj:setPositionY(pos.y + 30); elseif self.viewId == MJDefine.PlayerViewType.Top then local mj = self.handCards[#self.handCards]; local pos = mj:getPosition(); mj:setPositionX(pos.x - 30); end end if not operates or table.nums(operates)==0 then self:setOutCardEnable(true) MJDefine.outCardSendGuo = false else self:setOutCardEnable(true) MJDefine.outCardSendGuo = true -- self:canOutCard(true) end if self.viewId==MJDefine.MyViewId then MJSound.PlayGetCard() end -- self:moveLastCard() end end --[[ 显示胡的牌 @param card 胡的牌 ]] function huamajiangHandCardView:onGetHuCard (huCard, isClean,data) if self:isUseNew3D() then self._huCardView:getHuCards(huCard, isClean) else self.huCards = self.huCards or {}; if isClean then self.huCards = {}; end for k, v in ipairs(huCard) do table.insert(self.huCards, v); end local huCards = self.huCards; local viewId = self.viewId; if not (huCards and table.nums(huCards) > 0) then logD("胡牌数据为空!") return ; end -- huCards = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8}; if not self.huCardLayout[viewId] then self.huCardLayout[viewId] = cc.Layout:create(); self.ui.Items.Layout_Hu_Card:addChild(self.huCardLayout[viewId]); end local k = {} for idx,v in ipairs(self.huCardLayout[viewId]:getChildren()) do if v:getOpacity() < 255 then table.insert(k,idx) end end for _, idx in ipairs(k) do huCards[idx].opacity = 125 end self.huCardLayout[viewId]:removeAllChildren(); local huCardsLayout = self.huCardLayout[viewId]; for k, v in ipairs(huCards) do local huCard = v.huCard; local huType = v.huType; local opacity = v.opacity; local vid = viewId; local scale = 0.75; if viewId == MJDefine.PlayerViewType.MyViewId then scale = 0.7; end local card = MJ:new(huCard, MJDefine.MJType.Operate, vid, self.desktopType); local w = card:getContentSize().width * scale; local h = card:getContentSize().height * scale; card:setScale(scale); if huCard ~= 0 and huType == MJDefine.MJHuType.Zimo then -- 自摸牌,设置颜色显示 card:setColor(cc.c3b(237,236,134)); end --换行数量 local cNum = 15 local col = k % cNum col = col == 0 and cNum or col if viewId == MJDefine.PlayerViewType.My then if self.desktopType == MJDefine.DesktopType.ThreeD then local x = (1 - k) * (w - 2); card:setPositionX(x); else local x = (1 - col) * (w - 2); local y = (math.ceil(k/cNum)-1) * 12 card:setPosition(cc.p(x,y)); end elseif viewId == MJDefine.PlayerViewType.Right then if self.desktopType == MJDefine.DesktopType.ThreeD then local y = (1 - k) * (h - 14); local x = (k - 1) * 5; card:setPosition(cc.p(x, y)); else local y = (1 - col) * (h - 9); y = y + (math.ceil(k/cNum)-1) * 8 card:setPositionY(y); end elseif viewId == MJDefine.PlayerViewType.Left then if self.desktopType == MJDefine.DesktopType.ThreeD then local y = (k - 1) * (h - 14); local x = (k - 1) * 5; card:setPosition(cc.p(x, y)); else local y = (col - 1) * (h - 9); y = y + (math.ceil(k/cNum)-1) * 8 card:setPositionY(y); end card:setLocalZOrder(#huCards - col); elseif viewId == MJDefine.PlayerViewType.Top then if self.desktopType == MJDefine.DesktopType.ThreeD then local x = (k - 1) * (w - 2); card:setPositionX(x); else local x = (col - 1) * (w - 1); local y = (math.ceil(k/cNum)-1) * 12 card:setPosition(cc.p(x,y)); end end local count = app.room.roomInfo:getLuoBoCardCount(v); card:setLuoBoVisible(count > 0, count); if data and data.yipaoduoxiang and data.huPaiIndex and data.huPaiIndex > 1 or opacity then card:setOpacity(125) end huCardsLayout:addChild(card); end --local visibleSize = cc.Director:getInstance():getVisibleSize(); local visibleSize = cc.size(1280,720) if viewId == MJDefine.PlayerViewType.My then if self.desktopType == MJDefine.DesktopType.ThreeD then huCardsLayout:setPosition(cc.p((visibleSize.width - 300) * g_radio_x, 155 * g_radio_y)); else huCardsLayout:setPosition(cc.p((visibleSize.width - 300) * g_radio_x, 160 * g_radio_y)); end elseif viewId == MJDefine.PlayerViewType.Right then if self.desktopType == MJDefine.DesktopType.ThreeD then huCardsLayout:setPosition(cc.p((visibleSize.width - 250) * g_radio_x, (visibleSize.height - 190) * g_radio_y)); else huCardsLayout:setPosition(cc.p((visibleSize.width - 205) * g_radio_x, (visibleSize.height - 150) * g_radio_y)); end elseif viewId == MJDefine.PlayerViewType.Left then if self.desktopType == MJDefine.DesktopType.ThreeD then huCardsLayout:setPosition(cc.p(190 * g_radio_x, 250 * g_radio_y)); else huCardsLayout:setPosition(cc.p(205 * g_radio_x, 250 * g_radio_y)); end elseif viewId == MJDefine.PlayerViewType.Top then huCardsLayout:setPosition(cc.p(435 * g_radio_x, (visibleSize.height - 100) * g_radio_y)); end end end function huamajiangHandCardView:setOutCardEnable(b) if self:isUseNew3D() then self._handcard:setOutCardEnable(b) else self.isOutCard=b if b then self:moveLastCard() end if self.viewId==MJDefine.MyViewId and self.ui.Items.Button_Sure then -- self.ui.Items.Button_Sure:setVisible(b) end end end --不管是否自动对齐,红中始终保持放在最左边 function huamajiangHandCardView:sortRedMahjong() local redNum = 0 for k,mj in pairs(self.handCards) do if mj.value == 65 then redNum = redNum + 1 table.remove(self.handCards,k) table.insert(self.handCards,redNum,mj) end end end function huamajiangHandCardView:removeHandCard(arg) if self:isUseNew3D() then self._handcard:removeHandCard(arg) else if type(arg)=="number" then arg={ {card=arg} } end if self.viewId==MJDefine.MyViewId or self.isReplay then for k,v in pairs(arg) do local mj=self:getMjByValue(v.card) if mj then table.removeItem(self.handCards,mj) mj:removeFromParent() end end else -- local num=#self.handCards-#arg -- print(num) for i=#self.handCards,#self.handCards-#arg+1,-1 do if self.handCards[i] then self.handCards[i]:removeFromParent() table.remove(self.handCards,i) end end end end end function huamajiangHandCardView:removeHandCardByNum(value,num) if self:isUseNew3D() then self._handcard:removeHandCardByNum(value, num) else if self.viewId==MJDefine.MyViewId or self.isReplay then for i=1,num do local mj = self:getMjByValue(value) if mj then table.removeItem(self.handCards,mj) mj:removeFromParent() end end else -- local num=#self.handCards-#arg -- print(num) for i=#self.handCards,#self.handCards-num+1,-1 do self.handCards[i]:removeFromParent() table.remove(self.handCards,i) end end end end -- function huamajiangHandCardView:touchOutCard() -- huamajiangHandCardView.super.touchOutCard(self) -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing}) -- end function huamajiangHandCardView:getGroup(card,opTypes) if self:isUseNew3D() then return self._handcard:getGroup(card, opTypes) else for kk, vv in pairs(opTypes) do opType = vv; for k,v in pairs(self.handGroupCards) do if v.opType==opType then if v.opType == MJDefine.MJOperateType.OPREATE_ANGANG then if (v.mjs[1].value==card or v.mjs[2].value == card or v.mjs[3].value == card or v.mjs[4].value == card) then return v; end else if (v.mjs[1].value==card or v.mjs[2].value == card or v.mjs[3].value == card) then return v; end end end end end end end function huamajiangHandCardView:createGroupCards(arg,fromViewId) if self:isUseNew3D() then self._handcard:createGroupCards(arg, fromViewId) else local x=self.initX local y=self.initY local MJGroupStartOffSet = MJDefine.MJGroupStartOffSet[self.desktopType] for k,v in pairs(arg) do if not fromViewId then fromViewId = v.fromViewId end local group = nil; if v.opType == MJDefine.MJOperateType.OPREATE_ANGANG then group = self:getGroup(v.values[1], {MJDefine.MJOperateType.OPREATE_ANGANG}); if group then local cards = group:getCards(); if cards and cards[4] then group:refreshCardNum(cards[4], v.cardNum); return ; end end end group=MJGroupFactory.CreateGroup(v.values,v.showType,self.viewId,self.desktopType, v.cardNum) if group then --设置碰杠来源 --group:setDirection(self.viewId,v.fromViewId1) if group.setAnColor and (v.opType == MJDefine.MJOperateType.OPREATE_PENG or v.opType == MJDefine.MJOperateType.OPREATE_ZHIGANG or v.opType == MJDefine.MJOperateType.OPREATE_BAGANG) then --牌的阴影显示刚好和视图id相反 if v.fromViewId == 1 then v.fromViewId = 3 elseif v.fromViewId==3 then v.fromViewId = 1 end -- 杠牌对家,换成第四张 if v.opType ~= MJDefine.MJOperateType.OPREATE_PENG then if v.fromViewId==2 then v.fromViewId = 4 end end group:setAnColor(v.opCard, v.fromViewId) end local cards = group:getCards(); if cards and cards[4] then group:refreshCardNum(cards[4], v.cardNum); end if v.opType == MJDefine.MJOperateType.OPREATE_BAGANG then if cards and cards[4] then cards[4]:setOperateBlackImage(0,self.viewId) end end group.fromViewId = v.fromViewId ---保留触发操作的玩家位置,补杠需要 group.opType=v.opType self.ui.Items.Layout_Hand_Card:addChild(group,-4+#self.handGroupCards) group:setPosition(cc.p(x+MJGroupStartOffSet[self.viewId].x,y+MJGroupStartOffSet[self.viewId].y)) x,y=huamajiangPositionCompnent.getGroupPosition(self.viewId,x,y,group,self.desktopType) table.insert(self.handGroupCards,group) end end --更新起始位置 self.initX=x self.initY=y end end --添加杠操作按钮 function huamajiangHandCardView:addOperateBtn(operates) local x=self.ui.Items.Layout_Operate:getContentSize().width local y=self.ui.Items.Layout_Operate:getContentSize().height/2 local btnOperate=cc.Button:createNode() btnOperate:setDefaults() btnOperate:setText("") btnOperate:loadTextureNormal(MJDefine.MJOperateImage[operates[1].opType]) btnOperate:ignoreAnchorPointForPosition(false) self.btnPosX = self.btnPosX-MJDefine.MJ_OPERATE_PADDING btnOperate:setPosition(cc.p(self.btnPosX, y)) self.ui.Items.Layout_Operate:addChild(btnOperate,2) -- if operates and table.nums(operates) <=1 then -- self.btnPosX = self.btnPosX-50 -- btnOperate:setPosition(cc.p(self.btnPosX, y)) -- local gangBg = cc.Layout:create() -- gangBg:setBackGroundImageScale9Enabled(true) -- gangBg:setBackGroundImage("huamajiang_room_gangBg.png",cc.TextureResType.plistType) -- gangBg:setPosition(cc.p(btnOperate:getPositionX()+30, y-40)) -- gangBg:setSize(cc.size(80,80)) -- self.ui.Items.Layout_Operate:addChild(gangBg) -- gangBg:registerClick(function(sender) -- self:sendOp({opType = operates[1].opType,opCard = operates[1].opCard,redNum = operates[1].redNum}) -- end) -- local mj=MJ:new(operates[1].opCard,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType) -- mj:setScale(0.5) -- mj:setAnchorPoint(cc.p(0.5,0.5)) -- gangBg:addChild(mj) -- mj:setPosition(cc.p(gangBg:getContentSize().width/2+10, gangBg:getContentSize().height/2)) -- end btnOperate:registerClick(function() -- playBtnEffect() if operates and table.nums(operates) <=1 then self:sendOp({opType = operates[1].opType,opCard = operates[1].opCard,redNum = operates[1].redNum}) else self:showGangItem(operates) end end) end function huamajiangHandCardView:showGangItem(operates) self.ui.Items.Layout_OperateItem:setVisible(true) self.ui.Items.Layout_Operate_Content:removeAllChildren() local col = 0 local count = 6 local temp = self.ui.Items.Layout_MJ_Item local _size = temp:getContentSize() self.ui.Items.Layout_OperateItem:setSize(cc.size(#operates*133,_size.height + 5)) self.ui.Items.Layout_OperateItem:setPosition(cc.p(940,160 + 114)) local _size1 = self.ui.Items.Layout_OperateItem:getContentSize() self.ui.Items.Layout_Operate_Content:setSize(cc.size(_size1.width, _size1.height)) self.ui.Items.Layout_Operate_Content:setPosition(cc.p(_size1.width,0)) local history = {}; for k,v in pairs(operates) do if not history[v.opCard] then history[v.opCard] = true; local item = self.ui.Items.Layout_MJ_Item:getCopied() local mj=MJ:new(v.opCard,MJDefine.MJType.Stand,self.viewId,self.desktopType) item:addChild(mj) local size = item:getContentSize() mj:setPosition(cc.p(size.width/2,size.height/2)) self.ui.Items.Layout_Operate_Content:addChild(item) mj:registerClick(function() self:sendOp({opType = v.opType,opCard = v.opCard,redNum = v.redNum}) end) -- local col = k local row = math.ceil(k/count) -- logD(k.." :".. (k%count)) -- local isChangeRow = k%count==0 local x = self.ui.Items.Layout_Operate_Content:getContentSize().width-col*133 local y = (row-1)*size.height item:setPositionX(x) item:setPositionY(y) col = col+1 if k%count==0 then col = 0 end end end -- local count = table.nums(operates) -- local padding=10 -- local width=self.ui.Items.Layout_OperateItem:getContentSize().width -- local height=self.ui.Items.Layout_OperateItem:getContentSize().height -- local layoutItem = cc.Layout:create() -- layoutItem:setBackGroundImageScale9Enabled(true) -- --layoutItem:setBackGroundImage("mj/res/ui/zy_fangjian/mj_gang_bg.png") -- layoutItem:setAnchorPoint(cc.p(0.5,1)) -- self.ui.Items.Layout_OperateItem:addChild(layoutItem) -- if count <= 3 then -- layoutItem:setSize(cc.size(230*count+padding*count,height+padding)) -- else -- layoutItem:setSize(cc.size(230*3+padding*3,height*(math.floor(count/3)+1)+(math.floor(count/3)+1)*padding)) -- --self.ui.Items.Layout_OperateItem:setSize(cc.size(230*3+padding*3,height*(math.floor(count/3)+1)+(math.floor(count/3)+1)*padding)) -- end -- layoutItem:setPosition(cc.p(width/2,height)) -- local layoutHeight = layoutItem:getContentSize().height -- local y = 0 -- for k,v in ipairs(operates) do -- local layout=cc.Layout:create() -- layout:setBackGroundImageScale9Enabled(true) -- layout:setBackGroundImage("mj/res/ui/zy_fangjian/mj_gang_bg.png") -- self.ui.Items.Layout_OperateItem:addChild(layout) -- layout:setSize(cc.size(230,height)) -- layout:setAnchorPoint(cc.p(0,1)) -- if k%3 == 1 then -- y = layoutHeight -15- height*(math.floor(k/3)+1)-10*(math.floor(k/3)+1) -- end -- if count < 3 then -- layout:setPosition(cc.p(-145+padding*(k-1)+230*(k-1),layoutHeight-15)) -- elseif count == 3 then -- layout:setPosition(cc.p(-260+padding*(k-1)+230*(k-1),layoutHeight-15)) -- else -- layout:setPosition(cc.p(-260+padding*(k%3-1)+230*(k%3-1),y)) -- if k%3 == 0 then -- layout:setPosition(cc.p(-260+padding*2+230*2,y)) -- end -- end -- for i=1,4 do -- local mj -- if v.redNum > 0 and i<=v.redNum then -- mj=MJ:new(65,MJDefine.MJType.Stand,self.viewId,self.desktopType) -- else -- mj=MJ:new(v.opCard,MJDefine.MJType.Stand,self.viewId,self.desktopType) -- end -- mj:setScale(0.6) -- layout:addChild(mj) -- local mjWidth = mj:getContentSize().width*0.6 -- mj:setAnchorPoint(cc.p(0.5,0.5)) -- mj:setPosition(32+3*(i-1)+mjWidth*(i-1),layout:getContentSize().height/2) -- end -- layout:registerClick(function ( sender ) -- self:sendOp({opType = v.opType,opCard = v.opCard,redNum = v.redNum}) -- end) -- end end function huamajiangHandCardView:hideOperateItem() if self.ui.Items.Layout_OperateItem then self.ui.Items.Layout_Operate_Content:removeAllChildren() self.ui.Items.Layout_OperateItem:setVisible(false) end end --显示操作 function huamajiangHandCardView:showOperate(operates,card,isMyGetCard) if not operates or table.nums(operates)==0 then return end print(table.tostring(operates)) local card = card or 0 self:hideOperateItem() self:hideOperate() if operates and table.nums(operates) > 0 then self.ui.Items.Button_Sure:setVisible(false) end local newOperates = {} --有操作默认添加过的操作 --非忽略过默认添加 if not app.room.roomInfo.passGuo then local operate=MJMessage.OperateRequest:new() operate.opType=MJDefine.MJOperateType.OPREATE_CANCEL operate.opCard=card operate.redNum = 0 table.insert(newOperates,1,operate) end --table.insert(operates.Datas,1,operate) self.ui.Items.Layout_Operate:removeAllChildren() self.ui.Items.Layout_Operate:setVisible(true) local x=self.ui.Items.Layout_Operate:getContentSize().width local y=self.ui.Items.Layout_Operate:getContentSize().height/2 self.btnPosX = x local gangCards ={} --所有杠組合 local onceGang = false local isCanHu = false --operates.Datas包含所有碰杠组合,服务器不管是否贴鬼碰/杠,需客户端自己分离贴鬼碰和无贴鬼碰 for k,v in pairs(operates.Datas) do if v.opType ~= MJDefine.MJOperateType.OPREATE_CANCEL then if MJDefine.isTieGui == true then --选择贴鬼碰/杠 if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) or onceGang == false then if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) then isCanHu = true end table.insert(newOperates,v) end if (v.opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_BAGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_ANGANG) then onceGang = true table.insert(gangCards,v) end else if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) then isCanHu = true table.insert(newOperates,v) end --不勾选贴鬼碰/杠时,过滤掉带红中的碰杠 if v.redNum == 0 and v.opType ~= MJDefine.MJOperateType.OPREATE_DIANPAOHU and (v.opType ~= MJDefine.MJOperateType.OPREATE_ZIMOHU) then if onceGang == false then table.insert(newOperates,v) end if (v.opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_BAGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_ANGANG) then onceGang = true table.insert(gangCards,v) end end end end end if table.nums(newOperates) >= 2 then local function sortOperate(opA,opB) if opA.opType 4 then oldCardNum = oldCardNum - 1; local cards = oldGroup:getCards(); if cards and cards[4] then oldGroup:refreshCardNum(cards[4], oldCardNum); return ; end end local fromViewId = oldGroup.fromViewId -- 杠牌对家,换成第四张 if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then fromViewId = 4 end if app.room:getMaxPlayerCount()==4 and fromViewId == 2 then fromViewId = 4 end --local redNum = newRedNum + oldRedNum local newGroup=MJGroupFactory.CreateGroup({card,card,card},MJDefine.MJGroupType.Peng,self.viewId,self.desktopType,cardNum) if newGroup.setAnColor then newGroup:setAnColor(card, fromViewId) end newGroup.fromViewId = fromViewId newGroup.opType=MJDefine.MJOperateType.OPREATE_PENG newGroup:setPosition(oldGroup:getPosition()) self.ui.Items.Layout_Hand_Card:addChild(newGroup) local index=table.indexOf(self.handGroupCards,oldGroup) table.remove(self.handGroupCards,index) table.insert(self.handGroupCards,index,newGroup) oldGroup:removeFromParent() end end function huamajiangHandCardView:lockHandCard(isForbidTouch) if self:isUseNew3D() then self._handcard:lockHandCard(isForbidTouch) else self._isLock = true; for k,v in pairs(self.handCards) do v:setStatus(MJDefine.MJStatus.Disable) end if isForbidTouch then self:getEventDispatcher():removeEventListenersForTarget(self) end end end function huamajiangHandCardView:moveLastOpenCard() local count=#self.handCards if count>=2 then local frontMj=self.handCards[count-1] local lastMj=self.handCards[count] local margin=0 local frontX=frontMj:getPositionX() local frontY=frontMj:getPositionY() local lastX=lastMj:getPositionX() local lastY=lastMj:getPositionY() local MJLastHandCardOffset=MJDefine.MJLastHandCardOffset[self.desktopType] local MJ_HAND_CARD_LEFT_PADDING_HEIGHT = MJDefine.MJ_HAND_CARD_LEFT_PADDING_HEIGHT[self.desktopType] --根据视图ID 计算坐标 if self.viewId==MJDefine.PlayerViewType.My then margin=lastMj:getContentSize().width -- if math.abs(lastX-frontX)==margin then lastMj:setPositionX(lastX+MJLastHandCardOffset[self.viewId].x) -- end elseif self.viewId==MJDefine.PlayerViewType.Left then margin=MJ_HAND_CARD_LEFT_PADDING_HEIGHT -- if math.abs(lastY-frontY)==margin then lastMj:setPositionX(lastX+MJLastHandCardOffset[self.viewId].x) lastMj:setPositionY(lastY+MJLastHandCardOffset[self.viewId].y) -- end elseif self.viewId==MJDefine.PlayerViewType.Right then margin=MJ_HAND_CARD_LEFT_PADDING_HEIGHT -- if math.abs(lastY-frontY)==margin then lastMj:setPositionX(lastX+MJLastHandCardOffset[self.viewId].x) lastMj:setPositionY(lastY+MJLastHandCardOffset[self.viewId].y) -- end elseif self.viewId==MJDefine.PlayerViewType.Top then margin=lastMj:getContentSize().width-MJDefine.MJ_HAND_CARD_TOP_OFFSET_X -- print("width:"..lastMj:getContentSize().width) -- if math.abs(lastX-frontX)==margin then lastMj:setPositionX(lastX+MJLastHandCardOffset[self.viewId].x) -- end end end end function huamajiangHandCardView:onTouchBegan(touch) logD("huamajiangHandCardView:onTouchBegan") local lastMj=self.touchMJ self.touchMJ=nil self.isTouchMove=false -- if self.touchMJ then -- self.touchMJ:setPositionY(self.initY) -- self.touchMJ:setStatus(MJDefine.MJStatus.Normal) -- self.touchMJ=nil -- end local index = -1; local touchPos=self:convertToNodeSpace(touch:getLocation()) for k,v in pairs(self.handCards) do local width = v:getContentSize().width local height = v:getContentSize().height local x = v:getPosition().x-width/2 local y = v:getPosition().y-height/2 local rect = cc.Rectangle:new(x,y,width,height) if rect:contains(touchPos.x,touchPos.y) then if #self.handCards + #self.handGroupCards * 3 ~= 14 then -- 非抓牌状态 self.touchMJ = nil; break else -- 抓牌状态 if self._isLock and k ~= #self.handCards then self.touchMJ = nil; break end end self.touchMJ=v logD("huamajiangHandCardView:onTouchBegan touchMJ", self.touchMJ.value) if self.touchMJ.status==MJDefine.MJStatus.Select then --双击出牌 logD("huamajiangHandCardView:onTouchBegan outCard") self:sendOutCard() return false else logD("huamajiangHandCardView:onTouchBegan selectCard") self.touchMJ:recordPostion(cc.p(self.touchMJ:getPositionX(),self.initY)) self.touchMJ:runSelectAnimation() self.touchMJ:setStatus(MJDefine.MJStatus.Select) app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing,card=self.touchMJ.value}) end index = k; break end end --lastMj 有可能被移除 必须 tolua.isnull 判断一次 if lastMj and not tolua.isnull(lastMj) and lastMj~=self.touchMJ then lastMj:runDeSelectAnimation(true) lastMj:setStatus(MJDefine.MJStatus.Normal) end if self.touchMJ then app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard,value = self.touchMJ.value}) else app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard}) app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing}) return false end return true end function huamajiangHandCardView:onTouchMove(touch) local touchPos=self:convertToNodeSpace(touch:getLocation()) local prePos=self:convertToNodeSpace(touch:getPreviousLocation()) local x=math.abs(prePos.x-touchPos.x) local y=math.abs(prePos.y-touchPos.y) if x>5 or y>5 then logD("onTouchMove : ------------2") self.isTouchMove=true end if not tolua.isnull(self.touchMJ) and self.isTouchMove==true then self.touchMJ:setPosition(touchPos) self.touchMJ:setLocalZOrder(1) end end function huamajiangHandCardView:touchOutCard() if self.touchMJ and self.isTouchMove and not tolua.isnull(self.touchMJ) then logD("huamajiangHandCardView:touchOutCard", "touchMJ", self.touchMJ.value) if self.touchMJ:getPositionY()>MJDefine.MJ_TOUCH_OUT_CARD_Y and self.isOutCard then self:sendOutCard() else self.touchMJ:restorePostion() self.touchMJ:setStatus(MJDefine.MJStatus.Normal) app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard}) app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing}) if self.isOutCard then self:moveLastCard() end end end self.isTouchMove=false end --[[ 移除最后一张手牌 ]] function huamajiangHandCardView:removeLastHandCard () if self:isUseNew3D() then return self._handcard:removeLastHandCard() else if #self.handCards + #self.handGroupCards * 3 <= 13 then return false; end local last= #self.handCards; self.handCards[last]:removeFromParent(); table.remove(self.handCards,last); return true; end end --[[ 创建手牌 ]] function huamajiangHandCardView:createHandCards (arg) if self:isUseNew3D() then self._handcard:createHandCards(arg) else huamajiangHandCardView.super.createHandCards(self, arg); self:refreshLuoBoCards(); end end --[[ 刷新手牌中萝卜牌的显示 ]] function huamajiangHandCardView:refreshLuoBoCards () if self:isUseNew3D() then self._handcard:refreshLuoBoCards() else for k, card in ipairs(self.handCards or {}) do local count = app.room:getLuoBoCardCount(card:getValue()) or 0; card:setLuoBoVisible(count > 0, count) end for k,v in pairs(self.handGroupCards) do local cards = v:getCards(); for _, card in pairs(cards) do local cardValue = card:getValue(); if cardValue > 0 then local count = app.room:getLuoBoCardCount(cardValue) or 0; cards[1]:setLuoBoVisible(count > 0, count) break; end end end end end --[[ 获取最后一张牌 ]] function huamajiangHandCardView:getLastCard( ) if self:isUseNew3D() then return self._handcard:getLastCard() else return self.handCards[#self.handCards]; end end function huamajiangHandCardView:isLock () if self:isUseNew3D() then return self._handcard:isLock() else return self._isLock; end end function huamajiangHandCardView:createOutCards(arg) if self:isUseNew3D() then self._outCardView:createOutCards(arg) else if type(arg)=="number" then arg={ {card=arg} } end for k,v in pairs(arg) do print("测试:"..v.card) local mj=MJ:new(tonumber(v.card),MJDefine.MJType.Out,self.viewId,self.desktopType) self.ui.Items.Layout_Hand_Card:addChild(mj) table.insert(self.outCards,mj) local x,y=huamajiangPositionCompnent.getOutCardPosition(self.viewId,self.outX,self.outY,mj,#self.outCards,self.desktopType,app.room.roomInfo.nMaxPlayCount) mj:setPosition(x,y) end end end function huamajiangHandCardView:outCardFalg(event) if event.viewId == MJDefine.MyViewId then self:hideOperateItem() self:hideOperate() end if self:isUseNew3D() then event.pointerPath = "mj_huamajiang/res/zy_fangjian/room/huamajiang_pointer.png" self._outCardView:outCardFalg(event) else for k,v in pairs(self.outCards) do for i,child in pairs(v:getChildren()) do local tag = child:getTag() if tag ~= MJ.MJ_HAND_CARD_FLAG_LAIZI then child:removeFromParent() end end end local mj=self.outCards[#self.outCards] if event.value and mj and mj.value==event.value and event.viewId==self.viewId then local flag = cc.Sprite:create() flag:setTexture("mj_huamajiang/res/zy_fangjian/room/huamajiang_pointer.png"); -- flag:setScale(0.8) mj:addChild(flag) flag:setPosition(mj:getContentSize().width/2,mj:getContentSize().height) local moveBy=cc.MoveBy:create(0.5,cc.p(0, 30)) flag:runAction(cc.RepeatForever:create(cc.Sequence:create(moveBy,moveBy:reverse()))) end end end --- huamajiangHandCardView:runOutCardAction 出牌动画 -- @param value 牌值 -- @param callback 播放成功回调 function huamajiangHandCardView:runOutCardAction(value,callback) if self:isUseNew3D() then self._handcard:runOutCardAction(value, callback) else MJSound.PlayOutCard() self:createOutCards(value) local outCard=self.outCards[#self.outCards] local showCard=MJ:new(value,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType) self:addChild(showCard) showCard:setScale(MJDefine.MJ_OUT_CARD_SCALE) showCard:setPosition(self.showCardPostion) local rotate=0 if self.viewId==MJDefine.PlayerViewType.Left then rotate=-45 elseif self.viewId==MJDefine.PlayerViewType.Right then rotate=45 end local actions={ cc.ScaleTo:create(MJDefine.MJ_TIME_OUT_CARD_SCALE,1), cc.DelayTime:create(MJDefine.MJ_TIME_OUT_CARD_WAIT), cc.Spawn:create( cc.Spawn:create( cc.MoveTo:create(MJDefine.MJ_TIME_OUT_CARD,outCard:getPosition()), cc.ScaleTo:create(MJDefine.MJ_TIME_OUT_CARD,MJDefine.MJ_OUT_CARD_SCALE) ), cc.RotateBy:create(MJDefine.MJ_TIME_OUT_CARD,rotate) ), cc.CallFunc:create(function() -- MJSound.PlayOutCard() if outCard and not tolua.isnull(outCard) then outCard:setVisible(true) end if callback then callback() end end), cc.RemoveSelf:create(), } showCard:runAction(cc.Sequence:create(actions)) end end function huamajiangHandCardView:getHandCardNodes() if self:isUseNew3D() then return self._handcard:getHandCardNodes() else return self.handCards end end --判断是否符合换三张规则 function huamajiangHandCardView:checkIsInSwapRule() local roomInfo=app.room.roomInfo local gameInfo=json.decode(roomInfo.strGameInfo) local swapcolorcard = getNumBand(gameInfo.specRule, 0x80000) local selectNums = #self._selectCards logD("huamajiangHandCardView:checkIsInSwapRule1 "..selectNums) if selectNums ~= 3 then return false end --如果勾选了可换不同花色则不需要花色判断 只判断数量 if swapcolorcard > 0 and selectNums == 3 then return true end if swapcolorcard==0 then local huase = self._selectCards[1]:getMJColorType() logD("huamajiangHandCardView:checkIsInSwapRule2 "..huase) for i,v in pairs(self._selectCards) do local tHuase = v:getMJColorType() logD("huamajiangHandCardView:checkIsInSwapRule3 "..tHuase) if tHuase ~= huase then return false end end logD("huamajiangHandCardView:checkIsInSwapRule4 ") return true end end return huamajiangHandCardView