您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字

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