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ů.

1301 řádky
40 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 xueliuHandCardView = class("xueliuHandCardView", MJHandCardView)
  9. function xueliuHandCardView:ctor(viewId,desktopType)
  10. xueliuHandCardView.super.ctor(self,viewId,desktopType)
  11. end
  12. function xueliuHandCardView:onEnter()
  13. xueliuHandCardView.super.onEnter(self)
  14. self.huCardLayout = {};
  15. --绑定事件
  16. self:bindEvent(app.room , MJDefine.MJEvent.checkIsNeedSendGuo , handler(self , self.checkIsNeedSendGuo))
  17. end
  18. function xueliuHandCardView:loadUI()
  19. local ui
  20. if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold or self.desktopType==MJDefine.DesktopType.TwoDL then
  21. ui = loadUI("mj_xueliu/res/ui_fangjian/mj_xueliu_hand_card_2d.ui");
  22. else
  23. ui = loadUI("mj_xueliu/res/ui_fangjian/mj_xueliu_hand_card.ui");
  24. end
  25. self.ui = ui;
  26. self:addChild(ui)
  27. end
  28. function xueliuHandCardView:initView()
  29. if self:isUseNew3D() then
  30. self:initNew3DUI()
  31. else
  32. xueliuHandCardView.super.initView(self)
  33. self:hideOperateItem()
  34. if app.room:getMaxPlayerCount()~= 2 then
  35. if self.viewId == MJDefine.PlayerViewType.My then
  36. self.outX=self.outX-30
  37. end
  38. end
  39. local roomInfo = app.room.roomInfo or {}
  40. local strGameInfo = roomInfo.strGameInfo
  41. local gameInfo = json.decode(strGameInfo) or {}
  42. local cardNum = tonumber(gameInfo.handcard or 13)
  43. if MJDefine.HandCardStartPosOfCardNum[cardNum][self.viewId] then
  44. self.initX = MJDefine.HandCardStartPosOfCardNum[cardNum][self.viewId].x
  45. self.initY = MJDefine.HandCardStartPosOfCardNum[cardNum][self.viewId].y
  46. end
  47. end
  48. end
  49. function xueliuHandCardView:pushTing()
  50. if self:isUseNew3D() then
  51. self._handcard:pushTing()
  52. else
  53. local tings=app.room.roomInfo.tings
  54. if tings then
  55. for k,v in pairs(tings) do
  56. for _,mj in pairs(self.handCards) do
  57. if mj.value==v.outCard then
  58. mj:setTing(true)
  59. end
  60. end
  61. end
  62. end
  63. end
  64. end
  65. --摸牌
  66. function xueliuHandCardView:onGetCard(operates,card,isSwap)
  67. if self:isUseNew3D() then
  68. self.touchMJ = nil
  69. self:createHandCards(card)
  70. if not operates or table.nums(operates) == 0 then
  71. self._handcard:setOutCardEnable(true)
  72. MJDefine.outCardSendGuo = false
  73. else
  74. self._handcard:setOutCardEnable(true)
  75. MJDefine.outCardSendGuo = true
  76. -- self:canOutCard(true)
  77. end
  78. -- todo lwq 血流, 胡牌以后,不能自己再打出牌
  79. if self.viewId==MJDefine.MyViewId then
  80. if self.isHu and self.isHu == 1 then
  81. self._handcard:setOutCardEnable(false)
  82. end
  83. end
  84. if self.viewId==MJDefine.MyViewId then
  85. MJSound.PlayGetCard()
  86. end
  87. else
  88. if self.viewId==MJDefine.MyViewId then
  89. self:resetHandCardsPosAndOpacity()
  90. end
  91. self:createHandCards(card)
  92. self:resetCardsSortValue()--为了给刚摸上的牌重新赋值排序值
  93. if self.viewId==MJDefine.PlayerViewType.Right and not self.isReplay then
  94. self:resetHandCards()
  95. end
  96. if isSwap and isSwap == true then return end --如果是换牌阶段,返回
  97. if not operates or table.nums(operates)==0 then
  98. self:setOutCardEnable(true)
  99. MJDefine.outCardSendGuo = false
  100. else
  101. self:setOutCardEnable(true)
  102. MJDefine.outCardSendGuo = true
  103. -- self:canOutCard(true)
  104. end
  105. if self.viewId==MJDefine.MyViewId then
  106. MJSound.PlayGetCard()
  107. end
  108. end
  109. end
  110. function xueliuHandCardView:setOutCardEnable(b)
  111. if self:isUseNew3D() then
  112. self._handcard:setOutCardEnable(b)
  113. else
  114. self.isOutCard=b
  115. if b then
  116. self:moveLastCard()
  117. end
  118. if self.viewId==MJDefine.MyViewId and self.ui.Items.Button_Sure then
  119. -- self.ui.Items.Button_Sure:setVisible(b)
  120. end
  121. end
  122. end
  123. --不管是否自动对齐,红中始终保持放在最左边
  124. function xueliuHandCardView:sortRedMahjong()
  125. local redNum = 0
  126. for k,mj in pairs(self.handCards) do
  127. if mj.value == 65 then
  128. redNum = redNum + 1
  129. table.remove(self.handCards,k)
  130. table.insert(self.handCards,redNum,mj)
  131. end
  132. end
  133. end
  134. function xueliuHandCardView:removeHandCardByNum(value,num,redNum)
  135. redNum = redNum or 0
  136. if self:isUseNew3D() then
  137. self._handcard:removeHandCardByNum(value, num,redNum)
  138. else
  139. if self.viewId==MJDefine.MyViewId or self.isReplay then
  140. for i=1,num do
  141. local mj
  142. if redNum > 0 and i <= redNum then
  143. mj=self:getMjByValue(65) --红中值
  144. else
  145. mj=self:getMjByValue(value)
  146. end
  147. if mj then
  148. table.removeItem(self.handCards,mj)
  149. mj:removeFromParent()
  150. end
  151. end
  152. else
  153. -- local num=#self.handCards-#arg
  154. -- print(num)
  155. for i=#self.handCards,#self.handCards-num+1,-1 do
  156. if self.handCards[i] then
  157. self.handCards[i]:removeFromParent()
  158. table.remove(self.handCards,i)
  159. end
  160. end
  161. end
  162. end
  163. end
  164. function xueliuHandCardView:getGroup(card,opType)
  165. if self:isUseNew3D() then
  166. return self._handcard:getGroup(card, opTypes)
  167. else
  168. for k,v in pairs(self.handGroupCards) do
  169. if v.opType==opType and (v.mjs[1].value==card or v.mjs[2].value == card or v.mjs[3].value == card) then
  170. local redNum = 0
  171. for i,mj in pairs(v.mjs) do
  172. --先取出原组合的红中个数
  173. if mj.value == 65 then
  174. redNum = redNum + 1
  175. end
  176. end
  177. return v,redNum
  178. end
  179. end
  180. end
  181. end
  182. function xueliuHandCardView:createGroupCards(arg,fromViewId)
  183. if self:isUseNew3D() then
  184. self._handcard:createGroupCards(arg, fromViewId)
  185. else
  186. local x=self.initX
  187. local y=self.initY
  188. local MJGroupStartOffSet = MJDefine.MJGroupStartOffSet[self.desktopType]
  189. for k,v in pairs(arg) do
  190. if not fromViewId then
  191. fromViewId = v.fromViewId
  192. end
  193. local group=MJGroupFactory.CreateGroup(v.values,v.showType,self.viewId,self.desktopType,v.redNum)
  194. if group then
  195. --设置碰杠来源
  196. --group:setDirection(self.viewId,v.fromViewId1)
  197. if group.setAnColor and (v.opType == MJDefine.MJOperateType.OPREATE_PENG
  198. or v.opType == MJDefine.MJOperateType.OPREATE_ZHIGANG
  199. or v.opType == MJDefine.MJOperateType.OPREATE_BAGANG) then
  200. --牌的阴影显示刚好和视图id相反
  201. if v.fromViewId == 1 then v.fromViewId = 3
  202. elseif v.fromViewId==3 then v.fromViewId = 1 end
  203. -- 杠牌对家,换成第四张
  204. if v.opType ~= MJDefine.MJOperateType.OPREATE_PENG then
  205. if v.fromViewId==2 then v.fromViewId = 4 end
  206. end
  207. group:setAnColor(v.opCard, v.fromViewId)
  208. end
  209. if v.opType == MJDefine.MJOperateType.OPREATE_BAGANG and group.mjs and group.mjs[4] then
  210. --group.mjs[4]:setOutBlackImage(0,self.viewId)
  211. end
  212. group.fromViewId = v.fromViewId ---保留触发操作的玩家位置,补杠需要
  213. group.opType=v.opType
  214. self.ui.Items.Layout_Hand_Card:addChild(group,-4+#self.handGroupCards)
  215. group:setPosition(cc.p(x+MJGroupStartOffSet[self.viewId].x,y+MJGroupStartOffSet[self.viewId].y))
  216. x,y=MJPositionCompnent.getGroupPosition(self.viewId,x,y,group,self.desktopType)
  217. table.insert(self.handGroupCards,group)
  218. end
  219. end
  220. --更新起始位置
  221. self.initX=x
  222. self.initY=y
  223. end
  224. end
  225. --添加杠操作按钮
  226. function xueliuHandCardView:addOperateBtn(operates)
  227. local x=self.ui.Items.Layout_Operate:getContentSize().width
  228. local y=self.ui.Items.Layout_Operate:getContentSize().height/2
  229. local btnOperate=cc.Button:createNode()
  230. btnOperate:setDefaults()
  231. btnOperate:setText("")
  232. btnOperate:loadTextureNormal(MJDefine.MJOperateImage[operates[1].opType])
  233. btnOperate:ignoreAnchorPointForPosition(false)
  234. self.btnPosX = self.btnPosX-MJDefine.MJ_OPERATE_PADDING
  235. btnOperate:setPosition(cc.p(self.btnPosX, y))
  236. self.ui.Items.Layout_Operate:addChild(btnOperate,2)
  237. if operates and table.nums(operates) <=1 then
  238. self.btnPosX = self.btnPosX-50
  239. btnOperate:setPosition(cc.p(self.btnPosX, y))
  240. local gangBg = cc.Layout:create()
  241. gangBg:setBackGroundImageScale9Enabled(true)
  242. gangBg:setBackGroundImage("mj_xueliu/res/zy_fangjian/xzddadd/xzdd_room_gangBg.png",0)
  243. gangBg:setPosition(cc.p(btnOperate:getPositionX()+30, y-40))
  244. gangBg:setSize(cc.size(80,80))
  245. self.ui.Items.Layout_Operate:addChild(gangBg)
  246. gangBg:registerClick(function(sender)
  247. self:sendOp({opType = operates[1].opType,opCard = operates[1].opCard,redNum = operates[1].redNum})
  248. end)
  249. local mj=MJ:new(operates[1].opCard,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
  250. mj:setScale(0.5)
  251. mj:setAnchorPoint(cc.p(0.5,0.5))
  252. gangBg:addChild(mj)
  253. mj:setPosition(cc.p(gangBg:getContentSize().width/2+10, gangBg:getContentSize().height/2))
  254. end
  255. btnOperate:registerClick(function()
  256. -- playBtnEffect()
  257. if operates and table.nums(operates) <=1 then
  258. self:sendOp({opType = operates[1].opType,opCard = operates[1].opCard,redNum = operates[1].redNum})
  259. else
  260. self:showGangItem(operates)
  261. end
  262. end)
  263. end
  264. function xueliuHandCardView:showGangItem(operates)
  265. self.ui.Items.Layout_OperateItem:setVisible(true)
  266. self.ui.Items.Layout_Operate_Content:removeAllChildren()
  267. local col = 0
  268. local count = 6
  269. -- todo lwq
  270. local hengIndex = 0
  271. for k,v in pairs(operates) do
  272. hengIndex = hengIndex + 1
  273. end
  274. local temp = self.ui.Items.Layout_MJ_Item
  275. local _size = temp:getContentSize()
  276. self.ui.Items.Layout_OperateItem:setSize(cc.size(hengIndex*133,_size.height + 5))
  277. self.ui.Items.Layout_OperateItem:setPosition(cc.p(940,160 + 114))
  278. local _size1 = self.ui.Items.Layout_OperateItem:getContentSize()
  279. self.ui.Items.Layout_Operate_Content:setSize(cc.size(_size1.width, _size1.height))
  280. self.ui.Items.Layout_Operate_Content:setPosition(cc.p(_size1.width,0))
  281. for k,v in pairs(operates) do
  282. local item = self.ui.Items.Layout_MJ_Item:getCopied()
  283. local mj=MJ:new(v.opCard,MJDefine.MJType.Stand,self.viewId,self.desktopType)
  284. item:addChild(mj)
  285. local size = item:getContentSize()
  286. mj:setPosition(cc.p(size.width/2,size.height/2))
  287. self.ui.Items.Layout_Operate_Content:addChild(item)
  288. --self.ui.Items.Layout_OperateItem:addChild(item)
  289. mj:registerClick(function()
  290. self:sendOp({opType = v.opType,opCard = v.opCard,redNum = v.redNum})
  291. end)
  292. -- local col = k
  293. local row = math.ceil(k/count)
  294. -- logD(k.." :".. (k%count))
  295. -- local isChangeRow = k%count==0
  296. local x = self.ui.Items.Layout_Operate_Content:getContentSize().width-col*133
  297. --local x = self.ui.Items.Layout_OperateItem:getContentSize().width-col*133
  298. local y = (row-1)*size.height
  299. item:setPositionX(x)
  300. item:setPositionY(y)
  301. col = col+1
  302. if k%count==0 then
  303. col = 0
  304. end
  305. end
  306. -- local count = table.nums(operates)
  307. -- local padding=10
  308. -- local width=self.ui.Items.Layout_OperateItem:getContentSize().width
  309. -- local height=self.ui.Items.Layout_OperateItem:getContentSize().height
  310. -- local layoutItem = cc.Layout:create()
  311. -- layoutItem:setBackGroundImageScale9Enabled(true)
  312. -- --layoutItem:setBackGroundImage("mj/res/ui/zy_fangjian/mj_gang_bg.png")
  313. -- layoutItem:setAnchorPoint(cc.p(0.5,1))
  314. -- self.ui.Items.Layout_OperateItem:addChild(layoutItem)
  315. -- if count <= 3 then
  316. -- layoutItem:setSize(cc.size(230*count+padding*count,height+padding))
  317. -- else
  318. -- layoutItem:setSize(cc.size(230*3+padding*3,height*(math.floor(count/3)+1)+(math.floor(count/3)+1)*padding))
  319. -- --self.ui.Items.Layout_OperateItem:setSize(cc.size(230*3+padding*3,height*(math.floor(count/3)+1)+(math.floor(count/3)+1)*padding))
  320. -- end
  321. -- layoutItem:setPosition(cc.p(width/2,height))
  322. -- local layoutHeight = layoutItem:getContentSize().height
  323. -- local y = 0
  324. -- for k,v in ipairs(operates) do
  325. -- local layout=cc.Layout:create()
  326. -- layout:setBackGroundImageScale9Enabled(true)
  327. -- layout:setBackGroundImage("mj/res/ui/zy_fangjian/mj_gang_bg.png")
  328. -- self.ui.Items.Layout_OperateItem:addChild(layout)
  329. -- layout:setSize(cc.size(230,height))
  330. -- layout:setAnchorPoint(cc.p(0,1))
  331. -- if k%3 == 1 then
  332. -- y = layoutHeight -15- height*(math.floor(k/3)+1)-10*(math.floor(k/3)+1)
  333. -- end
  334. -- if count < 3 then
  335. -- layout:setPosition(cc.p(-145+padding*(k-1)+230*(k-1),layoutHeight-15))
  336. -- elseif count == 3 then
  337. -- layout:setPosition(cc.p(-260+padding*(k-1)+230*(k-1),layoutHeight-15))
  338. -- else
  339. -- layout:setPosition(cc.p(-260+padding*(k%3-1)+230*(k%3-1),y))
  340. -- if k%3 == 0 then
  341. -- layout:setPosition(cc.p(-260+padding*2+230*2,y))
  342. -- end
  343. -- end
  344. -- for i=1,4 do
  345. -- local mj
  346. -- if v.redNum > 0 and i<=v.redNum then
  347. -- mj=MJ:new(65,MJDefine.MJType.Stand,self.viewId,self.desktopType)
  348. -- else
  349. -- mj=MJ:new(v.opCard,MJDefine.MJType.Stand,self.viewId,self.desktopType)
  350. -- end
  351. -- mj:setScale(0.6)
  352. -- layout:addChild(mj)
  353. -- local mjWidth = mj:getContentSize().width*0.6
  354. -- mj:setAnchorPoint(cc.p(0.5,0.5))
  355. -- mj:setPosition(32+3*(i-1)+mjWidth*(i-1),layout:getContentSize().height/2)
  356. -- end
  357. -- layout:registerClick(function ( sender )
  358. -- self:sendOp({opType = v.opType,opCard = v.opCard,redNum = v.redNum})
  359. -- end)
  360. -- end
  361. end
  362. function xueliuHandCardView:hideOperateItem()
  363. if self.ui.Items.Layout_OperateItem then
  364. self.ui.Items.Layout_Operate_Content:removeAllChildren()
  365. self.ui.Items.Layout_OperateItem:setVisible(false)
  366. end
  367. end
  368. --显示操作
  369. function xueliuHandCardView:showOperate(operates,card,isMyGetCard)
  370. if not operates or table.nums(operates)==0 then return end
  371. print(table.tostring(operates))
  372. local card = card or 0
  373. self:hideOperateItem()
  374. self:hideOperate()
  375. if operates and table.nums(operates) > 0 then
  376. self.ui.Items.Button_Sure:setVisible(false)
  377. end
  378. self.operates = operates
  379. local newOperates = {}
  380. --有操作默认添加过的操作
  381. local operate=MJMessage.OperateRequest:new()
  382. operate.opType=MJDefine.MJOperateType.OPREATE_CANCEL
  383. operate.opCard=card
  384. operate.redNum = 0
  385. --table.insert(operates.Datas,1,operate)
  386. table.insert(newOperates,1,operate)
  387. self.ui.Items.Layout_Operate:removeAllChildren()
  388. self.ui.Items.Layout_Operate:setVisible(true)
  389. local x=self.ui.Items.Layout_Operate:getContentSize().width
  390. local y=self.ui.Items.Layout_Operate:getContentSize().height/2
  391. self.btnPosX = x
  392. local gangCards ={} --所有杠組合
  393. local onceGang = false
  394. local isCanHu = false
  395. --operates.Datas包含所有碰杠组合,服务器不管是否贴鬼碰/杠,需客户端自己分离贴鬼碰和无贴鬼碰
  396. for k,v in pairs(operates.Datas) do
  397. if v.opType ~= MJDefine.MJOperateType.OPREATE_CANCEL then
  398. if MJDefine.isTieGui == true then --选择贴鬼碰/杠
  399. if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) or onceGang == false then
  400. if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) then
  401. isCanHu = true
  402. end
  403. table.insert(newOperates,v)
  404. end
  405. if (v.opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_BAGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  406. onceGang = true
  407. table.insert(gangCards,v)
  408. end
  409. else
  410. if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) then
  411. isCanHu = true
  412. table.insert(newOperates,v)
  413. end
  414. --不勾选贴鬼碰/杠时,过滤掉带红中的碰杠
  415. if v.redNum == 0 and v.opType ~= MJDefine.MJOperateType.OPREATE_DIANPAOHU and (v.opType ~= MJDefine.MJOperateType.OPREATE_ZIMOHU) then
  416. if onceGang == false then
  417. table.insert(newOperates,v)
  418. end
  419. if (v.opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_BAGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  420. onceGang = true
  421. table.insert(gangCards,v)
  422. end
  423. end
  424. end
  425. end
  426. end
  427. print(table.tostring(newOperates))
  428. if table.nums(newOperates) >= 2 then
  429. local function sortOperate(opA,opB)
  430. if opA.opType<opB.opType then
  431. return true
  432. elseif opA.opType==opB.opType then
  433. if opA.opCard<opB.opCard then
  434. return true
  435. end
  436. end
  437. return false
  438. end
  439. table.sort(newOperates,sortOperate)
  440. --没有碰杠操作,此条件只有不勾选贴鬼碰/杠才可能会执行
  441. else
  442. --如果不是自己摸牌的情况下
  443. if not isMyGetCard then --app.room.roomInfo.outCardUserId~=app.room:getMyUserId() then --
  444. print("not isMyGetCard")
  445. self:sendOp({opType = MJDefine.MJOperateType.OPREATE_CANCEL,opCard=card,redNum=0})
  446. MJDefine.isSendGuo = true
  447. return;
  448. end
  449. --是自己摸牌
  450. self:hideOperate()
  451. self:setOutCardEnable(true)
  452. logD("xueliuHandCardView:showOperate setOutCardEnable true")
  453. end
  454. local pengCard = {}
  455. for k,v in pairs(newOperates) do
  456. if MJDefine.MJOperateImage[v.opType] then
  457. if(v.opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_BAGANG) or (v.opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  458. self:addOperateBtn(gangCards)
  459. elseif v.opType==MJDefine.MJOperateType.OPREATE_PENG then
  460. table.insert(pengCard,v)
  461. self:addOperateBtn(pengCard)
  462. elseif (v.opType~=MJDefine.MJOperateType.OPREATE_ZHIGANG) or (v.opType~=MJDefine.MJOperateType.OPREATE_BAGANG) or (v.opType~=MJDefine.MJOperateType.OPREATE_ANGANG) or (v.opType~=MJDefine.MJOperateType.OPREATE_PENG) then
  463. --非碰杠进入这里
  464. local btnOperate=cc.Button:createNode()
  465. btnOperate:setDefaults()
  466. btnOperate:setText("")
  467. btnOperate:loadTextureNormal(MJDefine.MJOperateImage[v.opType])
  468. btnOperate:ignoreAnchorPointForPosition(false)
  469. self.btnPosX = self.btnPosX-MJDefine.MJ_OPERATE_PADDING
  470. btnOperate:setPosition(cc.p(self.btnPosX, y))
  471. self.ui.Items.Layout_Operate:addChild(btnOperate)
  472. --ljx 修复胡牌后有杠操作时没有过按钮显示 增加onceGang变量控制
  473. if v.opType == MJDefine.MJOperateType.OPREATE_CANCEL then
  474. if self.isHu and self.isHu == 1 and not onceGang then
  475. -- 杠有过,免的枪杆胡了
  476. btnOperate:setVisible(false)
  477. end
  478. end
  479. if isCanHu and isCanHu == true and v.opType == MJDefine.MJOperateType.OPREATE_CANCEL then
  480. local function qiHuConfirm()
  481. local content = string.format("确定放弃胡牌吗?")
  482. local okCallBack = function ()
  483. self:sendOp(v)
  484. end
  485. local cancelCallBack = function ()
  486. end
  487. showConfirmDialog(content,okCallBack,cancelCallBack)
  488. end
  489. btnOperate:registerClick(qiHuConfirm)
  490. else
  491. btnOperate:registerClick(function()
  492. -- playBtnEffect()
  493. self:sendOp(v)
  494. end)
  495. end
  496. end
  497. end
  498. end
  499. end
  500. function xueliuHandCardView:sendOp(value)
  501. local request = MJMessage.OperateRequest:new()
  502. request.opType = value.opType
  503. request.opCard = value.opCard
  504. self.operates = self.operates or {}
  505. local opNum = 2--table.nums(self.operates)
  506. --[[if opNum and opNum > 0 then
  507. for _,v in ipairs(self.operates.Datas or {}) do
  508. table.insert(request.operates.Datas, v)
  509. end
  510. end--]]
  511. --request.opNum = opNum
  512. --request.operates = self.operates
  513. logE("xueliuHandCardView:sendOp"..table.tostring(request))
  514. --[[self.ui:sendMsg(app.room, MJDefine.MJEvent.Operate, request, function(status, response)
  515. logE("MJHandCardView showOperate() response = ", table.tostring(response))
  516. end)--]]
  517. app.room:sendOperateCard(value,self.operates)
  518. self:hideOperateItem()
  519. self:hideOperate()
  520. self.operates = nil
  521. if value.opType == MJDefine.MJOperateType.OPREATE_CANCEL then
  522. app.room:dispatchEvent({name = MJDefine.MJEvent.SendGuo})
  523. end
  524. --self:setTing(false)
  525. --app.room:resetTings()
  526. end
  527. --检测是否需要先发过(有操作出牌的情况下要先发过)
  528. function xueliuHandCardView:checkIsNeedSendGuo()
  529. if self.ui.Items.Layout_Operate and self.ui.Items.Layout_Operate:isVisible() and self.viewId == MJDefine.MyViewId and not self.isNotSendIng then
  530. self.isNotSendIng = true
  531. self:sendOp({opType = MJDefine.MJOperateType.OPREATE_CANCEL,opCard=card,redNum=0})
  532. self.ui:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function()
  533. self.isNotSendIng = false
  534. end)))
  535. end
  536. end
  537. --发送出牌消息
  538. function xueliuHandCardView:sendOutCard()
  539. if not self.isOutCard or not self.touchMJ then return end
  540. if not self.touchMJ.value or self.touchMJ.value == 0 then return end
  541. self:checkIsNeedSendGuo()
  542. self:hideOperate()
  543. -- if MJDefine.outCardSendGuo == true then
  544. -- self:sendOp({opType = MJDefine.MJOperateType.OPREATE_CANCEL,opCard=0,redNum=0})
  545. -- -- self:runDelay(0.1,function()
  546. -- xueliuHandCardView.super.sendOutCard(self)
  547. -- -- end)
  548. -- else
  549. xueliuHandCardView.super.sendOutCard(self)
  550. -- end
  551. app.room.roomInfo.lastOutViewId = MJDefine.MyViewId
  552. self:checkQueAndDisableOtherCard()
  553. -- local request = MJMessage.Card:new()
  554. -- request.card = self.touchMJ.value
  555. -- -- logE("LHQRecordView:setOutCardVisible"..table.tostring(request))
  556. -- self.ui:sendMsg(app.room, MJDefine.MJEvent.OutCard, request, function(status, response)
  557. -- logE("MJHandCardView sendOutCard() response = ", table.tostring(response))
  558. -- end)
  559. -- --音效
  560. -- local userInfo=app.room:getUserInfoByViewId(self.viewId)
  561. -- if userInfo then
  562. -- MJSound.PlayMJSound(userInfo.sex,request.card)
  563. -- end
  564. -- app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value=self.touchMJ.value,viewId=self.viewId})
  565. -- self:setOutCardEnable(false)
  566. -- app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  567. -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  568. -- self:setTing(false)
  569. -- app.room:resetTings()
  570. -- self.touchMJ=nil
  571. end
  572. --恢复麻将位置和透明度
  573. function xueliuHandCardView:resetHandCardsPosAndOpacity()
  574. local initX,initY=self:getInitHandCardPostion()
  575. local x=initX
  576. local y=initY
  577. local insertX=0
  578. local insertY=0
  579. if MJDefine.isAutomatic == true then
  580. self:sortHandCards()
  581. else
  582. end
  583. for k,mj in pairs(self.handCards) do
  584. mj:setPosition(x,y)
  585. mj:setOpacity(255)
  586. x,y=MJPositionCompnent.getHandCardPosition(self.viewId,initX,initY,mj,k,self.desktopType)
  587. end
  588. return insertX,insertY
  589. end
  590. function xueliuHandCardView:resetHandCards(insertMj,isAnimation)
  591. if self:isUseNew3D() then
  592. self._handcard:resetHandCards(insertMj,isAnimation)
  593. else
  594. -- local initX=self.initX
  595. -- local initY=self.initY
  596. local initX,initY=self:getInitHandCardPostion()
  597. local x=initX
  598. local y=initY
  599. local insertX=0
  600. local insertY=0
  601. if MJDefine.isAutomatic == true then
  602. self:sortHandCards()
  603. else
  604. -- self:sortRedMahjong()
  605. end
  606. for k,mj in pairs(self.handCards) do
  607. if mj.status ~= MJDefine.MJStatus.Disable then
  608. mj:setStatus(MJDefine.MJStatus.Normal)
  609. mj:stopAllActions()
  610. end
  611. logD("k:"..k.." value:"..mj.value)
  612. if insertMj==mj then --记录插入麻将的坐标 动画需要
  613. insertX=x
  614. insertY=y
  615. else
  616. if isAnimation then
  617. mj:runAction(cc.MoveTo:create(0.1,cc.p(x,y)))
  618. else
  619. mj:setPosition(x,y)
  620. end
  621. end
  622. x,y=MJPositionCompnent.getHandCardPosition(self.viewId,initX,initY,mj,k,self.desktopType)
  623. end
  624. return insertX,insertY
  625. end
  626. end
  627. function xueliuHandCardView:moveRestHandCards(insertMj,isAnimation)
  628. local initX,initY=self:getInitHandCardPostion()
  629. local x=initX
  630. local y=initY
  631. local insertX=0
  632. local insertY=0
  633. for k,mj in pairs(self.handCards) do
  634. --如果可以出牌 最后的麻将不重置位置
  635. -- local isLastCard = self.isOutCard and k==#self.handCards
  636. -- if isLastCard then
  637. -- break
  638. -- end
  639. if mj.status ~= MJDefine.MJStatus.Disable then
  640. mj:setStatus(MJDefine.MJStatus.Normal)
  641. mj:stopAllActions()
  642. end
  643. logD("k:"..k.." value:"..mj.value)
  644. if insertMj==mj then --记录插入麻将的坐标 动画需要
  645. insertX=x
  646. insertY=y
  647. else
  648. if isAnimation then
  649. mj:runAction(cc.MoveTo:create(0.1,cc.p(x,y)))
  650. else
  651. mj:setPosition(x,y)
  652. end
  653. end
  654. x,y=MJPositionCompnent.getHandCardPosition(self.viewId,initX,initY,mj,k,self.desktopType)
  655. end
  656. return insertX,insertY
  657. end
  658. --[[function xueliuHandCardView:onTouchEnd(touch)
  659. if MJDefine.isAutomatic == false then
  660. local touchPos=self:convertToNodeSpace(touch:getLocation())
  661. local newHandCards = {}
  662. for k,mj in pairs(self.handCards) do
  663. table.insert(newHandCards,k,mj)
  664. local width = mj:getContentSize().width
  665. local height = mj:getContentSize().height
  666. local x = mj:getPosition().x-width/2
  667. local y = mj:getPosition().y-height/2
  668. local rect = cc.Rectangle:new(x,y,width,height)
  669. if rect:contains(touchPos.x,touchPos.y) then
  670. if self.handCards[k] then
  671. table.remove(newHandCards,k)
  672. end
  673. if self.touchMJ and not tolua.isnull(self.touchMJ) then
  674. table.insert(newHandCards,k,self.touchMJ)
  675. end
  676. end
  677. end
  678. self.handCards = nil
  679. self.handCards = DeepCopy(newHandCards)
  680. end
  681. self:touchOutCard()
  682. end
  683. --]]
  684. function xueliuHandCardView:buGang(card,newRedNum)
  685. newRedNum = newRedNum or 0
  686. if self:isUseNew3D() then
  687. self._handcard:buGang(card, newRedNum)
  688. else
  689. local oldGroup,oldRedNum=self:getGroup(card,MJDefine.MJOperateType.OPREATE_PENG)
  690. if not oldGroup then return end
  691. local fromViewId = oldGroup.fromViewId
  692. -- 杠牌对家,换成第四张
  693. if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
  694. fromViewId = 4
  695. end
  696. if app.room:getMaxPlayerCount()==4 and fromViewId == 2 then
  697. fromViewId = 4
  698. end
  699. local redNum = newRedNum + oldRedNum
  700. local newGroup=MJGroupFactory.CreateGroup({card,card,card,card},MJDefine.MJGroupType.Gang,self.viewId,self.desktopType,redNum)
  701. if newGroup.setAnColor then
  702. newGroup:setAnColor(card, fromViewId)
  703. end
  704. newGroup.fromViewId = fromViewId
  705. newGroup.opType=MJDefine.MJOperateType.OPREATE_BAGANG
  706. newGroup:setPosition(oldGroup:getPosition())
  707. if newGroup.mjs and newGroup.mjs[4] then
  708. newGroup.mjs[4]:setOutBlackImage(0,self.viewId)
  709. end
  710. self.ui.Items.Layout_Hand_Card:addChild(newGroup)
  711. local index=table.indexOf(self.handGroupCards,oldGroup)
  712. table.remove(self.handGroupCards,index)
  713. table.insert(self.handGroupCards,index,newGroup)
  714. oldGroup:removeFromParent()
  715. end
  716. end
  717. function xueliuHandCardView:retoreBuGang(card,newRedNum)
  718. newRedNum = newRedNum or 0
  719. if self:isUseNew3D() then
  720. self._handcard:restoreBuGang(card, cardNum)
  721. else
  722. local oldGroup,oldRedNum=self:getGroup(card,MJDefine.MJOperateType.OPREATE_BAGANG)
  723. if not oldGroup then return end
  724. local fromViewId = oldGroup.fromViewId
  725. -- 杠牌对家,换成第四张
  726. if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
  727. fromViewId = 4
  728. end
  729. if app.room:getMaxPlayerCount()==4 and fromViewId == 2 then
  730. fromViewId = 4
  731. end
  732. --local redNum = newRedNum + oldRedNum
  733. local redNum = oldRedNum
  734. local newGroup=MJGroupFactory.CreateGroup({card,card,card},MJDefine.MJGroupType.Peng,self.viewId,self.desktopType,redNum)
  735. if newGroup.setAnColor then
  736. newGroup:setAnColor(card, fromViewId)
  737. end
  738. newGroup.fromViewId = fromViewId
  739. newGroup.opType=MJDefine.MJOperateType.OPREATE_PENG
  740. newGroup:setPosition(oldGroup:getPosition())
  741. self.ui.Items.Layout_Hand_Card:addChild(newGroup)
  742. local index=table.indexOf(self.handGroupCards,oldGroup)
  743. table.remove(self.handGroupCards,index)
  744. table.insert(self.handGroupCards,index,newGroup)
  745. oldGroup:removeFromParent()
  746. end
  747. end
  748. function xueliuHandCardView:lockHandCard(isForbidTouch)
  749. if self:isUseNew3D() then
  750. self._handcard:lockHandCard(isForbidTouch)
  751. else
  752. for k,v in pairs(self.handCards) do
  753. v:setStatus(MJDefine.MJStatus.Disable)
  754. end
  755. self:getEventDispatcher():removeEventListenersForTarget(self)
  756. end
  757. end
  758. function xueliuHandCardView:moveLastOpenCard()
  759. local count=#self.handCards
  760. if count>=2 then
  761. local frontMj=self.handCards[count-1]
  762. local lastMj=self.handCards[count]
  763. local margin=0
  764. local frontX=frontMj:getPositionX()
  765. local frontY=frontMj:getPositionY()
  766. local lastX=lastMj:getPositionX()
  767. local lastY=lastMj:getPositionY()
  768. local MJLastHandCardOffset=MJDefine.MJLastHandCardOffset[self.desktopType]
  769. local MJ_HAND_CARD_LEFT_PADDING_HEIGHT = MJDefine.MJ_HAND_CARD_LEFT_PADDING_HEIGHT[self.desktopType]
  770. --根据视图ID 计算坐标
  771. if self.viewId==MJDefine.PlayerViewType.My then
  772. margin=lastMj:getContentSize().width
  773. -- if math.abs(lastX-frontX)==margin then
  774. lastMj:setPositionX(lastX+MJLastHandCardOffset[self.viewId].x)
  775. -- end
  776. elseif self.viewId==MJDefine.PlayerViewType.Left then
  777. margin=MJ_HAND_CARD_LEFT_PADDING_HEIGHT
  778. -- if math.abs(lastY-frontY)==margin then
  779. lastMj:setPositionX(lastX+MJLastHandCardOffset[self.viewId].x)
  780. lastMj:setPositionY(lastY+MJLastHandCardOffset[self.viewId].y)
  781. -- end
  782. elseif self.viewId==MJDefine.PlayerViewType.Right then
  783. margin=MJ_HAND_CARD_LEFT_PADDING_HEIGHT
  784. -- if math.abs(lastY-frontY)==margin then
  785. lastMj:setPositionX(lastX+MJLastHandCardOffset[self.viewId].x)
  786. lastMj:setPositionY(lastY+MJLastHandCardOffset[self.viewId].y)
  787. -- end
  788. elseif self.viewId==MJDefine.PlayerViewType.Top then
  789. margin=lastMj:getContentSize().width-MJDefine.MJ_HAND_CARD_TOP_OFFSET_X
  790. -- print("width:"..lastMj:getContentSize().width)
  791. -- if math.abs(lastX-frontX)==margin then
  792. lastMj:setPositionX(lastX+MJLastHandCardOffset[self.viewId].x)
  793. -- end
  794. end
  795. end
  796. end
  797. function xueliuHandCardView:onTouchMove(touch)
  798. xueliuHandCardView.super.onTouchMove(self,touch)
  799. if self.touchMJ and self.isTouchMove==true then
  800. local pos = self.touchMJ:getPosition()
  801. local index = nil
  802. for k,v in pairs(self.handCards) do
  803. local width = v:getContentSize().width
  804. local height = v:getContentSize().height
  805. local x = v:getPosition().x-width/2
  806. local y = v:getPosition().y-height/2
  807. local rect = cc.Rectangle:new(x,y,width*0.8,height*0.8)
  808. --如果可以出牌 最后的麻将不参与移动操作
  809. -- local isLastCard = self.isOutCard and k==#self.handCards
  810. if rect:contains(pos.x,pos.y) and v ~=self.touchMJ and not isLastCard then
  811. index = k
  812. break
  813. end
  814. end
  815. if index then
  816. local touchMJIndex = table.indexOf(self.handCards,self.touchMJ)
  817. local offsetIndex = touchMJIndex-index
  818. local num = math.abs(offsetIndex)-1
  819. --大于0则往左移动 3-1:3-2 2-1 小于0右 5-8:5-6 6-7 7-8
  820. local reduce = offsetIndex>0 and -1 or 1
  821. for i = touchMJIndex,index-reduce,reduce do
  822. self.handCards[i],self.handCards[i+reduce] = self.handCards[i+reduce],self.handCards[i]
  823. end
  824. local x,y = self:moveRestHandCards(self.touchMJ)
  825. self.touchMJ:recordPostion(cc.p(x,y))
  826. end
  827. end
  828. end
  829. function xueliuHandCardView:touchOutCard()
  830. if self.touchMJ and self.isTouchMove then
  831. if self.touchMJ:getPositionY()>MJDefine.MJ_TOUCH_OUT_CARD_Y and self.isOutCard then
  832. self:sendOutCard()
  833. else
  834. self.touchMJ:restorePostion()
  835. self.touchMJ:setStatus(MJDefine.MJStatus.Normal)
  836. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  837. app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  838. if self.isOutCard then
  839. self:moveLastCard()
  840. end
  841. end
  842. end
  843. self.isTouchMove=false
  844. end
  845. function xueliuHandCardView:outCardFalg(event)
  846. if event.viewId == MJDefine.MyViewId then
  847. self:hideOperateItem()
  848. self:hideOperate()
  849. end
  850. if self:isUseNew3D() then
  851. self._outCardView:outCardFalg(event)
  852. else
  853. for k,v in pairs(self.outCards) do
  854. for i,child in pairs(v:getChildren()) do
  855. local tag = child:getTag()
  856. if tag ~= MJ.MJ_HAND_CARD_FLAG_LAIZI then
  857. child:removeFromParent()
  858. end
  859. end
  860. end
  861. local mj=self.outCards[#self.outCards]
  862. if event.value and mj and mj.value==event.value and event.viewId==self.viewId then
  863. local flag = cc.Sprite:create()
  864. flag:setTexture("mj_xueliu/res/zy_fangjian/xzdd_pointer.png");
  865. -- flag:setScale(0.8)
  866. mj:addChild(flag)
  867. flag:setPosition(mj:getContentSize().width/2,mj:getContentSize().height)
  868. local moveBy=cc.MoveBy:create(0.5,cc.p(0, 30))
  869. flag:runAction(cc.RepeatForever:create(cc.Sequence:create(moveBy,moveBy:reverse())))
  870. end
  871. end
  872. end
  873. function xueliuHandCardView:getHandCardNodes()
  874. if self:isUseNew3D() then
  875. return self._handcard:getHandCardNodes()
  876. else
  877. return self.handCards
  878. end
  879. end
  880. function xueliuHandCardView:isUseNew3D()
  881. --return true
  882. if self.desktopType == MJDefine.DesktopType.TwoDL then
  883. return false
  884. else
  885. return true
  886. end
  887. end
  888. --[[function xueliuHandCardView:sortHandCards()
  889. if self:isUseNew3D() then
  890. self._handcard:sortHandCards()
  891. else
  892. xueliuHandCardView.super.sortHandCards(self)
  893. end
  894. end--]]
  895. --创建换三张的牌
  896. function xueliuHandCardView:createSwapCards(cards, idx)
  897. local group = nil
  898. if self:isUseNew3D() then
  899. local data = {
  900. huCard = cards,
  901. huType = -1,
  902. }
  903. group = self._huCardView:createCard(data, idx)
  904. else
  905. group = MJ:new(cards, MJDefine.MJType.Out, self.viewId, self.desktopType) -- 这个没调位置,判断认为现在的麻将都会走userNew3d
  906. end
  907. return group
  908. end
  909. function xueliuHandCardView:setIsHupai(hu)
  910. self.isHu = hu
  911. -- if hu == 0 then
  912. -- self._handcard:setOutCardEnable(true)
  913. -- end
  914. -- self._handcard:setIsHupai(hu) -- 胡了后,牌躺下
  915. end
  916. --设置定缺类型 0万,1同,2条
  917. function xueliuHandCardView:setQueType(que)
  918. if self:isUseNew3D() then
  919. self._handcard:setQueType(que)
  920. else
  921. self.queType = que
  922. --设置完定缺牌后,重新设置一下麻将的排序值,目标为了把定缺牌放到右边
  923. self:resetCardsSortValue()
  924. end
  925. end
  926. function xueliuHandCardView:resetCardsSortValue()
  927. for k,v in pairs(self.handCards) do
  928. if v:getMJColorType() == self.queType then
  929. v.sortValue = v.value + 100
  930. end
  931. end
  932. end
  933. --[[
  934. 移除最后一张手牌
  935. ]]
  936. function xueliuHandCardView:removeLastHandCard ()
  937. if self:isUseNew3D() then
  938. return self._handcard:removeLastHandCard()
  939. else
  940. if #self.handCards + #self.handGroupCards * 3 <= 13 then
  941. return false;
  942. end
  943. local last= #self.handCards;
  944. self.handCards[last]:removeFromParent();
  945. table.remove(self.handCards,last);
  946. return true;
  947. end
  948. end
  949. --[[
  950. 显示胡的牌
  951. @param card 胡的牌
  952. ]]
  953. function xueliuHandCardView:onGetHuCard (huCard, isClean,data)
  954. if self:isUseNew3D() then
  955. self._huCardView:getHuCards(huCard, isClean)
  956. else
  957. self.huCards = self.huCards or {};
  958. if isClean then
  959. self.huCards = {};
  960. end
  961. for k, v in ipairs(huCard) do
  962. table.insert(self.huCards, v);
  963. end
  964. local huCards = self.huCards;
  965. local viewId = self.viewId;
  966. if not (huCards and table.nums(huCards) > 0) then
  967. logD("胡牌数据为空!")
  968. return ;
  969. end
  970. -- huCards = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8};
  971. if not self.huCardLayout[viewId] then
  972. self.huCardLayout[viewId] = cc.Layout:create();
  973. self.ui.Items.Layout_Hu_Card:addChild(self.huCardLayout[viewId]);
  974. end
  975. local k = {}
  976. for idx,v in ipairs(self.huCardLayout[viewId]:getChildren()) do
  977. if v:getOpacity() < 255 then
  978. table.insert(k,idx)
  979. end
  980. end
  981. for _, idx in ipairs(k) do
  982. huCards[idx].opacity = 125
  983. end
  984. self.huCardLayout[viewId]:removeAllChildren();
  985. local huCardsLayout = self.huCardLayout[viewId];
  986. for k, v in ipairs(huCards) do
  987. local huCard = v.huCard;
  988. local huType = v.huType;
  989. local opacity = v.opacity;
  990. local vid = viewId;
  991. local scale = 0.75;
  992. if viewId == MJDefine.PlayerViewType.MyViewId then
  993. scale = 0.7;
  994. end
  995. local card = MJ:new(huCard, MJDefine.MJType.Operate, vid, self.desktopType);
  996. local w = card:getContentSize().width * scale;
  997. local h = card:getContentSize().height * scale;
  998. card:setScale(scale);
  999. if huCard ~= 0 and huType == MJDefine.MJHuType.Zimo then
  1000. -- 自摸牌,设置颜色显示
  1001. card:setColor(cc.c3b(237,236,134));
  1002. end
  1003. if viewId == MJDefine.PlayerViewType.My then
  1004. if self.desktopType == MJDefine.DesktopType.ThreeD then
  1005. local x = (1 - k) * (w - 2);
  1006. card:setPositionX(x);
  1007. else
  1008. local x = (1 - k) * (w - 2);
  1009. card:setPositionX(x);
  1010. end
  1011. elseif viewId == MJDefine.PlayerViewType.Right then
  1012. if self.desktopType == MJDefine.DesktopType.ThreeD then
  1013. local y = (1 - k) * (h - 14);
  1014. local x = (k - 1) * 5;
  1015. card:setPosition(cc.p(x, y));
  1016. else
  1017. local y = (1 - k) * (h - 9);
  1018. card:setPositionY(y);
  1019. end
  1020. elseif viewId == MJDefine.PlayerViewType.Left then
  1021. if self.desktopType == MJDefine.DesktopType.ThreeD then
  1022. local y = (k - 1) * (h - 14);
  1023. local x = (k - 1) * 5;
  1024. card:setPosition(cc.p(x, y));
  1025. else
  1026. local y = (k - 1) * (h - 9);
  1027. card:setPositionY(y);
  1028. end
  1029. card:setLocalZOrder(#huCards - k);
  1030. elseif viewId == MJDefine.PlayerViewType.Top then
  1031. if self.desktopType == MJDefine.DesktopType.ThreeD then
  1032. local x = (k - 1) * (w - 2);
  1033. card:setPositionX(x);
  1034. else
  1035. local x = (k - 1) * (w - 1);
  1036. card:setPositionX(x);
  1037. end
  1038. end
  1039. -- local count = app.room.roomInfo:getLuoBoCardCount(v);
  1040. -- card:setLuoBoVisible(count > 0, count);
  1041. if data and data.yipaoduoxiang and data.huPaiIndex and data.huPaiIndex > 1 or opacity then
  1042. card:setOpacity(125)
  1043. end
  1044. huCardsLayout:addChild(card);
  1045. end
  1046. --local visibleSize = cc.Director:getInstance():getVisibleSize();
  1047. local visibleSize = cc.size(1280,720)
  1048. if viewId == MJDefine.PlayerViewType.My then
  1049. if self.desktopType == MJDefine.DesktopType.ThreeD then
  1050. huCardsLayout:setPosition(cc.p((visibleSize.width - 300) * g_radio_x, 155 * g_radio_y));
  1051. else
  1052. huCardsLayout:setPosition(cc.p((visibleSize.width - 300) * g_radio_x, 160 * g_radio_y));
  1053. end
  1054. elseif viewId == MJDefine.PlayerViewType.Right then
  1055. if self.desktopType == MJDefine.DesktopType.ThreeD then
  1056. huCardsLayout:setPosition(cc.p((visibleSize.width - 250) * g_radio_x, (visibleSize.height - 190) * g_radio_y));
  1057. else
  1058. huCardsLayout:setPosition(cc.p((visibleSize.width - 205) * g_radio_x, (visibleSize.height - 150) * g_radio_y));
  1059. end
  1060. elseif viewId == MJDefine.PlayerViewType.Left then
  1061. if self.desktopType == MJDefine.DesktopType.ThreeD then
  1062. huCardsLayout:setPosition(cc.p(190 * g_radio_x, 250 * g_radio_y));
  1063. else
  1064. huCardsLayout:setPosition(cc.p(205 * g_radio_x, 250 * g_radio_y));
  1065. end
  1066. elseif viewId == MJDefine.PlayerViewType.Top then
  1067. huCardsLayout:setPosition(cc.p(435 * g_radio_x, (visibleSize.height - 100) * g_radio_y));
  1068. end
  1069. end
  1070. end
  1071. --玩家
  1072. function xueliuHandCardView:onXueliuOutHuCard(card,callback)
  1073. -- self:createOutCards(card)
  1074. if self:isUseNew3D() then
  1075. -- self._handcard:onOutCard(card, callback) --todo lwq
  1076. if self.viewId~=MJDefine.MyViewId then --其他玩家删除最后一个牌
  1077. local mj=self:getMjByValue(card)
  1078. if mj then
  1079. self:removeHandCard(card)
  1080. -- self:resetHandCards()--todo lwq
  1081. else
  1082. local last=#self.handCards
  1083. if last and self.handCards[last] then
  1084. self.handCards[last]:removeFromParent()
  1085. table.remove(self.handCards,last)
  1086. end
  1087. end
  1088. else
  1089. -- self:setOutCardEnable(false)
  1090. -- local mj=self:getMjByValueReverseOrder(card)
  1091. -- local mj = self:getMjByValue(card)
  1092. -- --插牌
  1093. -- -- if mj==self.handCards[#self.handCards] then
  1094. -- -- table.removeItem(self.handCards,mj)
  1095. -- -- -- self:resetHandCards() -- tod lwq
  1096. -- -- else
  1097. -- -- table.removeItem(self.handCards,mj)
  1098. -- -- -- self:runInsertCardAction() --todo lwq
  1099. -- -- end
  1100. -- if mj then
  1101. -- -- self:removeHandCard(card) -- todo lwq
  1102. -- mj:removeFromParent() --todo
  1103. -- mj=nil --todo
  1104. -- end
  1105. self._handcard:onOutCard(card, callback) --todo lwq
  1106. end
  1107. -- todo lwq test
  1108. self._huCardView:onOutXueliuHuCard(card, callback)
  1109. else
  1110. self:runOutCardAction(card,callback)
  1111. if self.viewId~=MJDefine.MyViewId then --其他玩家删除最后一个牌
  1112. local mj=self:getMjByValue(card)
  1113. if mj then
  1114. self:removeHandCard(card)
  1115. self:resetHandCards()
  1116. -- mj:removeFromParent()
  1117. else
  1118. local last=#self.handCards
  1119. if last and self.handCards[last] then
  1120. self.handCards[last]:removeFromParent()
  1121. table.remove(self.handCards,last)
  1122. end
  1123. end
  1124. else
  1125. -- self:runOutCardAction(self.touchMJ.value)
  1126. -- app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value=self.touchMJ.value,viewId=self.viewId})
  1127. self:setOutCardEnable(false)
  1128. local mj=self:getMjByValueReverseOrder(card)
  1129. --插牌
  1130. if mj==self.handCards[#self.handCards] then
  1131. table.removeItem(self.handCards,mj)
  1132. self:resetHandCards()
  1133. else
  1134. table.removeItem(self.handCards,mj)
  1135. self:runInsertCardAction()
  1136. end
  1137. -- self:removeHandCard(card)
  1138. -- self:resetHandCards()
  1139. if mj then
  1140. mj:removeFromParent()
  1141. mj=nil
  1142. end
  1143. end
  1144. -- local memberInfo=app.room.roomInfo.memberList[data.response.nUserId]
  1145. local userInfo=app.room:getUserInfoByViewId(self.viewId)
  1146. if userInfo and (self.viewId~=MJDefine.MyViewId or self.isReplay) then
  1147. MJSound.PlayMJSound(userInfo.sex,card)
  1148. end
  1149. end
  1150. end
  1151. return xueliuHandCardView