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

741 lines
22 KiB

  1. local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine")
  2. local MJ = MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  3. local MJRoomDaJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView")
  4. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  5. local MJRoomXiaoJuView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomXiaoJuView")
  6. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  7. -- 房间设置界面
  8. local huamajiangRoomXiaoJuView = class("huamajiangRoomXiaoJuView", MJRoomXiaoJuView)
  9. local MJ_WIDTH=47
  10. --起始位置
  11. local MJ_HAND_CARD_INIT_X=130+50
  12. local MJ_HAND_CARD_INIT_Y=40
  13. local MJ_GROUP_CARD_INIT_X=100
  14. --麻将组间隔
  15. local MJ_GROUP_PADDING_X= 10
  16. --麻将直接间隔
  17. local MJ_PADDING_X=-3
  18. --胡牌麻将间隔
  19. local MJ_HU_X=8
  20. --暗杠上面的牌Y轴偏移量
  21. local GANG_OFFSET_Y=16
  22. function huamajiangRoomXiaoJuView:ctor(...)
  23. huamajiangRoomXiaoJuView.super.ctor(self,...)
  24. self.desktopType = MJDefine.DesktopType.TwoD
  25. end
  26. function huamajiangRoomXiaoJuView:loadUI()
  27. local ui = loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_xiaoju_jiesuan.ui")
  28. self.ui = ui
  29. self:addChild(ui)
  30. end
  31. function huamajiangRoomXiaoJuView:onEnter()
  32. huamajiangRoomXiaoJuView.super.onEnter(self)
  33. self:createTransparentFlowBtn()
  34. end
  35. ---
  36. -- 创建一个透明的流水按钮,查牌界面需要用到
  37. --
  38. function huamajiangRoomXiaoJuView:createTransparentFlowBtn()
  39. if self._btnFlow then
  40. return
  41. end
  42. self._btnFlow = cc.Layout:create()
  43. self._btnFlow:setSize(cc.size(77, 77))
  44. self._btnFlow:setAnchorPoint(cc.p(0.5, 0.5))
  45. self._btnFlow:setPosition(cc.p(1234, 354))
  46. self._btnFlow:registerClick(handler(self, self.onButtonFlowClicked))
  47. -- 需要调整位置,可反注释下面这句代码看效果
  48. -- self._btnFlow:setBackGroundColorType(cc.LayoutBackGroundColorType.solid);
  49. -- self._btnFlow:setBackGroundColor(cc.c3b(255, 0, 0))
  50. self.ui.Items.Layout_Sure:addChild(self._btnFlow)
  51. end
  52. ---
  53. -- 透明按钮点击事件,打开流水之口
  54. --
  55. function huamajiangRoomXiaoJuView:onButtonFlowClicked()
  56. logD("huamajiangRoomXiaoJuView:onButtonFlowClicked")
  57. playBtnEffect();
  58. local request = MJMessage.GameFlowReq:new()
  59. request.nUserId = app.room:getMyUserId()
  60. self.ui:sendMsg(app.room, MJDefine.MJEvent.ReqFlowInfo, request)
  61. --app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_BTN_SHOW_FLOW_VIEW_CLICKED, response = nil});
  62. end
  63. function huamajiangRoomXiaoJuView:initPlayerView()
  64. local roomInfo=app.room.roomInfo
  65. self.ui.Items.Layout_Player:removeAllChildren()
  66. self.items={}
  67. for k,v in pairs(roomInfo.memberList) do
  68. --local i = v.nSeatId+1
  69. local userId = app.room:getViewIdByUserId(v.nUserId)
  70. local nSeatId = app.room:getSeatIdByViewId(userId)
  71. local i = nSeatId+1
  72. local item=self:createPlayerItem()
  73. item.index = i;
  74. self:setPlayerItemInfo(item,v)
  75. self.items[i]=item
  76. -- table.insert(self.items,)
  77. end
  78. table.sort(self.items, function(a, b)
  79. return a.index < b.index;
  80. end);
  81. for k, v in pairs(self.items or {}) do
  82. self.ui.Items.Layout_Player:addChild(self.items[k])
  83. end
  84. end
  85. function huamajiangRoomXiaoJuView:createPlayerItem()
  86. local ui=loadUI("mj_huamajiang/res/ui_fangjian/mj_huamajiang_xiaoju_item.ui")
  87. autoAdapt(ui)
  88. return ui
  89. end
  90. function huamajiangRoomXiaoJuView:setPlayerItemInfo(ui,player)
  91. local roomInfo=app.room.roomInfo
  92. local resultInfo=roomInfo.memberList
  93. local nodeBg = ui.Items["ImageView_ItemBg"]
  94. -- local nodeBg2 = ui.Items[bg2]
  95. -- local nodeLose = self.ui.Items[lose]
  96. local nodeHead = ui.Items["ImageView_Head"]
  97. local nodeName = ui.Items["Text_Name"]
  98. local nodeBenJu = ui.Items["TextBMFont_Score"]
  99. local bmFontScore = true
  100. if not nodeBenJu then
  101. nodeBenJu = ui.Items["Text_Score"]
  102. bmFontScore = false
  103. end
  104. local nodeHu = ui.Items["ImageView_Hu"]
  105. local nodeBanker= ui.Items["ImageView_Banker"]
  106. local nodeResult= ui.Items["Text_ResultInfo"]
  107. local btnDetail = ui.Items["Button_Detail"];
  108. local imgViewId = ui.Items["ImageView_ViewId"];
  109. btnDetail:registerClick(function ()
  110. local roomInfo = app.room.roomInfo;
  111. local data = {};
  112. local allPlayerScoreInfo = roomInfo.allPlayerScoreInfo;
  113. local luoboCards = roomInfo:getLuoBoCards();
  114. luoboCards = roomInfo:getLuoBoCardsSummary(luoboCards)
  115. data.luoboCards = luoboCards;
  116. if allPlayerScoreInfo[player.nUserId] then
  117. local scoreData = {};
  118. for k, v in ipairs(allPlayerScoreInfo[player.nUserId]) do
  119. table.insert(scoreData, json.decode(v));
  120. end
  121. data.detail = scoreData
  122. app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_BTN_SHOW_FLOW_VIEW_CLICKED, response = data});
  123. else
  124. local request = MJMessage.GameFlowReq:new()
  125. request.nUserId = player.nUserId
  126. self.ui:sendMsg(app.room, MJDefine.MJEvent.ReqFlowInfo, request)
  127. end
  128. -- local roomInfo = app.room.roomInfo;
  129. -- local data = {};
  130. -- local scoreInfo = player.scoreInfo;
  131. -- local luoboCards = roomInfo:getLuoBoCards();
  132. -- luoboCards = roomInfo:getLuoBoCardsSummary(luoboCards)
  133. -- local scoreData = {};
  134. -- for k, v in ipairs(scoreInfo) do
  135. -- table.insert(scoreData, json.decode(v));
  136. -- end
  137. -- data.detail = scoreData
  138. -- data.luoboCards = luoboCards;
  139. -- app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_BTN_SHOW_FLOW_VIEW_CLICKED, response = data});
  140. end);
  141. local viewOrder = player.nSeatId + 1;
  142. imgViewId:loadTexture(string.format("mj_huamajiang/res/zy_fangjian/player/huamajiang_seat_%s.png", viewOrder));
  143. --[[local huType = {
  144. [1] = "自摸(",
  145. [2] = "接炮(",
  146. [3] = "抢杠胡(",
  147. }--]]
  148. --[[local infoTab = {
  149. ["agang"] = "暗杠(x",
  150. ["bgang"] = "补杠(x",
  151. ["diangang_cnt"] = "点杠(x",
  152. ["mgang"] = "明杠(x",
  153. }--]]
  154. local color = (app.room:getMyUserId() == player.nUserId) and cc.c3b(255,243,176) or cc.c3b(230,192,117);
  155. local infoStr = self:setHuType(player.nUserId)
  156. nodeResult:setText(infoStr)
  157. nodeResult:setColor(color);
  158. local userInfo = app.room:getUserInfo(player.nUserId)
  159. --先设置默认头像
  160. local width = nodeHead:getContentSize().width
  161. local nickname = ""
  162. if userInfo and userInfo.nickname then
  163. nickname = getSubStringNickname(userInfo.nickname)
  164. self:updateUserHead(nodeHead,player.nUserId, userInfo.sex, userInfo.headimgurl);
  165. end
  166. nodeName:setText(nickname)
  167. nodeHu:setVisible(false)
  168. if table.nums(player.huCards) > 0 then
  169. nodeHu:setVisible(true)
  170. nodeHu:loadTexture("mj_huamajiang/res/zy_fangjian/operate/huamajiang_effect_hu.png")
  171. end
  172. --黄庄才会查叫和查花猪
  173. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  174. if table.nums(player.huCards) <= 0 then
  175. if player.isDj == 1 then
  176. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_chajiao.png")
  177. nodeHu:setVisible(true)
  178. nodeHu:setScale(0.4)
  179. end
  180. end
  181. end
  182. local bankSeatId = roomInfo:getBankSeatId();
  183. if app.room:getUserIdBySeatId(bankSeatId) ~= player.nUserId then
  184. nodeBanker:setVisible(false)
  185. end
  186. if app.room:getMyUserId() == player.nUserId then
  187. nodeBg:loadTexture("xj_my_bg.png",cc.TextureResType.plistType)
  188. --[[else
  189. nodeBg:loadTexture("xj_other_bg.png",cc.TextureResType.plistType)--]]
  190. end
  191. if tonumber(player.nTurnScore) > 0 then
  192. nodeBenJu:setText("+"..player.nTurnScore)
  193. else
  194. nodeBenJu:setText(player.nTurnScore)
  195. if tonumber(player.nTurnScore) < 0 and bmFontScore == true then
  196. nodeBenJu:setFntFile("res/fonts/dt_jian_num.fnt")
  197. end
  198. end
  199. -- --番数
  200. ui.Items.Text_FanShu:setVisible(false);
  201. -- ui.Items.Text_FanShu:setText(player.fanshu.."番")
  202. --[[ local viewId = app.room:getViewIdByUserId(player.nUserId)
  203. if viewId and viewId>0 and viewId<=4 then
  204. if viewId == 4 then
  205. ui.Items.ImageView_Pos:loadTexture("result_pos_0.png",1)
  206. else
  207. ui.Items.ImageView_Pos:loadTexture(string.format("result_pos_%d.png", viewId), 1)
  208. end
  209. else
  210. ui.Items.ImageView_Pos:setVisible(false)
  211. end--]]
  212. --现在是飘
  213. ui.Items.ImageView_Pos:setVisible(player.isPiao==1)
  214. end
  215. function huamajiangRoomXiaoJuView:setHuType(userId)
  216. do
  217. -- 暂时不走这个方法
  218. return "";
  219. end
  220. local roomInfo = app.room.roomInfo
  221. local strGameInfo = roomInfo:getGameRule();
  222. local str = ""
  223. local huType1 = {
  224. [1] = "自摸(",
  225. [2] = "接炮(",
  226. [3] = "抢杠胡(",
  227. }
  228. local huOrder1 = 0
  229. local player = roomInfo.memberList[userId]
  230. if player then
  231. huOrder1 = player.huOrder
  232. --胡牌顺序
  233. if player.result == MJDefine.MJGameHuType.HU_ZIMO then
  234. local huNum = 0
  235. --快速成局时,strGameInfo.playnum默认传来的是4人
  236. if strGameInfo.isfaststart == 1 then
  237. huNum = roomInfo:getMaxPlayerCount() - player.huOrder
  238. else
  239. huNum = strGameInfo.playnum - player.huOrder
  240. end
  241. str = str..huType1[player.result]..huNum.."家) "
  242. elseif player.result == MJDefine.MJGameHuType.HU_DIANPAO or player.result == MJDefine.MJGameHuType.HU_QIANGGANG then
  243. local viewId = app.room:getViewIdBySeatId(player.dpSeatId)
  244. local userInfo = app.room:getUserInfoByViewId(viewId)
  245. local nickname = getSubStringNickname(userInfo.nickname)
  246. str = str..huType1[player.result]..nickname..") "
  247. end
  248. --牌型
  249. -- for k,v in pairs(MJDefine.MJGamePaiType) do
  250. -- local newType = self:_and(player.huType,v)
  251. -- if self:_and(player.huType,v) ~= 0 then
  252. -- local newType = self:_and(player.huType,v)
  253. -- str = str..MJDefine.MJGameHuStr[newType].." "
  254. -- end
  255. -- end
  256. str = str .. self:getPaiTypeStr(player)
  257. if player.result > 0 or player.huType > 0 then
  258. if player.isPiao == 1 then
  259. str = str.."飘".." "
  260. end
  261. if player.luoboNum > 0 then
  262. str = str.."萝卜x"..player.luoboNum.." "
  263. end
  264. else
  265. if player.isPiao == 1 then
  266. str = str.."飘".." "
  267. end
  268. if player.isBaoPai == 1 then
  269. str = str.."报叫".." "
  270. elseif player.isBaoPai == 2 then
  271. str = str.."博自摸".." "
  272. end
  273. end
  274. local ganginfo = json.decode(player.ganginfo)
  275. if ganginfo then
  276. if ganginfo.agang then
  277. str = str.."暗杠x"..ganginfo.agang.." "
  278. end
  279. if ganginfo.mgang then
  280. str = str.."明杠x"..ganginfo.mgang.." "
  281. end
  282. if ganginfo.bgang then
  283. str = str.."巴杠x"..ganginfo.bgang.." "
  284. end
  285. if ganginfo.dgang then
  286. str = str.."点杠x"..ganginfo.dgang.." "
  287. end
  288. if ganginfo.guogang then
  289. str = str.."过手杠x"..ganginfo.guogang.." "
  290. end
  291. end
  292. end
  293. return str
  294. end
  295. --合并牌型得到最终的字符串
  296. function huamajiangRoomXiaoJuView:getPaiTypeStr(player)
  297. local strTab = {}
  298. -- 花麻将没有huType
  299. -- for k,v in pairs(MJDefine.MJGamePaiType) do
  300. -- local newType = self:_and(player.huType,v)
  301. -- if newType ~= 0 then
  302. -- table.insert(strTab,MJDefine.MJGameHuStr[newType] or "")
  303. -- end
  304. -- end
  305. -- if player.result > 0 or player.huType > 0 then
  306. -- if player.genCount > 0 then
  307. -- table.insert(strTab,player.genCount.."归")
  308. -- end
  309. -- end
  310. dump(strTab)
  311. --logD(table.toString(strTab))
  312. for _,v in pairs(MJDefine.MJGameHuMargeTab) do
  313. local list = v.tab
  314. local str = v.name
  315. dump(list)
  316. local indexs= {}
  317. for _,v in pairs(list) do
  318. local index = table.indexOf(strTab, v)
  319. if index~= -1 then
  320. table.insert(indexs,index)
  321. end
  322. end
  323. if #indexs == #list then --如果都找到则合并
  324. for k,v in pairs(list) do
  325. table.removeItem(strTab,v)
  326. end
  327. -- logD(str)
  328. table.insert(strTab,str)
  329. end
  330. end
  331. local info = ""
  332. for k,v in pairs(strTab) do
  333. info = info..v.." "
  334. end
  335. return info
  336. end
  337. function huamajiangRoomXiaoJuView:createHandCards(layer,arg,seatId)
  338. for k,v in pairs(arg) do
  339. local mj=MJ:new(v.card,MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  340. layer:addChild(mj)
  341. self:checkIsLuoBo(mj)
  342. mj:setPosition(cc.p(self.initX[seatId],MJ_HAND_CARD_INIT_Y))
  343. self.initX[seatId]=self.initX[seatId]+mj:getContentSize().width+MJ_PADDING_X
  344. end
  345. end
  346. function huamajiangRoomXiaoJuView:createHuCard(layer,card,seatId)
  347. local mj=MJ:new(card,MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  348. self:checkIsLuoBo(mj)
  349. layer:addChild(mj)
  350. mj:setPosition(cc.p(self.initX[seatId],MJ_HAND_CARD_INIT_Y))
  351. self.initX[seatId]=self.initX[seatId]+mj:getContentSize().width+MJ_PADDING_X
  352. local flag = cc.Sprite:create("mj/res/ui/zy_fangjian/mj_hu_flag.png")
  353. mj:addChild(flag)
  354. flag:setPosition(cc.p(16,55))
  355. end
  356. function huamajiangRoomXiaoJuView:createChi(values)
  357. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  358. node:setAnchorPoint(cc.p(0.5,0.5))
  359. node:ignoreAnchorPointForPosition(false)
  360. local width=0
  361. local height=0
  362. for i=1,3 do
  363. if values[i] then
  364. local mj = MJ:new(values[i],MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  365. if i == 1 then
  366. self:checkIsLuoBo(mj)
  367. end
  368. node:addChild(mj)
  369. local mjWidth=mj:getContentSize().width
  370. local mjHeight=mj:getContentSize().height
  371. local x=mjWidth/2+(i-1)*(mjWidth+MJ_PADDING_X)
  372. local y=mjHeight/2
  373. width=width+mjWidth
  374. height=mjHeight
  375. mj:setPosition(x,y)
  376. end
  377. end
  378. node:setContentSize(cc.size(width,height))
  379. return node
  380. end
  381. function huamajiangRoomXiaoJuView:createGang(values, cardNum)
  382. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  383. node:setAnchorPoint(cc.p(0.5,0.5))
  384. node:ignoreAnchorPointForPosition(false)
  385. local width=0
  386. local height=0
  387. for i=1,4 do
  388. if values[i] then
  389. local mj = MJ:new(values[i],MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  390. if i == 1 then
  391. self:checkIsLuoBo(mj)
  392. end
  393. node:addChild(mj)
  394. local mjWidth=mj:getContentSize().width
  395. local mjHeight=mj:getContentSize().height
  396. if i <= 3 then
  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. else
  403. local x = mjWidth/2+(2-1)*(mjWidth+MJ_PADDING_X)
  404. local y=mjHeight/2 + 12
  405. height = mjHeight
  406. mj:setPosition(x,y)
  407. mj:refreshCardNum(cardNum);
  408. end
  409. mj:setTag(1000 + i);
  410. end
  411. end
  412. node:setContentSize(cc.size(width,height))
  413. return node
  414. end
  415. function huamajiangRoomXiaoJuView:createAnGang(values, cardNum)
  416. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  417. node:setAnchorPoint(cc.p(0.5,0.5))
  418. node:ignoreAnchorPointForPosition(false)
  419. local width=0
  420. local height=0
  421. for i=1,4 do
  422. if values[i] then
  423. local mj
  424. if i <= 3 then
  425. mj=MJ:new(0,MJDefine.MJType.OutBlack,MJDefine.MyViewId,self.desktopType)
  426. if self.desktopType == MJDefine.DesktopType.TwoD or self.desktopType == MJDefine.DesktopType.TwoDGold then
  427. mj:setAutoSize(false)
  428. mj:setSize(cc.size(44,68))
  429. end
  430. else
  431. mj=MJ:new(values[i],MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  432. mj:refreshCardNum(cardNum);
  433. end
  434. node:addChild(mj)
  435. local offsetY = 0;
  436. local mjWidth=mj:getContentSize().width
  437. local mjHeight=mj:getContentSize().height
  438. if i <= 3 then
  439. local x=mjWidth/2+(i-1)*(mjWidth+MJ_PADDING_X) + 4
  440. local y=mjHeight/2 + 4 - offsetY
  441. width=width+mjWidth
  442. height=mjHeight
  443. mj:setPosition(x,y)
  444. else
  445. local x=mjWidth/2+(2-1)*(mjWidth+MJ_PADDING_X) + 2
  446. local y=mjHeight/2 + 10 + 2 - offsetY
  447. height=mjHeight
  448. mj:setPosition(x, y);
  449. end
  450. if i == 1 then
  451. local luoboCount = app.room.roomInfo:getLuoBoCardCount(values[i]);
  452. mj:setLuoBoVisible(luoboCount > 0, luoboCount);
  453. end
  454. end
  455. end
  456. node:setContentSize(cc.size(width,height))
  457. return node
  458. end
  459. function huamajiangRoomXiaoJuView:createBaGang(values, cardNum)
  460. local node = self:createGang(values, cardNum);
  461. local mj = node:getChildByTag(1000 + 4);
  462. if mj then
  463. mj:setOutBlackImage(0, MJDefine.MyViewId);
  464. end
  465. return node;
  466. end
  467. -- function huamajiangRoomXiaoJuView:createAnGang(values)
  468. -- local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  469. -- node:setAnchorPoint(cc.p(0.5,0.5))
  470. -- node:ignoreAnchorPointForPosition(false)
  471. -- local width=0
  472. -- local height=0
  473. -- for i=1,4 do
  474. -- if values[i] then
  475. -- local mj
  476. -- if i <= 3 then
  477. -- mj=MJ:new(values[i],MJDefine.MJType.OutBlack,MJDefine.MyViewId,self.desktopType)
  478. -- else
  479. -- mj=MJ:new(values[i],MJDefine.MJType.Out,MJDefine.MyViewId)
  480. -- end
  481. -- self:checkIsLuoBo(mj)
  482. -- node:addChild(mj)
  483. -- local mjWidth=mj:getContentSize().width
  484. -- local mjHeight=mj:getContentSize().height
  485. -- local x=mjWidth/2+(i-1)*(mjWidth+MJ_PADDING_X)
  486. -- local y=mjHeight/2
  487. -- width=width+mjWidth
  488. -- height=mjHeight
  489. -- mj:setPosition(x,y)
  490. -- end
  491. -- end
  492. -- node:setContentSize(cc.size(width,height))
  493. -- return node
  494. -- end
  495. function huamajiangRoomXiaoJuView:createGroupCards(layer,arg,seatId)
  496. local handlers={
  497. [MJDefine.MJGroupType.Chi]=handler(self,self.createChi),
  498. [MJDefine.MJGroupType.Peng]=handler(self,self.createChi),
  499. [MJDefine.MJGroupType.Gang]=handler(self,self.createGang),
  500. [MJDefine.MJGroupType.AnGang]=handler(self,self.createAnGang),
  501. [MJDefine.MJGroupType.BaGang] = handler(self, self.createBaGang),
  502. }
  503. for k,v in pairs(arg) do
  504. if handlers[v.opType] then
  505. local group=handlers[v.opType](v.values, v.cardNum)
  506. local w=(group:getContentSize().width-MJ_WIDTH)/2
  507. group:setPosition(cc.p(self.initX[seatId]+w,MJ_HAND_CARD_INIT_Y))
  508. if k<#arg then
  509. self.initX[seatId]=self.initX[seatId]+group:getContentSize().width+MJ_GROUP_PADDING_X
  510. else
  511. self.initX[seatId]=self.initX[seatId]+group:getContentSize().width+MJ_GROUP_PADDING_X
  512. end
  513. layer:addChild(group)
  514. end
  515. end
  516. end
  517. -- 获取组合牌组
  518. function huamajiangRoomXiaoJuView:getChangeGruopDatas(g)
  519. -- dump(g, "getChangeGruopDatas")
  520. local opType=MJDefine.MJOperateToGroupType[g.opType]
  521. local showType=MJDefine.MJOperateToGroupType[g.opType]
  522. local opCard=g.opCard
  523. local cardNum = g.cardNum
  524. local fromViewId = nil
  525. local targetSeatId = g.targetSeatId--操作位置座位号
  526. local fromUserId = g.opUserId or g.fromUserId --触发操作玩家
  527. if fromUserId<=0 or targetSeatId==nil then
  528. else
  529. fromViewId = app.room:transPos( targetSeatId, app.room:getSeatIdByUserId(fromUserId))
  530. --判断是否是对面玩家,对面玩家的话要做一次翻转
  531. local opViewId = app.room:getViewIdBySeatId(targetSeatId)
  532. if opViewId == 2 then --对面
  533. if fromViewId==1 then fromViewId = 3
  534. elseif fromViewId==3 then fromViewId = 1 end
  535. end
  536. --三人玩只有上下家
  537. if app.room:getMaxPlayerCount()==3 and fromViewId==2 then fromViewId = 3 end
  538. if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
  539. if showType == MJDefine.MJGroupType.Peng then
  540. fromViewId = 2
  541. else
  542. fromViewId = 4
  543. end
  544. end
  545. end
  546. --组合一下牌
  547. local group={
  548. opType=opType,
  549. showType=showType,
  550. values={},
  551. opCard = opCard,
  552. cardNum = cardNum,
  553. fromViewId = fromViewId
  554. }
  555. if MJDefine.MJGroupType.Chi==showType then
  556. elseif MJDefine.MJGroupType.Peng==showType then
  557. group.values={opCard,opCard,opCard}
  558. else
  559. group.values={opCard,opCard,opCard,opCard}
  560. end
  561. return group
  562. end
  563. function huamajiangRoomXiaoJuView:initWeaveCard()
  564. local roomInfo=app.room.roomInfo
  565. self.initX={}
  566. for k,v in pairs(roomInfo.memberList) do
  567. local userId = app.room:getViewIdByUserId(v.nUserId)
  568. local nSeatId = app.room:getSeatIdByViewId(userId)
  569. local i = nSeatId+1
  570. local groups={}
  571. for _, group in pairs(v.operates) do
  572. table.insert(groups, self:getChangeGruopDatas(group))
  573. end
  574. self.initX[i]=MJ_HAND_CARD_INIT_X
  575. self:createGroupCards(self.items[i].Items.Layout_Player,groups,i)
  576. self.initX[i] = self.initX[i]
  577. self:createHandCards(self.items[i].Items.Layout_Player,v.handCards,i)
  578. -- 花麻将不需要显示胡的牌
  579. -- --创建胡的牌
  580. -- if v.huCard and v.huCard ~= 0 then
  581. -- self.initX[i]=self.initX[i]+MJ_HU_X
  582. -- self:createHuCard(self.items[i].Items.Layout_Player,v.huCard,i)
  583. -- -- self:createHandCards(self.items[i].Items.Layout_Player,{{card=v.huCard}},i)
  584. -- end
  585. end
  586. end
  587. function huamajiangRoomXiaoJuView:initOther()
  588. local roomInfo = app.room.roomInfo
  589. self.ui.Items.Text_Round:setText("局数:"..roomInfo.nGameStartCount..'/'..roomInfo.nTotalGameNum)
  590. --规则
  591. local ruleAll = MJWanFa.getWanFaInfo(roomInfo:getStrGameInfo())
  592. -- self.ui.Items.Text_Rule:setText(ruleAll)
  593. local item = self.ui.Items.Text_Rule:getCopied()
  594. item:setVisible(true)
  595. item:setText(ruleAll)
  596. self.ui.Items.ListView:addChild(item)
  597. self.ui.Items.ListView:hideAllBar()
  598. self.ui.Items.ListView:getInnerContainer():setAutoSize(true)
  599. self.ui.Items.ListView:requestDoLayout();
  600. self.ui.Items.ListView:doLayout();
  601. --时间
  602. self.ui.Items.Text_Time:setText(os.date("%m-%d %X"))--(getTimeString())
  603. --房号
  604. self.ui.Items.Text_RoomNum:setText("房号:" .. roomInfo:getShowTableId());
  605. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  606. self.ui.Items.ImageView_Title:loadTexture("xj_liuju.png",cc.TextureResType.plistType)
  607. end
  608. end
  609. -- function huamajiangRoomXiaoJuView:d2b(arg)
  610. -- self.data32={}
  611. -- for i=1,32 do
  612. -- self.data32[i]=2^(32-i)
  613. -- end
  614. -- local tr={}
  615. -- for i=1,32 do
  616. -- if arg >= self.data32[i] then
  617. -- tr[i]=1
  618. -- arg=arg-self.data32[i]
  619. -- else
  620. -- tr[i]=0
  621. -- end
  622. -- end
  623. -- return tr
  624. -- end
  625. -- function huamajiangRoomXiaoJuView:b2d(arg)
  626. -- local nr=0
  627. -- for i=1,32 do
  628. -- if arg[i] ==1 then
  629. -- nr=nr+2^(32-i)
  630. -- end
  631. -- end
  632. -- return nr
  633. -- end
  634. -- function huamajiangRoomXiaoJuView:_and(a,b)
  635. -- local op1=self:d2b(a)
  636. -- local op2=self:d2b(b)
  637. -- local r={}
  638. -- for i=1,32 do
  639. -- if op1[i]==1 and op2[i]==1 then
  640. -- r[i]=1
  641. -- else
  642. -- r[i]=0
  643. -- end
  644. -- end
  645. -- local c = self:b2d(r)
  646. -- return c
  647. -- end
  648. --[[
  649. 检查是否萝卜牌
  650. ]]
  651. function huamajiangRoomXiaoJuView:checkIsLuoBo(mj)
  652. if not mj then return end
  653. local count = app.room:getLuoBoCardCount(mj.value) or 0;
  654. mj:setLuoBoVisible(count > 0, count)
  655. end
  656. function huamajiangRoomXiaoJuView:onBtnSureClicked()
  657. if app.room.roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  658. huamajiangRoomXiaoJuView.super.onClickZongJieSuan(self)
  659. else
  660. huamajiangRoomXiaoJuView.super.onBtnSureClicked(self)
  661. end
  662. end
  663. return huamajiangRoomXiaoJuView