|
- 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 xueliuHandCardView = class("xueliuHandCardView", MJHandCardView)
-
- function xueliuHandCardView:ctor(viewId,desktopType)
- xueliuHandCardView.super.ctor(self,viewId,desktopType)
- end
-
- function xueliuHandCardView:onEnter()
- xueliuHandCardView.super.onEnter(self)
-
- self.huCardLayout = {};
- --绑定事件
- self:bindEvent(app.room , MJDefine.MJEvent.checkIsNeedSendGuo , handler(self , self.checkIsNeedSendGuo))
- end
-
- function xueliuHandCardView: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_xueliu/res/ui_fangjian/mj_xueliu_hand_card_2d.ui");
- else
- ui = loadUI("mj_xueliu/res/ui_fangjian/mj_xueliu_hand_card.ui");
- end
- self.ui = ui;
- self:addChild(ui)
- end
-
- function xueliuHandCardView:initView()
- if self:isUseNew3D() then
- self:initNew3DUI()
- else
- xueliuHandCardView.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 xueliuHandCardView: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 xueliuHandCardView: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
-
- -- todo lwq 血流, 胡牌以后,不能自己再打出牌
- if self.viewId==MJDefine.MyViewId then
- if self.isHu and self.isHu == 1 then
- self._handcard:setOutCardEnable(false)
- end
- 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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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_xueliu/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 xueliuHandCardView:showGangItem(operates)
- self.ui.Items.Layout_OperateItem:setVisible(true)
- self.ui.Items.Layout_Operate_Content:removeAllChildren()
- local col = 0
- local count = 6
-
- -- todo lwq
- local hengIndex = 0
- for k,v in pairs(operates) do
- hengIndex = hengIndex + 1
- end
- local temp = self.ui.Items.Layout_MJ_Item
- local _size = temp:getContentSize()
-
- self.ui.Items.Layout_OperateItem:setSize(cc.size(hengIndex*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))
-
- 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)
- --self.ui.Items.Layout_OperateItem: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 x = self.ui.Items.Layout_OperateItem: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 xueliuHandCardView: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 xueliuHandCardView: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<opB.opType then
- return true
- elseif opA.opType==opB.opType then
- if opA.opCard<opB.opCard then
- return true
- end
- end
- return false
- end
- table.sort(newOperates,sortOperate)
-
- --没有碰杠操作,此条件只有不勾选贴鬼碰/杠才可能会执行
- else
-
- --如果不是自己摸牌的情况下
- if not isMyGetCard then --app.room.roomInfo.outCardUserId~=app.room:getMyUserId() then --
- print("not isMyGetCard")
- self:sendOp({opType = MJDefine.MJOperateType.OPREATE_CANCEL,opCard=card,redNum=0})
- MJDefine.isSendGuo = true
- return;
- end
- --是自己摸牌
- self:hideOperate()
- self:setOutCardEnable(true)
-
- logD("xueliuHandCardView:showOperate setOutCardEnable true")
- end
-
- local pengCard = {}
- for k,v in pairs(newOperates) do
- if MJDefine.MJOperateImage[v.opType] then
- if(v.opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_BAGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
- self:addOperateBtn(gangCards)
- elseif v.opType==MJDefine.MJOperateType.OPREATE_PENG then
- table.insert(pengCard,v)
- self:addOperateBtn(pengCard)
- elseif (v.opType~=MJDefine.MJOperateType.OPREATE_ZHIGANG) or (v.opType~=MJDefine.MJOperateType.OPREATE_BAGANG) or (v.opType~=MJDefine.MJOperateType.OPREATE_ANGANG) or (v.opType~=MJDefine.MJOperateType.OPREATE_PENG) then
- --非碰杠进入这里
- local btnOperate=cc.Button:createNode()
- btnOperate:setDefaults()
- btnOperate:setText("")
- btnOperate:loadTextureNormal(MJDefine.MJOperateImage[v.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)
-
- --ljx 修复胡牌后有杠操作时没有过按钮显示 增加onceGang变量控制
- if v.opType == MJDefine.MJOperateType.OPREATE_CANCEL then
- if self.isHu and self.isHu == 1 and not onceGang then
- -- 杠有过,免的枪杆胡了
- btnOperate:setVisible(false)
- end
- end
-
- if isCanHu and isCanHu == true and v.opType == MJDefine.MJOperateType.OPREATE_CANCEL then
- local function qiHuConfirm()
- local content = string.format("确定放弃胡牌吗?")
- local okCallBack = function ()
- self:sendOp(v)
- end
- local cancelCallBack = function ()
-
- end
- showConfirmDialog(content,okCallBack,cancelCallBack)
- end
- btnOperate:registerClick(qiHuConfirm)
- else
- btnOperate:registerClick(function()
- -- playBtnEffect()
- self:sendOp(v)
-
- end)
- end
- end
- end
- end
- end
-
- function xueliuHandCardView:sendOp(value)
- local request = MJMessage.OperateRequest:new()
- request.opType = value.opType
- request.opCard = value.opCard
- self.operates = self.operates or {}
- local opNum = 2--table.nums(self.operates)
- --[[if opNum and opNum > 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("xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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()
- -- xueliuHandCardView.super.sendOutCard(self)
- -- -- end)
- -- else
- xueliuHandCardView.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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView: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 xueliuHandCardView:onTouchMove(touch)
- xueliuHandCardView.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 xueliuHandCardView: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 xueliuHandCardView: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_xueliu/res/zy_fangjian/xzdd_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 xueliuHandCardView:getHandCardNodes()
- if self:isUseNew3D() then
- return self._handcard:getHandCardNodes()
- else
- return self.handCards
- end
- end
-
- function xueliuHandCardView:isUseNew3D()
- --return true
- if self.desktopType == MJDefine.DesktopType.TwoDL then
- return false
- else
- return true
- end
- end
-
- --[[function xueliuHandCardView:sortHandCards()
- if self:isUseNew3D() then
- self._handcard:sortHandCards()
- else
- xueliuHandCardView.super.sortHandCards(self)
- end
- end--]]
-
- --创建换三张的牌
- function xueliuHandCardView: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
-
-
- function xueliuHandCardView:setIsHupai(hu)
- self.isHu = hu
-
- -- if hu == 0 then
- -- self._handcard:setOutCardEnable(true)
- -- end
- -- self._handcard:setIsHupai(hu) -- 胡了后,牌躺下
- end
-
-
- --设置定缺类型 0万,1同,2条
- function xueliuHandCardView:setQueType(que)
- if self:isUseNew3D() then
- self._handcard:setQueType(que)
- else
- self.queType = que
- --设置完定缺牌后,重新设置一下麻将的排序值,目标为了把定缺牌放到右边
- self:resetCardsSortValue()
- end
- end
-
- function xueliuHandCardView:resetCardsSortValue()
- for k,v in pairs(self.handCards) do
- if v:getMJColorType() == self.queType then
- v.sortValue = v.value + 100
- end
- end
- end
-
-
- --[[
- 移除最后一张手牌
- ]]
- function xueliuHandCardView: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
-
- --[[
- 显示胡的牌
- @param card 胡的牌
- ]]
- function xueliuHandCardView: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
-
- 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 - k) * (w - 2);
- card:setPositionX(x);
- 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 - k) * (h - 9);
- 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 = (k - 1) * (h - 9);
- card:setPositionY(y);
- end
- card:setLocalZOrder(#huCards - k);
- 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 = (k - 1) * (w - 1);
- card:setPositionX(x);
- 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 xueliuHandCardView:onXueliuOutHuCard(card,callback)
- -- self:createOutCards(card)
- if self:isUseNew3D() then
- -- self._handcard:onOutCard(card, callback) --todo lwq
-
- if self.viewId~=MJDefine.MyViewId then --其他玩家删除最后一个牌
- local mj=self:getMjByValue(card)
- if mj then
- self:removeHandCard(card)
- -- self:resetHandCards()--todo lwq
- else
- local last=#self.handCards
- if last and self.handCards[last] then
- self.handCards[last]:removeFromParent()
- table.remove(self.handCards,last)
- end
- end
- else
- -- self:setOutCardEnable(false)
-
- -- local mj=self:getMjByValueReverseOrder(card)
- -- local mj = self:getMjByValue(card)
- -- --插牌
- -- -- if mj==self.handCards[#self.handCards] then
- -- -- table.removeItem(self.handCards,mj)
- -- -- -- self:resetHandCards() -- tod lwq
- -- -- else
- -- -- table.removeItem(self.handCards,mj)
- -- -- -- self:runInsertCardAction() --todo lwq
- -- -- end
-
- -- if mj then
- -- -- self:removeHandCard(card) -- todo lwq
- -- mj:removeFromParent() --todo
- -- mj=nil --todo
- -- end
-
- self._handcard:onOutCard(card, callback) --todo lwq
- end
-
- -- todo lwq test
- self._huCardView:onOutXueliuHuCard(card, callback)
- else
- self:runOutCardAction(card,callback)
-
- if self.viewId~=MJDefine.MyViewId then --其他玩家删除最后一个牌
- local mj=self:getMjByValue(card)
- if mj then
- self:removeHandCard(card)
- self:resetHandCards()
- -- mj:removeFromParent()
- else
- local last=#self.handCards
- if last and self.handCards[last] then
- self.handCards[last]:removeFromParent()
- table.remove(self.handCards,last)
- end
- end
- else
- -- self:runOutCardAction(self.touchMJ.value)
- -- app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value=self.touchMJ.value,viewId=self.viewId})
- self:setOutCardEnable(false)
-
- local mj=self:getMjByValueReverseOrder(card)
- --插牌
- if mj==self.handCards[#self.handCards] then
- table.removeItem(self.handCards,mj)
- self:resetHandCards()
- else
- table.removeItem(self.handCards,mj)
- self:runInsertCardAction()
- end
-
- -- self:removeHandCard(card)
- -- self:resetHandCards()
- if mj then
- mj:removeFromParent()
- mj=nil
- end
- end
-
- -- local memberInfo=app.room.roomInfo.memberList[data.response.nUserId]
- local userInfo=app.room:getUserInfoByViewId(self.viewId)
- if userInfo and (self.viewId~=MJDefine.MyViewId or self.isReplay) then
- MJSound.PlayMJSound(userInfo.sex,card)
- end
- end
- end
-
- return xueliuHandCardView
|