選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

132 行
3.7 KiB

  1. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  2. local CommonGroupChi = class("CommonGroupChi", function ()
  3. local node = cc.Node:create()
  4. return node
  5. end)
  6. function CommonGroupChi:ctor(values, viewId, groupIndex)
  7. self._values = values
  8. self._viewId = viewId
  9. self._cardNodes = {}
  10. self._groupIndex = groupIndex or 1
  11. self:initViews()
  12. end
  13. function CommonGroupChi:initViews()
  14. if not self._values then
  15. return
  16. end
  17. for index, value in ipairs(self._values) do
  18. local card = self:createCard(value, self._viewId, index, self._groupIndex)
  19. local x, y = self:getCardPosition(card, index)
  20. self:addChild(card)
  21. table.insert(self._cardNodes, card)
  22. end
  23. self:refreshZOrder()
  24. end
  25. function CommonGroupChi:getViewId()
  26. return self._viewId
  27. end
  28. function CommonGroupChi:createCard(value, viewId, index, groupIndex)
  29. local CardClass = require(MJDefine.MJConfig_2d.MAHJONG_CARD)
  30. local tmpIndex = (index >= 4) and 2 or index
  31. local mjIndex = (groupIndex - 1) * 3 + tmpIndex
  32. local mjCard = CardClass:new(value, viewId, MJDefine.MJConfig_2d.MJType.Operate, mjIndex)
  33. local x, y = self:getCardPosition(mjCard, index)
  34. mjCard:setPosition(x, y)
  35. return mjCard
  36. end
  37. function CommonGroupChi:getCardPosition(mjCard, mjIndex)
  38. local x = 0
  39. local y = 0
  40. local viewId = self:getViewId()
  41. local cardSize = mjCard:getContentSize()
  42. local groupOffset = self:getGroupOffsetConfig(viewId)
  43. local offset = groupOffset[mjIndex]
  44. if viewId == MJDefine.PlayerViewType.My then
  45. x = (mjIndex - 1) * (cardSize.width + offset.x)
  46. y = offset.y
  47. elseif viewId == MJDefine.PlayerViewType.Right then
  48. x = offset.x
  49. y = (mjIndex - 1) * (cardSize.height + offset.y)
  50. elseif viewId == MJDefine.PlayerViewType.Top then
  51. x = (1 - mjIndex) * (cardSize.width + offset.x)
  52. y = offset.y
  53. elseif viewId == MJDefine.PlayerViewType.Left then
  54. x = offset.x
  55. y = (1 - mjIndex) * (cardSize.height + offset.y)
  56. end
  57. return x, y
  58. end
  59. -- function CommonGroupChi:updateGroupSize(cardSize)
  60. -- local groupWidth = 0
  61. -- local groupHeight = 0
  62. -- local width = cardSize.width
  63. -- local height = cardSize.height
  64. -- local viewId = self:getViewId()
  65. -- local offset = MJDefine.MJConfig_2d.GroupOffsetConfig[viewId]
  66. -- if viewId == MJDefine.PlayerViewType.My then
  67. -- width = cardSize.width * 3 + offset.x * 2
  68. -- height = cardSize.height
  69. -- elseif viewId == MJDefine.PlayerViewType.Right then
  70. -- width = cardSize.width
  71. -- height = cardSize.height * 3 + offset.y * 2
  72. -- elseif viewId == MJDefine.PlayerViewType.Top then
  73. -- width = cardSize.width * 3 + offset.x * 2
  74. -- height = cardSize.heights
  75. -- elseif viewId == MJDefine.PlayerViewType.Left then
  76. -- width = cardSize.width
  77. -- height = cardSize.height * 3 + offset.y * 2
  78. -- end
  79. -- self:setContentSize(groupWidth, groupHeight)
  80. -- end
  81. function CommonGroupChi:refreshZOrder()
  82. local count = table.nums(self._cardNodes) or 3
  83. for k, v in ipairs(self._cardNodes) do
  84. local zorder = 0
  85. if self._viewId == 1 then
  86. zorder = (k < 4) and (count - k) or 4
  87. end
  88. v:setLocalZOrder(zorder)
  89. end
  90. end
  91. function CommonGroupChi:customRefresh(groupData)
  92. end
  93. function CommonGroupChi:getCards()
  94. return self._cardNodes or {}
  95. end
  96. function CommonGroupChi:getValues()
  97. return self._values or {}
  98. end
  99. function CommonGroupChi:getGroupIndex()
  100. return self._groupIndex
  101. end
  102. ---
  103. -- 获取组合牌偏移配置
  104. -- @param viewId
  105. -- @return
  106. --
  107. function CommonGroupChi:getGroupOffsetConfig(viewId)
  108. return MJDefine.MJConfig_2d.GroupCardOffsetConfig[viewId]
  109. end
  110. return CommonGroupChi