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.

169 lines
6.4 KiB

  1. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  2. local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
  3. local BaseMahjong3DCard = MJFramework.MJFrameworkClassImprot("mj.luaScript.Common.3d.Mahjong3DCard")
  4. local Card3D = class("Card3D", BaseMahjong3DCard)
  5. function Card3D:ctor(...)
  6. Card3D.super.ctor(self, ...)
  7. end
  8. --- Card3D:setLuoBoVisible 显示萝卜标识
  9. -- @param isVisible 是否显示,为true时,count可不传
  10. -- @param count 萝卜牌数量
  11. function Card3D:setLuoBoVisible(isVisible, count, groupIndex)
  12. if self._mjType == MJDefine.MJConfig_3d.MJType.Stand then
  13. if self._viewId ~= MJDefine.PlayerViewType.My then
  14. return
  15. end
  16. end
  17. local viewId = self:getViewId()
  18. local imgFlag = self:getChildByName("img_luobo_flag")
  19. if not imgFlag then
  20. imgFlag = cc.ImageView:create()
  21. self:addChild(imgFlag)
  22. end
  23. imgFlag:setVisible(isVisible)
  24. if not isVisible then
  25. imgFlag:setVisible(false)
  26. return
  27. end
  28. local imgPath = string.format("mj_huamajiang/res/zy_fangjian/card/flag_luobo/huamajiang_flag_luobo_%d.png", count)
  29. imgFlag:loadTexture(imgPath, 0)
  30. imgFlag:setName("img_luobo_flag")
  31. local cfg = nil
  32. local rotationCfg = nil
  33. if self._mjType == MJDefine.MJConfig_3d.MJType.Operate or self._mjType == MJDefine.MJConfig_3d.MJType.OperateBlack then
  34. cfg = MJDefine.MJConfig_3d.OpCardLuoBoFlagPos[viewId][groupIndex];
  35. rotationCfg = MJDefine.MJConfig_3d.OpCardLuoBoFlagScale[viewId][groupIndex]
  36. elseif self._mjType == MJDefine.MJConfig_3d.MJType.Open then
  37. cfg = MJDefine.MJConfig_3d.OpenCardLuoBoFlagPos[viewId][self._cardIndex]
  38. rotationCfg = MJDefine.MJConfig_3d.OpenCardLuoBoFlagScale[viewId][self._cardIndex]
  39. else
  40. cfg = MJDefine.HandCardLuoBoFlagPos[MJDefine.DesktopType.ThreeD][viewId];
  41. end
  42. if cfg then
  43. imgFlag:setPosition(cc.p(cfg.x, cfg.y));
  44. imgFlag:setScale(cfg.scale);
  45. end
  46. if rotationCfg then
  47. imgFlag:setEulerRotation(cc.vec3(rotationCfg.x, rotationCfg.y, rotationCfg.z))
  48. end
  49. end
  50. ---
  51. -- 刷新多头杠数量
  52. -- @param cardNum
  53. -- @return
  54. --
  55. function Card3D:refreshCardNum(cardNum, groupIndex)
  56. local viewId = self:getViewId()
  57. local imgFlag = self:getChildByName("img_cardnum_flag")
  58. if not imgFlag then
  59. imgFlag = cc.ImageView:create()
  60. self:addChild(imgFlag)
  61. end
  62. imgFlag:setVisible(cardNum > 4)
  63. if not (cardNum and cardNum > 4) then
  64. return
  65. end
  66. local imgPath = string.format("mj_huamajiang/res/zy_fangjian/card/flag_gang/huamajiang_flag_gang_%d.png", cardNum)
  67. imgFlag:loadTexture(imgPath, 0)
  68. imgFlag:setName("img_cardnum_flag")
  69. local cfg = nil
  70. local rotationCfg = nil
  71. if self._mjType == MJDefine.MJConfig_3d.MJType.Out then
  72. cfg = MJDefine.OutDuoGangFlagPos[MJDefine.DesktopType.ThreeD][viewId];
  73. cfg.x = cfg.pos.x
  74. cfg.y = cfg.pos.y
  75. else
  76. cfg = MJDefine.MJConfig_3d.OpDuoGangFlagPos[viewId][groupIndex];
  77. rotationCfg = MJDefine.MJConfig_3d.OpDuoGangFlagRotationConfig[viewId][groupIndex]
  78. end
  79. if cfg then
  80. imgFlag:setPosition(cc.p(cfg.x, cfg.y));
  81. imgFlag:setScale(cfg.scale);
  82. end
  83. if rotationCfg then
  84. imgFlag:setEulerRotation(cc.vec3(rotationCfg.x, rotationCfg.y, rotationCfg.z))
  85. end
  86. end
  87. function Card3D:initBackImage()
  88. if self._mjType == MJDefine.MJConfig_3d.MJType.Out and app.room:getMaxPlayerCount() == 2 then
  89. if self._cardIndex > 57 then
  90. if self._viewId == MJDefine.PlayerViewType.My then
  91. self._cardIndex = self._cardIndex - 19 * math.ceil((self._cardIndex - 57) / 19)
  92. elseif self._viewId == MJDefine.PlayerViewType.Top then
  93. self._cardIndex = self._cardIndex - 57
  94. end
  95. local scale = self._viewId == MJDefine.PlayerViewType.Top and 0.98 or 1.02
  96. self:setScale(scale)
  97. end
  98. local tpl = "mj_3d_outcard2_%s_%s.png"
  99. local imgName = string.format( tpl, self._viewType, self._cardIndex)
  100. local md5Name = MJFunction.get3dCardMd5ByName(imgName)
  101. if not md5Name then
  102. logD("[LUA ERROR] Card3D:initBackImage imgName:" .. imgName)
  103. return
  104. end
  105. self:loadTextureFromPlist(md5Name)
  106. else
  107. if self._mjType == MJDefine.MJConfig_3d.MJType.Out then
  108. if self._cardIndex > 33 then
  109. self._cardIndex = self._cardIndex - 11 * math.ceil((self._cardIndex - 33) / 11)
  110. end
  111. elseif self._mjType == MJDefine.MJConfig_3d.MJType.Hu or self._mjType == MJDefine.MJConfig_3d.MJType.HuBlack then
  112. if self._cardIndex > 40 then
  113. self._cardIndex = self._cardIndex - 20 * math.ceil((self._cardIndex - 40) / 20)
  114. end
  115. end
  116. local imgName = ""
  117. if self._mjType == MJDefine.MJConfig_3d.MJType.Stand then
  118. -- 本家手牌只有一张牌,cardIndex写死1
  119. local cardIndex = self._viewId == MJDefine.MyViewId and 1 or self._cardIndex
  120. local tpl = "mj_3d_handcard_%s_%s.png"
  121. imgName = string.format(tpl, self._viewType, cardIndex)
  122. elseif self._mjType == MJDefine.MJConfig_3d.MJType.Out then
  123. local tpl = "mj_3d_outcard_%s_%s.png"
  124. imgName = string.format( tpl, self._viewType, self._cardIndex)
  125. elseif self._mjType == MJDefine.MJConfig_3d.MJType.OutBlack then
  126. elseif self._mjType == MJDefine.MJConfig_3d.MJType.Operate then
  127. local tpl = "mj_3d_op_%s_fore_%s.png"
  128. imgName = string.format(tpl, self._viewType, self._cardIndex)
  129. elseif self._mjType == MJDefine.MJConfig_3d.MJType.OperateBlack then
  130. local tpl = "mj_3d_op_%s_back_%s.png"
  131. imgName = string.format(tpl, self._viewType, self._cardIndex)
  132. elseif self._mjType == MJDefine.MJConfig_3d.MJType.Hu then
  133. local tpl = "mj_3d_hu_%s_fore_%s.png"
  134. imgName = string.format(tpl, self._viewType, self._cardIndex)
  135. elseif self._mjType == MJDefine.MJConfig_3d.MJType.HuBlack then
  136. local tpl = "mj_3d_hu_%s_back_%s.png"
  137. imgName = string.format(tpl, self._viewType, self._cardIndex )
  138. elseif self._mjType == MJDefine.MJConfig_3d.MJType.Open then
  139. local tpl = "mj_3d_open_%s_fore_%s.png"
  140. imgName = string.format(tpl, self._viewType, self._cardIndex)
  141. elseif self._mjType == MJDefine.MJConfig_3d.MJType.OpenBlack then
  142. local tpl = "mj_3d_open_%s_back_%s.png"
  143. imgName = string.format(tpl, self._viewType, self._cardIndex)
  144. end
  145. local md5Name = MJFunction.get3dCardMd5ByName(imgName)
  146. if not md5Name then
  147. logD("[LUA ERROR] Mahjong3DCard:initBackImage imgName:" .. imgName)
  148. return
  149. end
  150. self:loadTextureFromPlist(md5Name)
  151. end
  152. end
  153. return Card3D