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.

145 lines
3.4 KiB

  1. local CardNode = class("CardNode", function()
  2. local node = cc.Node:create()
  3. return node
  4. end)
  5. local DoushisiPokerUtil = require("zp_doushisi.luaScript.Views.Room.doushisiPokerUtil")
  6. local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  7. local NORMAL_COLOR = cc.c3b(0xff, 0xff, 0xff)
  8. local NORMAL_STATE = false
  9. local DOWN_COLOR = cc.c3b(0xb3, 0xaa, 0xaa)
  10. local DOWN_STATE = true
  11. local DOWN_DLT = 60
  12. local CardNode = class("CardNode",cc.UIView)
  13. function CardNode:ctor(cardType)
  14. self.cardType = cardType or ZPDef.CardType.CARD_TYPE_HAND
  15. if self.cardType == ZPDef.CardType.CARD_TYPE_HAND then
  16. local ui = loadUI("zp_doushisi/res/ui/ui_fangjian/doushisi_handcardnode.ui")
  17. self.ui = ui
  18. self:addChild(ui)
  19. self.imgBg = self.ui.Items.cardBg
  20. self.zheZhao = self.ui.Items.ImageView_ZheZhao
  21. self.youIcon = self.ui.Items.ImageView_You
  22. self.laiziIcon = self.ui.Items.ImageView_laizi
  23. else
  24. local ui = loadUI("zp_doushisi/res/ui/ui_fangjian/doushisi_quitcardnode.ui")
  25. self.ui = ui
  26. self:addChild(ui)
  27. self.laiziIcon = self.ui.Items.ImageView_laizi
  28. end
  29. self._val = -1
  30. self._isLast = false
  31. self._touchWidth = 60
  32. self._selectedHeight = 0
  33. self._normalHeight = 0
  34. self._press = NORMAL_STATE
  35. self._noTouch = false--当前牌不可选择
  36. self._canTouch = true
  37. self._hasSet = false
  38. end
  39. function CardNode:setCard( val )
  40. self._val = val
  41. self.imgBg.value = val
  42. if val <= 0 then
  43. self.imgBg:loadTexture("dss_cards_back.png", 1)
  44. else
  45. local cardPng = DoushisiPokerUtil.pokerPng(val,self.cardType)
  46. self.imgBg:loadTexture(cardPng, 1)
  47. end
  48. self:setLaiZiIconVis(false)
  49. self:setYouIconVis(false)
  50. self:setZheZhaoVis(false)
  51. if val > 0x50 then
  52. self:setLaiZiIconVis(true)
  53. end
  54. end
  55. function CardNode:setLaiZiIconVis( is )
  56. self.laiziIcon:setVisible(is)
  57. end
  58. function CardNode:setYouIconVis( is )
  59. self.youIcon:setVisible(is)
  60. self.zheZhao:setVisible(is)
  61. end
  62. function CardNode:setZheZhaoVis( is )
  63. self.zheZhao:setVisible(is)
  64. end
  65. function CardNode:setCardIsYouCard(is)
  66. self:setZheZhaoVis(is)
  67. self:setYouIconVis(is)
  68. end
  69. function CardNode:getVal()
  70. return self._val
  71. end
  72. --设置已经挪动了位置
  73. function CardNode:setHasSet(is)
  74. self._hasSet = is
  75. end
  76. -- 将牌设置为正常状态
  77. function CardNode:setNormal()
  78. if self.imgBg then
  79. self.imgBg:setPosition(cc.p(0, 0))
  80. end
  81. end
  82. -- 将牌设置为正常状态
  83. function CardNode:isDoWn()
  84. if self.imgBg then
  85. local pt = self.imgBg:getPosition()
  86. if pt.y == 40 then
  87. return true
  88. end
  89. --self.imgBg:setPosition(cc.p(0, 0))
  90. end
  91. return false
  92. end
  93. ---设置牌是否能触摸
  94. function CardNode:setCardTouchEnabled(is)
  95. self._canTouch = is
  96. --self.imgBg:setTouchEnabled(is)
  97. end
  98. --设置牌的点击事件
  99. function CardNode:addCardTouchEventListener(onTouchBegan,onTouchMove,onTouchEnd,onTouchCancel)
  100. if self.imgBg then
  101. self.imgBg:setTouchEnabled(true)
  102. self.imgBg:registerTouchEvent(onTouchBegan, onTouchMove, onTouchEnd, onTouchCancel)
  103. end
  104. end
  105. function CardNode:getRect()
  106. if self._noTouch then
  107. return cc.rect(0, 0, 0, 0)
  108. end
  109. local spt = self:getParent():convertToWorldSpace(cc.p(self:getPosition()))
  110. local s = self.imgBg:getContentSize()
  111. s.width = s.width * self:getScaleX()
  112. s.height = s.height * self:getScaleY()
  113. if not self._isLast then
  114. return cc.rect(spt.x-s.width/2, spt.y-s.height/2, self._touchWidth*self:getScaleX(), s.height)
  115. else
  116. return cc.rect(spt.x-s.width/2, spt.y-s.height/2, s.width, s.height)
  117. end
  118. end
  119. return CardNode