Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

145 řádky
4.7 KiB

  1. local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
  2. local CommonOutCardView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Common.2d.CommonOutCardView")
  3. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  4. local OutCardView2D = class("OutCardView2D", CommonOutCardView)
  5. function OutCardView2D:ctor(...)
  6. OutCardView2D.super.ctor(self, ...)
  7. end
  8. function OutCardView2D:getOutCardPosition(mjCard, mjIndex)
  9. local x = 0
  10. local y = 0
  11. local viewId = self:getViewId()
  12. local playerCount = app.room:getMaxPlayerCount()
  13. local mjRowCount = MJDefine.MJConfig_2d.OutCardRowCount[playerCount][viewId]
  14. local col = mjIndex % mjRowCount
  15. col = col == 0 and mjRowCount or col
  16. local row = math.ceil(mjIndex / mjRowCount)
  17. local startPos = MJDefine.MJConfig_2d.OutCardStartPos[viewId]
  18. local offset = MJDefine.MJConfig_2d.OutCardOffsetConfig[viewId]
  19. local cardSize = mjCard:getContentSize()
  20. if playerCount == 2 then
  21. startPos = MJDefine.MJConfig_2d.OutCardStartPos2[viewId]
  22. offset = MJDefine.MJConfig_2d.OutCardOffsetConfig2[viewId]
  23. end
  24. if viewId == MJDefine.PlayerViewType.My then
  25. x = startPos.x + (col - 1) * (cardSize.width + offset.x)
  26. --y = startPos.y + (1 - row) * (cardSize.height + offset.y)
  27. y = startPos.y + (row - 1) * (cardSize.height + offset.y)
  28. elseif viewId == MJDefine.PlayerViewType.Right then
  29. --x = startPos.x + (row - 1) * (cardSize.width + offset.x)
  30. x = startPos.x + (1 - row) * (cardSize.width + offset.x)
  31. y = startPos.y + (col - 1) * (cardSize.height + offset.y)
  32. elseif viewId == MJDefine.PlayerViewType.Top then
  33. x = startPos.x + (1 - col) * (cardSize.width + offset.x)
  34. --y = startPos.y + (row - 1) * (cardSize.height + offset.y)
  35. y = startPos.y + (1 - row) * (cardSize.height + offset.y)
  36. elseif viewId == MJDefine.PlayerViewType.Left then
  37. --x = startPos.x + (1 - row) * (cardSize.width + offset.x)
  38. x = startPos.x + (row - 1) * (cardSize.width + offset.x)
  39. y = startPos.y + (1 - col) * (cardSize.height + offset.y)
  40. end
  41. return x, y
  42. end
  43. function OutCardView2D:refreshZOrder()
  44. local viewId = self:getViewId()
  45. if viewId == MJDefine.PlayerViewType.My or viewId == MJDefine.PlayerViewType.Right then
  46. local count = table.nums(self._outCardNodes)
  47. for k, v in ipairs(self._outCardNodes or {}) do
  48. v:setLocalZOrder(count - k)
  49. end
  50. else
  51. end
  52. end
  53. function OutCardView2D:onOutCard(card, callback)
  54. MJSound.PlayOutCard()
  55. self:addCard(card)
  56. self:refreshZOrder()
  57. if callback then
  58. callback()
  59. end
  60. self:runOutCardAction(card)
  61. end
  62. --³öÅÆ¶¯»­
  63. function OutCardView2D:runOutCardAction(value,callback)
  64. local outCard=self._outCardNodes[#self._outCardNodes]
  65. local linshui_mj_color = loadUserInfo("mj_linshui_desktop_2d_mjType") or MJDefine.DesktopType.TwoDL
  66. local CardClass
  67. if linshui_mj_color == "2dl" then
  68. CardClass = require("mj_linshui.luaScript.Views.2d.Card_2d_L")
  69. else
  70. CardClass = require(MJDefine.MJConfig_2d.MAHJONG_CARD)
  71. end
  72. local showCard = CardClass:new(value, 4, MJDefine.MJConfig_2d.MJType.Stand, 1)
  73. --local showCard=MJ:new(value,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
  74. self:addChild(showCard)
  75. showCard:setLocalZOrder(9999)
  76. --showCard:setScale(MJDefine.MJ_OUT_CARD_SCALE)
  77. showCardPostion = {
  78. [1] = {x = 1015*g_radio_x, y = 423*g_radio_y},
  79. [2] = {x = 641*g_radio_x, y = 571*g_radio_y},
  80. [3] = {x = 265*g_radio_x, y = 423*g_radio_y},
  81. [4] = {x = 640*g_radio_x, y = 210*g_radio_y},
  82. }
  83. showCard:setPosition(showCardPostion[self._viewId])
  84. local rotate=0
  85. if self._viewId==MJDefine.PlayerViewType.Left then
  86. rotate=-45
  87. elseif self._viewId==MJDefine.PlayerViewType.Right then
  88. rotate=45
  89. end
  90. local actions={
  91. --cc.ScaleTo:create(MJDefine.MJ_TIME_OUT_CARD_SCALE,1),
  92. cc.DelayTime:create(MJDefine.MJ_TIME_OUT_CARD_WAIT),
  93. --[[cc.Spawn:create(
  94. cc.Spawn:create(
  95. cc.MoveTo:create(MJDefine.MJ_TIME_OUT_CARD,outCard:getPosition()),
  96. cc.ScaleTo:create(MJDefine.MJ_TIME_OUT_CARD,MJDefine.MJ_OUT_CARD_SCALE)
  97. ),
  98. cc.RotateBy:create(MJDefine.MJ_TIME_OUT_CARD,rotate)
  99. ),--]]
  100. cc.CallFunc:create(function()
  101. -- MJSound.PlayOutCard()
  102. if outCard and not tolua.isnull(outCard) then
  103. --outCard:setVisible(true)
  104. end
  105. showCard:setVisible(false)
  106. if callback then callback() end
  107. end),
  108. cc.RemoveSelf:create(),
  109. }
  110. showCard:runAction(cc.Sequence:create(actions))
  111. end
  112. function OutCardView2D:onSelectCard(event)
  113. if not event then
  114. return
  115. end
  116. local value = event.value;
  117. for k, v in ipairs(self._outCardNodes or {}) do
  118. if (not value) or value <= 0 then
  119. v:setNormalColor()
  120. else
  121. if v:getValue() == value then
  122. v:setColor(cc.c3b(243, 147, 9))
  123. else
  124. v:setNormalColor()
  125. end
  126. end
  127. end
  128. end
  129. return OutCardView2D