Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

897 linhas
27 KiB

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