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.

545 rivejä
16 KiB

  1. local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  2. local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
  3. local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound")
  4. local ZPRoomCard=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomCard")
  5. local ZPRoomXiaoJuChaPaiView = ZPFramework.ZPFrameworkClassImprot("zp_base.luaScript.Views.Room.ZPRoomXiaoJuChaPaiView")
  6. local XichongRoomCard=ZPFramework.ZPImport("zp_xichong.luaScript.Views.Room.xichongRoomCard")
  7. local xichongRoomXiaoJuChaPaiView = class("xichongRoomXiaoJuChaPaiView", ZPRoomXiaoJuChaPaiView)
  8. function xichongRoomXiaoJuChaPaiView:ctor(desktopType)
  9. xichongRoomXiaoJuChaPaiView.super.ctor(self)
  10. self.desktopType = desktopType or ZPDef.GameStyleType.XIANDAI
  11. end
  12. function xichongRoomXiaoJuChaPaiView:onEnter()
  13. xichongRoomXiaoJuChaPaiView.super.onEnter(self)
  14. self:initJDLiangPaiPos()
  15. self:setDeskTopType(self.desktopType)
  16. end
  17. function xichongRoomXiaoJuChaPaiView:loadUI()
  18. local ui = loadUI("zp_xichong/res/ui/ui_fangjian/xichong_ui_xiaoju_chapai.ui");
  19. self.ui = ui;
  20. self:addChild(ui);
  21. end
  22. function xichongRoomXiaoJuChaPaiView:setDeskTopType(desktopType)
  23. self.desktopType = desktopType or ZPDef.GameStyleType.XIANDAI
  24. if self.desktopType == ZPDef.GameStyleType.XIANDAI then
  25. self.ui.Items.Layout_DiPai_JD_1:setVisible(false)
  26. self.ui.Items.Layout_DiPai_JD_2:setVisible(false)
  27. self.ui.Items.Layout_DiPai_JD_3:setVisible(false)
  28. self.ui.Items.Layout_DiPai_1:setVisible(true)
  29. self.ui.Items.Layout_DiPai_2:setVisible(true)
  30. self.ui.Items.Layout_DiPai_3:setVisible(true)
  31. else
  32. self.ui.Items.Layout_DiPai_JD_1:setVisible(true)
  33. self.ui.Items.Layout_DiPai_JD_2:setVisible(true)
  34. self.ui.Items.Layout_DiPai_JD_3:setVisible(true)
  35. self.ui.Items.Layout_DiPai_1:setVisible(false)
  36. self.ui.Items.Layout_DiPai_2:setVisible(false)
  37. self.ui.Items.Layout_DiPai_3:setVisible(false)
  38. end
  39. end
  40. function xichongRoomXiaoJuChaPaiView:liangShouPai(isRecontect)
  41. --胡牌类型
  42. local huType = ZPDef.ReconnectHuType.NO_HU
  43. --房间信息
  44. local roomInfo = app.room.roomInfo
  45. --正常结束取值
  46. local tt = roomInfo.playList
  47. --重连取值
  48. if isRecontect then
  49. tt = roomInfo.arrayTableInfo
  50. end
  51. if (roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL) then
  52. --胡的牌
  53. local huCard = roomInfo.huCard
  54. --出牌者ID或者点炮的ID,自摸这个是nil,有人点炮这个是有值的
  55. local showViewId = nil
  56. local dianPaoViewId = app.room:getViewIdByUserId(roomInfo.dianPaoUserId)
  57. --重连
  58. if isRecontect then
  59. showViewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
  60. else
  61. --小局结算
  62. showViewId = dianPaoViewId
  63. end
  64. for k,huinfo in pairs(roomInfo.hupaiInfo) do
  65. huCard = huinfo.huCard
  66. local nUserId = huinfo.huPaiUid
  67. local viewId = app.room:getViewIdByUserId(nUserId)
  68. --显示胡的那个牌
  69. if isRecontect and roomInfo.isZiMoHu and roomInfo.isZiMoHu ~= 1 then
  70. if self.showHuCardCallBack then
  71. self.showHuCardCallBack(showViewId,huCard)
  72. end
  73. end
  74. --赢家手牌
  75. local cardList = {}
  76. cardList = roomInfo.memberList[nUserId].cardList
  77. if roomInfo.isZiMoHu and roomInfo.isZiMoHu ~= 1 then
  78. local isFind = false
  79. if table.nums(cardList) > 0 then
  80. for i = 1,self.lieShuMax do
  81. local cardColList = cardList[i] or {}
  82. for idx,value in pairs(cardColList) do
  83. if value == huCard then
  84. table.remove(cardColList,idx)
  85. isFind = true
  86. break
  87. end
  88. end
  89. if isFind then
  90. break
  91. end
  92. end
  93. end
  94. end
  95. end
  96. end
  97. --[[
  98. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG and not isRecontect then
  99. --胡的牌
  100. local huCard = roomInfo.huCard
  101. --出牌者ID或者点炮的ID,自摸这个是nil,有人点炮这个是有值的
  102. local showViewId = nil
  103. local dianPaoViewId = app.room:getViewIdByUserId(roomInfo.dianPaoUserId)
  104. --重连
  105. if isRecontect then
  106. showViewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
  107. else
  108. --小局结算
  109. showViewId = dianPaoViewId
  110. end
  111. for k,huinfo in pairs(roomInfo.hupaiInfo) do
  112. huCard = huinfo.huCard
  113. local nUserId = huinfo.huPaiUid
  114. local viewId = app.room:getViewIdByUserId(nUserId)
  115. --显示胡的那个牌
  116. if isRecontect then
  117. if self.showHuCardCallBack then
  118. self.showHuCardCallBack(showViewId,huCard)
  119. end
  120. end
  121. --赢家手牌
  122. local cardList = {}
  123. cardList = roomInfo.memberList[nUserId].cardList
  124. local paoTiHU = false
  125. for k,v in pairs(tt) do
  126. if k == nUserId then
  127. if v.tableWeaveCard and #v.tableWeaveCard > 0 then
  128. local lastWeaveCard = v.tableWeaveCard[#v.tableWeaveCard]
  129. if (lastWeaveCard.type == ZPDef.SendCardType.KAN_THREE_SAME or lastWeaveCard.type == ZPDef.SendCardType.DIRTY_THREE_SAME
  130. or lastWeaveCard.type == ZPDef.SendCardType.DUI_THREE_SAME) and huCard == lastWeaveCard.card then
  131. local tcardlst = {huCard,huCard,huCard}
  132. table.insert(cardList,tcardlst)
  133. elseif (lastWeaveCard.type == ZPDef.SendCardType.GUN_ZI_FOUR_SAME or lastWeaveCard.type == ZPDef.SendCardType.KUAI_SHUI_FOUR_SAME
  134. or lastWeaveCard.type == ZPDef.SendCardType.CHI_PAI_TI or lastWeaveCard.type == ZPDef.SendCardType.CHI_PAI_SHAO_PAO
  135. or lastWeaveCard.type == ZPDef.SendCardType.CHI_PAI_PENG_PAO) and huCard == lastWeaveCard.card then
  136. local tcardlst = {huCard,huCard,huCard,huCard}
  137. table.insert(cardList,tcardlst)
  138. end
  139. end
  140. end
  141. end
  142. end
  143. end
  144. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
  145. for k,huinfo in pairs(roomInfo.hupaiInfo) do
  146. local huCard = huinfo.huCard
  147. local nUserId = huinfo.huPaiUid
  148. local cardList = roomInfo.memberList[nUserId].cardList
  149. if cardList and #cardList > 0 then
  150. local isfindJiaoPai = false
  151. for i=#cardList,1,-1 do
  152. local cardLie = cardList[i]
  153. for j=1,4 do
  154. if cardLie[j] and cardLie[j] == huCard then
  155. cardLie.jiaopaiIdx = j
  156. isfindJiaoPai = true
  157. break
  158. end
  159. end
  160. if isfindJiaoPai then
  161. break
  162. end
  163. end
  164. end
  165. end
  166. end
  167. ]]
  168. for k,v in pairsByKeys(tt) do
  169. local myUserID = app.room:getMyUserId()
  170. local nUserId = v.nUserId
  171. if myUserID ~= nUserId then
  172. local cardList = roomInfo.memberList[nUserId].cardList
  173. logE("cardList:"..table.tostring(cardList))
  174. if self.desktopType == ZPDef.GameStyleType.JINGDIAN then
  175. self:createHandCardInJDType(nUserId)
  176. else
  177. self:createHandCard(nUserId)
  178. end
  179. end
  180. end
  181. app.room.roomInfo.huCardType = huType
  182. return huType
  183. end
  184. function xichongRoomXiaoJuChaPaiView:showDiPai()
  185. local roomInfo = app.room.roomInfo
  186. self.ui.Items.Layout_dipai:removeAllChildren()
  187. self.ui.Items.Layout_dipai:setVisible(false)
  188. self.ui.Items.ImageView_DiPai:setVisible(false)
  189. if true then
  190. return
  191. end
  192. --显示剩余底牌
  193. local jiantouImg = cc.ImageView:createNode();
  194. jiantouImg:setAnchorPoint(cc.p(0,0));
  195. jiantouImg:loadTextureFromPlist("zipai_arrow.png");
  196. local dipaiSize = table.nums(roomInfo.dipaiList);
  197. local nodeDipai = self.ui.Items.Layout_dipai
  198. --没有底牌不显示底牌背景
  199. if dipaiSize <= 0 then
  200. self.ui.Items.ImageView_DiPai:setVisible(false)
  201. else
  202. self.ui.Items.ImageView_DiPai:setVisible(true)
  203. end
  204. local scale = 1--self.littleCardScale + 0.03
  205. local tmp = {}
  206. local max = table.nums(roomInfo.dipaiList)
  207. for i = max,1,-1 do
  208. local card = roomInfo.dipaiList[i]
  209. table.insert(tmp,card)
  210. end
  211. for dipaiK,dipaiV in pairsByKeys(tmp) do
  212. local cardImg = cc.ImageView:createNode();
  213. cardImg:setAnchorPoint(cc.p(0,0));
  214. local fileName = ZPFuc.getZPCardImgByValue(dipaiV.chessCards,ZPDef.CardType.CARD_TYPE_TABLE)
  215. cardImg:loadTextureFromPlist(fileName);
  216. cardImg:setScale(scale)
  217. local showColNum = 8
  218. local getHeightCount = function (count)
  219. if count >= showColNum then
  220. return math.floor(count/showColNum)
  221. else
  222. return 0
  223. end
  224. end
  225. local x = (dipaiK - 1) % showColNum
  226. local width = cardImg:getContentSize().width * scale + 3;
  227. local height = cardImg:getContentSize().height * scale;
  228. local adjustPos = cc.p(width * x,height * getHeightCount(dipaiK - 1))
  229. local tarPos = cc.p(width * (showColNum - 1) - adjustPos.x,0 + adjustPos.y)
  230. cardImg:setPosition(tarPos);
  231. nodeDipai:addChild(cardImg);
  232. if dipaiK == dipaiSize then
  233. local x = (dipaiK) % showColNum
  234. local adjustPos = cc.p(width * x,height * getHeightCount(dipaiK))
  235. local tarPos = cc.p(width * (showColNum - 1) - adjustPos.x,0 + adjustPos.y)
  236. jiantouImg:setPosition(tarPos)
  237. if dipaiK == showColNum or dipaiK == showColNum * 2 then
  238. x = (dipaiK - 1) % showColNum
  239. adjustPos = cc.p(width * x,height * getHeightCount(dipaiK - 1))
  240. tarPos = cc.p(width * (showColNum - 1) - adjustPos.x - width,0 + adjustPos.y)
  241. jiantouImg:setPosition(tarPos)
  242. end
  243. nodeDipai:addChild(jiantouImg);
  244. end
  245. end
  246. end
  247. --初始化小局查牌界面亮手牌的位置
  248. function xichongRoomXiaoJuChaPaiView:initLiangPaiPos()
  249. self.boxPosList1 = {}
  250. local weaveCardPos1 = self.ui.Items.Layout_LiangPai_1:getPosition()
  251. local tempY = 42
  252. local tempX = 38
  253. for i = 1, 18 do
  254. --矩形3
  255. local indexX = i
  256. local indexY = 1
  257. if i >= 7 and i < 13 then
  258. indexY = 2
  259. indexX = i - 6
  260. elseif i >= 13 then
  261. indexY = 3
  262. indexX = i - 12
  263. end
  264. self.boxPosList1[i] = cc.p(weaveCardPos1.x + tempX * (indexX - 1),weaveCardPos1.y - tempY * (indexY- 1))
  265. end
  266. self.boxPosList2 = {}
  267. local weaveCardPos2 = self.ui.Items.Layout_LiangPai_2:getPosition()
  268. for i = 1, 18 do
  269. --矩形3
  270. local indexX = i
  271. local indexY = 1
  272. if i >= 10 and i < 20 then
  273. indexY = 2
  274. indexX = i - 9
  275. end
  276. self.boxPosList2[i] = cc.p(weaveCardPos2.x + tempX * (indexX - 1),weaveCardPos2.y - tempY * (indexY- 1))
  277. end
  278. self.boxPosList3 = {}
  279. local weaveCardPos3 = self.ui.Items.Layout_LiangPai_3:getPosition()
  280. for i = 1, 18 do
  281. --矩形3
  282. local indexX = i
  283. local indexY = 1
  284. if i >= 7 and i < 13 then
  285. indexY = 2
  286. indexX = i - 6
  287. elseif i >= 13 then
  288. indexY = 3
  289. indexX = i - 12
  290. end
  291. self.boxPosList3[i] = cc.p(weaveCardPos3.x + tempX * (indexX - 1),weaveCardPos3.y - tempY * (indexY- 1))
  292. end
  293. end
  294. --初始化经典模式下小局查牌界面亮手牌的位置
  295. function xichongRoomXiaoJuChaPaiView:initJDLiangPaiPos()
  296. self.boxJDPosList1 = {}
  297. local weaveCardPos1 = self.ui.Items.Layout_LiangPai_JD_1:getPosition()
  298. local tempY = 30
  299. local tempX = 30
  300. for i = 1, 18 do
  301. --矩形3
  302. local indexX = 1
  303. local indexY = i
  304. if i >= 10 then
  305. indexX = 2
  306. indexY = i - 9
  307. end
  308. self.boxJDPosList1[i] = cc.p(weaveCardPos1.x + 45 * (indexX - 1),weaveCardPos1.y + tempY * (indexY- 1))
  309. end
  310. self.boxJDPosList2 = {}
  311. local weaveCardPos2 = self.ui.Items.Layout_LiangPai_JD_2:getPosition()
  312. for i = 1, 18 do
  313. --矩形3
  314. local indexX = i
  315. local indexY = 1
  316. self.boxJDPosList2[i] = cc.p(weaveCardPos2.x - tempX * (indexX - 1),weaveCardPos2.y - tempY * (indexY- 1))
  317. end
  318. self.boxJDPosList3 = {}
  319. local weaveCardPos3 = self.ui.Items.Layout_LiangPai_JD_3:getPosition()
  320. for i = 1, 18 do
  321. --矩形3
  322. local indexX = 1
  323. local indexY = i
  324. if i >= 10 then
  325. indexX = 2
  326. indexY = i - 9
  327. end
  328. self.boxJDPosList3[i] = cc.p(weaveCardPos3.x + 45 * (indexX - 1),weaveCardPos3.y - tempY * (indexY- 1))
  329. end
  330. end
  331. local DI_PAI_TAG = 100
  332. function xichongRoomXiaoJuChaPaiView:createHandCard(nUserId)
  333. logE("====================changpaiRoomXiaoJuChaPaiView:createHandCard()===================");
  334. local cardList = app.room.roomInfo.memberList[nUserId].cardList
  335. --过滤手牌为空的情况
  336. if not cardList or table.nums(cardList) <= 0 then
  337. return
  338. end
  339. local viewId = app.room:getViewIdByUserId(nUserId)
  340. local layoutNode = string.format("Layout_DiPai_%d",viewId)
  341. for k,child in pairs(self.ui.Items[layoutNode]:getChildren()) do
  342. local tag = child:getTag()
  343. if tag == DI_PAI_TAG then
  344. child:removeFromParent()
  345. end
  346. end
  347. if app.room:getActualPlayerNum() == 3 then --三人的时候对家不用显示
  348. self.ui.Items.Layout_DiPai_2:setVisible(false)
  349. end
  350. local handcardlist = {}
  351. for i = 1,self.lieShuMax do
  352. local value = cardList[i] or {}
  353. for k,v in pairs(value) do
  354. table.insert(handcardlist,v)
  355. end
  356. end
  357. --不管有无数据,默认创建10列数据
  358. if viewId == 1 then
  359. for k,v in pairs(handcardlist) do
  360. local cardImg = cc.ImageView:createNode();
  361. cardImg:setAnchorPoint(cc.p(0,0));
  362. local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_TABLE)
  363. cardImg:loadTextureFromPlist(fileName);
  364. cardImg:setTag(DI_PAI_TAG)
  365. local pos = self.boxPosList1[k]
  366. cardImg:setPosition(pos)
  367. self.ui.Items[layoutNode]:addChild(cardImg,1)
  368. end
  369. elseif viewId == 2 then
  370. for k,v in pairs(handcardlist) do
  371. local cardImg = cc.ImageView:createNode();
  372. cardImg:setAnchorPoint(cc.p(0,0));
  373. local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_TABLE)
  374. cardImg:loadTextureFromPlist(fileName);
  375. local pos = self.boxPosList2[k]
  376. cardImg:setTag(DI_PAI_TAG)
  377. cardImg:setPosition(pos)
  378. self.ui.Items[layoutNode]:addChild(cardImg,1)
  379. end
  380. elseif viewId == 3 then
  381. for k,v in pairs(handcardlist) do
  382. local cardImg = cc.ImageView:createNode();
  383. cardImg:setAnchorPoint(cc.p(0,0));
  384. local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_TABLE)
  385. cardImg:loadTextureFromPlist(fileName);
  386. local pos = self.boxPosList3[k]
  387. cardImg:setPosition(pos)
  388. cardImg:setTag(DI_PAI_TAG)
  389. self.ui.Items[layoutNode]:addChild(cardImg,1)
  390. end
  391. end
  392. end
  393. function xichongRoomXiaoJuChaPaiView:createHandCardInJDType(nUserId)
  394. logE("====================changpaiRoomXiaoJuChaPaiView:createHandCard()===================");
  395. local cardList = app.room.roomInfo.memberList[nUserId].cardList
  396. --过滤手牌为空的情况
  397. if not cardList or table.nums(cardList) <= 0 then
  398. return
  399. end
  400. local viewId = app.room:getViewIdByUserId(nUserId)
  401. local layoutNode = string.format("Layout_DiPai_JD_%d",viewId)
  402. for k,child in pairs(self.ui.Items[layoutNode]:getChildren()) do
  403. local tag = child:getTag()
  404. if tag == DI_PAI_TAG then
  405. child:removeFromParent()
  406. end
  407. end
  408. if app.room:getActualPlayerNum() == 3 then --三人的时候对家不用显示
  409. self.ui.Items.Layout_DiPai_JD_2:setVisible(false)
  410. end
  411. local handcardlist = {}
  412. for i = 1,self.lieShuMax do
  413. local value = cardList[i] or {}
  414. for k,v in pairs(value) do
  415. table.insert(handcardlist,v)
  416. end
  417. end
  418. --不管有无数据,默认创建10列数据
  419. if viewId == 1 then
  420. for k,v in pairs(handcardlist) do
  421. local cardImg = cc.ImageView:createNode();
  422. cardImg:setAnchorPoint(cc.p(0,0));
  423. cardImg:setEulerRotation(cc.vec3(0,0,180))
  424. local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_GROUPCARD,ZPDef.GameStyleType.JINGDIAN)
  425. cardImg:loadTextureFromPlist(fileName);
  426. cardImg:setTag(DI_PAI_TAG)
  427. local pos = self.boxJDPosList1[k]
  428. cardImg:setPosition(pos)
  429. self.ui.Items[layoutNode]:addChild(cardImg,1)
  430. end
  431. elseif viewId == 2 then
  432. for k,v in pairs(handcardlist) do
  433. local cardImg = cc.ImageView:createNode();
  434. cardImg:setAnchorPoint(cc.p(0,0));
  435. cardImg:setEulerRotation(cc.vec3(0,0,-90))
  436. local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_GROUPCARD,ZPDef.GameStyleType.JINGDIAN)
  437. cardImg:loadTextureFromPlist(fileName);
  438. local pos = self.boxJDPosList2[k]
  439. cardImg:setTag(DI_PAI_TAG)
  440. cardImg:setPosition(pos)
  441. self.ui.Items[layoutNode]:addChild(cardImg,1)
  442. end
  443. elseif viewId == 3 then
  444. for k,v in pairs(handcardlist) do
  445. local cardImg = cc.ImageView:createNode();
  446. cardImg:setAnchorPoint(cc.p(0,0));
  447. local fileName = ZPFuc.getZPCardImgByValue(v,ZPDef.CardType.CARD_TYPE_GROUPCARD,ZPDef.GameStyleType.JINGDIAN)
  448. cardImg:loadTextureFromPlist(fileName);
  449. local pos = self.boxJDPosList3[k]
  450. cardImg:setPosition(pos)
  451. cardImg:setTag(DI_PAI_TAG)
  452. self.ui.Items[layoutNode]:addChild(cardImg,1)
  453. end
  454. end
  455. end
  456. --判断列数是否是砍牌
  457. function xichongRoomXiaoJuChaPaiView:getCurrentColIsKan(list)
  458. local isKan = false
  459. return isKan
  460. end
  461. function xichongRoomXiaoJuChaPaiView:PlayHuangZhuangAni(bShowAni)
  462. local nodeDipai = self.ui.Items.Layout_XiaoJu_LiangPai
  463. --黄庄不显示结算,增加黄庄动画
  464. local tip = cc.ImageView:createNode();
  465. tip:setAnchorPoint(cc.p(0.5,0.5));
  466. tip:loadTextureFromPlist("zp_room_chapai_huangzhuang.png");
  467. tip:setPosition(cc.p(nodeDipai:getContentSize().width / 2,nodeDipai:getContentSize().height / 2+70))
  468. tip:setTag(1000)
  469. nodeDipai:addChild(tip);
  470. if bShowAni then
  471. tip:setScale(5.0)
  472. local seq = cc.Sequence:create(cc.ScaleTo:create(0.2,0.8),cc.ScaleTo:create(0.15,1.2),cc.ScaleTo:create(0.1,1))
  473. tip:runAction(seq)
  474. end
  475. end
  476. return xichongRoomXiaoJuChaPaiView