您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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