Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

751 rader
22 KiB

  1. local RoomXiaoJuView = class("RoomXiaoJuView_Coin", cc.UIView)
  2. local MJ = MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  3. local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine")
  4. local MJWanFa = MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  5. local MJRoomDaJuView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView")
  6. local MJRoomXiaoJuPlayerInfo = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomXiaoJuPlayerInfo")
  7. local CoinFunctions = import("luaScript.Views.Coin.Util.CoinFunctions")
  8. local CoinData = import("luaScript.Views.Coin.Data.CoinData")
  9. local CoinGameLogic = import("luaScript.Views.Coin.CoinGameLogic")
  10. local HuCardType = {
  11. INIT = 0, --//没有牌型
  12. MEN_QING = 1, --//门清
  13. QUAN_QUI_REN = 2, --//全球人
  14. QING_YI_SE = 3, --//清一色
  15. ZI_YI_SE = 4, --//字一色
  16. QI_XIAO_DUI = 5, --//七小对
  17. HAO_HUA_QI_XIAO_DUI = 6, --//豪华七小对
  18. TWO_HAO_HUA_QI_XIAO_DUI = 7, --//双豪华七小对
  19. THREE_HAO_HUA_QI_XIAO_DUI = 8, --//三豪华七小对
  20. PENG_PENG_HU = 9, --//碰碰胡
  21. QIANG_GANG_HU = 10, --//抢杠胡
  22. GANG_SHANG_HUA = 11, --//杠上花
  23. GANG_XIA_HUA = 12, --//杠下花
  24. SHI_SAN = 13
  25. }
  26. local HuCardTypeStr = {
  27. [HuCardType.INIT] = "平胡", --//没有牌型
  28. [HuCardType.MEN_QING] = "门清", --//门清
  29. [HuCardType.QUAN_QUI_REN] = "全求人", --//全球人
  30. [HuCardType.QING_YI_SE] = "清一色", --//清一色
  31. [HuCardType.ZI_YI_SE] = "字一色", --//字一色
  32. [HuCardType.QI_XIAO_DUI] = "七小对", --//七小对
  33. [HuCardType.HAO_HUA_QI_XIAO_DUI] = "豪华七小对", --//豪华七小对
  34. [HuCardType.TWO_HAO_HUA_QI_XIAO_DUI] = "双豪华七小对", --//双豪华七小对
  35. [HuCardType.THREE_HAO_HUA_QI_XIAO_DUI] = "三豪华七小对", --//三豪华七小对
  36. [HuCardType.PENG_PENG_HU] = "碰碰胡", --//碰碰胡
  37. [HuCardType.QIANG_GANG_HU] = "抢杠胡", --//抢杠胡
  38. [HuCardType.GANG_SHANG_HUA] = "杠上花", --//杠上花
  39. [HuCardType.GANG_XIA_HUA] = "杠下花", --//杠下花
  40. [HuCardType.SHI_SAN] = ""
  41. }
  42. --起始位置
  43. local MJ_HAND_CARD_INIT_X = 130+35
  44. local MJ_HAND_CARD_INIT_Y = 40
  45. local MJ_GROUP_CARD_INIT_X = 100
  46. --麻将组间隔
  47. local MJ_GROUP_PADDING_X = 0
  48. --麻将直接间隔
  49. local MJ_PADDING_X = -3
  50. --胡牌麻将间隔
  51. local MJ_HU_X = 8
  52. --麻将宽度
  53. local MJ_WIDTH = 47
  54. --暗杠上面的牌Y轴偏移量
  55. local GANG_OFFSET_Y = 16
  56. function RoomXiaoJuView:ctor(add_coupons)
  57. RoomXiaoJuView.super.ctor(self)
  58. self:loadUI()
  59. self.add_coupons = add_coupons
  60. self:bindEvent(app.hall, "couponsAdd", handler(self, self.changeLiquan))
  61. end
  62. function RoomXiaoJuView:loadUI()
  63. local ui = loadUI("mj_luzhougui/res/ui_fangjian/mj_luzhou_xiaoju_coin.ui")
  64. self:addChild(ui)
  65. self.ui = ui
  66. end
  67. function RoomXiaoJuView:createPlayerItem()
  68. local ui = loadUI("mj_luzhougui/res/ui_fangjian/mj_luzhou_xiaoju_item.ui")
  69. autoAdapt(ui)
  70. return ui
  71. end
  72. function RoomXiaoJuView:onEnter()
  73. RoomXiaoJuView.super.onEnter(self)
  74. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile("mj/res/ui/zy_fangjian/mj_xiao_ju.plist")
  75. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile("mj/res/ui/zy_fangjian/mj_xiaoju_new.plist")
  76. -- 继续游戏
  77. self.ui.Items.Button_Next:registerClick(handler(self, self.onClickNext))
  78. -- 继续游戏
  79. self.ui.Items.Button_Sure:registerClick(handler(self, self.onClickNext))
  80. -- 查牌
  81. self.ui.Items.Button_Cha:registerClick(handler(self, self.onClickClose))
  82. -- 分享
  83. self.ui.Items.Button_Share:registerClick(handler(self, self.onClickShare))
  84. -- 关闭
  85. self.ui.Items.Button_Close:registerClick(handler(self, self.onClickCloseToHall))
  86. --初始化人物信息
  87. self:initPlayerView()
  88. --初始化组合牌
  89. self:initWeaveCard()
  90. --初始化其他数据
  91. self:initOther()
  92. end
  93. function RoomXiaoJuView:changeLiquan(eventData)
  94. --礼券
  95. if eventData then
  96. self.add_coupons = tonumber(eventData.attr.add_counpons or 0)
  97. end
  98. self.add_coupons = self.add_coupons or 0
  99. if self.add_coupons > 0 then
  100. self.ui.Items.Image_Quan:setVisible(true)
  101. self.ui.Items.TextBMFont_Quan:setText(string.format("+%d", tonumber(self.add_coupons)))
  102. else
  103. self.ui.Items.Image_Quan:setVisible(false)
  104. end
  105. end
  106. function RoomXiaoJuView:initPlayerView()
  107. local roomInfo=app.room.roomInfo
  108. self.ui.Items.Layout_Player:removeAllChildren()
  109. self.items={}
  110. for k,v in pairs(roomInfo.memberList) do
  111. --local i = v.nSeatId+1
  112. local userId = app.room:getViewIdByUserId(v.nUserId)
  113. local nSeatId = app.room:getSeatIdByViewId(userId)
  114. local i = nSeatId+1
  115. local item=self:createPlayerItem()
  116. self.ui.Items.Layout_Player:addChild(item)
  117. self:setPlayerItemInfo(item,v)
  118. self.items[i]=item
  119. -- table.insert(self.items,)
  120. end
  121. end
  122. function RoomXiaoJuView:setPlayerItemInfo(ui,player)
  123. local roomInfo=app.room.roomInfo
  124. local resultInfo=roomInfo.memberList
  125. local bg = "ImageView_ItemBg"--"ImageView_Win_"..i..""
  126. -- local bg2 = "ImageView_ItemBg_2"
  127. -- local lose = "ImageView_Lose_"..i
  128. local head = "ImageView_Head"
  129. local name = "Text_Name"
  130. local benJuScore = "TextBMFont_Score"
  131. local benJuScore1 = "Text_Score"
  132. local hu = "ImageView_Hu"
  133. local info = "Button_Info"
  134. local result="Text_ResultInfo"
  135. local nodeBg = ui.Items[bg]
  136. -- local nodeBg2 = ui.Items[bg2]
  137. -- local nodeLose = self.ui.Items[lose]
  138. local nodeHead = ui.Items[head]
  139. local nodeName = ui.Items[name]
  140. local nodeBenJu = ui.Items[benJuScore]
  141. local bmFontScore = true
  142. if not nodeBenJu then
  143. nodeBenJu = ui.Items[benJuScore1]
  144. bmFontScore = false
  145. end
  146. local nodeHu = ui.Items[hu]
  147. local nodeBanker= ui.Items.ImageView_Banker
  148. local nodeResult= ui.Items[result]
  149. --[[local huType = {
  150. [1] = "自摸(",
  151. [2] = "接炮(",
  152. [3] = "抢杠胡(",
  153. }--]]
  154. --[[local infoTab = {
  155. ["agang"] = "暗杠(x",
  156. ["bgang"] = "补杠(x",
  157. ["diangang_cnt"] = "点杠(x",
  158. ["mgang"] = "明杠(x",
  159. }--]]
  160. local infoStr = self:setHuType(player.nUserId)
  161. nodeResult:setText(infoStr)
  162. local userInfo = app.room:getUserInfo(player.nUserId)
  163. --先设置默认头像
  164. local width = nodeHead:getContentSize().width
  165. local nickname = ""
  166. if userInfo and userInfo.nickname then
  167. nickname = getSubStringNickname(userInfo.nickname)
  168. self:updateUserHead(nodeHead,player.nUserId, userInfo.sex, userInfo.headimgurl);
  169. end
  170. nodeName:setText(nickname)
  171. nodeHu:setVisible(false)
  172. if player.result>0 then
  173. nodeHu:setVisible(true)
  174. local orderNum = cc.Sprite:create("mj/res/ui/zy_fangjian/operate/mj_effect_num"..player.huOrder..".png")
  175. if player.result == MJDefine.MJGameHuType.HU_ZIMO then--自摸 huOrder
  176. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_zimo.png")
  177. orderNum:setPosition(cc.p(260,65))
  178. elseif player.result == MJDefine.MJGameHuType.HU_DIANPAO or player.result == MJDefine.MJGameHuType.HU_QIANGGANG then --点炮胡
  179. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_jiepao.png")
  180. orderNum:setPosition(cc.p(300,65))
  181. --nodeHu:setScale(1)
  182. end
  183. nodeHu:addChild(orderNum)
  184. end
  185. --黄庄才会查叫和查花猪
  186. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  187. if player.result <= 0 and player.isDj == 1 then
  188. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_chajiao.png")
  189. nodeHu:setVisible(true)
  190. nodeHu:setScale(0.4)
  191. end
  192. if player.result <= 0 and player.isHz == 1 then --花猪
  193. nodeHu:loadTexture("mj/res/ui/zy_fangjian/operate/mj_effect_chahuazhu.png")
  194. nodeHu:setScale(0.4)
  195. nodeHu:setVisible(true)
  196. end
  197. end
  198. if app.room:getUserIdBySeatId(app.room.roomInfo.nBankSeatId)~=player.nUserId then
  199. nodeBanker:setVisible(false)
  200. end
  201. if app.room:getMyUserId() == player.nUserId then
  202. nodeBg:loadTexture("xj_my_bg.png",cc.TextureResType.plistType)
  203. --[[else
  204. nodeBg:loadTexture("xj_other_bg.png",cc.TextureResType.plistType)--]]
  205. end
  206. if tonumber(player.nTurnScore) > 0 then
  207. nodeBenJu:setText("+"..player.nTurnScore)
  208. else
  209. nodeBenJu:setText(player.nTurnScore)
  210. if tonumber(player.nTurnScore) < 0 and bmFontScore == true then
  211. nodeBenJu:setFntFile("res/fonts/dt_jian_num.fnt")
  212. end
  213. end
  214. --番数
  215. ui.Items.Text_FanShu:setText(player.fanshu.."番")
  216. local viewId = app.room:getViewIdByUserId(player.nUserId)
  217. --local seatId = app.room:getSeatIdByViewId(viewId)
  218. if viewId and viewId>0 and viewId<=4 then
  219. if viewId == 4 then
  220. ui.Items.ImageView_Pos:loadTexture("result_pos_0.png",1)
  221. else
  222. ui.Items.ImageView_Pos:loadTexture(string.format("result_pos_%d.png", viewId), 1)
  223. end
  224. else
  225. ui.Items.ImageView_Pos:setVisible(false)
  226. end
  227. end
  228. function RoomXiaoJuView:setHuType(userId)
  229. local roomInfo = app.room.roomInfo
  230. local strGameInfo = json.decode(roomInfo.strGameInfo)
  231. local str = ""
  232. local huType1 = {
  233. [1] = "自摸(",
  234. [2] = "接炮(",
  235. [3] = "抢杠胡(",
  236. }
  237. local huOrder1 = 0
  238. local player = roomInfo.memberList[userId]
  239. if player then
  240. huOrder1 = player.huOrder
  241. --胡牌顺序
  242. if player.result == MJDefine.MJGameHuType.HU_ZIMO then
  243. local huNum = 0
  244. --快速成局时,strGameInfo.playnum默认传来的是4人
  245. if strGameInfo.isfaststart == 1 then
  246. huNum = roomInfo.nMaxPlayCount - player.huOrder
  247. else
  248. huNum = strGameInfo.playnum - player.huOrder
  249. end
  250. str = str..huType1[player.result]..huNum.."家) "
  251. elseif player.result == MJDefine.MJGameHuType.HU_DIANPAO or player.result == MJDefine.MJGameHuType.HU_QIANGGANG then
  252. local viewId = app.room:getViewIdBySeatId(player.dpSeatId)
  253. local userInfo = app.room:getUserInfoByViewId(viewId)
  254. local nickname = getSubStringNickname(userInfo.nickname)
  255. str = str..huType1[player.result]..nickname..") "
  256. end
  257. str = str .. self:getPaiTypeStr(player)
  258. if player.result > 0 then
  259. if player.isXiQian > 0 then
  260. str = str.."喜钱 "
  261. end
  262. end
  263. end
  264. return str
  265. end
  266. --合并牌型得到最终的字符串
  267. function RoomXiaoJuView:getPaiTypeStr(player)
  268. local strTab = {}
  269. for k,v in pairs(MJDefine.MJGamePaiType) do
  270. local newType = self:_and(player.huType or 0,v)
  271. if newType ~= 0 then
  272. table.insert(strTab,MJDefine.MJGameHuStr[newType] or "")
  273. end
  274. end
  275. if player.result > 0 then
  276. if player.genCount > 0 then
  277. table.insert(strTab,player.genCount.."归")
  278. end
  279. end
  280. dump(strTab)
  281. --logD(table.toString(strTab))
  282. for _,v in pairs(MJDefine.MJGameHuMargeTab) do
  283. local list = v.tab
  284. local str = v.name
  285. dump(list)
  286. local indexs= {}
  287. for _,v in pairs(list) do
  288. local index = table.indexOf(strTab, v)
  289. if index~= -1 then
  290. table.insert(indexs,index)
  291. end
  292. end
  293. if #indexs == #list then --如果都找到则合并
  294. for k,v in pairs(list) do
  295. table.removeItem(strTab,v)
  296. end
  297. -- logD(str)
  298. table.insert(strTab,str)
  299. end
  300. end
  301. local info = ""
  302. for k,v in pairs(strTab) do
  303. info = info..v.." "
  304. end
  305. return info
  306. end
  307. function RoomXiaoJuView:initWeaveCard()
  308. local roomInfo=app.room.roomInfo
  309. self.initX={}
  310. for k,v in pairs(roomInfo.memberList) do
  311. local userId = app.room:getViewIdByUserId(v.nUserId)
  312. local nSeatId = app.room:getSeatIdByViewId(userId)
  313. local i = nSeatId+1
  314. local groups={}
  315. for _,group in pairs(v.gruoupCards) do
  316. table.insert(groups,self:getChangeGruopDatas(group))
  317. end
  318. self.initX[i]=MJ_HAND_CARD_INIT_X
  319. self:createGroupCards(self.items[i].Items.Layout_Player,groups,i)
  320. self.initX[i] = self.initX[i] + 10
  321. self:createHandCards(self.items[i].Items.Layout_Player,v.handCards,i)
  322. --创建胡的牌
  323. if v.huCard and v.huCard ~= 0 then
  324. self.initX[i]=self.initX[i]+MJ_HU_X
  325. self:createHuCard(self.items[i].Items.Layout_Player,v.huCard,i)
  326. -- self:createHandCards(self.items[i].Items.Layout_Player,{{card=v.huCard}},i)
  327. end
  328. end
  329. end
  330. function RoomXiaoJuView:createHuCard(layer,card,seatId)
  331. local mj=MJ:new(card,MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  332. layer:addChild(mj)
  333. mj:setPosition(cc.p(self.initX[seatId],MJ_HAND_CARD_INIT_Y))
  334. self.initX[seatId]=self.initX[seatId]+mj:getContentSize().width+MJ_PADDING_X
  335. local flag = cc.Sprite:create("mj/res/ui/zy_fangjian/mj_hu_flag.png")
  336. mj:addChild(flag)
  337. if self.desktopType == MJDefine.DesktopType.TwoDGold then
  338. flag:setPosition(cc.p(16,40))
  339. else
  340. flag:setPosition(cc.p(16,55))
  341. end
  342. end
  343. --移除手牌胡的牌
  344. function RoomXiaoJuView:removeHuCard(player)
  345. if player.result ~= MJDefine.MJGameResultType.Win then
  346. return
  347. end
  348. for k, v in pairs(player.handCards) do
  349. if v.card == self.huCard then
  350. table.remove(player.handCards.Datas, k)
  351. return
  352. end
  353. end
  354. end
  355. -- 获取组合牌组
  356. function RoomXiaoJuView:getChangeGruopDatas(g,redNum)
  357. -- dump(g, "getChangeGruopDatas")
  358. local opType=MJDefine.MJOperateToGroupType[g.opType]
  359. local showType=MJDefine.MJOperateToGroupType[g.opType]
  360. local opCard=g.opCard
  361. local redNum = g.redNum
  362. local fromViewId = nil
  363. local targetSeatId = g.targetSeatId--操作位置座位号
  364. local fromUserId = g.opUserId or g.fromUserId --触发操作玩家
  365. if fromUserId<=0 or targetSeatId==nil then
  366. else
  367. fromViewId = app.room:transPos( targetSeatId, app.room:getSeatIdByUserId(fromUserId))
  368. --判断是否是对面玩家,对面玩家的话要做一次翻转
  369. local opViewId = app.room:getViewIdBySeatId(targetSeatId)
  370. if opViewId == 2 then --对面
  371. if fromViewId==1 then fromViewId = 3
  372. elseif fromViewId==3 then fromViewId = 1 end
  373. end
  374. --三人玩只有上下家
  375. if app.room:getMaxPlayerCount()==3 and fromViewId==2 then fromViewId = 3 end
  376. if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
  377. if showType == MJDefine.MJGroupType.Peng then
  378. fromViewId = 2
  379. else
  380. fromViewId = 4
  381. end
  382. end
  383. end
  384. --组合一下牌
  385. local group={
  386. opType=opType,
  387. showType=showType,
  388. values={},
  389. opCard = opCard,
  390. redNum = redNum,
  391. fromViewId = fromViewId
  392. }
  393. if MJDefine.MJGroupType.Chi==showType then
  394. elseif MJDefine.MJGroupType.Peng==showType then
  395. group.values={opCard,opCard,opCard}
  396. else
  397. group.values={opCard,opCard,opCard,opCard}
  398. end
  399. return group
  400. end
  401. -- 创建吃牌组合节点
  402. function RoomXiaoJuView:createChi(values,redNum)
  403. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  404. node:setAnchorPoint(cc.p(0.5,0.5))
  405. node:ignoreAnchorPointForPosition(false)
  406. local width=0
  407. local height=0
  408. for i=1,3 do
  409. if values[i] then
  410. local mj
  411. if redNum > 0 and i <= redNum then
  412. mj=MJ:new(65,MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  413. else
  414. mj=MJ:new(values[i],MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  415. end
  416. node:addChild(mj)
  417. local mjWidth=mj:getContentSize().width
  418. local mjHeight=mj:getContentSize().height
  419. local x=mjWidth/2+(i-1)*(mjWidth+MJ_PADDING_X)
  420. local y=mjHeight/2
  421. width=width+mjWidth
  422. height=mjHeight
  423. mj:setPosition(x,y)
  424. end
  425. end
  426. node:setContentSize(cc.size(width,height))
  427. return node
  428. end
  429. function RoomXiaoJuView:createGang(values,redNum)
  430. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  431. node:setAnchorPoint(cc.p(0.5,0.5))
  432. node:ignoreAnchorPointForPosition(false)
  433. local width=0
  434. local height=0
  435. for i=1,4 do
  436. if values[i] then
  437. local mj
  438. if redNum > 0 and i <= redNum then
  439. mj=MJ:new(65,MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  440. else
  441. mj=MJ:new(values[i],MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  442. end
  443. node:addChild(mj)
  444. local mjWidth=mj:getContentSize().width
  445. local mjHeight=mj:getContentSize().height
  446. local x=mjWidth/2+(i-1)*(mjWidth+MJ_PADDING_X)
  447. local y=mjHeight/2
  448. width=width+mjWidth
  449. height=mjHeight
  450. mj:setPosition(x,y)
  451. end
  452. end
  453. node:setContentSize(cc.size(width,height))
  454. return node
  455. end
  456. function RoomXiaoJuView:createAnGang(values,redNum)
  457. local node=cc.Layer:create()--Color:create(cc.c4b(255,0,0,255))
  458. node:setAnchorPoint(cc.p(0.5,0.5))
  459. node:ignoreAnchorPointForPosition(false)
  460. local width=0
  461. local height=0
  462. for i=1,4 do
  463. if values[i] then
  464. local mj
  465. if i <= 3 then
  466. mj=MJ:new(values[i],MJDefine.MJType.OutBlack,MJDefine.MyViewId,self.desktopType)
  467. else
  468. --[[if redNum > 0 then
  469. mj=MJ:new(65,MJDefine.MJType.Out,MJDefine.MyViewId)
  470. else
  471. mj=MJ:new(values[i],MJDefine.MJType.Out,MJDefine.MyViewId)
  472. end--]]
  473. mj=MJ:new(values[i],MJDefine.MJType.Out,MJDefine.MyViewId)
  474. end
  475. node:addChild(mj)
  476. local mjWidth=mj:getContentSize().width
  477. local mjHeight=mj:getContentSize().height
  478. local x=mjWidth/2+(i-1)*(mjWidth+MJ_PADDING_X)
  479. local y=mjHeight/2
  480. width=width+mjWidth
  481. height=mjHeight
  482. mj:setPosition(x,y)
  483. end
  484. end
  485. node:setContentSize(cc.size(width,height))
  486. return node
  487. end
  488. function RoomXiaoJuView:createGroupCards(layer,arg,seatId)
  489. local handlers={
  490. [MJDefine.MJGroupType.Chi]=handler(self,self.createChi),
  491. [MJDefine.MJGroupType.Peng]=handler(self,self.createChi),
  492. [MJDefine.MJGroupType.Gang]=handler(self,self.createGang),
  493. [MJDefine.MJGroupType.AnGang]=handler(self,self.createGang),
  494. }
  495. for k,v in pairs(arg) do
  496. if handlers[v.opType] then
  497. local group=handlers[v.opType](v.values,v.redNum)
  498. local w=(group:getContentSize().width-MJ_WIDTH)/2
  499. group:setPosition(cc.p(self.initX[seatId]+w,MJ_HAND_CARD_INIT_Y))
  500. if k<#arg then
  501. self.initX[seatId]=self.initX[seatId]+group:getContentSize().width+MJ_GROUP_PADDING_X
  502. else
  503. self.initX[seatId]=self.initX[seatId]+group:getContentSize().width+MJ_GROUP_PADDING_X
  504. end
  505. layer:addChild(group)
  506. end
  507. end
  508. end
  509. function RoomXiaoJuView:createHandCards(layer,arg,seatId)
  510. for k,v in pairs(arg) do
  511. local mj=MJ:new(v.card,MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  512. layer:addChild(mj)
  513. mj:setPosition(cc.p(self.initX[seatId],MJ_HAND_CARD_INIT_Y))
  514. self.initX[seatId]=self.initX[seatId]+mj:getContentSize().width+MJ_PADDING_X
  515. end
  516. end
  517. function RoomXiaoJuView:initOther()
  518. local roomInfo = app.room.roomInfo
  519. --规则
  520. local ruleAll = string.format("泸州鬼麻将 %d人 80颗(5颗起胡) 12鬼 报叫、过张升番可胡、听牌提示、一炮多响头家庄", roomInfo.nMaxPlayCount)
  521. self.ui.Items.Text_Rule:setText(ruleAll)
  522. --时间
  523. self.ui.Items.Text_SystemTime:setText(getTimeString3())
  524. --设置房间等级
  525. self.ui.Items.Text_CoinLevel:setText(CoinFunctions.getLevelDisplayText(app.room.roomInfo.serverLevel))
  526. --设置底分
  527. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  528. self.ui.Items.Text_BaseScore:setText(string.format("底分%s", gameInfo.baseScore or 50))
  529. --礼券
  530. self:changeLiquan()
  531. --隐藏二维码
  532. self.ui.Items.Image_Share:setVisible(false)
  533. local isHuangZhuang = app.room.roomInfo.stopFlag == MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG
  534. if isHuangZhuang then
  535. return
  536. end
  537. --显示输赢标题
  538. local myMemberInfo = roomInfo.memberList[app.room:getMyUserId()]
  539. if tonumber(myMemberInfo.nTurnScore) == 0 then
  540. self.ui.Items.ImageView_Title:loadTexture("mj/res/ui/zy_jingbichang/mj_coin_xiaoju_bushubuying.png")
  541. elseif tonumber(myMemberInfo.nTurnScore) > 0 then
  542. self.ui.Items.ImageView_Title:loadTexture("mj/res/ui/zy_jingbichang/mj_coin_xiaoju_niyingle.png")
  543. else
  544. self.ui.Items.ImageView_Title:loadTexture("mj/res/ui/zy_jingbichang/mj_coin_xiaoju_nishule.png")
  545. end
  546. end
  547. function RoomXiaoJuView:updateUserHead(nodeHead, nUserId, sex, headimgurl)
  548. setPlayerHeadImage(nUserId, headimgurl, nodeHead)
  549. end
  550. -- 关闭
  551. function RoomXiaoJuView:onClickClose()
  552. playBtnEffect()
  553. self.ui.Items.Layout_Sure:setVisible(true)
  554. self.ui.Items.Layout_Content:setVisible(false)
  555. end
  556. -- 关闭退出到大厅
  557. function RoomXiaoJuView:onClickCloseToHall()
  558. playBtnEffect()
  559. --self.roomInfo.isGameOver == false
  560. if app.room then
  561. self.ui:sendMsg(app.room, "callLeaveRequest")
  562. end
  563. setShowCountAll(false)
  564. local data = {
  565. gameId = GAME_IDS.LuZhouMJ or app.gameId,
  566. isCoin = true
  567. }
  568. app:gotoView(import("luaScript.Views.Main.MainView"):new(data))
  569. end
  570. -- 分享
  571. function RoomXiaoJuView:onClickShare()
  572. playBtnEffect()
  573. --分享截图时,需要显示下载的二维码
  574. --self.ui.Items.Image_Share:setVisible(true)
  575. self.ui.Items.Image_Share:setVisible(false)
  576. local fileName =
  577. cc.FileUtils:getInstance():getWritablePath() .. "gameID" .. tostring(GAME_IDS.LuZhouMJ) .. "_coin_screen.jpg"
  578. cc.FileUtils:getInstance():screenToFile(
  579. fileName,
  580. function(ret)
  581. if 1 == tonumber(ret) then
  582. local info = {}
  583. info.scene = "talk"
  584. info.contentType = "image"
  585. info.image = fileName
  586. info.imageWidth = 1000
  587. info.thumbWidth = 100
  588. app.plugin:shareGame(info)
  589. else
  590. showTooltip("截图保存失败")
  591. end
  592. end
  593. )
  594. end
  595. -- 继续游戏
  596. function RoomXiaoJuView:onClickNext()
  597. playBtnEffect()
  598. --发送离开房间
  599. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallLeaveRequest)
  600. local gameData = CoinData.getInstance():getGameData() or {}
  601. local ruleList = gameData.ruleList or {}
  602. local gameId = tonumber(app.gameId)
  603. local gameRuleInfo = ruleList[gameId]
  604. if gameRuleInfo then
  605. local serverLevel = app.room.roomInfo.serverLevel
  606. local minServerLevel = 10
  607. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  608. gameInfo.gamerule = gameInfo.gamerule or 1
  609. minServerLevel = minServerLevel + tonumber(gameInfo.gamerule)
  610. local minCoinInfo = gameRuleInfo["" .. minServerLevel]
  611. local curCoinInfo = gameRuleInfo["" .. serverLevel]
  612. if tonumber(app.user.loginInfo.curJingbiNum) < tonumber(minCoinInfo.min_money) or
  613. tonumber(app.user.loginInfo.curJingbiNum) >= tonumber(curCoinInfo.min_money)
  614. then
  615. CoinGameLogic.requestEnterCoinGame(gameId, gameInfo.gamerule, serverLevel, tonumber(curCoinInfo.min_money))
  616. else
  617. CoinGameLogic.requestEnterCoinGame(gameId, gameInfo.gamerule)
  618. end
  619. else
  620. CoinData.getInstance():requestGameServerConfig()
  621. end
  622. end
  623. function RoomXiaoJuView:d2b(arg)
  624. self.data32={}
  625. for i=1,32 do
  626. self.data32[i]=2^(32-i)
  627. end
  628. local tr={}
  629. for i=1,32 do
  630. if arg >= self.data32[i] then
  631. tr[i]=1
  632. arg=arg-self.data32[i]
  633. else
  634. tr[i]=0
  635. end
  636. end
  637. return tr
  638. end
  639. function RoomXiaoJuView:b2d(arg)
  640. local nr=0
  641. for i=1,32 do
  642. if arg[i] ==1 then
  643. nr=nr+2^(32-i)
  644. end
  645. end
  646. return nr
  647. end
  648. function RoomXiaoJuView:_and(a,b)
  649. local op1=self:d2b(a)
  650. local op2=self:d2b(b)
  651. local r={}
  652. for i=1,32 do
  653. if op1[i]==1 and op2[i]==1 then
  654. r[i]=1
  655. else
  656. r[i]=0
  657. end
  658. end
  659. local c = self:b2d(r)
  660. return c
  661. end
  662. return RoomXiaoJuView