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 MJPositionCompnent = MJFramework.MJImport("mj.luaScript.Views.Compnent.MJPositionCompnent") 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 bazhongHandCardView = class("bazhongHandCardView", MJHandCardView) function bazhongHandCardView:ctor(viewId,desktopType) bazhongHandCardView.super.ctor(self,viewId,desktopType) end function bazhongHandCardView:onEnter() bazhongHandCardView.super.onEnter(self) --绑定事件 self:bindEvent(app.room , MJDefine.MJEvent.checkIsNeedSendGuo , handler(self , self.checkIsNeedSendGuo)) end function bazhongHandCardView:loadUI() local ui if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold or self.desktopType==MJDefine.DesktopType.TwoDL then ui = loadUI("mj_bazhong/res/ui_fangjian/mj_bazhong_hand_card_2d.ui"); else ui = loadUI("mj_bazhong/res/ui_fangjian/mj_bazhong_hand_card.ui"); end self.ui = ui; self:addChild(ui) end function bazhongHandCardView:initView() if self:isUseNew3D() then self:initNew3DUI() else bazhongHandCardView.super.initView(self) self:hideOperateItem() if app.room:getMaxPlayerCount()~= 2 then if self.viewId == MJDefine.PlayerViewType.My then self.outX=self.outX-30 end end local roomInfo = app.room.roomInfo or {} local strGameInfo = roomInfo.strGameInfo local gameInfo = json.decode(strGameInfo) or {} local cardNum = tonumber(gameInfo.handcard or 13) if MJDefine.HandCardStartPosOfCardNum[cardNum][self.viewId] then self.initX = MJDefine.HandCardStartPosOfCardNum[cardNum][self.viewId].x self.initY = MJDefine.HandCardStartPosOfCardNum[cardNum][self.viewId].y end end end function bazhongHandCardView:pushTing() if self:isUseNew3D() then self._handcard:pushTing() else local tings=app.room.roomInfo.tings 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 bazhongHandCardView:onGetCard(operates,card,isSwap) if self:isUseNew3D() then self.touchMJ = nil self:createHandCards(card) 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 if self.viewId==MJDefine.MyViewId then self:resetHandCardsPosAndOpacity() end self:createHandCards(card) self:resetCardsSortValue()--为了给刚摸上的牌重新赋值排序值 if self.viewId==MJDefine.PlayerViewType.Right and not self.isReplay then self:resetHandCards() end if isSwap and isSwap == true then return 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 end end function bazhongHandCardView: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 bazhongHandCardView: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 bazhongHandCardView:removeHandCardByNum(value,num,redNum) redNum = redNum or 0 if self:isUseNew3D() then self._handcard:removeHandCardByNum(value, num,redNum) else if self.viewId==MJDefine.MyViewId or self.isReplay then for i=1,num do local mj if redNum > 0 and i <= redNum then mj=self:getMjByValue(65) --红中值 else mj=self:getMjByValue(value) end 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 if self.handCards[i] then self.handCards[i]:removeFromParent() table.remove(self.handCards,i) end end end end end function bazhongHandCardView:getGroup(card,opType) if self:isUseNew3D() then return self._handcard:getGroup(card, opTypes) else for k,v in pairs(self.handGroupCards) do if v.opType==opType and (v.mjs[1].value==card or v.mjs[2].value == card or v.mjs[3].value == card) then local redNum = 0 for i,mj in pairs(v.mjs) do --先取出原组合的红中个数 if mj.value == 65 then redNum = redNum + 1 end end return v,redNum end end end end function bazhongHandCardView: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=MJGroupFactory.CreateGroup(v.values,v.showType,self.viewId,self.desktopType,v.redNum) 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 if v.opType == MJDefine.MJOperateType.OPREATE_BAGANG and group.mjs and group.mjs[4] then --group.mjs[4]:setOutBlackImage(0,self.viewId) 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=MJPositionCompnent.getGroupPosition(self.viewId,x,y,group,self.desktopType) table.insert(self.handGroupCards,group) end end --更新起始位置 self.initX=x self.initY=y end end --添加杠操作按钮 function bazhongHandCardView: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("mj_bazhong/res/zy_fangjian/xzddadd/xzdd_room_gangBg.png",0) 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 bazhongHandCardView:showGangItem(operates) self.ui.Items.Layout_OperateItem:setVisible(true) self.ui.Items.Layout_Operate_Content:removeAllChildren() local col = 0 local count = 6 for k,v in pairs(operates) do 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 -- 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 bazhongHandCardView: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 bazhongHandCardView: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 self.operates = operates local newOperates = {} --有操作默认添加过的操作 local operate=MJMessage.OperateRequest:new() operate.opType=MJDefine.MJOperateType.OPREATE_CANCEL operate.opCard=card operate.redNum = 0 --table.insert(operates.Datas,1,operate) table.insert(newOperates,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 print(table.tostring(newOperates)) if table.nums(newOperates) >= 2 then local function sortOperate(opA,opB) if opA.opType 0 then for _,v in ipairs(self.operates.Datas or {}) do table.insert(request.operates.Datas, v) end end--]] --request.opNum = opNum --request.operates = self.operates logE("bazhongHandCardView:sendOp"..table.tostring(request)) --[[self.ui:sendMsg(app.room, MJDefine.MJEvent.Operate, request, function(status, response) logE("MJHandCardView showOperate() response = ", table.tostring(response)) end)--]] app.room:sendOperateCard(value,self.operates) self:hideOperateItem() self:hideOperate() self.operates = nil if value.opType == MJDefine.MJOperateType.OPREATE_CANCEL then app.room:dispatchEvent({name = MJDefine.MJEvent.SendGuo}) end --self:setTing(false) --app.room:resetTings() end --检测是否需要先发过(有操作出牌的情况下要先发过) function bazhongHandCardView:checkIsNeedSendGuo() if self.ui.Items.Layout_Operate and self.ui.Items.Layout_Operate:isVisible() and self.viewId == MJDefine.MyViewId and not self.isNotSendIng then self.isNotSendIng = true self:sendOp({opType = MJDefine.MJOperateType.OPREATE_CANCEL,opCard=card,redNum=0}) self.ui:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function() self.isNotSendIng = false end))) end end --发送出牌消息 function bazhongHandCardView:sendOutCard() if not self.isOutCard or not self.touchMJ then return end if not self.touchMJ.value or self.touchMJ.value == 0 then return end self:checkIsNeedSendGuo() self:hideOperate() -- if MJDefine.outCardSendGuo == true then -- self:sendOp({opType = MJDefine.MJOperateType.OPREATE_CANCEL,opCard=0,redNum=0}) -- -- self:runDelay(0.1,function() -- bazhongHandCardView.super.sendOutCard(self) -- -- end) -- else bazhongHandCardView.super.sendOutCard(self) -- end app.room.roomInfo.lastOutViewId = MJDefine.MyViewId self:checkQueAndDisableOtherCard() -- local request = MJMessage.Card:new() -- request.card = self.touchMJ.value -- -- logE("LHQRecordView:setOutCardVisible"..table.tostring(request)) -- self.ui:sendMsg(app.room, MJDefine.MJEvent.OutCard, request, function(status, response) -- logE("MJHandCardView sendOutCard() response = ", table.tostring(response)) -- end) -- --音效 -- local userInfo=app.room:getUserInfoByViewId(self.viewId) -- if userInfo then -- MJSound.PlayMJSound(userInfo.sex,request.card) -- end -- app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value=self.touchMJ.value,viewId=self.viewId}) -- self:setOutCardEnable(false) -- app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard}) -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing}) -- self:setTing(false) -- app.room:resetTings() -- self.touchMJ=nil end --恢复麻将位置和透明度 function bazhongHandCardView:resetHandCardsPosAndOpacity() local initX,initY=self:getInitHandCardPostion() local x=initX local y=initY local insertX=0 local insertY=0 if MJDefine.isAutomatic == true then self:sortHandCards() else end for k,mj in pairs(self.handCards) do mj:setPosition(x,y) mj:setOpacity(255) x,y=MJPositionCompnent.getHandCardPosition(self.viewId,initX,initY,mj,k,self.desktopType) end return insertX,insertY end function bazhongHandCardView:resetHandCards(insertMj,isAnimation) if self:isUseNew3D() then self._handcard:resetHandCards(insertMj,isAnimation) else -- local initX=self.initX -- local initY=self.initY local initX,initY=self:getInitHandCardPostion() local x=initX local y=initY local insertX=0 local insertY=0 if MJDefine.isAutomatic == true then self:sortHandCards() else -- self:sortRedMahjong() end for k,mj in pairs(self.handCards) do if mj.status ~= MJDefine.MJStatus.Disable then mj:setStatus(MJDefine.MJStatus.Normal) mj:stopAllActions() end logD("k:"..k.." value:"..mj.value) if insertMj==mj then --记录插入麻将的坐标 动画需要 insertX=x insertY=y else if isAnimation then mj:runAction(cc.MoveTo:create(0.1,cc.p(x,y))) else mj:setPosition(x,y) end end x,y=MJPositionCompnent.getHandCardPosition(self.viewId,initX,initY,mj,k,self.desktopType) end return insertX,insertY end end function bazhongHandCardView:moveRestHandCards(insertMj,isAnimation) local initX,initY=self:getInitHandCardPostion() local x=initX local y=initY local insertX=0 local insertY=0 for k,mj in pairs(self.handCards) do --如果可以出牌 最后的麻将不重置位置 -- local isLastCard = self.isOutCard and k==#self.handCards -- if isLastCard then -- break -- end if mj.status ~= MJDefine.MJStatus.Disable then mj:setStatus(MJDefine.MJStatus.Normal) mj:stopAllActions() end logD("k:"..k.." value:"..mj.value) if insertMj==mj then --记录插入麻将的坐标 动画需要 insertX=x insertY=y else if isAnimation then mj:runAction(cc.MoveTo:create(0.1,cc.p(x,y))) else mj:setPosition(x,y) end end x,y=MJPositionCompnent.getHandCardPosition(self.viewId,initX,initY,mj,k,self.desktopType) end return insertX,insertY end --[[function bazhongHandCardView:onTouchEnd(touch) if MJDefine.isAutomatic == false then local touchPos=self:convertToNodeSpace(touch:getLocation()) local newHandCards = {} for k,mj in pairs(self.handCards) do table.insert(newHandCards,k,mj) local width = mj:getContentSize().width local height = mj:getContentSize().height local x = mj:getPosition().x-width/2 local y = mj:getPosition().y-height/2 local rect = cc.Rectangle:new(x,y,width,height) if rect:contains(touchPos.x,touchPos.y) then if self.handCards[k] then table.remove(newHandCards,k) end if self.touchMJ and not tolua.isnull(self.touchMJ) then table.insert(newHandCards,k,self.touchMJ) end end end self.handCards = nil self.handCards = DeepCopy(newHandCards) end self:touchOutCard() end --]] function bazhongHandCardView:buGang(card,newRedNum) newRedNum = newRedNum or 0 if self:isUseNew3D() then self._handcard:buGang(card, newRedNum) else local oldGroup,oldRedNum=self:getGroup(card,MJDefine.MJOperateType.OPREATE_PENG) if not oldGroup then return 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,card},MJDefine.MJGroupType.Gang,self.viewId,self.desktopType,redNum) if newGroup.setAnColor then newGroup:setAnColor(card, fromViewId) end newGroup.fromViewId = fromViewId newGroup.opType=MJDefine.MJOperateType.OPREATE_BAGANG newGroup:setPosition(oldGroup:getPosition()) if newGroup.mjs and newGroup.mjs[4] then newGroup.mjs[4]:setOutBlackImage(0,self.viewId) end 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 bazhongHandCardView:retoreBuGang(card,newRedNum) newRedNum = newRedNum or 0 if self:isUseNew3D() then self._handcard:restoreBuGang(card, cardNum) else local oldGroup,oldRedNum=self:getGroup(card,MJDefine.MJOperateType.OPREATE_BAGANG) if not oldGroup then return 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 redNum = oldRedNum local newGroup=MJGroupFactory.CreateGroup({card,card,card},MJDefine.MJGroupType.Peng,self.viewId,self.desktopType,redNum) 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 bazhongHandCardView:lockHandCard(isForbidTouch) if self:isUseNew3D() then self._handcard:lockHandCard(isForbidTouch) else for k,v in pairs(self.handCards) do v:setStatus(MJDefine.MJStatus.Disable) end self:getEventDispatcher():removeEventListenersForTarget(self) end end function bazhongHandCardView: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 bazhongHandCardView:onTouchMove(touch) bazhongHandCardView.super.onTouchMove(self,touch) if self.touchMJ and self.isTouchMove==true then local pos = self.touchMJ:getPosition() local index = nil 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*0.8,height*0.8) --如果可以出牌 最后的麻将不参与移动操作 -- local isLastCard = self.isOutCard and k==#self.handCards if rect:contains(pos.x,pos.y) and v ~=self.touchMJ and not isLastCard then index = k break end end if index then local touchMJIndex = table.indexOf(self.handCards,self.touchMJ) local offsetIndex = touchMJIndex-index local num = math.abs(offsetIndex)-1 --大于0则往左移动 3-1:3-2 2-1 小于0右 5-8:5-6 6-7 7-8 local reduce = offsetIndex>0 and -1 or 1 for i = touchMJIndex,index-reduce,reduce do self.handCards[i],self.handCards[i+reduce] = self.handCards[i+reduce],self.handCards[i] end local x,y = self:moveRestHandCards(self.touchMJ) self.touchMJ:recordPostion(cc.p(x,y)) end end end function bazhongHandCardView:touchOutCard() if self.touchMJ and self.isTouchMove then 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 bazhongHandCardView:outCardFalg(event) if event.viewId == MJDefine.MyViewId then self:hideOperateItem() self:hideOperate() end if self:isUseNew3D() then 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_bazhong/res/zy_fangjian/bazhong_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 function bazhongHandCardView:getHandCardNodes() if self:isUseNew3D() then return self._handcard:getHandCardNodes() else return self.handCards end end function bazhongHandCardView:isUseNew3D() --return true if self.desktopType == MJDefine.DesktopType.TwoDL then return false else return true end end --[[function bazhongHandCardView:sortHandCards() if self:isUseNew3D() then self._handcard:sortHandCards() else bazhongHandCardView.super.sortHandCards(self) end end--]] --创建换三张的牌 function bazhongHandCardView:createSwapCards(cards, idx) local group = nil if self:isUseNew3D() then local data = { huCard = cards, huType = -1, } group = self._huCardView:createCard(data, idx) else group = MJ:new(cards, MJDefine.MJType.Out, self.viewId, self.desktopType) -- 这个没调位置,判断认为现在的麻将都会走userNew3d end return group end --设置定缺类型 0万,1同,2条 function bazhongHandCardView:setQueType(que) if self:isUseNew3D() then self._handcard:setQueType(que) else self.queType = que --设置完定缺牌后,重新设置一下麻将的排序值,目标为了把定缺牌放到右边 self:resetCardsSortValue() end end function bazhongHandCardView:resetCardsSortValue() for k,v in pairs(self.handCards) do if v:getMJColorType() == self.queType then v.sortValue = v.value + 100 end end end --判断是否符合换三张规则 function bazhongHandCardView:checkIsInSwapRule() local roomInfo=app.room.roomInfo local gameInfo=json.decode(roomInfo.strGameInfo) logD("bazhongHandCardView:gameInfo.swapcolourcard "..gameInfo.swapcolourcard) local selectNums = #self._selectCards logD("bazhongHandCardView:checkIsInSwapRule1 "..selectNums) if selectNums ~= 3 then return false end --如果勾选了可换不同花色则不需要花色判断 只判断数量 if tonumber(gameInfo.swapcolourcard)==1 and selectNums == 3 then return true end if not gameInfo.swapcolourcard or tonumber(gameInfo.swapcolourcard)==0 then local huase = self._selectCards[1]:getMJColorType() logD("bazhongHandCardView:checkIsInSwapRule2 "..huase) for i,v in pairs(self._selectCards) do local tHuase = v:getMJColorType() logD("bazhongHandCardView:checkIsInSwapRule3 "..tHuase) if tHuase ~= huase then return false end end logD("bazhongHandCardView:checkIsInSwapRule4 ") return true end end return bazhongHandCardView