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

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