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.

328 rivejä
9.5 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 ChangPaiRoomCard=ZPFramework.ZPImport("zp_changpai.luaScript.Views.Room.changpaiRoomCard")
  7. local changpaiRoomXiaoJuChaPaiView = class("changpaiRoomXiaoJuChaPaiView", ZPRoomXiaoJuChaPaiView)
  8. local ChangpaiCard = ZPFramework.ZPImport("zp_changpai.luaScript.Views.Room.changpaiCard")
  9. function changpaiRoomXiaoJuChaPaiView:ctor(colorType)
  10. changpaiRoomXiaoJuChaPaiView.super.ctor(self)
  11. self.colorType = colorType or ZPDef.ColorType.White
  12. end
  13. function changpaiRoomXiaoJuChaPaiView:onEnter()
  14. changpaiRoomXiaoJuChaPaiView.super.onEnter(self)
  15. end
  16. function changpaiRoomXiaoJuChaPaiView:loadUI()
  17. local ui = loadUI("zp_changpai/res/ui/ui_fangjian/changpai_ui_xiaoju_chapai.ui");
  18. self.ui = ui;
  19. self:addChild(ui);
  20. end
  21. function changpaiRoomXiaoJuChaPaiView:liangShouPai(isRecontect)
  22. --胡牌类型
  23. local huType = ZPDef.ReconnectHuType.NO_HU
  24. --房间信息
  25. local roomInfo = app.room.roomInfo
  26. --正常结束取值
  27. local tt = roomInfo.playList
  28. --重连取值
  29. if isRecontect then
  30. tt = roomInfo.arrayTableInfo
  31. end
  32. local enterCardHu = roomInfo.isEnterCardHu
  33. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL then
  34. --胡的牌
  35. local huCard = roomInfo.huCard
  36. --出牌者ID或者点炮的ID,自摸这个是nil,有人点炮这个是有值的
  37. local showViewId = nil
  38. local dianPaoViewId = app.room:getViewIdByUserId(roomInfo.dianPaoUserId)
  39. --重连
  40. if isRecontect then
  41. showViewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
  42. else
  43. --小局结算
  44. showViewId = dianPaoViewId
  45. end
  46. for k,v in pairs(roomInfo.hupaiInfo) do
  47. local nUserId = v.huPaiUid
  48. local viewId = app.room:getViewIdByUserId(nUserId)
  49. if isRecontect and roomInfo.isZiMoHu and roomInfo.isZiMoHu ~= 1 and roomInfo.isQiangBaHu and roomInfo.isQiangBaHu ~= 1 then
  50. if self.showHuCardCallBack then
  51. self.showHuCardCallBack(showViewId,huCard)
  52. end
  53. end
  54. --赢家手牌
  55. local cardList = {}
  56. cardList = roomInfo.memberList[nUserId].cardList
  57. if roomInfo.isZiMoHu and roomInfo.isZiMoHu ~= 1 then
  58. local isFind = false
  59. if table.nums(cardList) > 0 then
  60. for i = 1,self.lieShuMax do
  61. local cardColList = cardList[i] or {}
  62. for idx,value in pairs(cardColList) do
  63. if value == huCard then
  64. table.remove(cardColList,idx)
  65. isFind = true
  66. break
  67. end
  68. end
  69. if isFind then
  70. break
  71. end
  72. end
  73. end
  74. end
  75. end
  76. end
  77. for k,v in pairsByKeys(tt) do
  78. local myUserID = app.room:getMyUserId()
  79. local nUserId = v.nUserId
  80. if myUserID ~= nUserId then
  81. local cardList = roomInfo.memberList[nUserId].cardList
  82. logE("cardList:"..table.tostring(cardList))
  83. self:createHandCard(nUserId)
  84. end
  85. end
  86. app.room.roomInfo.huCardType = huType
  87. return huType
  88. end
  89. function changpaiRoomXiaoJuChaPaiView:setCardColorType(colorType)
  90. self.colorType = colorType or ZPDef.ColorType.White
  91. end
  92. function changpaiRoomXiaoJuChaPaiView:showDiPai()
  93. local roomInfo = app.room.roomInfo
  94. self.ui.Items.Layout_dipai:removeAllChildren()
  95. --显示剩余底牌
  96. local jiantouImg = cc.ImageView:createNode();
  97. jiantouImg:setAnchorPoint(cc.p(0,0));
  98. jiantouImg:loadTextureFromPlist("zipai_arrow.png");
  99. local dipaiSize = table.nums(roomInfo.dipaiList);
  100. local nodeDipai = self.ui.Items.Layout_dipai
  101. --没有底牌不显示底牌背景
  102. if dipaiSize <= 0 then
  103. self.ui.Items.ImageView_DiPai:setVisible(false)
  104. else
  105. self.ui.Items.ImageView_DiPai:setVisible(true)
  106. end
  107. local scale = 0.9--self.littleCardScale + 0.03
  108. if self.colorType == ZPDef.ColorType.YELLOW then
  109. scale = 0.75
  110. end
  111. local tmp = {}
  112. local max = table.nums(roomInfo.dipaiList)
  113. for i = max,1,-1 do
  114. local card = roomInfo.dipaiList[i]
  115. table.insert(tmp,card)
  116. end
  117. for dipaiK,dipaiV in pairsByKeys(tmp) do
  118. local cardImg = cc.ImageView:createNode();
  119. cardImg:setAnchorPoint(cc.p(0,0));
  120. local fileName = ZPFuc.getZPCardImgByValue(dipaiV.chessCards,ZPDef.CardType.CARD_TYPE_QUIT,self.colorType)
  121. cardImg:loadTextureFromPlist(fileName);
  122. cardImg:setScale(scale)
  123. local showColNum = 10
  124. local getHeightCount = function (count)
  125. if count >= showColNum then
  126. return math.floor(count/showColNum)
  127. else
  128. return 0
  129. end
  130. end
  131. local x = (dipaiK - 1) % showColNum
  132. local width = cardImg:getContentSize().width * scale + 3;
  133. local height = cardImg:getContentSize().height * scale;
  134. local adjustPos = cc.p(width * x,height * getHeightCount(dipaiK - 1))
  135. local tarPos = cc.p(width * (showColNum - 1) - adjustPos.x,0 + adjustPos.y)
  136. cardImg:setPosition(tarPos);
  137. nodeDipai:addChild(cardImg);
  138. if dipaiK == dipaiSize then
  139. local x = (dipaiK) % showColNum
  140. local adjustPos = cc.p(width * x,height * getHeightCount(dipaiK))
  141. local tarPos = cc.p(width * (showColNum - 1) - adjustPos.x,0 + adjustPos.y)
  142. jiantouImg:setPosition(tarPos)
  143. if dipaiK == showColNum or dipaiK == showColNum * 2 then
  144. x = (dipaiK - 1) % showColNum
  145. adjustPos = cc.p(width * x,height * getHeightCount(dipaiK - 1))
  146. tarPos = cc.p(width * (showColNum - 1) - adjustPos.x - width,0 + adjustPos.y)
  147. jiantouImg:setPosition(tarPos)
  148. end
  149. nodeDipai:addChild(jiantouImg);
  150. end
  151. end
  152. end
  153. --初始化小局查牌界面亮手牌的位置
  154. function changpaiRoomXiaoJuChaPaiView:initLiangPaiPos()
  155. self.boxPosList1 = {}
  156. local weaveCardPos1 = self.ui.Items.Layout_LiangPai_1:getPosition()
  157. local tempY = 28
  158. local tempX = 34
  159. if self.colorType == ZPDef.ColorType.YELLOW then
  160. tempX = 30
  161. tempY = 30
  162. end
  163. for i = 1, 16 do
  164. --矩形3
  165. local indexX = i
  166. local indexY = 1
  167. if i >= 7 and i < 13 then
  168. indexY = 2
  169. indexX = i - 6
  170. elseif i >= 13 then
  171. indexY = 3
  172. indexX = i - 12
  173. end
  174. self.boxPosList1[i] = cc.p(weaveCardPos1.x - tempX * (indexX - 1),weaveCardPos1.y - tempY * (indexY- 1))
  175. end
  176. self.boxPosList2 = {}
  177. local weaveCardPos2 = self.ui.Items.Layout_LiangPai_2:getPosition()
  178. for i = 1, 16 do
  179. --矩形3
  180. local indexX = i
  181. local indexY = 1
  182. if i >= 7 and i < 13 then
  183. indexY = 2
  184. indexX = i - 6
  185. elseif i >= 13 then
  186. indexY = 3
  187. indexX = i - 12
  188. end
  189. self.boxPosList2[i] = cc.p(weaveCardPos2.x - tempX * (indexX - 1),weaveCardPos2.y - tempY * (indexY- 1))
  190. end
  191. self.boxPosList3 = {}
  192. local weaveCardPos3 = self.ui.Items.Layout_LiangPai_3:getPosition()
  193. for i = 1, 16 do
  194. --矩形3
  195. local indexX = i
  196. local indexY = 1
  197. if i >= 7 and i < 13 then
  198. indexY = 2
  199. indexX = i - 6
  200. elseif i >= 13 then
  201. indexY = 3
  202. indexX = i - 12
  203. end
  204. self.boxPosList3[i] = cc.p(weaveCardPos3.x + tempX * (indexX - 1),weaveCardPos3.y - tempY * (indexY- 1))
  205. end
  206. end
  207. function changpaiRoomXiaoJuChaPaiView:createHandCard(nUserId)
  208. logE("====================changpaiRoomXiaoJuChaPaiView:createHandCard()===================");
  209. local cardList = app.room.roomInfo.memberList[nUserId].cardList
  210. --过滤手牌为空的情况
  211. if not cardList or table.nums(cardList) <= 0 then
  212. return
  213. end
  214. local viewId = app.room:getViewIdByUserId(nUserId)
  215. if (not viewId) and app.room:getActualPlayerNum() == 2 then
  216. viewId = 1;
  217. end
  218. local handcardlist = {}
  219. for i = 1,self.lieShuMax do
  220. local value = cardList[i] or {}
  221. for k,v in pairs(value) do
  222. table.insert(handcardlist,v)
  223. end
  224. end
  225. --不管有无数据,默认创建10列数据
  226. if viewId == 1 then
  227. for k,v in pairs(handcardlist) do
  228. local changpai = ChangpaiCard:new(v,ZPDef.CardType.CARD_TYPE_QUIT,viewId,self.colorType)
  229. if self.colorType == ZPDef.ColorType.White then
  230. changpai:setScale(0.9)
  231. else
  232. changpai:setScale(0.7)
  233. end
  234. local pos = self.boxPosList1[k]
  235. changpai:setPosition(pos)
  236. self.ui.Items.Layout_HandCard:addChild(changpai,1)
  237. end
  238. elseif viewId == 2 then
  239. for k,v in pairs(handcardlist) do
  240. local changpai = ChangpaiCard:new(v,ZPDef.CardType.CARD_TYPE_QUIT,viewId,self.colorType)
  241. if self.colorType == ZPDef.ColorType.White then
  242. changpai:setScale(0.9)
  243. else
  244. changpai:setScale(0.7)
  245. end
  246. local pos = self.boxPosList2[k]
  247. changpai:setPosition(pos)
  248. self.ui.Items.Layout_HandCard:addChild(changpai,1)
  249. end
  250. elseif viewId == 3 then
  251. for k,v in pairs(handcardlist) do
  252. local changpai = ChangpaiCard:new(v,ZPDef.CardType.CARD_TYPE_QUIT,viewId,self.colorType)
  253. if self.colorType == ZPDef.ColorType.White then
  254. changpai:setScale(0.9)
  255. else
  256. changpai:setScale(0.7)
  257. end
  258. local pos = self.boxPosList3[k]
  259. changpai:setPosition(pos)
  260. self.ui.Items.Layout_HandCard:addChild(changpai,1)
  261. end
  262. end
  263. end
  264. --判断列数是否是砍牌
  265. function changpaiRoomXiaoJuChaPaiView:getCurrentColIsKan(list)
  266. local isKan = false
  267. return isKan
  268. end
  269. function changpaiRoomXiaoJuChaPaiView:PlayHuangZhuangAni(bShowAni)
  270. local nodeDipai = self.ui.Items.Layout_XiaoJu_LiangPai
  271. --黄庄不显示结算,增加黄庄动画
  272. local tip = cc.ImageView:createNode();
  273. tip:setAnchorPoint(cc.p(0.5,0.5));
  274. tip:loadTextureFromPlist("zp_room_chapai_huangzhuang.png");
  275. tip:setPosition(cc.p(nodeDipai:getContentSize().width / 2,nodeDipai:getContentSize().height / 2+70))
  276. tip:setTag(1000)
  277. nodeDipai:addChild(tip);
  278. if bShowAni then
  279. tip:setScale(5.0)
  280. 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))
  281. tip:runAction(seq)
  282. end
  283. end
  284. return changpaiRoomXiaoJuChaPaiView