local function touchBegan(touch, event)
self.m_addClickCardIndex = -1
self.m_removeClickCardIndex = -1
self.m_cardInStructIndex = -1
self.m_firstTouchCardValue = Common.INVALID_CARD
self.m_beginPos = touch:getLocation()
self.isTuoPai = false
self.m_selectCardF = nil
self.m_oldTouCardIdnex = -1
local isTouchTongHua = false
if self.m_nPositionIndex == 0 then
self.m_touchBomb = true
local bRet,index = self:isTouchCardsInside(self.m_beginPos.x,self.m_beginPos.y)
if bRet then
self.m_touchCardIndex = index
self.m_touchMoveSelectCards = {}
self.m_firstTouchCardValue = self.m_cardArray[self.m_touchCardIndex]:getCardValue()
self.m_cardInStructIndex = self:getCardInStruct(self.m_cardArray[self.m_touchCardIndex]:getCardValue())
if self.m_lastTouchCardIndex ~= self.m_cardInStructIndex then
if self.m_cardDataStruct[self.m_cardInStructIndex] then
local cardItem = self.m_cardDataStruct[self.m_cardInStructIndex]
if cardItem then
local cardIndex = cardItem[#cardItem].index
if self.m_cardArray[cardIndex] and cardIndex == index then
self.m_selectCardF = self.m_cardArray[cardIndex]
end
end
end
-- local oldTouCardIdnex = self.m_lastTouchCardIndex
-- self.m_lastTouchCardIndex = self.m_cardInStructIndex
-- if self.m_cardDataStruct[self.m_cardInStructIndex] then
-- local cardItem = self.m_cardDataStruct[self.m_cardInStructIndex]
-- local isSetOtherCardNormal = false
-- for i = 1,table.nums(cardItem) do
-- local cardIndex = cardItem[i].index
-- if self.m_cardArray[cardIndex] then
-- if self.m_cardArray[cardIndex]:getIsDarkStatus() then
-- self.m_cardArray[cardIndex]:setIsDarkStatus(false)
-- self:removeTouchCardInfo(cardIndex,self.m_cardArray[cardIndex]:getCardValue())
-- self.m_cardInStructIndex = -1
-- else
-- self.m_cardArray[cardIndex]:setIsDarkStatus(true)
-- self:setTouchCardInfo(cardIndex,self.m_cardArray[cardIndex]:getCardValue())
-- isSetOtherCardNormal = true
-- end
-- end
-- end
-- --判断2个索引中是个王的
-- local oldCardS = nil
-- local lastCards = nil
-- local isContainSame = false
-- if oldTouCardIdnex ~= -1 then
-- oldCardS = self.m_cardDataStruct[oldTouCardIdnex]
-- lastCards = self.m_cardDataStruct[self.m_cardInStructIndex]
-- isContainSame = self:isContainSameCard(oldCardS[1].index, lastCards[1].index)
-- end
-- if isSetOtherCardNormal and not isContainSame then
-- self:setOtherCardsDown(self.m_cardArray[self.m_touchCardIndex]:getCardValue())
-- end
-- if not isContainSame then
-- self:resetPos()
-- end
-- self:resetCardItemPosY()
-- end
self.isTuoPai = true
else
self.isTuoPai = false
self.m_cardInStructIndex = self:getCardInStruct(self.m_cardArray[self.m_touchCardIndex]:getCardValue())
local cardItem = self.m_cardDataStruct[self.m_cardInStructIndex]
if cardItem then
local isCanMove = false
if not (cardItem[1].cardType == 2 and not self.m_service:isCanChaiTongHua()) then
isCanMove = true
end
if isCanMove then
if self.m_cardArray[index]:getIsDarkStatus() then
self.m_cardArray[index]:setIsDarkStatus(false)
self:removeTouchCardInfo(self.m_touchCardIndex,self.m_cardArray[self.m_touchCardIndex]:getCardValue())
else
self.m_cardArray[index]:setIsDarkStatus(true)
self:setTouchCardInfo(self.m_touchCardIndex,self.m_cardArray[self.m_touchCardIndex]:getCardValue())
end
else
self.m_cardArray[index]:setIsDarkStatus(true)
self:setTouchCardInfo(self.m_touchCardIndex,self.m_cardArray[self.m_touchCardIndex]:getCardValue())
end
self.m_touchCardIndex = index
self.m_touchMoveSelectCards = {}
end
end
return true
else
if not self:isContianTouch(self.m_beginPos.x,self.m_beginPos.y) then
self:setAllCardsDown()
end
end
if self.m_setAllCardsDownCallBack ~= nil then
self.m_setAllCardsDownCallBack()
end
if self.m_service:getCurChair() ~= self.m_service:getUserManager():getSelfSeatIndex() then
--self:setAllCardsDown()
end
if self.m_touchEndCallBack ~= nil then
self.m_touchMoveSelectCards = {}
self.m_touchEndCallBack(self.m_touchMoveSelectCards)
end
end
return false
end
local function touchMove(touch, event)
local curPos = touch:getLocation()
local moveClickCardIndex = -1
self.iscanMoveCard = false
if self.m_nPositionIndex == 0 and self.m_touchBomb then
if self.m_touchCardIndex ~= -1 then
local bRet,index = self:isTouchCardsInside(curPos.x,curPos.y)
local touchLocation = curPos
local oldTouchLocation = touch:getPreviousLocation()
local translation = cc.p(touchLocation.x - oldTouchLocation.x, touchLocation.y - oldTouchLocation.y)
-- if bRet then
-- local firstValue = self.m_cardArray[index]:getCardValue()
-- local curMoveIndex = self:getCardInStruct(firstValue)
if self.m_cardInStructIndex ~= -1 and self.isTuoPai and self.m_lastTouchCardIndex == -1 and self.m_selectCardF then
local cardItem = self.m_cardDataStruct[self.m_cardInStructIndex]
if cardItem then
if math.abs(self.m_beginPos.y - curPos.y) > 30 or math.abs(self.m_beginPos.x - curPos.x) > 30 then
--处理移动
for i = 1, table.nums(cardItem) do
local cardIndex = cardItem[i].index
local moveCard = self.m_cardArray[cardIndex]
local getCardPos = moveCard:getCardItemPosition()
local movePos = cc.p(getCardPos.x + translation.x, getCardPos.y+ translation.y)
moveCard:getCardItem():setPosition(movePos)
moveCard:getCardItem():setLocalZOrder(150); --//改变移动牌的层级
end
self.iscanMoveCard = true
end
end
end
-- end
log.d("touchMove = ",bRet,index)
if bRet then
moveClickCardIndex = index
end
if moveClickCardIndex ~= -1 then
local cardStructIndex = self:getCardInStruct(self.m_cardArray[moveClickCardIndex]:getCardValue())
local moveCardStructNums = 0
if self.m_cardDataStruct[cardStructIndex] then
moveCardStructNums = table.nums(self.m_cardDataStruct[cardStructIndex])
end
local addStructIndex = -1
if self.m_cardArray[self.m_addClickCardIndex] then
addStructIndex = self:getCardInStruct(self.m_cardArray[self.m_addClickCardIndex]:getCardValue())
end
local removeStructIndex = -1
if self.m_cardArray[self.m_removeClickCardIndex] then
removeStructIndex = self:getCardInStruct(self.m_cardArray[self.m_removeClickCardIndex]:getCardValue())
end
local isCanMove = false
local cardItem = self.m_cardDataStruct[self.m_cardInStructIndex]
if cardItem then
if not (cardItem[1].cardType == 2 and not self.m_service:isCanChaiTongHua()) then
isCanMove = true
end
end
if cardStructIndex == self.m_cardInStructIndex and isCanMove and moveClickCardIndex ~= self.m_touchCardIndex then
if not self.m_cardArray[moveClickCardIndex]:getIsDarkStatus() and self.m_addClickCardIndex ~= moveClickCardIndex then
self:removeTouchCardInfo(moveClickCardIndex,self.m_cardArray[moveClickCardIndex]:getCardValue())
self.m_cardArray[moveClickCardIndex]:setIsDarkStatus(true)
self.m_removeClickCardIndex = moveClickCardIndex
log.d("m_removeClickCardIndex = ",moveClickCardIndex)
elseif self.m_cardArray[moveClickCardIndex]:getIsDarkStatus() and self.m_removeClickCardIndex ~= moveClickCardIndex then
local cardStructIndex = self:getCardInStruct(self.m_cardArray[moveClickCardIndex]:getCardValue())
self:setTouchCardInfo(moveClickCardIndex,self.m_cardArray[moveClickCardIndex]:getCardValue())
self.m_cardArray[moveClickCardIndex]:setIsDarkStatus(false)
self.m_addClickCardIndex = moveClickCardIndex
log.d("m_addClickCardIndex = ",moveClickCardIndex)
end
end
else
self.m_addClickCardIndex = -1
self.m_removeClickCardIndex = -1
end
end
end
end
local function touchEnd(touch, event)
local curPos = touch:getLocation()
if self.m_nPositionIndex == 0 then
if self.iscanMoveCard and self.m_cardInStructIndex ~= -1 and self.m_lastTouchCardIndex == -1 and self.isTuoPai then
self.iscanMoveCard = false
self.isTuoPai = false
local selectCardPos = self.m_selectCardF:getCardItemPosition()
local cardItem = self.m_cardDataStruct[self.m_cardInStructIndex]
local selfPlayerIndex = self.m_service:getUserManager():getSelfSeatIndex()
if selectCardPos.y > self.m_outline and cardItem and self.m_service:getCanOut() and selfPlayerIndex == self.m_service:getCurChair() then
--出牌逻辑了
local outCardArry = {}
local cardType = -1
for j=1, table.nums(cardItem) do
local cardIndex = cardItem[j].index
cardType = cardItem[j].cardType
table.insert( outCardArry, self.m_cardArray[cardIndex]:getCardValue())
end
self.m_touchMoveSelectCards = {}
self.m_service:sendOutCards(outCardArry,-1, "")
--不能压的牌 回到手牌
if not GameLogic:getInstance():canYapai(outCardArry, cardType) then
self:resetPos()
end
else
self:resetPos()
end
self.m_touchMoveSelectCards = {}
return
end
self.isrestIndex = false
if self.m_cardInStructIndex ~= self.m_lastTouchCardIndex and not self.iscanMoveCard then
self.isrestIndex = true
self.m_oldTouCardIdnex = self.m_lastTouchCardIndex
self.m_lastTouchCardIndex = self.m_cardInStructIndex
if self.m_cardDataStruct[self.m_cardInStructIndex] then
local cardItem = self.m_cardDataStruct[self.m_cardInStructIndex]
local isSetOtherCardNormal = false
for i = 1,table.nums(cardItem) do
local cardIndex = cardItem[i].index
if self.m_cardArray[cardIndex] then
if self.m_cardArray[cardIndex]:getIsDarkStatus() then
-- self.m_cardArray[cardIndex]:setIsDarkStatus(false)
self:removeTouchCardInfo(cardIndex,self.m_cardArray[cardIndex]:getCardValue())
self.m_cardInStructIndex = -1
else
if self.m_selectCardF then
self.m_cardArray[cardIndex]:setIsDarkStatus(true)
end
self:setTouchCardInfo(cardIndex,self.m_cardArray[cardIndex]:getCardValue())
isSetOtherCardNormal = true
end
end
end
--判断2个索引中是个王的
local oldCardS = nil
local lastCards = nil
local isContainSame = false
if self.m_oldTouCardIdnex ~= -1 then
oldCardS = self.m_cardDataStruct[self.m_oldTouCardIdnex]
lastCards = self.m_cardDataStruct[self.m_cardInStructIndex]
isContainSame = self:isContainSameCard(oldCardS[1].index, lastCards[1].index)
end
if isSetOtherCardNormal and not isContainSame then
self:setOtherCardsDown(self.m_cardArray[self.m_touchCardIndex]:getCardValue())
end
if not isContainSame then
self:resetPos()
end
self:resetCardItemPosY()
end
end
if self.m_touchEndCallBack ~= nil then
self.m_touchEndCallBack(self.m_touchMoveSelectCards)
end
self:setCardUpBySeleteArray(self.m_touchMoveSelectCards)
else
end
local cardArray = self:getChooseCardValue()
if table.nums(cardArray) == 0 and not self.m_isUpCard then
self.m_lastTouchCardIndex = -1
end
self.m_touchBomb = false
self.m_touchMoveSelectCards = {}
self.m_addClickCardIndex = -1
self.m_removeClickCardIndex = -1
self.m_cardInStructIndex = -1
self.m_firstTouchCardValue = Common.INVALID_CARD
self.iscanMoveCard = false
self.m_selectCardF = nil
end
if self.m_nPositionIndex == 0 then
util.TouchHelper:add_touch_listener(self, { touchBegan, touchEnd, touchMove, touchEnd }, true, true)
end