|
- 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 zigong7zHandCardView=MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Game.zigong7zHandCardView")
- local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
-
- local zigong7zHandCardView = class("zigong7zHandCardView", cc.UIView)
-
- -- 组件
- local HandCard_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_HandCard_Component'
- local OutCard_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_OutCard_Component'
- local HuCard_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_HuCard_Component'
-
- function zigong7zHandCardView:ctor(viewId,desktopType)
- zigong7zHandCardView.super.ctor(self)
-
- self.viewId=viewId or MJDefine.MyViewId
- self.desktopType=desktopType or MJDefine.DesktopType.ThreeD
-
- --初始化视图
- self:initView()
-
- self.handCards={}
- self.handGroupCards={}
- self.outCards={}
- self.touchMJ=nil
- self.isOutCard=false
- self.isReplay=false
-
- if self.viewId == MJDefine.PlayerViewType.My then
- self:initTouchEvent()
- end
- end
-
- function zigong7zHandCardView:initView()
- self:loadUI()
-
- if self.ui.Items.Layout_Hand_Card then
- self.ui.Items.Layout_Hand_Card:setVisible(false)
- end
- if self.ui.Items.Button_Sure then
- self.ui.Items.Button_Sure:setVisible(false)
- end
-
- local MJConfig = MJDefine.MJConfig_2d
- if self.desktopType == MJDefine.DesktopType.ThreeD then
- MJConfig = MJDefine.MJConfig_3d
- end
-
- local MahjongHandCard = require(HandCard_Component)
- local MahjongOutCardView = require(OutCard_Component)
- local MahjongHuCardView = require(HuCard_Component)
-
- self._handcard = MahjongHandCard:new(self, self.viewId, self.desktopType)
- self:addChild(self._handcard)
-
- self._outCardView = MahjongOutCardView:new(self.viewId, self.desktopType)
- self:addChild(self._outCardView)
-
-
- self._huCardView = MahjongHuCardView:new(self.viewId, self.desktopType)
- self:addChild(self._huCardView)
-
-
- self.ui:setLocalZOrder(10)
- end
-
- -- 加载ui
- function zigong7zHandCardView:loadUI()
- local ui
- if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold then
- ui = loadUI("mj_zigong7z/res/ui_fangjian/mj_zigong_hand_card_2d.ui");
- else
- ui = loadUI("mj_zigong7z/res/ui_fangjian/mj_zigong_hand_card.ui");
- end
- autoAdapt(ui)
- self.ui = ui;
- self:addChild(ui)
- end
-
- function zigong7zHandCardView:pushTing()
- self._handcard:pushTing()
- end
-
- --摸牌
- function zigong7zHandCardView:onGetCard(operates,card)
- 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
- end
-
- function zigong7zHandCardView:setOutCardEnable(b)
- self._handcard:setOutCardEnable(b)
- end
-
- --不管是否自动对齐,红中始终保持放在最左边
- function zigong7zHandCardView: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 zigong7zHandCardView:removeHandCardByNum(value,num,redNum)
- self._handcard:removeHandCardByNum(value, num,redNum)
- end
-
- function zigong7zHandCardView:getGroup(card,opType)
- return self._handcard:getGroup(card, opTypes)
- end
-
- --添加杠操作按钮
- function zigong7zHandCardView: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("zg_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 zigong7zHandCardView:sendOutCard()
- if not self.isOutCard or not self.touchMJ then return end
- app.room:dispatchEvent({name = MJDefine.MJEvent.HideOperateLayer})
- zigong7zHandCardView.super.sendOutCard(self)
- app.room.roomInfo.lastOutViewId = MJDefine.MyViewId
- end
-
- --恢复麻将位置和透明度
- function zigong7zHandCardView:resetHandCardsPosAndOpacity()
- logD("zigong7zHandCardView: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 zigong7zHandCardView:resetHandCards(insertMj,isAnimation)
- self._handcard:resetHandCards(insertMj,isAnimation)
- end
-
- function zigong7zHandCardView: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 zigong7zHandCardView:buGang(card,newRedNum)
- self._handcard:buGang(card, cardNum)
- end
-
- function zigong7zHandCardView:retoreBuGang(card,newRedNum)
- self._handcard:restoreBuGang(card, cardNum)
- end
-
- function zigong7zHandCardView:lockHandCard(isForbidTouch)
- self._handcard:lockHandCard(isForbidTouch)
- end
-
- function zigong7zHandCardView: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.LeftUp 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.LeftDown 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.RightUp 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.RightDown 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 zigong7zHandCardView:onTouchMove(touch)
- zigong7zHandCardView.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 zigong7zHandCardView:touchOutCard()
- if self.touchMJ and self.isTouchMove and (not tolua.isnull(self.touchMJ)) 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 zigong7zHandCardView:outCardFalg(event)
- if event.viewId == MJDefine.MyViewId then
- app.room:dispatchEvent({name = MJDefine.MJEvent.HideOperateLayer})
- end
-
- self._outCardView:outCardFalg(event)
- end
-
- function zigong7zHandCardView:getHandCardNodes()
- return self._handcard:getHandCardNodes()
- end
-
- function zigong7zHandCardView:createHandCards(arg)
- self._handcard:createHandCards(arg)
- end
-
- function zigong7zHandCardView:createOutCards(arg)
- self._outCardView:createOutCards(arg)
- end
-
- function zigong7zHandCardView:createGroupCards(arg,fromViewId)
- self._handcard:createGroupCards(arg, fromViewId)
- end
-
- function zigong7zHandCardView:createOpenHandCards(arg)
- self._handcard:createOpenHandCards(arg)
- end
-
- function zigong7zHandCardView:initTouchEvent()
- if self._isReplay then--回放不需要触摸事件
- self:getEventDispatcher():removeEventListenersForTarget(self)
- return
- end
-
- self._handcard:initTouchEvent()
- end
-
- -- 获得麻将的initY坐标
- function zigong7zHandCardView:getHandCardPosInitY()
- local x, y = self._handcard:getCardPosition(self._handcard:getLastCard(), self._handcard:getViewId(), self._handcard:getHandCardsLength())
- return y or 0
- end
-
- --设置是否回放
- function zigong7zHandCardView:setReplay(b)
- self._handcard:setReplay(b)
- end
-
- function zigong7zHandCardView:onEnter()
- zigong7zHandCardView.super.onEnter(self)
-
- --绑定事件
- self:bindEvent(app.room , MJDefine.MJEvent.SelectCard , handler(self , self.selectCard))
- self:bindEvent(app.room , MJDefine.MJEvent.OutCardFalg , handler(self , self.outCardFalg))
- end
-
- --最后一张牌显示箭头
- function zigong7zHandCardView:pushLastCardTing()
- self._handcard:pushLastCardTing()
- end
-
- function zigong7zHandCardView:setTing(b)
- local handCarsNum = self:getHandCardsNum()
- if not (handCarsNum%3 == 2) then--如果不是出牌阶段,不显示箭头
- b = false
- end
- self._handcard:setTing(b)
- end
-
- function zigong7zHandCardView:selectCard(event)
- --if not self.touchMJ then return end
- if event.value then
- for k,v in pairs(self.outCards) do
- if not tolua.isnull(v) then
- if v.value==event.value then
- v:setStatus(MJDefine.MJStatus.Select)
- else
- v:setStatus(MJDefine.MJStatus.Normal)
- end
- end
- end
- else
- --self:setTing(false)
- for k,v in pairs(self.outCards) do
- if v.status~=MJDefine.MJStatus.Disable and (not tolua.isnull(v)) then
- v:setStatus(MJDefine.MJStatus.Normal)
- end
- end
- end
- -- app.room:dispatchEvent({name = "showProp",response = response});
- end
-
- function zigong7zHandCardView:isCanOutCard()
- return self._handcard:isCanOutCard(true)
- end
-
- function zigong7zHandCardView:moveLastCard()
- 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
- local space = math.ceil(math.abs(lastX-frontX))
- if space == 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 zigong7zHandCardView:getInitHandCardPostion()
- local initX=self.initX
- local initY=self.initY
-
- local MJGroupWithMJMargin=MJDefine.MJGroupWithMJMargin[self.desktopType]
-
- --如果有麻将组重新定位手牌位置
- if #self.handGroupCards>0 then
- local lastGroup=self.handGroupCards[#self.handGroupCards]
- if self.viewId==MJDefine.PlayerViewType.My then
- -- initX=initX--+MJGroupWithMJMargin[self.viewId].x
- elseif self.viewId==MJDefine.PlayerViewType.Left then
- initX=initX+MJGroupWithMJMargin[self.viewId].x
- initY=lastGroup:getPositionY()-lastGroup:getContentSize().height/2-MJGroupWithMJMargin[self.viewId].y
- elseif self.viewId==MJDefine.PlayerViewType.Right then
- initX=initX+MJGroupWithMJMargin[self.viewId].x
- initY=lastGroup:getPositionY()+lastGroup:getContentSize().height/2+MJGroupWithMJMargin[self.viewId].y
- elseif self.viewId==MJDefine.PlayerViewType.Top then
- -- initX=initX--+MJGroupWithMJMargin[self.viewId].x
- end
- end
-
- return initX,initY
- end
-
- function zigong7zHandCardView:removeAllHandCards()
- self._handcard:removeAllHandCards()
- end
-
- --删除触摸事件only
- function zigong7zHandCardView:removeTouchEventOnly()
- self:getEventDispatcher():removeEventListenersForTarget(self)
- end
-
- --初始化换牌触摸事件
- function zigong7zHandCardView:initSwapCardTouchEvent()
- if self._isReplay then--回放不需要触摸事件
- self:getEventDispatcher():removeEventListenersForTarget(self)
- return
- end
- self._handcard:initSwapCardTouchEvent()
- end
-
- --初始化摆牌触摸事件
- function zigong7zHandCardView:initBaiCardTouchEvent()
- if self._isReplay then--回放不需要触摸事件
- self:getEventDispatcher():removeEventListenersForTarget(self)
- return
- end
-
- self._handcard:initBaiCardTouchEvent()
- end
-
- function zigong7zHandCardView:removeTouchEvent()
- self:getEventDispatcher():removeEventListenersForTarget(self)
- if self.ui.Items.Button_Sure then
- self.ui.Items.Button_Sure:setVisible(false)
- self.ui.Items.Button_Sure:removeFromParent()
- self.ui.Items.Button_Sure=nil
- end
- self:setTing(false)
- end
-
- --换三张时的触摸事件
- function zigong7zHandCardView:onSwapTouchBegan(touch)
- self._selectCards = self._selectCards or {}
-
- 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
- self.touchMJ=v
- if self.touchMJ:getSelected()==MJDefine.MJStatus.Select then
- self.touchMJ:runDeSelectAnimationWithTime(0.1)
- self.touchMJ:setSelected(MJDefine.MJStatus.Normal)
- table.removeItem(self._selectCards,self.touchMJ)
- else
- self.touchMJ:recordPostion(cc.p(self.touchMJ:getPositionX(),self.initY))
- self.touchMJ:runSelectAnimation()
- self.touchMJ:setSelected(MJDefine.MJStatus.Select)
- table.insert(self._selectCards,self.touchMJ)
- end
- if self:checkIsInSwapRule() then
- app.room:dispatchEvent({name = MJDefine.MJEvent.CheckIsInSwapRule,canCommit=true})
- else
- app.room:dispatchEvent({name = MJDefine.MJEvent.CheckIsInSwapRule,canCommit=false})
- end
- break
- end
- end
- end
-
- --判断是否符合换三张规则
- function zigong7zHandCardView:checkIsInSwapRule()
- return self._handcard:checkIsInSwapRule()
- end
-
- --获取选择的牌
- function zigong7zHandCardView:getSelectedCards()
- return self._handcard:getSelectedCards()
- end
-
- --通过传进来的参数cards来选出手牌里的cards,服务器推荐选牌用
- function zigong7zHandCardView:selectCardsByCards(cards)
- self._handcard:selectCardsByCards(cards)
- end
-
- --删除选中的牌
- function zigong7zHandCardView:deleteSelectedCards()
- self._handcard:deleteSelectedCards()
- end
-
- --设置定缺类型 0万,1同,2条
- function zigong7zHandCardView:setQueType(que)
- self._handcard:setQueType(que)
- end
-
- --检查手牌是否有定缺牌
- function zigong7zHandCardView:checkHandCardHaveQue(que)
- return self._handcard:checkHandCardHaveQue(que)
- end
-
- --检测定缺牌,屏蔽缺牌以外的牌(定缺牌打完钱不能打别的牌)
- function zigong7zHandCardView:checkQueAndDisableOtherCard()
- self._handcard:checkQueAndDisableOtherCard()
- end
-
- --设置所有手牌状态为Disable
- function zigong7zHandCardView:setHandCardsDidable()
- self._handcard:setHandCardsDidable()
- end
-
- --设置非打出去能听的牌Disable
- function zigong7zHandCardView:setNotTingCardDidable(is)
- self._handcard:setNotTingCardDidable(is)
- end
-
- --创建换三张的牌
- function zigong7zHandCardView:createSwapCards(cards)
- local group = self._handcard:createSwapCards(cards)
- if group then
- self.ui.Items.Layout_Animation:addChild(group,1,SWAP_CARD_TAG)
- local pos = self:getAnimationPostion()
- if self.viewId==MJDefine.MyViewId then
- pos.x = pos.x - 50
- elseif self.viewId==MJDefine.PlayerViewType.Top then
- pos.y = pos.y - 20
- end
- group:setPosition(pos)
- end
- end
-
- --删除换三张的牌
- function zigong7zHandCardView:deleteSwapCards()
- local swapCardsUI = self.ui.Items.Layout_Animation:getChildByTag(SWAP_CARD_TAG)
- if swapCardsUI and (not tolua.isnull(swapCardsUI)) then
- swapCardsUI:removeFromParent()
- swapCardsUI = nil
- end
- end
-
- --插牌动画
- function zigong7zHandCardView:runInsertCardAction()
- self:getEventDispatcher():removeEventListenersForTarget(self)
- local insertMj=self.handCards[#self.handCards]
- local iX=insertMj:getPositionX()
- local iY=insertMj:getPositionY()
- local height=insertMj:getContentSize().height
- local x,y=self:resetHandCards(insertMj,true)
- local actions={
- cc.MoveTo:create(0.1,cc.p(insertMj:getPositionX(),insertMj:getPositionY()+height)),
- cc.MoveTo:create(0.1,cc.p(x,insertMj:getPositionY()+height)),
- cc.MoveTo:create(0.1,cc.p(x,self.initY)),
- cc.CallFunc:create(function()
- self:initTouchEvent()
- if self.touchMJ and not tolua.isnull(self.touchMJ) then
- self:resetHandCards()
- end
- end)
- }
- insertMj:runAction(cc.Sequence:create(actions))
- end
-
- --出牌动画
- function zigong7zHandCardView:runOutCardAction(value)
- local outCardBgPath = 'mj_zigong7z/res/zy_fangjian/zigong_outcard_bg.png'
- local outCardBg = cc.ImageView:create(outCardBgPath)
- self:addChild(outCardBg)
-
- local showCard=MJ:new(value,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
- outCardBg:addChild(showCard)
-
- local outCardSize = outCardBg:getContentSize()
- showCard:setPosition(cc.p(outCardSize.width/2, outCardSize.height/2))
-
- outCardBg:setPosition(self:getOutCardShowPostion())
- local actions={
- cc.DelayTime:create(MJDefine.MJ_TIME_OUT_CARD_WAIT),
- cc.Spawn:create(
- cc.Spawn:create(
- cc.ScaleTo:create(MJDefine.MJ_TIME_OUT_CARD,MJDefine.MJ_TIME_OUT_CARD)
- )
- ),
- cc.CallFunc:create(function()
- showCard:removeFromParent()
- end),
- cc.RemoveSelf:create(),
- }
- outCardBg:runAction(cc.Sequence:create(actions))
- end
-
- function zigong7zHandCardView:getMjByValue(value)
- return self._handcard:getMjByValue(value)
- end
-
- --倒序遍历手牌
- function zigong7zHandCardView:getMjByValueReverseOrder(value)
- for i = #self.handCards,1,-1 do
- local v = self.handCards[i]
- if v.value==value then
- return v
- end
- end
- end
-
- function zigong7zHandCardView:removeHandCard(arg)
- self._handcard:removeHandCard(arg)
- end
-
- function zigong7zHandCardView:removeOutCard(arg)
- self._outCardView:removeOutCard(arg)
- end
-
- --玩家出牌
- function zigong7zHandCardView:onOutCard(card,callback)
- self:runOutCardAction(card)
- self._handcard:onOutCard(card, callback)
- self._outCardView:onOutCard(card, callback)
- end
-
- function zigong7zHandCardView:getAnimationPostion()
- return self.ui.Items["Layout_Aniamtion_"..self.viewId]:getPosition()
- end
-
- function zigong7zHandCardView:getOutCardShowPostion()
- return self.ui.Items["ImageView_Show_"..self.viewId]:getPosition()
- end
-
- --获取手牌数量
- function zigong7zHandCardView:getHandCardsNum()
- return self._handcard:getHandCardsLength()
- end
-
- return zigong7zHandCardView
|