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.

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