25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

366 lines
11 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 = class("ZPRoomXiaoJuChaPaiView", cc.UIView)
  6. function ZPRoomXiaoJuChaPaiView:ctor(nextCallBackFun)
  7. ZPRoomXiaoJuChaPaiView.super.ctor(self);
  8. self.lieShuMax = 15
  9. self.littleCardScale = 1
  10. self.nextCallBack = nextCallBackFun
  11. end
  12. function ZPRoomXiaoJuChaPaiView:loadUI()
  13. local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_xiaoju_chapai.ui");
  14. self.ui = ui;
  15. self:addChild(ui);
  16. end
  17. function ZPRoomXiaoJuChaPaiView:onEnter()
  18. ZPRoomXiaoJuChaPaiView.super.onEnter(self)
  19. self:loadUI()
  20. --查牌
  21. self.ui.Items.Button_QueDing:registerClick(handler(self , self.onClickQueDing))
  22. self:initLiangPaiPos()
  23. end
  24. function ZPRoomXiaoJuChaPaiView:onClickQueDing()
  25. if self.nextCallBack then
  26. self.nextCallBack()
  27. end
  28. end
  29. function ZPRoomXiaoJuChaPaiView:PlayHuangZhuangAni(bShowAni)
  30. local nodeDipai = self.ui.Items.Layout_XiaoJu_LiangPai
  31. --黄庄不显示结算,增加黄庄动画
  32. local tip = cc.ImageView:createNode();
  33. tip:setAnchorPoint(cc.p(0.5,0.5));
  34. tip:loadTextureFromPlist("zp_room_chapai_huangzhuang.png");
  35. tip:setPosition(cc.p(nodeDipai:getContentSize().width / 2,nodeDipai:getContentSize().height / 2))
  36. tip:setTag(1000)
  37. nodeDipai:addChild(tip);
  38. if bShowAni then
  39. tip:setScale(5.0)
  40. 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))
  41. tip:runAction(seq)
  42. end
  43. end
  44. function ZPRoomXiaoJuChaPaiView:liangShouPai(isRecontect)
  45. --胡牌类型
  46. local huType = ZPDef.ReconnectHuType.NO_HU
  47. --房间信息
  48. local roomInfo = app.room.roomInfo
  49. --正常结束取值
  50. local tt = roomInfo.playList
  51. --重连取值
  52. if isRecontect then
  53. tt = roomInfo.arrayTableInfo
  54. end
  55. if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL then
  56. --胡的牌
  57. local huCard = roomInfo.huCard
  58. --出牌者ID或者点炮的ID,自摸这个是nil,有人点炮这个是有值的
  59. local showViewId = nil
  60. local dianPaoViewId = app.room:getViewIdByUserId(roomInfo.dianPaoUserId)
  61. --重连
  62. if isRecontect then
  63. showViewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
  64. else
  65. --小局结算
  66. showViewId = dianPaoViewId
  67. end
  68. for k,v in pairs(roomInfo.hupaiInfo) do
  69. local nUserId = v.huPaiUid
  70. local viewId = app.room:getViewIdByUserId(nUserId)
  71. --显示胡的那个牌
  72. if isRecontect then
  73. --[[if roomInfo.dianPaoUserId == -1 and showViewId then
  74. if huCard ~= 0 then
  75. self:playMoPaiAni(table.nums(roomInfo.dipaiList),huCard,showViewId,0,1,nil,true)
  76. end
  77. else
  78. self:setOutCardVisible(true,showViewId,huCard,false,nil,true)
  79. end--]]
  80. if self.showHuCardCallBack then
  81. self.showHuCardCallBack(showViewId,huCard)
  82. end
  83. end
  84. --赢家手牌
  85. local cardList = {}
  86. cardList = roomInfo.memberList[nUserId].cardList
  87. --判断赢家是否吃胡
  88. local isHandHaveHuCard = false
  89. local isFindChi = false
  90. for key,list in pairs(cardList) do
  91. for i = 1,3 do
  92. if list[i] == huCard then
  93. isHandHaveHuCard = true
  94. isFindChi = true
  95. break
  96. end
  97. end
  98. if isFindChi then
  99. break
  100. end
  101. end
  102. --是否是跑胡或提胡
  103. local paoTiHU = false
  104. --如果是吃胡
  105. if isHandHaveHuCard then
  106. huType = ZPDef.ReconnectHuType.CHI_HU
  107. --吃胡操作,去掉手里胡的那张
  108. local isFind = false
  109. if table.nums(cardList) > 0 then
  110. for i = 1,self.lieShuMax do
  111. local cardColList = cardList[i] or {}
  112. for idx,value in pairs(cardColList) do
  113. if value == huCard then
  114. table.remove(cardColList,idx)
  115. isFind = true
  116. break
  117. end
  118. end
  119. if isFind then
  120. break
  121. end
  122. end
  123. end
  124. else
  125. for k,v in pairs(tt) do
  126. if k == nUserId then
  127. for key,value in pairs(v.tableWeaveCard) do
  128. local list,operationType = ZPFuc.getZPCardList(value.card,value.type)
  129. if operationType == ZPDef.OpType.OP_TYPE_MINGWEI and huCard == value.card
  130. or operationType == ZPDef.OpType.OP_TYPE_ANWEI and huCard == value.card then
  131. huType = ZPDef.ReconnectHuType.WEI_HU
  132. elseif operationType == ZPDef.OpType.OP_TYPE_PENG and huCard == value.card then
  133. huType = ZPDef.ReconnectHuType.PENG_HU
  134. elseif operationType == ZPDef.OpType.OP_TYPE_PAO and huCard == value.card then
  135. if value.type == ZPDef.SendCardType.CHI_PAI_SHAO_PAO then --x
  136. huType = ZPDef.ReconnectHuType.WEI_PAO_HU
  137. elseif value.type == ZPDef.SendCardType.CHI_PAI_PENG_PAO then
  138. huType = ZPDef.ReconnectHuType.PENG_PAO_HU
  139. elseif value.type == ZPDef.SendCardType.KUAI_SHUI_FOUR_SAME then
  140. huType = ZPDef.ReconnectHuType.KAN_PAO_HU
  141. end
  142. paoTiHU = true
  143. elseif operationType == ZPDef.OpType.OP_TYPE_TI and huCard == value.card then
  144. if value.type == ZPDef.SendCardType.CHI_PAI_TI then
  145. huType = ZPDef.ReconnectHuType.WEI_TI_HU
  146. elseif value.type == ZPDef.SendCardType.GUN_ZI_FOUR_SAME then
  147. huType = ZPDef.ReconnectHuType.KAN_TI_HU
  148. end
  149. paoTiHU = true
  150. elseif operationType == ZPDef.OpType.OP_TYPE_CHONG_PAO and huCard == value.card then
  151. paoTiHU = true
  152. end
  153. end
  154. end
  155. end
  156. end
  157. --添加2个牌
  158. if huType == ZPDef.ReconnectHuType.WEI_HU or huType == ZPDef.ReconnectHuType.PENG_HU then
  159. local tt = {huCard,huCard}
  160. table.insert(cardList,tt)
  161. elseif huType == ZPDef.ReconnectHuType.KAN_TI_HU or huType == ZPDef.ReconnectHuType.KAN_PAO_HU
  162. or (true == paoTiHU) then
  163. local tt = {huCard,huCard,huCard}
  164. table.insert(cardList,tt)
  165. end
  166. end
  167. end
  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. self:createHandCard(nUserId)
  175. end
  176. end
  177. app.room.roomInfo.huCardType = huType
  178. return huType
  179. end
  180. --[[
  181. 游戏结束或者重连,展示其余玩家手牌
  182. ]]
  183. function ZPRoomXiaoJuChaPaiView:createHandCard(nUserId)
  184. logE("====================RoomView:createHandCard()===================");
  185. local cardList = app.room.roomInfo.memberList[nUserId].cardList
  186. --过滤手牌为空的情况
  187. if not cardList or table.nums(cardList) <= 0 then
  188. return
  189. end
  190. local viewId = app.room:getViewIdByUserId(nUserId)
  191. --不管有无数据,默认创建10列数据
  192. if viewId == 1 then
  193. for i = 1,self.lieShuMax do
  194. local value = cardList[i] or {}
  195. local isKan = self:getCurrentColIsKan(value)
  196. local card = ZPRoomCard:new(value,ZPDef.CardType.CARD_TYPE_TABLE,i,isKan,true)
  197. local pos = self.boxPosList1[i]
  198. card.ui:setPosition(pos)
  199. self.ui.Items.Layout_HandCard:addChild(card.ui,1)
  200. end
  201. elseif viewId == 2 then
  202. for i = 1,self.lieShuMax do
  203. local value = cardList[i] or {}
  204. local isKan = self:getCurrentColIsKan(value)
  205. local card = ZPRoomCard:new(value,ZPDef.CardType.CARD_TYPE_TABLE,i,isKan,true)
  206. local pos = self.boxPosList2[i]
  207. card.ui:setPosition(pos)
  208. self.ui.Items.Layout_HandCard:addChild(card.ui,1)
  209. end
  210. elseif viewId == 3 then
  211. for i = 1,self.lieShuMax do
  212. local value = cardList[i] or {}
  213. local isKan = self:getCurrentColIsKan(value)
  214. local card = ZPRoomCard:new(value,ZPDef.CardType.CARD_TYPE_TABLE,i,isKan,true)
  215. local pos = self.boxPosList3[i]
  216. card.ui:setPosition(pos)
  217. self.ui.Items.Layout_HandCard:addChild(card.ui,1)
  218. end
  219. end
  220. end
  221. --判断列数是否是砍牌
  222. function ZPRoomXiaoJuChaPaiView:getCurrentColIsKan(list)
  223. local isKan = false
  224. if list[1] and list[2] and list[3] then
  225. if list[1] == list[2] and list[2] == list[3] then
  226. isKan = true
  227. end
  228. end
  229. return isKan
  230. end
  231. function ZPRoomXiaoJuChaPaiView:showDiPai()
  232. local roomInfo = app.room.roomInfo
  233. self.ui.Items.Layout_dipai:removeAllChildren()
  234. --显示剩余底牌
  235. local jiantouImg = cc.ImageView:createNode();
  236. jiantouImg:setAnchorPoint(cc.p(0,0));
  237. jiantouImg:loadTextureFromPlist("zipai_arrow.png");
  238. local dipaiSize = table.nums(roomInfo.dipaiList);
  239. local nodeDipai = self.ui.Items.Layout_dipai
  240. --没有底牌不显示底牌背景
  241. if dipaiSize <= 0 then
  242. self.ui.Items.ImageView_DiPai:setVisible(false)
  243. else
  244. self.ui.Items.ImageView_DiPai:setVisible(true)
  245. end
  246. local scale = 1--self.littleCardScale + 0.03
  247. local tmp = {}
  248. local max = table.nums(roomInfo.dipaiList)
  249. for i = max,1,-1 do
  250. local card = roomInfo.dipaiList[i]
  251. table.insert(tmp,card)
  252. end
  253. for dipaiK,dipaiV in pairsByKeys(tmp) do
  254. local cardImg = cc.ImageView:createNode();
  255. cardImg:setAnchorPoint(cc.p(0,0));
  256. local fileName = ZPFuc.getZPCardImgByValue(dipaiV.chessCards,ZPDef.CardType.CARD_TYPE_TABLE)
  257. cardImg:loadTextureFromPlist(fileName);
  258. cardImg:setScale(scale)
  259. local showColNum = 20
  260. local getHeightCount = function (count)
  261. if count >= showColNum then
  262. return math.floor(count/showColNum)
  263. else
  264. return 0
  265. end
  266. end
  267. local x = (dipaiK - 1) % showColNum
  268. local width = cardImg:getContentSize().width * scale;
  269. local height = cardImg:getContentSize().height * scale;
  270. local adjustPos = cc.p(width * x,height * getHeightCount(dipaiK - 1))
  271. local tarPos = cc.p(width * (showColNum - 1) - adjustPos.x,0 + adjustPos.y)
  272. cardImg:setPosition(tarPos);
  273. nodeDipai:addChild(cardImg);
  274. if dipaiK == dipaiSize then
  275. local x = (dipaiK) % showColNum
  276. local adjustPos = cc.p(width * x,height * getHeightCount(dipaiK))
  277. local tarPos = cc.p(width * (showColNum - 1) - adjustPos.x,0 + adjustPos.y)
  278. jiantouImg:setPosition(tarPos)
  279. if dipaiK == showColNum or dipaiK == showColNum * 2 then
  280. x = (dipaiK - 1) % showColNum
  281. adjustPos = cc.p(width * x,height * getHeightCount(dipaiK - 1))
  282. tarPos = cc.p(width * (showColNum - 1) - adjustPos.x - width,0 + adjustPos.y)
  283. jiantouImg:setPosition(tarPos)
  284. end
  285. nodeDipai:addChild(jiantouImg);
  286. end
  287. end
  288. end
  289. function ZPRoomXiaoJuChaPaiView:clearView()
  290. self.ui.Items.Layout_HandCard:removeAllChildren()
  291. self.ui.Items.Layout_dipai:removeAllChildren()
  292. --移除黄庄
  293. self.ui.Items.Layout_XiaoJu_LiangPai:removeChildByTag(1000)
  294. end
  295. --初始化小局查牌界面亮手牌的位置
  296. function ZPRoomXiaoJuChaPaiView:initLiangPaiPos()
  297. self.boxPosList1 = {}
  298. local weaveCardPos1 = self.ui.Items.Layout_LiangPai_1:getPosition()
  299. for i = 1, self.lieShuMax do
  300. --矩形3
  301. self.boxPosList1[i] = cc.p(weaveCardPos1.x - 36 * (i - 1),weaveCardPos1.y)
  302. end
  303. self.boxPosList2 = {}
  304. local weaveCardPos2 = self.ui.Items.Layout_LiangPai_2:getPosition()
  305. for i = 1, self.lieShuMax do
  306. --矩形3
  307. self.boxPosList2[i] = cc.p(weaveCardPos2.x + 36 * (i - 1),weaveCardPos2.y)
  308. end
  309. self.boxPosList3 = {}
  310. local weaveCardPos3 = self.ui.Items.Layout_LiangPai_3:getPosition()
  311. for i = 1, self.lieShuMax do
  312. --矩形3
  313. self.boxPosList3[i] = cc.p(weaveCardPos3.x + 36 * (i - 1),weaveCardPos3.y)
  314. end
  315. end
  316. --设置确定回调
  317. function ZPRoomXiaoJuChaPaiView:setQueDingCallBack(cback)
  318. self.nextCallBack = cback
  319. end
  320. --显示胡牌回调
  321. function ZPRoomXiaoJuChaPaiView:showHuCardCallBack(cback)
  322. self.showHuCardCallBack = cback
  323. end
  324. return ZPRoomXiaoJuChaPaiView;