Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

339 linhas
9.7 KiB

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