Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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