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 hongzhongHandCardView = class("hongzhongHandCardView", MJHandCardView) function hongzhongHandCardView:ctor(viewId,desktopType) hongzhongHandCardView.super.ctor(self,viewId,desktopType) end function hongzhongHandCardView:initView() if self:isUseNew3D() then self:loadUI() self.ui.Items.Layout_Hand_Card:setVisible(false) self.ui.Items.Layout_Operate: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._outCardView = MahjongOutCardView:new(self.viewId) self:addChild(self._outCardView) self._huCardView = MahjongHuCardView:new(self.viewId) self:addChild(self._huCardView) 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-200 elseif self.viewId == MJDefine.PlayerViewType.Top then self.outX=self.outX+180 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() end end function hongzhongHandCardView:onTouchBegan(touch) 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 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.status==MJDefine.MJStatus.Select then --双击出牌 self:sendOutCard() return false else --self.touchMJ:recordPostion(self.initY) --self.touchMJ:runSelectAnimation() --self.touchMJ:setStatus(MJDefine.MJStatus.Select) self.touchMJ:recordPostion(cc.p(self.touchMJ:getPositionX(), self.initY)) -- self.touchMJ:checkDltPos(touchPos) by c.mj --app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing,card=self.touchMJ.value}) end 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 hongzhongHandCardView:onTouchMove(touch) if not self.isOutCard then return end 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 self.touchMJ and (x>=1 or y>=1) then self.isTouchMove=true local dltx, dlty = self.touchMJ:getDltPos() self.touchMJ:setPosition(cc.p(touchPos.x-dltx, touchPos.y-dlty)) self.touchMJ:setLocalZOrder(1) --return true end --return false end function hongzhongHandCardView:onTouchEnd(touch) if self.touchMJ then local touchdis = self.touchMJ:getTouchDistance() if self.touchMJ:getTouchDistance()>MJDefine.MJ_TOUCH_OUT_CARD_Y then self:touchOutCard() else self.touchMJ:runSelectAnimation() self.touchMJ:setStatus(MJDefine.MJStatus.Select) app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing,card=self.touchMJ.value}) end end end function hongzhongHandCardView:onTouchCancel(touch) --self:touchOutCard() end function hongzhongHandCardView:touchOutCard() if self.touchMJ and self.isTouchMove then if self.touchMJ:getPositionY()>self.touchMJ.initPostion.y+MJDefine.MJ_TOUCH_OUT_CARD_Y 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 hongzhongHandCardView:createOutCards(arg) if self:isUseNew3D() then self._outCardView:createOutCards(arg) --获取出的牌,结算要显示中鸟 self.outCards = self._outCardView:getOutCardNodes() else -- arg={ -- {card=0x25}, -- {card=0x01}, -- {card=0x01}, -- {card=0x01}, -- {card=0x01}, -- {card=0x02}, -- {card=0x01}, -- {card=0x01}, -- {card=0x01}, -- {card=0x02}, -- {card=0x01}, -- {card=0x01}, -- {card=0x01}, -- {card=0x02}, -- } if type(arg)=="number" then arg={ {card=arg} } end -- local x=self.outX -- local y=self.outY for k,v in pairs(arg) do print("测试:"..v.card) local mj=MJ:new(v.card,MJDefine.MJType.Out,self.viewId,self.desktopType) self.ui.Items.Layout_Hand_Card:addChild(mj) table.insert(self.outCards,mj) -- --取余计算X坐标 从起始位置开始 默认应该为0 所以要减去1 -- local n=#self.outCards%MJDefine.MJChangeLinCount[self.viewId]-1 -- --向下取整判断是否换行 -- local m=math.floor(#self.outCards/MJDefine.MJChangeLinCount[self.viewId]) -- --如果刚好等于0则设置为换行的数 -- if #self.outCards%MJDefine.MJChangeLinCount[self.viewId]==0 then -- n=MJDefine.MJChangeLinCount[self.viewId]-1 -- m=m-1 -- end -- --根据视图ID 计算坐标 -- if self.viewId==MJDefine.PlayerViewType.My then -- x=self.outX+(mj:getContentSize().width-MJDefine.MJOutChangeOffSet[self.viewId].x)*n -- y=self.outY-m*(mj:getContentSize().height-MJDefine.MJOutChangeOffSet[self.viewId].y) -- elseif self.viewId==MJDefine.PlayerViewType.Left then -- x=self.outX-m*(mj:getContentSize().width-MJDefine.MJOutChangeOffSet[self.viewId].x)-n*MJDefine.MJOutOffSet[self.viewId].x -- y=self.outY-(mj:getContentSize().height-MJDefine.MJOutChangeOffSet[self.viewId].y)*n -- mj:setLocalZOrder(n-m) -- elseif self.viewId==MJDefine.PlayerViewType.Right then -- x=self.outX+m*(mj:getContentSize().width-MJDefine.MJOutChangeOffSet[self.viewId].x)-n*MJDefine.MJOutOffSet[self.viewId].x -- y=self.outY+(mj:getContentSize().height-MJDefine.MJOutChangeOffSet[self.viewId].y)*n -- mj:setLocalZOrder(-m-n) -- elseif self.viewId==MJDefine.PlayerViewType.Top then -- -- local scale=0.8 --上面的麻将要缩小 -- mj:setScale(MJDefine.MJ_TOP_SCALE) -- x=self.outX-(mj:getContentSize().width*MJDefine.MJ_TOP_SCALE-MJDefine.MJOutChangeOffSet[self.viewId].x)*n -- y=self.outY+m*(mj:getContentSize().height*MJDefine.MJ_TOP_SCALE-MJDefine.MJOutChangeOffSet[self.viewId].y) -- mj:setLocalZOrder(self:getContentSize().height-y) -- end local x,y=MJPositionCompnent.getOutCardPosition(self.viewId,self.outX,self.outY,mj,#self.outCards,self.desktopType,app.room.roomInfo.nMaxPlayCount) mj:setPosition(x,y) end end end --插牌动画 function hongzhongHandCardView:runInsertCardAction() 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,false) -- local actions={ -- cc.MoveTo:create(0.01,cc.p(insertMj:getPositionX(),insertMj:getPositionY()+height)), -- cc.MoveTo:create(0.01,cc.p(x,insertMj:getPositionY()+height)), -- cc.MoveTo:create(0.01,cc.p(x,self.initY)), -- } -- insertMj:runAction(cc.Sequence:create(actions)) insertMj:setPosition(cc.p(x,self.initY)) self:resetHandCards() end return hongzhongHandCardView