|
- local CardNode = class("CardNode", function()
- return cc.ImageView:create()
- end)
- 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
-
- function CardNode:ctor(o)
- local ui = loadUI("pk_paodekuai/res/ui/ui_room/ui_pdk_cardnode.ui")
- self.ui = ui
- self:addChild(ui)
- self.imgBg = self.ui.Items.cardBg
- self._val = -1
- self._isLast = false
- self._touchWidth = 60
- self._selectedHeight = 0
- self._normalHeight = 0
- self._press = NORMAL_STATE
- self._noTouch = false--当前牌不可选择
- end
-
- function CardNode:setCard( val )
- self._val = val
- if val <= 0 then
- self.imgBg:loadTexture("pdk_cards_back.png", 1)
- else
- local cardPng = pokerPng(val)
- self.imgBg:loadTexture(cardPng, 1)
- end
- end
-
- function CardNode:getVal()
- return self._val
- end
-
- -- 设置牌是否可以选中
- function CardNode:setNoTouch( is )
- self._noTouch = is
- if is == true then
- self.imgBg:setColor(DOWN_COLOR)
- else
- self.imgBg:setColor(NORMAL_COLOR)
- end
- end
-
- function CardNode:setNoTouchNormal( is )
- self._noTouch = is
- self.imgBg:setColor(NORMAL_COLOR)
- end
-
- -- 获取牌是否可以选中
- function CardNode:getNoTouch()
- return self._noTouch
- end
-
- -- 是否是排列中最后一张牌
- function CardNode:setLast( is )
- self._isLast = is
- end
-
- -- 设置按下状态
- function CardNode:setDown()
- if self._press ~= DOWN_STATE then
- self.imgBg:setColor(NORMAL_COLOR)--DOWN_COLOR
- self._press = DOWN_STATE
- local pt = self:getPosition()
- self:setPosition(cc.p(pt.x, self._selectedHeight))
- end
- end
-
- -- 设置选择状态高度
- function CardNode:setSelectedHeight( height )
- self._selectedHeight = height
- end
- -- 设置normal状态高度
- function CardNode:setNormalHeight( height )
- self._normalHeight = height
- end
- -- 设置选择状态牌颜色
- function CardNode:setDownColor()
- self.imgBg:setColor(DOWN_COLOR)
- end
- -- 是否选择状态
- function CardNode:isDown()
- return self._press == DOWN_STATE
- end
- -- 将牌设置为正常状态
- function CardNode:setNormal()
- if self._press ~= NORMAL_STATE and self.imgBg then
- self.imgBg:setColor(NORMAL_COLOR)
- self._press = NORMAL_STATE
- local pt = self:getPosition()
- self:setPosition(cc.p(pt.x, self._normalHeight))
- end
- end
- -- 将牌设置为正常状态颜色
- function CardNode:setNormalColor()
- self.imgBg:setColor(NORMAL_COLOR)
- end
- -- 是否正常状态
- function CardNode:isNormal()
- return self._press == NORMAL_STATE
- 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
|