You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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