Não pode escolher mais do que 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.

887 linhas
27 KiB

  1. local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine")
  2. local MJ = MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  3. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  4. local CardClass = require(MJDefine.MJConfig_2d.MAHJONG_CARD) -- 麻将牌
  5. local MJRoomXiaoJuView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomXiaoJuView")
  6. local ncmajRoomXiaoJuView = class("ncmajRoomXiaoJuView", MJRoomXiaoJuView)
  7. local MJ_WIDTH=47
  8. --起始位置
  9. local MJ_HAND_CARD_INIT_X=130+45
  10. local MJ_HAND_CARD_INIT_Y=40+12
  11. local MJ_GROUP_CARD_INIT_X=100
  12. local MJ_OPERATE_CARD_INIT_Y = 45 -- 操作牌y轴
  13. --麻将组间隔
  14. local MJ_GROUP_PADDING_X=0
  15. --麻将直接间隔
  16. local MJ_HANDCARD_PADDING_X = -38 -- 手牌麻将直接间隔(牌与牌)
  17. local MJ_OPERATE_PADDING_X = -3 -- 操作麻将直接间隔(牌与牌)
  18. --胡牌麻将间隔
  19. local MJ_HU_X=8
  20. --暗杠上面的牌Y轴偏移量
  21. local GANG_OFFSET_Y=13
  22. local MJ_HANDCARD_SCALE = 0.6 -- 手牌麻将的缩小值
  23. local MJ_OPERATE_SCALE = 0.75 -- 操作麻将的缩小值
  24. local IS_SHOW_ANGANG_CARD = false -- 暗杠牌是否要显示起来
  25. function ncmajRoomXiaoJuView:ctor(...)
  26. ncmajRoomXiaoJuView.super.ctor(self,...)
  27. if self.desktopType == MJDefine.DesktopType.ThreeD then
  28. self.desktopType = MJDefine.DesktopType.TwoD
  29. end
  30. CardClass = require(MJDefine.MJConfig_2d.MAHJONG_CARD) -- 麻将牌
  31. end
  32. function ncmajRoomXiaoJuView:loadUI()
  33. local ui = loadUI("mj_ncmaj/res/ui_fangjian/mj_ncmaj_xiaoju_jiesuan.ui")
  34. self.ui = ui
  35. self:addChild(ui)
  36. end
  37. function ncmajRoomXiaoJuView:onEnter()
  38. ncmajRoomXiaoJuView.super.onEnter(self)
  39. if G_LayerMain then
  40. G_LayerMain:showFloat(true)
  41. end
  42. if app.room.roomInfo.isEapCreate == 1 then
  43. self.ui.Items.Button_Next:setVisible(false)
  44. self.ui.Items.Button_Cha:setVisible(false)
  45. if app.room.roomInfo.nGameStartCount ~= app.room.roomInfo.nTotalGameNum then
  46. local t = app.room.roomInfo.EapTime
  47. self.ui.Items.Text_EapTime:setText("倒计时"..t.."秒后自动开始")
  48. self.ui.Items.Text_EapTime:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.DelayTime:create(1),cc.CallFunc:create(function()
  49. t=t-1
  50. if t<0 then
  51. t = 0
  52. self.ui.Items.Text_EapTime:stopAllActions()
  53. end
  54. self.ui.Items.Text_EapTime:setText("倒计时"..t.."秒后自动开始")
  55. end))))
  56. elseif app.room.roomInfo.nGameStartCount == app.room.roomInfo.nTotalGameNum then
  57. local t = app.room.roomInfo.EapTime
  58. self.ui.Items.Text_EapTime:setText("倒计时"..t.."秒后结束游戏")
  59. self.ui.Items.Text_EapTime:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.DelayTime:create(1),cc.CallFunc:create(function()
  60. t=t-1
  61. if t<0 then
  62. t = 0
  63. self.ui.Items.Text_EapTime:stopAllActions()
  64. --回到大厅 不打开总结算界面
  65. app.room:dispatchEvent({name =MJDefine.MJEvent.DismissClose})
  66. self:removeFromParent()
  67. runInNextFrame(function()
  68. local roomInfo = app.room.roomInfo
  69. -- 房间号
  70. local roomId = roomInfo.nShowTableId
  71. gotoMainView(roomInfo.gameId,roomId)
  72. end)
  73. end
  74. self.ui.Items.Text_EapTime:setText("倒计时"..t.."秒后结束游戏")
  75. end))))
  76. end
  77. end
  78. --self:createLuoBo()
  79. --local pos = self.ui.Items.Button_Next:getPosition()
  80. --self.ui.Items.Text_Tip_1:setPositionX(pos.x + 140)
  81. --self.ui.Items.Text_Tip_2:setPositionX(pos.x + 140)
  82. end
  83. function ncmajRoomXiaoJuView:initPlayerView()
  84. local roomInfo=app.room.roomInfo
  85. self.ui.Items.Layout_Player:removeAllChildren()
  86. self.items={}
  87. for k,v in pairs(roomInfo.memberList) do
  88. local userId = app.room:getViewIdByUserId(v.nUserId)
  89. local nSeatId = app.room:getSeatIdByViewId(userId)
  90. local i = nSeatId+1
  91. local item=self:createPlayerItem()
  92. self:setPlayerItemInfo(item,v)
  93. self.items[i]=item
  94. -- table.insert(self.items,)
  95. end
  96. for i=1,4 do
  97. if self.items[i] then
  98. self.ui.Items.Layout_Player:addChild(self.items[i])
  99. end
  100. end
  101. end
  102. --获取点炮玩家的坐位号
  103. function ncmajRoomXiaoJuView:getDPSeatID()
  104. local seatId = -1
  105. local roomInfo=app.room.roomInfo
  106. for k,v in pairs(roomInfo.memberList) do
  107. if v.result == MJDefine.MJGameHuType.HU_DIANPAO or v.result == MJDefine.MJGameHuType.HU_QIANGGANG then
  108. seatId = v.dpSeatId
  109. end
  110. end
  111. return seatId
  112. end
  113. function ncmajRoomXiaoJuView:createPlayerItem()
  114. local ui=loadUI("mj_ncmaj/res/ui_fangjian/mj_ncmaj_xiaoju_item.ui")
  115. autoAdapt(ui)
  116. return ui
  117. end
  118. function ncmajRoomXiaoJuView:setPlayerItemInfo(ui,player)
  119. local roomInfo=app.room.roomInfo
  120. local nSeatId = app.room:getSeatIdByUserId(player.nUserId)
  121. local resultInfo=roomInfo.memberList
  122. local bg = "ImageView_ItemBg"--"ImageView_Win_"..i..""
  123. -- local bg2 = "ImageView_ItemBg_2"
  124. -- local lose = "ImageView_Lose_"..i
  125. local head = "ImageView_Head"
  126. local name = "Text_Name"
  127. local benJuScore = "TextBMFont_Score"
  128. local benJuScore1 = "Text_Score"
  129. local hu = "ImageView_Hu"
  130. local info = "Button_Info"
  131. local result="Text_ResultInfo"
  132. --local gangfen = "Text_GangFen"
  133. --local hufen = "Text_HuFen"
  134. --ui.Items.TextBMFont_Score:setVisible(false)
  135. local nodeBg = ui.Items[bg]
  136. -- local nodeBg2 = ui.Items[bg2]
  137. -- local nodeLose = self.ui.Items[lose]
  138. local nodeHead = ui.Items[head]
  139. local nodeName = ui.Items[name]
  140. local nodeBenJu = ui.Items[benJuScore]
  141. local bmFontScore = true
  142. if not nodeBenJu then
  143. nodeBenJu = ui.Items[benJuScore1]
  144. bmFontScore = false
  145. end
  146. local nodeHu = ui.Items[hu]
  147. local nodeBanker= ui.Items.ImageView_Banker
  148. local nodeResult= ui.Items[result]
  149. --local nodeGangfen = ui.Items[gangfen]
  150. --local nodeHufen = ui.Items[hufen]
  151. local infoStr = self:setHuType(player.nUserId)
  152. nodeResult:setText(infoStr)
  153. local userInfo = app.room:getUserInfo(player.nUserId)
  154. --先设置默认头像
  155. local width = nodeHead:getContentSize().width
  156. local nickname = ""
  157. if userInfo and userInfo.nickname then
  158. nickname = getSubStringNickname(userInfo.nickname)
  159. self:updateUserHead(nodeHead,player.nUserId, userInfo.sex, userInfo.headimgurl);
  160. end
  161. nodeName:setText(nickname)
  162. --显示隐藏游戏内选手id(主办人和管理员不限制,只针对海选赛) -- todo lwq
  163. -- begin
  164. local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
  165. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  166. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  167. --隐私数据
  168. local clubInfo = app.club_php.clubList[app.club_php.clubID]
  169. self.cliext = clubInfo.groupext and clubInfo.groupext.cliext
  170. if not self.cliext or not self.cliext.is_hideUid or (self.cliext and self.cliext.is_hideUid == 1) then
  171. if clubInfo.role == ClubDefine.Job.Creator or clubInfo.role == ClubDefine.Job.Manager then
  172. nodeName:setVisible(true)
  173. else
  174. nodeName:setVisible(false)
  175. end
  176. end
  177. end
  178. end
  179. if player.nUserId == tonumber(app.user.loginInfo.uid) then
  180. nodeName:setVisible(true)
  181. end
  182. -- end
  183. nodeHu:setVisible(false)
  184. if player.result>0 then
  185. nodeHu:setVisible(true)
  186. local orderNum = cc.Sprite:create("mj/res/ui/zy_fangjian/operate/mj_effect_num"..player.huOrder..".png")
  187. if player.result == MJDefine.MJGameHuType.HU_ZIMO then--自摸 huOrder
  188. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_zimo.png")
  189. orderNum:setPosition(cc.p(260,65))
  190. if player.huOrder == 1 then
  191. local posSpr = self:createFromPos(nil,nSeatId+1)
  192. local tPos = nodeHu:getPosition()
  193. tPos.x = (tPos.x - 20)
  194. tPos.y = tPos.y - 46
  195. posSpr:setPosition(tPos)
  196. --nodeHu:getParent():addChild(posSpr)
  197. else
  198. local index = 0
  199. for k,v in pairs(roomInfo.memberList) do
  200. if v.result <= 0 or v.huOrder > player.huOrder then
  201. local formUid = v.nUserId
  202. local posSpr = self:createFromPos(formUid,nSeatId+1)
  203. local tPos = nodeHu:getPosition()
  204. tPos.y = tPos.y - 46
  205. tPos.x = (tPos.x + index*40)
  206. posSpr:setPosition(tPos)
  207. --nodeHu:getParent():addChild(posSpr)
  208. index = index + 1
  209. end
  210. end
  211. end
  212. elseif player.result == MJDefine.MJGameHuType.HU_DIANPAO or player.result == MJDefine.MJGameHuType.HU_QIANGGANG then --点炮胡
  213. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_hu.png")--mj_effect_jiepao
  214. orderNum:setPosition(cc.p(300,65))
  215. local formUid = app.room:getUserIdBySeatId(player.dpSeatId)
  216. local posSpr = self:createFromPos(formUid,nSeatId+1)
  217. local tPos = nodeHu:getPosition()
  218. tPos.x = tPos.x
  219. tPos.y = tPos.y - 46
  220. posSpr:setPosition(tPos)
  221. --nodeHu:getParent():addChild(posSpr)
  222. end
  223. --nodeHu:addChild(orderNum)
  224. end
  225. local isDianPao = (self:getDPSeatID() == nSeatId)
  226. if isDianPao then--如果自己是点炮玩家,显示一个点炮
  227. nodeHu:setVisible(true)
  228. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_fangpao.png")
  229. end
  230. --黄庄才会查叫和查花猪
  231. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  232. if player.result <= 0 and player.isDj == 1 then
  233. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_chajiao.png")
  234. nodeHu:setVisible(true)
  235. nodeHu:setScale(0.3)
  236. local noTingNum = 0--没有胡牌和听牌的玩家数
  237. for k,v in pairs(roomInfo.memberList) do
  238. if v.result <= 0 and v.isDj ~= 1 then
  239. noTingNum = noTingNum + 1
  240. end
  241. end
  242. for k,v in pairs(roomInfo.memberList) do
  243. local index = 1
  244. if v.result <= 0 and v.isDj ~= 1 then
  245. local formUid = v.nUserId
  246. local posSpr = self:createFromPos(formUid,nSeatId+1)
  247. local tPos = nodeHu:getPosition()
  248. tPos.y = tPos.y - 46
  249. if noTingNum > 1 then
  250. if index == 1 then
  251. tPos.x = -20
  252. elseif index == 2 then
  253. tPos.x = 20
  254. end
  255. end
  256. posSpr:setPosition(tPos)
  257. --nodeHu:getParent():addChild(posSpr)
  258. index = index + 1
  259. end
  260. end
  261. end
  262. --[[if player.result <= 0 and player.isHz == 1 then --花猪
  263. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_chahuazhu.png")
  264. nodeHu:setScale(0.3)
  265. nodeHu:setVisible(true)
  266. end--]]
  267. end
  268. if app.room:getUserIdBySeatId(app.room.roomInfo.nBankSeatId)~=player.nUserId then
  269. nodeBanker:setVisible(false)
  270. end
  271. if app.room:getMyUserId() == player.nUserId then
  272. nodeBg:loadTexture("xj_my_bg.png",cc.TextureResType.plistType)
  273. --[[else
  274. nodeBg:loadTexture("xj_other_bg.png",cc.TextureResType.plistType)--]]
  275. end
  276. if tonumber(player.nTurnScore) > 0 then
  277. nodeBenJu:setText("+"..player.nTurnScore)
  278. else
  279. nodeBenJu:setText(player.nTurnScore)
  280. if tonumber(player.nTurnScore) < 0 and bmFontScore == true then
  281. nodeBenJu:setFntFile("res/fonts/dt_jian_num.fnt")
  282. end
  283. end
  284. --番数
  285. ui.Items.Text_FanShu:setText(player.fanshu.."番")
  286. if player.isBaiPai == 1 then
  287. --str = str .. "摆牌".." "
  288. ui.Items.ImageView_Bai:loadTexture("mj_ncmaj/res/zy_fangjian/ncmajadd/ncmaj_xj_spr_baipai.png", 0)
  289. elseif player.isBaiPai == 2 then
  290. --str = str .. "摆独张".." "
  291. ui.Items.ImageView_Bai:loadTexture("mj_ncmaj/res/zy_fangjian/ncmajadd/ncmaj_xj_spr_baiduzhang.png", 0)
  292. end
  293. --[[local ganginfo = json.decode(player.ganginfo)
  294. if ganginfo then
  295. nodeGangfen:setText(ganginfo.gangScore or 0)
  296. nodeHufen:setText(ganginfo.huScore or 0)
  297. else
  298. nodeGangfen:setText(0)
  299. nodeHufen:setText(0)
  300. end--]]
  301. --[[ local viewId = app.room:getViewIdByUserId(player.nUserId)
  302. if viewId and viewId>0 and viewId<=4 then
  303. if viewId == 4 then
  304. ui.Items.ImageView_Pos:loadTexture("result_pos_0.png",1)
  305. else
  306. ui.Items.ImageView_Pos:loadTexture(string.format("result_pos_%d.png", viewId), 1)
  307. end
  308. else
  309. ui.Items.ImageView_Pos:setVisible(false)
  310. end--]]
  311. ui.Items.ImageView_Bai:setVisible(player.isBaiPai>0)
  312. ui.Items.ImageView_Piao:setVisible(player.isPiao>0)
  313. ui.Items.ImageView_Piao:setVisible(false)
  314. ui.Items.ImageView_Pos:loadTexture(string.format("mj_ncmaj/res/zy_fangjian/ncmajadd/ncmaj_xj_Pos_%d.png", nSeatId+1), 0)
  315. ui.Items.ImageView_Pos:setVisible(false)
  316. end
  317. function ncmajRoomXiaoJuView:setHuType(userId)
  318. local roomInfo = app.room.roomInfo
  319. local strGameInfo = json.decode(roomInfo.strGameInfo)
  320. local str = ""
  321. local huType1 = {
  322. [1] = "自摸(",
  323. [2] = "接炮(",
  324. [3] = "抢杠胡(",
  325. }
  326. local huOrder1 = 0
  327. local player = roomInfo.memberList[userId]
  328. if player then
  329. if player.isPiao > 0 then
  330. str = str.."飘"..player.isPiao.." "
  331. else
  332. str = str.."不飘".." "
  333. end
  334. huOrder1 = player.huOrder
  335. --胡牌顺序
  336. if player.result == MJDefine.MJGameHuType.HU_ZIMO then
  337. local huNum = 0
  338. --快速成局时,strGameInfo.playnum默认传来的是4人
  339. if strGameInfo.isfaststart == 1 then
  340. huNum = roomInfo.nMaxPlayCount - player.huOrder
  341. else
  342. huNum = strGameInfo.playnum - player.huOrder
  343. end
  344. --str = str..huType1[player.result]..huNum.."家) "
  345. elseif player.result == MJDefine.MJGameHuType.HU_DIANPAO or player.result == MJDefine.MJGameHuType.HU_QIANGGANG then
  346. local viewId = app.room:getViewIdBySeatId(player.dpSeatId)
  347. local userInfo = app.room:getUserInfoByViewId(viewId)
  348. local nickname = getSubStringNickname(userInfo.nickname)
  349. --str = str..huType1[player.result]..nickname..") "
  350. end
  351. --牌型
  352. for k,v in pairsByKeys(MJDefine.MJGamePaiType) do
  353. local newType = self:_and(player.huType,v)
  354. if self:_and(player.huType,v) ~= 0 and (v~=MJDefine.MJGamePaiType.BAI_PAI_HU and v~=MJDefine.MJGamePaiType.BAI_DU_ZHANG_HU) then--摆牌,摆独张
  355. local newType = self:_and(player.huType,v)
  356. str = str..MJDefine.MJGameHuStr[newType].." "
  357. end
  358. end
  359. --[[if MJDefine.MJGameHuStr[player.subPaiType] then
  360. str = str .. MJDefine.MJGameHuStr[player.subPaiType].." "
  361. end
  362. if MJDefine.MJGameHuStr[player.huType] then
  363. str = str .. MJDefine.MJGameHuStr[player.huType].." "
  364. end--]]
  365. --[[local specialType = {
  366. ["isJueZhang"] = "绝张",
  367. ["isJinGouDiao"] = "金钩钓",
  368. ["isHaiDiLaoYue"] = "海底捞月",
  369. ["isHaiDiPao"] = "海底炮",
  370. ["isGangShangKaiHua"] = "杠上开花",
  371. ["isGangShangPao"] = "杠上炮",
  372. ["isQiangGangHu"] = "抢杠胡",
  373. ["isMenQing"] = "门清",
  374. ["isZhongZhang"] = "中张",
  375. }--]]
  376. if player.result > 0 or player.huType > 0 then
  377. if player.genCount > 0 then
  378. str = str .. player.genCount.."根".." "
  379. end
  380. if player.isJueZhang > 0 then
  381. str = str .. "绝张".." "
  382. end
  383. if player.isJinGouDiao > 0 then
  384. str = str .. "金钩钓".." "
  385. end
  386. if player.isHaiDiLaoYue > 0 then
  387. str = str .. "海底捞月".." "
  388. end
  389. if player.isHaiDiPao > 0 then
  390. str = str .. "海底炮".." "
  391. end
  392. if player.isGangShangKaiHua > 0 then
  393. str = str .. "杠上开花".." "
  394. end
  395. if player.isGangShangPao > 0 then
  396. str = str .. "杠上炮".." "
  397. end
  398. if player.isQiangGangHu > 0 then
  399. str = str .. "抢杠胡".." "
  400. end
  401. if player.isMenQing > 0 then
  402. str = str .. "门清".." "
  403. end
  404. if player.isZhongZhang > 0 then
  405. str = str .. "中张".." "
  406. end
  407. else--没有胡牌显示摆牌
  408. end
  409. --摆牌 0没有摆1摆牌2独摆
  410. if player.isBaiPai == 1 then
  411. --str = str .. "摆牌".." "
  412. elseif player.isBaiPai == 2 then
  413. --str = str .. "摆独张".." "
  414. end
  415. if player.isBaoPai == 1 then
  416. str = str.."报叫".." "
  417. end
  418. local gangStr = roomInfo.opsCntMapString or roomInfo.ganginfo
  419. local ganginfo = json.decode(gangStr)
  420. local showGang = ganginfo[tostring(userId)]
  421. if ganginfo and showGang then
  422. if showGang.agang and showGang.agang >0 then
  423. str = str.."暗杠+"..showGang.agang.." "
  424. end
  425. if showGang.mgang and showGang.mgang>0 then
  426. str = str.."明杠+"..showGang.mgang.." "
  427. end
  428. if showGang.bgang and showGang.bgang>0 then
  429. str = str.."巴杠+"..showGang.bgang.." "
  430. end
  431. if showGang.diangang_cnt and showGang.diangang_cnt>0 then
  432. str = str.."点杠+"..showGang.diangang_cnt.." "
  433. end
  434. if showGang.gsgang and showGang.gsgang>0 then
  435. str = str.."过手杠+"..showGang.gsgang.." "
  436. end
  437. --[[if ganginfo.gangCnt and ganginfo.gangCnt > 0 then
  438. str = str..ganginfo.gangCnt.."杠".." "
  439. end--]]
  440. end
  441. end
  442. return str
  443. end
  444. --合并牌型得到最终的字符串
  445. function ncmajRoomXiaoJuView:getPaiTypeStr(player)
  446. local strTab = {}
  447. for k,v in pairs(MJDefine.MJGamePaiType) do
  448. local newType = self:_and(player.huType,v)
  449. if newType ~= 0 then
  450. table.insert(strTab,MJDefine.MJGameHuStr[newType] or "")
  451. end
  452. end
  453. if player.result > 0 or player.huType > 0 then
  454. if player.genCount > 0 then
  455. table.insert(strTab,player.genCount.."归")
  456. end
  457. end
  458. dump(strTab)
  459. --logD(table.toString(strTab))
  460. for _,v in pairs(MJDefine.MJGameHuMargeTab) do
  461. local list = v.tab
  462. local str = v.name
  463. dump(list)
  464. local indexs= {}
  465. for _,v in pairs(list) do
  466. local index = table.indexOf(strTab, v)
  467. if index~= -1 then
  468. table.insert(indexs,index)
  469. end
  470. end
  471. if #indexs == #list then --如果都找到则合并
  472. for k,v in pairs(list) do
  473. table.removeItem(strTab,v)
  474. end
  475. -- logD(str)
  476. table.insert(strTab,str)
  477. end
  478. end
  479. local info = ""
  480. for k,v in pairs(strTab) do
  481. info = info..v.." "
  482. end
  483. return info
  484. end
  485. function ncmajRoomXiaoJuView:createHandCards(layer,arg,seatId)
  486. for k,v in pairs(arg) do
  487. local mj = CardClass:new(v.card, MJDefine.MyViewId, MJDefine.MJType.Stand, 10)
  488. mj:setScale(MJ_HANDCARD_SCALE)
  489. layer:addChild(mj)
  490. mj:setPosition(cc.p(self.initX[seatId],MJ_HAND_CARD_INIT_Y))
  491. self.initX[seatId]=self.initX[seatId]+mj:getContentSize().width+MJ_HANDCARD_PADDING_X
  492. end
  493. end
  494. function ncmajRoomXiaoJuView:createHuCard(layer,card,seatId)
  495. local mj = CardClass:new(card, MJDefine.MyViewId, MJDefine.MJType.Stand, 10)
  496. mj:setScale(MJ_HANDCARD_SCALE)
  497. layer:addChild(mj)
  498. mj:setPosition(cc.p(self.initX[seatId],MJ_HAND_CARD_INIT_Y))
  499. self.initX[seatId]=self.initX[seatId]+mj:getContentSize().width+MJ_HANDCARD_PADDING_X
  500. local flag = cc.Sprite:create("mj/res/ui/zy_fangjian/mj_hu_flag.png")
  501. mj:addChild(flag)
  502. flag:setScale(2)
  503. flag:setPosition(cc.p(32,82))
  504. end
  505. function ncmajRoomXiaoJuView:createChi(values,redNum)
  506. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  507. node:setAnchorPoint(cc.p(0.5,0.5))
  508. node:ignoreAnchorPointForPosition(false)
  509. local width=0
  510. local height=0
  511. for i=1,3 do
  512. if values[i] then
  513. local mj = CardClass:new(values[i], MJDefine.MyViewId, MJDefine.MJType.Operate, 10)
  514. mj:setScale(MJ_OPERATE_SCALE)
  515. node:addChild(mj)
  516. local mjWidth=mj:getContentSize().width * MJ_OPERATE_SCALE
  517. local mjHeight=mj:getContentSize().height * MJ_OPERATE_SCALE
  518. local x=mjWidth/2+(i-1)*(mjWidth+MJ_OPERATE_PADDING_X)
  519. local y=mjHeight/2
  520. width=width+mjWidth
  521. height=mjHeight
  522. mj:setPosition(x,y)
  523. end
  524. end
  525. node:setContentSize(cc.size(width,height))
  526. return node
  527. end
  528. function ncmajRoomXiaoJuView:createGang(values,redNum,isBaGang)
  529. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  530. node:setAnchorPoint(cc.p(0.5,0.5))
  531. node:ignoreAnchorPointForPosition(false)
  532. local width=0
  533. local height=0
  534. for i=1,4 do
  535. if values[i] then
  536. local mj = CardClass:new(values[i], MJDefine.MyViewId, MJDefine.MJType.Operate, 10)
  537. mj:setScale(MJ_OPERATE_SCALE)
  538. if isBaGang and i == 4 then--血战巴杠朝上
  539. --mj:setOperateBackImage()
  540. end
  541. node:addChild(mj)
  542. local mjWidth=mj:getContentSize().width * MJ_OPERATE_SCALE
  543. local mjHeight=mj:getContentSize().height * MJ_OPERATE_SCALE
  544. local x=mjWidth/2+(i-1)*(mjWidth+MJ_OPERATE_PADDING_X)
  545. local y=mjHeight/2
  546. --width=width+mjWidth
  547. if i == 4 then
  548. mj:setLocalZOrder(2)
  549. y = mjHeight/2 + GANG_OFFSET_Y
  550. x = mjWidth/2 + (mjWidth+MJ_OPERATE_PADDING_X)
  551. else
  552. width = width + mjWidth
  553. end
  554. height=mjHeight
  555. mj:setPosition(x,y)
  556. end
  557. end
  558. node:setContentSize(cc.size(width,height))
  559. return node
  560. end
  561. function ncmajRoomXiaoJuView:createAnGang(values,redNum)
  562. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  563. node:setAnchorPoint(cc.p(0.5,0.5))
  564. node:ignoreAnchorPointForPosition(false)
  565. local width=0
  566. local height=0
  567. for i=1,4 do
  568. if values[i] then
  569. local mj = CardClass:new(values[i], MJDefine.MyViewId, MJDefine.MJType.Operate, 10)
  570. mj:setScale(MJ_OPERATE_SCALE)
  571. -- 暗杠盖牌
  572. if not IS_SHOW_ANGANG_CARD then
  573. if i <= 3 then
  574. mj:setOperateBackImage()
  575. end
  576. end
  577. node:addChild(mj)
  578. local mjWidth=mj:getContentSize().width * MJ_OPERATE_SCALE
  579. local mjHeight=mj:getContentSize().height * MJ_OPERATE_SCALE
  580. if i <= 3 then
  581. local x=mjWidth/2+(i-1)*(mjWidth+MJ_OPERATE_PADDING_X)
  582. local y=mjHeight/2
  583. width=width+mjWidth
  584. height=mjHeight
  585. mj:setPosition(x,y)
  586. else
  587. local x=mjWidth/2+(2-1)*(mjWidth+MJ_OPERATE_PADDING_X) - 1
  588. local y=mjHeight/2 + 16
  589. height=mjHeight
  590. mj:setPosition(x, y);
  591. end
  592. end
  593. end
  594. node:setContentSize(cc.size(width,height))
  595. return node
  596. end
  597. function ncmajRoomXiaoJuView:createGroupCards(layer,arg,seatId)
  598. local handlers={
  599. [MJDefine.MJGroupType.Chi]=handler(self,self.createChi),
  600. [MJDefine.MJGroupType.Peng]=handler(self,self.createChi),
  601. [MJDefine.MJGroupType.Gang]=handler(self,self.createGang),
  602. [MJDefine.MJGroupType.AnGang]=handler(self,self.createAnGang),
  603. }
  604. for k,v in pairs(arg) do
  605. if handlers[v.opType] then
  606. local group
  607. if v.orgType == MJDefine.MJOperateType.OPREATE_BAGANG then
  608. group=handlers[v.opType](v.values,v.redNum,true)
  609. else
  610. group=handlers[v.opType](v.values,v.redNum)
  611. end
  612. --[[local posSpr
  613. if v.opType == MJDefine.MJGroupType.Gang then
  614. if v.fromUserId > 10000 then
  615. posSpr = self:createFromPos(v.fromUserId,seatId)
  616. posSpr:setPosition(cc.p(group:getContentSize().width/2-3,-5))
  617. else
  618. posSpr = self:createFromPos(nil,seatId)
  619. posSpr:setPosition(cc.p(group:getContentSize().width/2-25,-5))
  620. end
  621. elseif v.opType == MJDefine.MJGroupType.AnGang then
  622. posSpr = self:createFromPos(nil,seatId)
  623. posSpr:setPosition(cc.p(group:getContentSize().width/2-25,-5))
  624. end
  625. if posSpr then
  626. group:addChild(posSpr)
  627. end--]]
  628. local w=(group:getContentSize().width-MJ_WIDTH)/2
  629. group:setPosition(cc.p(self.initX[seatId]+w,MJ_OPERATE_CARD_INIT_Y))
  630. if k<#arg then
  631. self.initX[seatId]=self.initX[seatId]+group:getContentSize().width+MJ_GROUP_PADDING_X
  632. else
  633. self.initX[seatId]=self.initX[seatId]+group:getContentSize().width+MJ_GROUP_PADDING_X
  634. end
  635. layer:addChild(group)
  636. end
  637. end
  638. end
  639. function ncmajRoomXiaoJuView:createFromPos(formUid,seatId,posY)-- 来源uid 自己的seatId
  640. local mLayout = cc.Layout:createNode()
  641. if formUid then
  642. local nSeatId = app.room:getSeatIdByUserId(formUid)--app.room:getSeatIdByViewId(formUid)
  643. local spr = cc.ImageView:createNode()
  644. local posName = string.format("mj_ncmaj/res/zy_fangjian/ncmajadd/ncmaj_xj_Pos_%d.png", nSeatId+1)
  645. spr:loadTexture(posName,0)
  646. local tSize = spr:getContentSize()
  647. mLayout:setSize(tSize)
  648. mLayout:addChild(spr)
  649. else
  650. local index = 1
  651. local maxNum = app.room.roomInfo.nMaxPlayCount or 4
  652. for i=1,maxNum do
  653. if i~=seatId then
  654. local spr = cc.ImageView:createNode()
  655. local posName = string.format("mj_ncmaj/res/zy_fangjian/ncmajadd/ncmaj_xj_Pos_%d.png", i)
  656. spr:loadTexture(posName,0)
  657. local contenSize = spr:getContentSize()
  658. local offsetX = index == 1 and -20 or 20
  659. local tPos = cc.p(0 + (index-1)*40,0)
  660. if maxNum == 2 then--2人玩事,数字标识居中
  661. tPos = cc.p(20,0)
  662. end
  663. spr:setPosition(tPos)
  664. mLayout:addChild(spr)
  665. index = index + 1
  666. end
  667. end
  668. end
  669. return mLayout
  670. end
  671. -- 获取组合牌组
  672. function ncmajRoomXiaoJuView:getChangeGruopDatas(g,redNum)
  673. -- dump(g, "getChangeGruopDatas")
  674. local opType=MJDefine.MJOperateToGroupType[g.opType]
  675. local showType=MJDefine.MJOperateToGroupType[g.opType]
  676. local opCard=g.opCard
  677. local redNum = g.redNum or 0
  678. local fromViewId = nil
  679. local targetSeatId = g.targetSeatId--操作位置座位号
  680. local fromUserId = g.opUserId or g.fromUserId or 0 --触发操作玩家
  681. if fromUserId<=0 or targetSeatId==nil then
  682. else
  683. fromViewId = app.room:transPos( targetSeatId, app.room:getSeatIdByUserId(fromUserId))
  684. --判断是否是对面玩家,对面玩家的话要做一次翻转
  685. local opViewId = app.room:getViewIdBySeatId(targetSeatId)
  686. if opViewId == 2 then --对面
  687. if fromViewId==1 then fromViewId = 3
  688. elseif fromViewId==3 then fromViewId = 1 end
  689. end
  690. --三人玩只有上下家
  691. if app.room:getMaxPlayerCount()==3 and fromViewId==2 then fromViewId = 3 end
  692. if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
  693. if showType == MJDefine.MJGroupType.Peng then
  694. fromViewId = 2
  695. else
  696. fromViewId = 4
  697. end
  698. end
  699. end
  700. --组合一下牌
  701. local group={
  702. opType=opType,
  703. showType=showType,
  704. values={},
  705. opCard = opCard,
  706. redNum = redNum,
  707. orgType = g.opType,--原始的类型,如巴杠会归结为杠 但是他原始操作是巴杠
  708. fromViewId = fromViewId,
  709. fromUserId = fromUserId,
  710. }
  711. if MJDefine.MJGroupType.Chi==showType then
  712. elseif MJDefine.MJGroupType.Peng==showType then
  713. group.values={opCard,opCard,opCard}
  714. else
  715. group.values={opCard,opCard,opCard,opCard}
  716. end
  717. return group
  718. end
  719. function ncmajRoomXiaoJuView:initWeaveCard()
  720. local roomInfo=app.room.roomInfo
  721. self.initX={}
  722. for k,v in pairs(roomInfo.memberList) do
  723. local userId = app.room:getViewIdByUserId(v.nUserId)
  724. local nSeatId = app.room:getSeatIdByViewId(userId)
  725. local i = nSeatId+1
  726. local groups={}
  727. for _,group in pairs(v.gruoupCards) do
  728. table.insert(groups,self:getChangeGruopDatas(group))
  729. end
  730. self.initX[i]=MJ_HAND_CARD_INIT_X
  731. self:createGroupCards(self.items[i].Items.Layout_Player,groups,i)
  732. self.initX[i] = self.initX[i] + 10
  733. self:createHandCards(self.items[i].Items.Layout_Player,v.handCards,i)
  734. --创建胡的牌
  735. if v.huCard and v.huCard ~= 0 then
  736. self.initX[i]=self.initX[i]+MJ_HU_X
  737. self:createHuCard(self.items[i].Items.Layout_Player,v.huCard,i)
  738. end
  739. end
  740. end
  741. function ncmajRoomXiaoJuView:initOther()
  742. local roomInfo = app.room.roomInfo
  743. self.ui.Items.Text_Round:setText("局数:"..roomInfo.nGameStartCount..'/'..roomInfo.nTotalGameNum)
  744. --规则
  745. local ruleAll = MJWanFa.getWanFaInfo(roomInfo.strGameInfo)
  746. -- self.ui.Items.Text_Rule:setText(ruleAll)
  747. local item = self.ui.Items.Text_Rule:getCopied()
  748. item:setVisible(true)
  749. item:setText(ruleAll)
  750. self.ui.Items.ListView:addChild(item)
  751. self.ui.Items.ListView:hideAllBar()
  752. self.ui.Items.ListView:getInnerContainer():setAutoSize(true)
  753. self.ui.Items.ListView:requestDoLayout();
  754. self.ui.Items.ListView:doLayout();
  755. --时间
  756. self.ui.Items.Text_Time:setText(os.date("%m-%d %X"))--(getTimeString())
  757. --房号
  758. self.ui.Items.Text_RoomNum:setText("房号:"..roomInfo.nShowTableId)
  759. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  760. self.ui.Items.ImageView_Title:loadTexture("xj_liuju.png",cc.TextureResType.plistType)
  761. end
  762. end
  763. function ncmajRoomXiaoJuView:d2b(arg)
  764. self.data32={}
  765. for i=1,32 do
  766. self.data32[i]=2^(32-i)
  767. end
  768. local tr={}
  769. for i=1,32 do
  770. if arg >= self.data32[i] then
  771. tr[i]=1
  772. arg=arg-self.data32[i]
  773. else
  774. tr[i]=0
  775. end
  776. end
  777. return tr
  778. end
  779. function ncmajRoomXiaoJuView:b2d(arg)
  780. local nr=0
  781. for i=1,32 do
  782. if arg[i] ==1 then
  783. nr=nr+2^(32-i)
  784. end
  785. end
  786. return nr
  787. end
  788. function ncmajRoomXiaoJuView:_and(a,b)
  789. local op1=self:d2b(a)
  790. local op2=self:d2b(b)
  791. local r={}
  792. for i=1,32 do
  793. if op1[i]==1 and op2[i]==1 then
  794. r[i]=1
  795. else
  796. r[i]=0
  797. end
  798. end
  799. local c = self:b2d(r)
  800. return c
  801. end
  802. --黄色麻将小局改成跟绿色麻将一样大
  803. function ncmajRoomXiaoJuView:changeMjSize(mj)
  804. if not mj then return end
  805. mj:setAutoSize(false)
  806. mj:setSize(cc.size(47,72))
  807. end
  808. return ncmajRoomXiaoJuView