local CardNode = class("CardNode", function() local node = cc.Node:create() return node end) local DoushisiPokerUtil = require("zp_doushisi.luaScript.Views.Room.doushisiPokerUtil") local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef") local NORMAL_COLOR = cc.c3b(0xff, 0xff, 0xff) local NORMAL_STATE = false local DOWN_COLOR = cc.c3b(0xb3, 0xaa, 0xaa) local DOWN_STATE = true local DOWN_DLT = 60 local CardNode = class("CardNode",cc.UIView) function CardNode:ctor(cardType) self.cardType = cardType or ZPDef.CardType.CARD_TYPE_HAND if self.cardType == ZPDef.CardType.CARD_TYPE_HAND then local ui = loadUI("zp_doushisi/res/ui/ui_fangjian/doushisi_handcardnode.ui") self.ui = ui self:addChild(ui) self.imgBg = self.ui.Items.cardBg self.zheZhao = self.ui.Items.ImageView_ZheZhao self.youIcon = self.ui.Items.ImageView_You self.laiziIcon = self.ui.Items.ImageView_laizi else local ui = loadUI("zp_doushisi/res/ui/ui_fangjian/doushisi_quitcardnode.ui") self.ui = ui self:addChild(ui) self.laiziIcon = self.ui.Items.ImageView_laizi end self._val = -1 self._isLast = false self._touchWidth = 60 self._selectedHeight = 0 self._normalHeight = 0 self._press = NORMAL_STATE self._noTouch = false--当前牌不可选择 self._canTouch = true self._hasSet = false end function CardNode:setCard( val ) self._val = val self.imgBg.value = val if val <= 0 then self.imgBg:loadTexture("dss_cards_back.png", 1) else local cardPng = DoushisiPokerUtil.pokerPng(val,self.cardType) self.imgBg:loadTexture(cardPng, 1) end self:setLaiZiIconVis(false) self:setYouIconVis(false) self:setZheZhaoVis(false) if val > 0x50 then self:setLaiZiIconVis(true) end end function CardNode:setLaiZiIconVis( is ) self.laiziIcon:setVisible(is) end function CardNode:setYouIconVis( is ) self.youIcon:setVisible(is) self.zheZhao:setVisible(is) end function CardNode:setZheZhaoVis( is ) self.zheZhao:setVisible(is) end function CardNode:setCardIsYouCard(is) self:setZheZhaoVis(is) self:setYouIconVis(is) end function CardNode:getVal() return self._val end --设置已经挪动了位置 function CardNode:setHasSet(is) self._hasSet = is end -- 将牌设置为正常状态 function CardNode:setNormal() if self.imgBg then self.imgBg:setPosition(cc.p(0, 0)) end end -- 将牌设置为正常状态 function CardNode:isDoWn() if self.imgBg then local pt = self.imgBg:getPosition() if pt.y == 40 then return true end --self.imgBg:setPosition(cc.p(0, 0)) end return false end ---设置牌是否能触摸 function CardNode:setCardTouchEnabled(is) self._canTouch = is --self.imgBg:setTouchEnabled(is) end --设置牌的点击事件 function CardNode:addCardTouchEventListener(onTouchBegan,onTouchMove,onTouchEnd,onTouchCancel) if self.imgBg then self.imgBg:setTouchEnabled(true) self.imgBg:registerTouchEvent(onTouchBegan, onTouchMove, onTouchEnd, onTouchCancel) end end function CardNode:getRect() if self._noTouch then return cc.rect(0, 0, 0, 0) end local spt = self:getParent():convertToWorldSpace(cc.p(self:getPosition())) local s = self.imgBg:getContentSize() s.width = s.width * self:getScaleX() s.height = s.height * self:getScaleY() if not self._isLast then return cc.rect(spt.x-s.width/2, spt.y-s.height/2, self._touchWidth*self:getScaleX(), s.height) else return cc.rect(spt.x-s.width/2, spt.y-s.height/2, s.width, s.height) end end return CardNode