You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.0 KiB

  1. local CardNode = class("CardNode", function()
  2. return cc.ImageView:create()
  3. end)
  4. local NORMAL_COLOR = cc.c3b(0xff, 0xff, 0xff)
  5. local NORMAL_STATE = false
  6. local DOWN_COLOR = cc.c3b(0xb3, 0xaa, 0xaa)
  7. local DOWN_STATE = true
  8. local DOWN_DLT = 60
  9. function CardNode:ctor(o)
  10. local ui = loadUI("pk_luzhoupdk/res/ui/ui_room/ui_lzpdk_cardnode.ui")
  11. self.ui = ui
  12. self:addChild(ui)
  13. self.imgBg = self.ui.Items.cardBg
  14. self._val = -1
  15. self._isLast = false
  16. self._touchWidth = 60
  17. self._selectedHeight = 0
  18. self._normalHeight = 0
  19. self._press = NORMAL_STATE
  20. self._noTouch = false--当前牌不可选择
  21. end
  22. function CardNode:setCard( val )
  23. self._val = val
  24. if val <= 0 then
  25. self.imgBg:loadTexture("pdk_cards_back.png", 1)
  26. else
  27. local cardPng = pokerPng(val)
  28. self.imgBg:loadTexture(cardPng, 1)
  29. end
  30. end
  31. function CardNode:getVal()
  32. return self._val
  33. end
  34. -- 设置牌是否可以选中
  35. function CardNode:setNoTouch( is )
  36. self._noTouch = is
  37. if is == true then
  38. self.imgBg:setColor(DOWN_COLOR)
  39. else
  40. self.imgBg:setColor(NORMAL_COLOR)
  41. end
  42. end
  43. function CardNode:setNoTouchNormal( is )
  44. self._noTouch = is
  45. self.imgBg:setColor(NORMAL_COLOR)
  46. end
  47. -- 获取牌是否可以选中
  48. function CardNode:getNoTouch()
  49. return self._noTouch
  50. end
  51. -- 是否是排列中最后一张牌
  52. function CardNode:setLast( is )
  53. self._isLast = is
  54. end
  55. -- 设置按下状态
  56. function CardNode:setDown()
  57. if self._press ~= DOWN_STATE then
  58. self.imgBg:setColor(NORMAL_COLOR)--DOWN_COLOR
  59. self._press = DOWN_STATE
  60. local pt = self:getPosition()
  61. self:setPosition(cc.p(pt.x, self._selectedHeight))
  62. end
  63. end
  64. -- 设置选择状态高度
  65. function CardNode:setSelectedHeight( height )
  66. self._selectedHeight = height
  67. end
  68. -- 设置normal状态高度
  69. function CardNode:setNormalHeight( height )
  70. self._normalHeight = height
  71. end
  72. -- 设置选择状态牌颜色
  73. function CardNode:setDownColor()
  74. self.imgBg:setColor(DOWN_COLOR)
  75. end
  76. -- 是否选择状态
  77. function CardNode:isDown()
  78. return self._press == DOWN_STATE
  79. end
  80. -- 将牌设置为正常状态
  81. function CardNode:setNormal()
  82. if self._press ~= NORMAL_STATE then
  83. self.imgBg:setColor(NORMAL_COLOR)
  84. self._press = NORMAL_STATE
  85. local pt = self:getPosition()
  86. self:setPosition(cc.p(pt.x, self._normalHeight))
  87. end
  88. end
  89. -- 将牌设置为正常状态颜色
  90. function CardNode:setNormalColor()
  91. self.imgBg:setColor(NORMAL_COLOR)
  92. end
  93. -- 是否正常状态
  94. function CardNode:isNormal()
  95. return self._press == NORMAL_STATE
  96. end
  97. function CardNode:getRect()
  98. if self._noTouch then
  99. return cc.rect(0, 0, 0, 0)
  100. end
  101. if not tolua.isnull(self) and (not tolua.isnull(self.imgBg)) then
  102. local spt = self:getParent():convertToWorldSpace(cc.p(self:getPosition()))
  103. local s = self.imgBg:getContentSize()
  104. s.width = s.width * self:getScaleX()
  105. s.height = s.height * self:getScaleY()
  106. if not self._isLast then
  107. return cc.rect(spt.x-s.width/2, spt.y-s.height/2, self._touchWidth*self:getScaleX(), s.height)
  108. else
  109. return cc.rect(spt.x-s.width/2, spt.y-s.height/2, s.width, s.height)
  110. end
  111. end
  112. end
  113. return CardNode