您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字

297 行
10 KiB

  1. local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  2. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  3. local MJGroupFactory=MJFramework.MJImport("mj.luaScript.Views.Game.MJGroupFactory")
  4. local MJPositionCompnent = MJFramework.MJImport("mj.luaScript.Views.Compnent.MJPositionCompnent")
  5. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  6. local MJHandCardView=MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Game.MJHandCardView")
  7. local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
  8. local hongzhongHandCardView = class("hongzhongHandCardView", MJHandCardView)
  9. function hongzhongHandCardView:ctor(viewId,desktopType)
  10. hongzhongHandCardView.super.ctor(self,viewId,desktopType)
  11. end
  12. function hongzhongHandCardView:initView()
  13. if self:isUseNew3D() then
  14. self:loadUI()
  15. self.ui.Items.Layout_Hand_Card:setVisible(false)
  16. self.ui.Items.Layout_Operate:setVisible(false)
  17. self.ui.Items.Button_Sure:setVisible(false)
  18. local MJConfig = MJDefine.MJConfig_2d
  19. if self.desktopType == MJDefine.DesktopType.ThreeD then
  20. MJConfig = MJDefine.MJConfig_3d
  21. end
  22. local MahjongHandCard = require(MJConfig.HANDCARD_VIEW)
  23. local MahjongOutCardView = require(MJConfig.OUTCARD_VIEW)
  24. local MahjongHuCardView = require(MJConfig.HU_CARD_VIEW)
  25. self._outCardView = MahjongOutCardView:new(self.viewId)
  26. self:addChild(self._outCardView)
  27. self._huCardView = MahjongHuCardView:new(self.viewId)
  28. self:addChild(self._huCardView)
  29. self._handcard = MahjongHandCard:new(self.viewId, self.desktopType)
  30. self:addChild(self._handcard)
  31. self.ui:setLocalZOrder(10)
  32. else
  33. self:loadUI()
  34. self.ui.Items.Layout_Operate:setVisible(false)
  35. self.ui.Items.Button_Sure:setVisible(false)
  36. self.ui.Items.Button_Sure:registerClick(function()
  37. if not self.touchMJ then
  38. showTooltip("请选择要出的麻将!")
  39. end
  40. self:sendOutCard()
  41. end)
  42. print("MJHandCardView:"..self.viewId)
  43. self.initX=self.ui.Items["ImageView_Start_"..self.viewId]:getPositionX()--MJDefine.MJStartPositions[self.viewId].x
  44. self.initY=self.ui.Items["ImageView_Start_"..self.viewId]:getPositionY()--MJDefine.MJStartPositions[self.viewId].y
  45. print("手牌起始位置self.initX = "..self.initX.."self.initY"..self.initY)
  46. if self.viewId == MJDefine.PlayerViewType.My then
  47. self.initX = self.initX + (CONST_WIDTH*g_radio_x-CONST_WIDTH)/2
  48. print("调整过后我的位置self.initX = "..self.initX.."self.initY"..self.initY)
  49. else
  50. self.initX = self.initX*g_radio_x
  51. self.initY = self.initY*g_radio_y
  52. print("调整过后其他人位置self.initX = "..self.initX.."self.initY"..self.initY)
  53. end
  54. self.outX=self.ui.Items["ImageView_Out_"..self.viewId]:getPositionX()
  55. self.outY=self.ui.Items["ImageView_Out_"..self.viewId]:getPositionY()
  56. print("出牌起始位置self.outX = "..self.outX.."self.outY"..self.outY)
  57. self.outX = self.outX*g_radio_x
  58. self.outY = self.outY*g_radio_y
  59. print("出牌调整后的起始位置self.outX = "..self.outX.."self.outY"..self.outY)
  60. --如果是2人房 调整出牌坐标
  61. if app.room.roomInfo.nMaxPlayCount==2 then
  62. if self.viewId == MJDefine.PlayerViewType.My then
  63. self.outX=self.outX-200
  64. elseif self.viewId == MJDefine.PlayerViewType.Top then
  65. self.outX=self.outX+180
  66. end
  67. end
  68. -- if self.viewId~=MJDefine.MyViewId then
  69. self.showCardPostion=self.ui.Items["ImageView_Show_"..self.viewId]:getPosition()
  70. -- end
  71. print("showCard起始位置self.showCardPostion x = "..self.showCardPostion.x.."y = "..self.showCardPostion.y)
  72. self.showCardPostion.x = self.showCardPostion.x*g_radio_x
  73. self.showCardPostion.y = self.showCardPostion.y*g_radio_y
  74. print("showCard调整后起始位置self.showCardPostion x = "..self.showCardPostion.x.."y = "..self.showCardPostion.y)
  75. self.ui.Items.Layout_Hand_Card:removeAllChildren()
  76. end
  77. end
  78. function hongzhongHandCardView:onTouchBegan(touch)
  79. local lastMj=self.touchMJ
  80. self.touchMJ=nil
  81. self.isTouchMove=false
  82. -- if self.touchMJ then
  83. -- self.touchMJ:setPositionY(self.initY)
  84. -- self.touchMJ:setStatus(MJDefine.MJStatus.Normal)
  85. -- self.touchMJ=nil
  86. -- end
  87. local touchPos=self:convertToNodeSpace(touch:getLocation())
  88. for k,v in pairs(self.handCards) do
  89. local width = v:getContentSize().width
  90. local height = v:getContentSize().height
  91. local x = v:getPosition().x-width/2
  92. local y = v:getPosition().y-height/2
  93. local rect = cc.Rectangle:new(x,y,width,height)
  94. if rect:contains(touchPos.x,touchPos.y) then
  95. self.touchMJ=v
  96. if self.touchMJ.status==MJDefine.MJStatus.Select then --双击出牌
  97. self:sendOutCard()
  98. return false
  99. else
  100. --self.touchMJ:recordPostion(self.initY)
  101. --self.touchMJ:runSelectAnimation()
  102. --self.touchMJ:setStatus(MJDefine.MJStatus.Select)
  103. self.touchMJ:recordPostion(cc.p(self.touchMJ:getPositionX(), self.initY))
  104. -- self.touchMJ:checkDltPos(touchPos) by c.mj
  105. --app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing,card=self.touchMJ.value})
  106. end
  107. break
  108. end
  109. end
  110. --lastMj 有可能被移除 必须 tolua.isnull 判断一次
  111. if lastMj and not tolua.isnull(lastMj) and lastMj~=self.touchMJ then
  112. lastMj:runDeSelectAnimation(true)
  113. lastMj:setStatus(MJDefine.MJStatus.Normal)
  114. end
  115. if self.touchMJ then
  116. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard,value = self.touchMJ.value})
  117. else
  118. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  119. app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  120. return false
  121. end
  122. return true
  123. end
  124. function hongzhongHandCardView:onTouchMove(touch)
  125. if not self.isOutCard then return end
  126. local touchPos=self:convertToNodeSpace(touch:getLocation())
  127. local prePos=self:convertToNodeSpace(touch:getPreviousLocation())
  128. local x = math.abs(prePos.x-touchPos.x)
  129. local y = math.abs(prePos.y-touchPos.y)
  130. if self.touchMJ and (x>=1 or y>=1) then
  131. self.isTouchMove=true
  132. local dltx, dlty = self.touchMJ:getDltPos()
  133. self.touchMJ:setPosition(cc.p(touchPos.x-dltx, touchPos.y-dlty))
  134. self.touchMJ:setLocalZOrder(1)
  135. --return true
  136. end
  137. --return false
  138. end
  139. function hongzhongHandCardView:onTouchEnd(touch)
  140. if self.touchMJ then
  141. local touchdis = self.touchMJ:getTouchDistance()
  142. if self.touchMJ:getTouchDistance()>MJDefine.MJ_TOUCH_OUT_CARD_Y then
  143. self:touchOutCard()
  144. else
  145. self.touchMJ:runSelectAnimation()
  146. self.touchMJ:setStatus(MJDefine.MJStatus.Select)
  147. app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing,card=self.touchMJ.value})
  148. end
  149. end
  150. end
  151. function hongzhongHandCardView:onTouchCancel(touch)
  152. --self:touchOutCard()
  153. end
  154. function hongzhongHandCardView:touchOutCard()
  155. if self.touchMJ and self.isTouchMove then
  156. if self.touchMJ:getPositionY()>self.touchMJ.initPostion.y+MJDefine.MJ_TOUCH_OUT_CARD_Y then
  157. self:sendOutCard()
  158. else
  159. self.touchMJ:restorePostion()
  160. self.touchMJ:setStatus(MJDefine.MJStatus.Normal)
  161. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  162. app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  163. -- if self.isOutCard then
  164. -- self:moveLastCard()
  165. -- end
  166. end
  167. end
  168. self.isTouchMove=false
  169. end
  170. function hongzhongHandCardView:createOutCards(arg)
  171. if self:isUseNew3D() then
  172. self._outCardView:createOutCards(arg)
  173. --获取出的牌,结算要显示中鸟
  174. self.outCards = self._outCardView:getOutCardNodes()
  175. else
  176. -- arg={
  177. -- {card=0x25},
  178. -- {card=0x01},
  179. -- {card=0x01},
  180. -- {card=0x01},
  181. -- {card=0x01},
  182. -- {card=0x02},
  183. -- {card=0x01},
  184. -- {card=0x01},
  185. -- {card=0x01},
  186. -- {card=0x02},
  187. -- {card=0x01},
  188. -- {card=0x01},
  189. -- {card=0x01},
  190. -- {card=0x02},
  191. -- }
  192. if type(arg)=="number" then
  193. arg={
  194. {card=arg}
  195. }
  196. end
  197. -- local x=self.outX
  198. -- local y=self.outY
  199. for k,v in pairs(arg) do
  200. print("测试:"..v.card)
  201. local mj=MJ:new(v.card,MJDefine.MJType.Out,self.viewId,self.desktopType)
  202. self.ui.Items.Layout_Hand_Card:addChild(mj)
  203. table.insert(self.outCards,mj)
  204. -- --取余计算X坐标 从起始位置开始 默认应该为0 所以要减去1
  205. -- local n=#self.outCards%MJDefine.MJChangeLinCount[self.viewId]-1
  206. -- --向下取整判断是否换行
  207. -- local m=math.floor(#self.outCards/MJDefine.MJChangeLinCount[self.viewId])
  208. -- --如果刚好等于0则设置为换行的数
  209. -- if #self.outCards%MJDefine.MJChangeLinCount[self.viewId]==0 then
  210. -- n=MJDefine.MJChangeLinCount[self.viewId]-1
  211. -- m=m-1
  212. -- end
  213. -- --根据视图ID 计算坐标
  214. -- if self.viewId==MJDefine.PlayerViewType.My then
  215. -- x=self.outX+(mj:getContentSize().width-MJDefine.MJOutChangeOffSet[self.viewId].x)*n
  216. -- y=self.outY-m*(mj:getContentSize().height-MJDefine.MJOutChangeOffSet[self.viewId].y)
  217. -- elseif self.viewId==MJDefine.PlayerViewType.Left then
  218. -- x=self.outX-m*(mj:getContentSize().width-MJDefine.MJOutChangeOffSet[self.viewId].x)-n*MJDefine.MJOutOffSet[self.viewId].x
  219. -- y=self.outY-(mj:getContentSize().height-MJDefine.MJOutChangeOffSet[self.viewId].y)*n
  220. -- mj:setLocalZOrder(n-m)
  221. -- elseif self.viewId==MJDefine.PlayerViewType.Right then
  222. -- x=self.outX+m*(mj:getContentSize().width-MJDefine.MJOutChangeOffSet[self.viewId].x)-n*MJDefine.MJOutOffSet[self.viewId].x
  223. -- y=self.outY+(mj:getContentSize().height-MJDefine.MJOutChangeOffSet[self.viewId].y)*n
  224. -- mj:setLocalZOrder(-m-n)
  225. -- elseif self.viewId==MJDefine.PlayerViewType.Top then
  226. -- -- local scale=0.8 --上面的麻将要缩小
  227. -- mj:setScale(MJDefine.MJ_TOP_SCALE)
  228. -- x=self.outX-(mj:getContentSize().width*MJDefine.MJ_TOP_SCALE-MJDefine.MJOutChangeOffSet[self.viewId].x)*n
  229. -- y=self.outY+m*(mj:getContentSize().height*MJDefine.MJ_TOP_SCALE-MJDefine.MJOutChangeOffSet[self.viewId].y)
  230. -- mj:setLocalZOrder(self:getContentSize().height-y)
  231. -- end
  232. local x,y=MJPositionCompnent.getOutCardPosition(self.viewId,self.outX,self.outY,mj,#self.outCards,self.desktopType,app.room.roomInfo.nMaxPlayCount)
  233. mj:setPosition(x,y)
  234. end
  235. end
  236. end
  237. --插牌动画
  238. function hongzhongHandCardView:runInsertCardAction()
  239. local insertMj=self.handCards[#self.handCards]
  240. local iX=insertMj:getPositionX()
  241. local iY=insertMj:getPositionY()
  242. local height=insertMj:getContentSize().height
  243. local x,y=self:resetHandCards(insertMj,false)
  244. -- local actions={
  245. -- cc.MoveTo:create(0.01,cc.p(insertMj:getPositionX(),insertMj:getPositionY()+height)),
  246. -- cc.MoveTo:create(0.01,cc.p(x,insertMj:getPositionY()+height)),
  247. -- cc.MoveTo:create(0.01,cc.p(x,self.initY)),
  248. -- }
  249. -- insertMj:runAction(cc.Sequence:create(actions))
  250. insertMj:setPosition(cc.p(x,self.initY))
  251. self:resetHandCards()
  252. end
  253. return hongzhongHandCardView