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

2727 lines
80 KiB

  1. local MJRoomToolView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView")
  2. local MJRoomMessageView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomMessageView")
  3. local MJRoomPlayerView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView")
  4. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  5. local MJHandCardView=MJFramework.MJImport("mj.luaScript.Views.Game.MJHandCardView")
  6. local MJRoomXiaoJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomXiaoJuView")
  7. local MJRoomDaJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView")
  8. local MJRoomDismissView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDismissView")
  9. local MJRoomDirection=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection")
  10. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  11. local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  12. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  13. local MJAnimationCompnent=MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent")
  14. local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
  15. local MJSound=MJFramework.MJImport("mj.luaScript.MJSound")
  16. local MJRoomView = class("MJRoomView", cc.UIView)
  17. function MJRoomView:ctor()
  18. MJRoomView.super.ctor(self);
  19. --玩家牌局面板
  20. self.playerHandCards={}
  21. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then -- viewType只保存2d 3d类型 mj_desktop_2d_mjType保存2d麻将类型
  22. local value = loadUserInfo("mj_desktop_2d_mjType")
  23. if value=="" or not value then
  24. value = MJDefine.DesktopType.TwoD
  25. saveUserInfo("mj_desktop_2d_mjType", value)
  26. end
  27. self.desktopType = value
  28. else
  29. self.desktopType = app.systemSetting.info.viewType
  30. end
  31. cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(
  32. cc.EventListenerCustom:create("applicationScreenSizeChanged" , handler(self, self.applicationScreenSizeChanged)), 1
  33. )
  34. end
  35. function MJRoomView:onEnter()
  36. MJRoomView.super.onEnter(self)
  37. --ui load
  38. self:loadUi()
  39. self:changeGameBg()
  40. -- 初始化GPS组件
  41. self:initGpsComponent();
  42. --加载纹理缓存
  43. self:loadTextureCache()
  44. -- --初始化视图
  45. self:initView()
  46. -- --初始化游戏事件按钮
  47. self:initGameButton()
  48. --默认状态
  49. self:defaultState()
  50. -- --监听事件
  51. self:bindAllEvent()
  52. self:onGameReconnection()
  53. self:startGame()
  54. MJSound.PlayGameBGM()
  55. self:changeWaterMark()
  56. -- playLHQMusic()
  57. self:initPlayGameAgain()
  58. self:checkCanDismiss()
  59. end
  60. function MJRoomView:loadUi()
  61. local ui = loadUI("mj/res/ui/ui_fangjian/mj_ui_fangjian.ui");
  62. self.ui = ui;
  63. self:addChild(ui);
  64. end
  65. ---
  66. -- 初始化大结算再来一局
  67. -- @return
  68. --
  69. function MJRoomView:initPlayGameAgain()
  70. local strGameInfo = app.room.roomInfo.strGameInfo
  71. local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0
  72. if not isInClub then
  73. logD("IPlayGameAgain.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局");
  74. return
  75. end
  76. local clubGameInfo = json.decode(strGameInfo) or {}
  77. if not clubGameInfo.ruleid then
  78. logD("IPlayGameAgain.initPlayGameAgain", "游戏包间id不存在,不能再来一局");
  79. return
  80. end
  81. dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid)
  82. end
  83. --更换水印,不同平台水印不同,在子游戏配置里面配置图片
  84. function MJRoomView:changeWaterMark()
  85. --[[ local roomInfo = app.room.roomInfo
  86. roomInfo.gameId = roomInfo.gameId or 0
  87. local config = getSubGameConfig(roomInfo.gameId ~= 0 and roomInfo.gameId or app.gameId)
  88. if config and config.logo and self.ui.Items.ImageView_Logo then
  89. self.ui.Items.ImageView_Logo:loadTexture(config.logo,0)
  90. end
  91. if config.isShowLogo ~= nil then
  92. self.ui.Items.ImageView_Logo:setVisible(config.isShowLogo);
  93. end--]]
  94. self:initLogo()
  95. end
  96. -- 水印
  97. function MJRoomView:initLogo()
  98. if tolua.isnull(self.ui.Items.ImageView_Logo) then return end
  99. if not (type(getSubGameRoomLogo) == 'function') then--大厅不支持此方法,则隐藏logo
  100. self.ui.Items.ImageView_Logo:setVisible(false);
  101. return
  102. end
  103. local roomInfo = app.room.roomInfo
  104. local gameInfo = json.decode(roomInfo.strGameInfo or "")
  105. local gamerule = tonumber(gameInfo.gamerule or 1)
  106. roomInfo.gameId = roomInfo.gameId or MJDefine.GameID or 0
  107. local logofile = getSubGameRoomLogo(roomInfo.gameId,gamerule)
  108. if logofile then
  109. self.ui.Items.ImageView_Logo:loadTexture(logofile)
  110. self.ui.Items.ImageView_Logo:setVisible(true);
  111. else
  112. self.ui.Items.ImageView_Logo:setVisible(false);
  113. end
  114. end
  115. --更换背景 是否更新桌面参数 (设置下局生效的时候需要)
  116. function MJRoomView:changeGameBg(isUpdateViewType)
  117. if isUpdateViewType then
  118. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色
  119. local value = loadUserInfo("mj_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD
  120. if value=="" or not value then
  121. value = MJDefine.DesktopType.TwoD
  122. saveUserInfo("mj_desktop_2d_mjType", value)
  123. end
  124. logD("changeGameBg value:"..value)
  125. -- if value ~= self.desktopType then --有改变
  126. -- cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile("mj/res/ui/zy_fangjian/mj_2d.plist")
  127. -- cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile("mj/res/ui/zy_fangjian/mj_2d_gold.plist")
  128. -- end
  129. self.desktopType = value
  130. else
  131. self.desktopType = app.systemSetting.info.viewType
  132. end
  133. self:loadTextureCache()
  134. logD("changeGameBg"..self.desktopType)
  135. end
  136. --更换2D桌面
  137. if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold then
  138. local defaultValue = tonumber(loadUserInfo("mj_desktop_2d_bg")) or 1
  139. local bgData = MJDefine.DesktopBG[defaultValue]
  140. self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
  141. else
  142. local defaultValue = tonumber(loadUserInfo("mj_desktop_3d_bg")) or 1
  143. local bgData = MJDefine.DesktopBG[defaultValue]
  144. self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
  145. end
  146. end
  147. function MJRoomView:startGame()
  148. --起飞
  149. app.net:onMsgResume()
  150. end
  151. function MJRoomView:loadTextureCache()
  152. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile("res/ui/zy_fangjian/RoomMenu/RoomMenu2.plist")
  153. loadSpriteFrameFile("mj/res/ui/zy_fangjian/animation/xipai/mj_xipai.plist")
  154. local mjRes = MJDefine.MJRes[self.desktopType]
  155. if mjRes then
  156. for k,v in pairs(mjRes) do
  157. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile(v)
  158. end
  159. end
  160. end
  161. function MJRoomView:onExit()
  162. MJRoomView.super.onExit(self)
  163. if self.Time then
  164. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  165. end
  166. if self.taiPaiTimer then
  167. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.taiPaiTimer)
  168. end
  169. if self.singleComponent then
  170. self.singleComponent:exit()
  171. end
  172. app.room:dispatchEvent({name=MJDefine.MJEvent.DismissClose});
  173. stopBGMusic()
  174. self:cleanCache()
  175. end
  176. function MJRoomView:initGameButton()
  177. --听牌按钮
  178. self.ui.Items.Button_Ting:registerClick(function()
  179. playBtnEffect()
  180. self.ui.Items.Button_Ting:setVisible(false)
  181. if self.ui.Items.Layout_Card_Panel:isVisible() then
  182. self.ui.Items.Layout_Card_Panel:setVisible(false)
  183. else
  184. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  185. end
  186. end)
  187. -- self.ui.Items.ImageView_Ting_Animation:runAction(cc.RepeatForever:create(cc.RotateBy:create(1,30)))
  188. self.ui.Items.Layout_TingPai:setVisible(false)
  189. --详细按钮
  190. self.ui.Items.Button_Info:registerClick(function()
  191. playBtnEffect()
  192. self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  193. end)
  194. self.ui.Items.Button_Info:setVisible(false)
  195. --点击空白
  196. self.ui.Items.Layout_Touch:registerClick(nil,function()
  197. -- 隐藏个人信息
  198. self.playerView:removePlayerInfoView()
  199. self.ui.Items.Layout_Rule:setVisible(false)
  200. self.toolView:setMenuVisible(false,true)
  201. if self.ui.Items.Layout_Card_Panel:isVisible() and app.room:isTingStatus() then
  202. --self.ui.Items.Layout_TingPai:setVisible(true)
  203. --self.ui.Items.Button_Ting:setVisible(true)
  204. -- else
  205. end
  206. self.ui.Items.Layout_Card_Panel:setVisible(false)
  207. end)
  208. end
  209. --隐藏俱乐部
  210. function MJRoomView:hideClub()
  211. --self.ui.Items.Button_Club:setVisible(false)
  212. if self.clubView and not tolua.isnull(self.clubView) then
  213. self.clubView:removeFromParent()
  214. self.clubView=nil
  215. end
  216. end
  217. function MJRoomView:initHandCardNodes()
  218. -- local roomConfig={
  219. -- [4]={MJDefine.PlayerViewType.My,MJDefine.PlayerViewType.Left,MJDefine.PlayerViewType.Right,MJDefine.PlayerViewType.Top},
  220. -- [3]={MJDefine.PlayerViewType.My,MJDefine.PlayerViewType.Left,MJDefine.PlayerViewType.Right},
  221. -- [2]={MJDefine.PlayerViewType.My,MJDefine.PlayerViewType.Top},
  222. -- }
  223. --玩家手牌相关
  224. if MJDefine.MJRoomPlayerSitConfig[app.room:getMaxPlayerCount()] then
  225. for k,v in pairs(MJDefine.MJRoomPlayerSitConfig[app.room:getMaxPlayerCount()]) do
  226. if self.playerHandCards[v] then
  227. self.playerHandCards[v]:removeFromParent()
  228. end
  229. self.playerHandCards[v] = MJHandCardView:new(v,self.desktopType)
  230. self.ui.Items.Layout_Player:addChild(self.playerHandCards[v],v)
  231. end
  232. end
  233. -- for i=1,app.room.roomInfo.nMaxPlayCount do
  234. -- end
  235. end
  236. function MJRoomView:initView()
  237. --暂时隐藏牌数
  238. if self.ui.Items.ImageView_CardNum then
  239. self.ui.Items.ImageView_CardNum:setVisible(false)
  240. end
  241. self.direcionView = MJRoomDirection:new(self.desktopType)
  242. self.ui.Items.Layout_Player:addChild(self.direcionView)
  243. self.direcionView:setVisible(false)
  244. --加载工具层
  245. self.toolView = MJRoomToolView:new()
  246. self:addChild(self.toolView)
  247. --UI相关
  248. self.playerView = MJRoomPlayerView:new()
  249. self.toolView.ui.Items.Layout_Chat:addChild(self.playerView)
  250. self:onChangeChatEnable()
  251. --定时器
  252. self.ui.Items.Text_Time:setText(MJFunction.getTimeString())
  253. if not self.Time then
  254. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  255. self.ui.Items.Text_Time:setText(MJFunction.getTimeString())
  256. end,1.0,false)
  257. end
  258. end
  259. function MJRoomView:defaultState()
  260. --队列初始化
  261. self.callbackQueue = {}
  262. self.callbackRunning = false
  263. --等待操作的显示
  264. --删除等待操作的显示
  265. if self.waitOperates and #self.waitOperates>0 then
  266. for k,v in pairs(self.waitOperates) do
  267. v:removeFromParent()
  268. end
  269. end
  270. self.waitOperates = {}
  271. self.playerView:setOffLineVisible(false)
  272. self.playerView:setPlayerVisible(false)
  273. if self.ui.Items.Layout_Rule then
  274. self.ui.Items.Layout_Rule:setVisible(false)
  275. end
  276. self:resetGame()
  277. end
  278. --显示查听的牌
  279. function MJRoomView:setChaTingCardViewVisible(bVisible,tingCards)
  280. if true == bVisible then
  281. print("---------setChaTingCardViewVisible-----------true")
  282. else
  283. print("---------setChaTingCardViewVisible-----------false")
  284. end
  285. self.ui.Items.Layout_TingPai:setVisible(bVisible)
  286. self.ui.Items.ListView_Cha_Ting:removeAllItems()
  287. self.ui.Items.ListView_Cha_Ting:getHBar():setVisible(false)
  288. local width=47
  289. local padding=8
  290. if tingCards then
  291. self.ui.Items.Layout_Card_Panel:setVisible(true)
  292. -- self.ui.Items.Layout_Card_Panel:removeAllChildren()
  293. if #tingCards==0 then
  294. local tingWidth=47+padding*2
  295. self.ui.Items.ListView_Cha_Ting:setSize(cc.size(tingWidth,self.ui.Items.ListView_Cha_Ting:getContentSize().height))
  296. self.ui.Items.Layout_Card_Panel:setSize(cc.size(tingWidth+83,self.ui.Items.Layout_Card_Panel:getContentSize().height))
  297. local layout=cc.Layout:create()
  298. local mj=cc.Sprite:createWithSpriteFrameName("mj_img_quanting.png")
  299. layout:addChild(mj)
  300. layout:setSize(cc.size(mj:getContentSize().width+padding,self.ui.Items.ListView_Cha_Ting:getContentSize().height))
  301. self.ui.Items.ListView_Cha_Ting:pushBackCustomItem(layout)
  302. mj:setPosition(layout:getContentSize().width/2,layout:getContentSize().height/2)
  303. else
  304. local count=#tingCards>10 and 10 or #tingCards
  305. local tingWidth=count*47+padding*(count+1)
  306. self.ui.Items.ListView_Cha_Ting:setSize(cc.size(tingWidth,self.ui.Items.ListView_Cha_Ting:getContentSize().height))
  307. self.ui.Items.Layout_Card_Panel:setSize(cc.size(tingWidth+83,self.ui.Items.Layout_Card_Panel:getContentSize().height))
  308. for k,v in pairs(tingCards) do
  309. local layout=cc.Layout:create()
  310. local mj=MJ:new(v.card,MJDefine.MJType.Out,MJDefine.MyViewId)
  311. -- mj:setScale(width/mj:getContentSize().width)
  312. layout:addChild(mj)
  313. layout:setSize(cc.size(width+padding,self.ui.Items.ListView_Cha_Ting:getContentSize().height))
  314. self.ui.Items.ListView_Cha_Ting:pushBackCustomItem(layout)
  315. mj:setPosition(layout:getContentSize().width/2,layout:getContentSize().height/2)--65)
  316. --数量显示
  317. -- local mjNumImg=cc.Sprite:createWithSpriteFrameName("mj_img_ting_num_bg.png")
  318. -- mjNumImg:setAnchorPoint(cc.p(1,0))
  319. -- mjNumImg:setPosition(mj:getContentSize().width-2,5)
  320. -- mj:addChild(mjNumImg)
  321. -- local mjNum = cc.Text:createNode()
  322. -- mjNum:setDefaults()
  323. -- mjNum:setAnchorPoint(cc.p(1,0))
  324. -- local config = mjNum:getFontConfig()
  325. -- config.fontSize = 30
  326. -- config.texColor = cc.c4b(251,213,130,255)
  327. -- -- config.outlineSize = 1
  328. -- -- config.effectColor = cc.c4b(0,0,0,255)
  329. -- mjNum:setFontConfig(config)
  330. -- mjNumImg:addChild(mjNum)
  331. -- mjNum:setPosition(cc.p(38,0))
  332. -- mjNum:setString(v.count)
  333. end
  334. end
  335. else
  336. self.ui.Items.Layout_Card_Panel:setVisible(false)
  337. end
  338. end
  339. function MJRoomView:setTingCardViewVisible(bVisible,tingCards)
  340. if true == bVisible then
  341. print("---------setTingCardViewVisible-----------true")
  342. else
  343. print("---------setTingCardViewVisible-----------true")
  344. end
  345. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(bVisible)
  346. self.ui.Items.ListView_Ting:removeAllItems()
  347. self.ui.Items.ListView_Ting:getHBar():setVisible(false)
  348. -- tingCards={
  349. -- {card=0x01},
  350. -- {card=0x01},
  351. -- {card=0x01},
  352. -- {card=0x01},
  353. -- {card=0x01},
  354. -- {card=0x01},
  355. -- {card=0x01},
  356. -- {card=0x01},
  357. -- {card=0x01},
  358. -- {card=0x01},
  359. -- {card=0x01},
  360. -- {card=0x01},
  361. -- {card=0x01},
  362. -- {card=0x01},
  363. -- {card=0x01},
  364. -- {card=0x01},
  365. -- {card=0x01},
  366. -- {card=0x01},
  367. -- {card=0x01},
  368. -- {card=0x01},
  369. -- {card=0x01},
  370. -- {card=0x01},
  371. -- {card=0x01},
  372. -- {card=0x01},
  373. -- {card=0x01},
  374. -- {card=0x01},
  375. -- {card=0x01},
  376. -- {card=0x01},
  377. -- {card=0x01},
  378. -- {card=0x01},
  379. -- {card=0x01},
  380. -- {card=0x01},
  381. -- }
  382. if not tingCards then return end
  383. local width=47
  384. local padding=8
  385. if #tingCards>=27 then
  386. local tingWidth=47+padding*2
  387. self.ui.Items.ListView_Ting:setSize(cc.size(tingWidth,self.ui.Items.ListView_Ting:getContentSize().height))
  388. self.ui.Items.Layout_Ting_Tip_Card_Panel:setSize(cc.size(tingWidth+83,self.ui.Items.Layout_Ting_Tip_Card_Panel:getContentSize().height))
  389. local layout=cc.Layout:create()
  390. local mj=cc.Sprite:createWithSpriteFrameName("mj_img_quanting.png")
  391. layout:addChild(mj)
  392. layout:setSize(cc.size(mj:getContentSize().width,self.ui.Items.ListView_Ting:getContentSize().height))
  393. self.ui.Items.ListView_Ting:pushBackCustomItem(layout)
  394. mj:setPosition(layout:getContentSize().width/2,layout:getContentSize().height/2)
  395. else
  396. local count=#tingCards>10 and 10 or #tingCards
  397. local tingWidth=count*47+padding*(count+1)
  398. self.ui.Items.ListView_Ting:setSize(cc.size(tingWidth,self.ui.Items.ListView_Ting:getContentSize().height))
  399. self.ui.Items.Layout_Ting_Tip_Card_Panel:setSize(cc.size(tingWidth+83,self.ui.Items.Layout_Ting_Tip_Card_Panel:getContentSize().height))
  400. for k,v in pairs(tingCards) do
  401. local layout=cc.Layout:create()
  402. local mj=MJ:new(v.card,MJDefine.MJType.Out,MJDefine.MyViewId)
  403. layout:addChild(mj)
  404. layout:setSize(cc.size(mj:getContentSize().width+padding,self.ui.Items.ListView_Ting:getContentSize().height))
  405. -- self.ui.Items.Layout_Ting_Tip_Card_Panel:addChild(mj)
  406. self.ui.Items.ListView_Ting:pushBackCustomItem(layout)
  407. mj:setPosition(layout:getContentSize().width/2,layout:getContentSize().height/2)--65)
  408. -- mj:setScale(0.5)
  409. local mjNum = cc.Text:createNode()
  410. mjNum:setDefaults()
  411. local config = mjNum:getFontConfig()
  412. config.fontSize = 18
  413. config.texColor = cc.c4b(0x98,0xcf,0x7b,255)--cc.c4b(251,213,130,255)
  414. mjNum:setFontConfig(config)
  415. layout:addChild(mjNum)
  416. mjNum:setPosition(cc.p(mj:getPositionX(),12))
  417. --mjNum:setString("x"..v.count)
  418. mjNum:setString(string.format("%d张", v.count))
  419. end
  420. end
  421. end
  422. --隐藏提示界面
  423. function MJRoomView:setGuideView(bVisible)
  424. self.ui.Items.Layout_tips:setVisible(bVisible)
  425. if bVisible then
  426. self.ui.Items.ImageView_3:playClip("tip")
  427. end
  428. end
  429. function MJRoomView:resetGame()
  430. logE("===========重置游戏数据===============")
  431. self.direcionView:setVisible(false)
  432. self.ui.Items.Text_CardNum:setText("")
  433. -- self.playerView:setOperatorTipVisible(false)
  434. self:setBtnSitDownVisible(false)
  435. self:setTingCardViewVisible(false)
  436. self:setChaTingCardViewVisible(false)
  437. self:setGuideView(false)
  438. for k,v in pairs(self.playerHandCards) do
  439. v:removeFromParent()
  440. end
  441. self.playerHandCards={}
  442. if self.xiaojuView then
  443. self.xiaojuView:removeFromParent()
  444. self.xiaojuView=nil
  445. end
  446. --隐藏工具界面 详情
  447. -- if self.toolView.ui.Items.ImageView_Rule_bg then
  448. -- self.toolView.ui.Items.ImageView_Rule_bg:setVisible(false)
  449. -- end
  450. --操作码
  451. -- self.operationLocalCode = 0
  452. -- self.isMoPaiOperator = false
  453. -- self.isGameOver = false
  454. -- self.isTianHu = false
  455. -- self.isGodHand = false
  456. -- --重置开招次数
  457. -- for i = 1,4 do
  458. -- -- self.playerZhao[i] = 0
  459. -- end
  460. end
  461. --更新房间基础数据
  462. function MJRoomView:updateRoomBaseData()
  463. --初始化背景
  464. -- local idx2 = tonumber(loadUserInfo("lhqgameBgPicture")) or 4
  465. -- self:setTableImg(idx2)
  466. --初始化方言
  467. -- local languageType = tonumber(loadUserInfo("lhqLanguageType")) or LHQ_GAME_LANGUAGE_TYPE.FANG_YAN
  468. -- setLHQCurLanguage(languageType)
  469. local roomInfo = app.room.roomInfo;
  470. -- 房间号
  471. self.ui.Items.Text_roomNum:setText("房号:"..tostring(roomInfo.nShowTableId));
  472. --局数
  473. self:updateGameNums()
  474. --房间玩法
  475. self.toolView:updateRule()
  476. -- local ruleAll = MJWanFa.getWanFaInfo(roomInfo.strGameInfo)--getLHQRuleStr();
  477. -- self.ui.Items.Text_Rule:setText(ruleAll)
  478. --local heght=self.ui.Items.Text_Rule:getContentSize().height+20
  479. --self.ui.Items.Layout_Rule:setSize(cc.size(self.ui.Items.Layout_Rule:getContentSize().width,self.ui.Items.Text_Rule:getContentSize().height))
  480. -- self.ui.Items.Layout_Rule:doLayout()
  481. self:onUserReadyResponse()
  482. for i = 1,4 do
  483. self.playerView:updatePlayerInfo(i)
  484. end
  485. self.toolView:updateButton()
  486. -- -- 是否显示邀请好友
  487. -- self:setWetChatVisible(table.nums(app.room.roomInfo.memberList) < app.room.roomInfo.nMaxPlayCount)
  488. -- if isReviewVersion() then
  489. -- self:setWetChatVisible(false);
  490. -- end
  491. -- -- 更新玩家手牌列表时,按需显示
  492. -- if app.room.roomInfo.nGameStartCount > 0 then
  493. -- self:setWetChatVisible(false)
  494. -- --self:setBtnSitDownVisible(false)
  495. -- end
  496. end
  497. function MJRoomView:getChangeGruopDatas(g)
  498. local opType=g.opType
  499. local showType=MJDefine.MJOperateToGroupType[g.opType]
  500. local opCard=g.opCard
  501. local opFromID = g.fromUserId
  502. --组合一下牌
  503. local group={
  504. opType=opType,
  505. showType=showType,
  506. values={}
  507. }
  508. if MJDefine.MJGroupType.Chi==showType then
  509. group.values={opCard,opCard+1,opCard+2}
  510. elseif MJDefine.MJGroupType.Peng==showType then
  511. group.values={opCard,opCard,opCard}
  512. else
  513. group.values={opCard,opCard,opCard,opCard}
  514. end
  515. if opFromID then
  516. group.fromViewId = app.room:getViewIdByUserId(opFromID)
  517. end
  518. return group
  519. end
  520. function MJRoomView:onGameReconnection()
  521. -- logD("LHQ当前版本号:"..getLHQCurVersion())
  522. --更新房间基础数据
  523. local roomInfo = app.room.roomInfo;
  524. self:updateRoomBaseData()
  525. -- self:updateAllGpsInfo()
  526. -- self:checkGpsDistance(nil,roomInfo.nGameStartCount==0)
  527. -- self:checkMyGpsNeedUpdate();
  528. self.toolView:updateButton()
  529. --显示离线状态
  530. for k,v in pairs(roomInfo.memberList) do
  531. local viewId = app.room:getViewIdByUserId(k)
  532. local nOffLineState = v.nOnlineStatus
  533. self.playerView:setPlayerOffLineVisible(nOffLineState ~= MJDefine.PlayerOnlineStatus.Online,viewId)
  534. end
  535. --断线重连
  536. if roomInfo.nGameStartCount > 0 then
  537. if self._fastRequestView then
  538. self._fastRequestView:removeSelf()
  539. self._fastRequestView = nil
  540. end
  541. local function runOnGameReconnection(onEnd)
  542. --隐藏俱乐部
  543. self:hideClub()
  544. local myUserId = app.room:getMyUserId()
  545. local memberStatus ={}
  546. local dismissUserId=0
  547. for k,v in pairs(roomInfo.memberList) do
  548. local viewId = app.room:getViewIdByUserId(k)
  549. local nOffLineState = v.nOnlineStatus
  550. --显示离线
  551. self.playerView:setPlayerOffLineVisible(nOffLineState ~= MJDefine.PlayerOnlineStatus.Online,viewId)
  552. --发起解散状态的ID
  553. if v.nDisbandStatus == 1 then
  554. dismissUserId=v.nUserId
  555. end
  556. if v.nDisbandStatus ~= 0 then
  557. table.insert(memberStatus,{userId = v.nUserId , status = v.nDisbandStatus})
  558. end
  559. end
  560. --显示解散界面
  561. if roomInfo.bUserDisbandGame==1 and dismissUserId~=0 and roomInfo.isGameOver~=1 then
  562. local view = require("luaScript.Views.Room.RoomDismissView"):new(dismissUserId,roomInfo.memberList,roomInfo.nDismissStateTime)--MJRoomDismissView:new(dismissUserId)
  563. -- view:setAnchorPoint(cc.p(0.5, 0.5))
  564. self:addChild(view,1)
  565. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus})
  566. -- app:showWaitDialog(view)
  567. end
  568. --如果一局结束,玩家点了准备,不再显示牌信息
  569. if MJDefine.GameStatus.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserId].nPlayerFlag == 1
  570. or MJDefine.GameStatus.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserId].nPlayerFlag == 1
  571. then --游戏为停止或开始状态
  572. self:onUserReadyResponse({nUserId=myUserId})
  573. if onEnd then
  574. onEnd()
  575. end
  576. return
  577. end
  578. self:updateBanker()
  579. self:initHandCardNodes()
  580. --初始化方位
  581. self.direcionView:initDirection(self.desktopType)
  582. self.direcionView:updateDirection(roomInfo.outCardSeatId)
  583. --显示用户的牌
  584. for userId,v in pairs(roomInfo.memberList) do
  585. local viewId = app.room:getViewIdByUserId(userId)
  586. if self.playerHandCards[viewId] then
  587. -- logE(v.handCards)
  588. --组合一下牌
  589. local groups={}
  590. if v.gruoupCards then
  591. for _,group in pairs(v.gruoupCards) do
  592. table.insert(groups,self:getChangeGruopDatas(group))
  593. end
  594. end
  595. self.playerHandCards[viewId]:createGroupCards(groups)
  596. self.playerHandCards[viewId]:createOutCards(v.outCards)
  597. self.playerHandCards[viewId]:createHandCards(v.handCards)
  598. if userId == myUserId then
  599. self.playerHandCards[viewId]:resetHandCards()
  600. --显示听
  601. if v.nTingStatus==MJDefine.MJTingStatus.Ting then
  602. self:setChaTingCardViewVisible(true)
  603. end
  604. --设置可以出牌
  605. --[[if roomInfo.isNeedOutCard==MJDefine.NeedOutCard.Need then
  606. self.playerHandCards[viewId]:setOutCardEnable(true)
  607. end --]]
  608. end
  609. if roomInfo.needOutCardId == userId then
  610. if userId == myUserId and roomInfo.lastOpCard~=0 then
  611. self.playerHandCards[viewId]:removeHandCard(roomInfo.lastOpCard)
  612. self.playerHandCards[viewId]:resetHandCards()
  613. self.playerHandCards[viewId]:createHandCards(roomInfo.lastOpCard)
  614. end
  615. self.playerHandCards[viewId]:setOutCardEnable(true)
  616. end
  617. end
  618. end
  619. --显示出牌角标
  620. local lastOutCardViewId = app.room:getViewIdByUserId(roomInfo.lastOutCardId)
  621. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value=roomInfo.lastOutCard,viewId=lastOutCardViewId})
  622. --设置可以出牌的人
  623. -- local outCardViewId = app.room:getViewIdBySeatId(roomInfo.outCardSeatId)
  624. -- if outCardViewId then
  625. -- if (outCardViewId~=MJDefine.MyViewId and roomInfo.lastOpCard==0) or (outCardViewId == MJDefine.MyViewId or roomInfo.isNeedOutCard) then
  626. -- self.playerHandCards[outCardViewId]:setOutCardEnable(true)
  627. -- end
  628. -- end
  629. --显示听标示
  630. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  631. --如果有操作显示操作按钮
  632. self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo.operates,roomInfo.lastOpCard)
  633. --显示结算界面
  634. if roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  635. self:showOpenCard()
  636. self:showXiaoJuView()
  637. -- for k,v in pairs(roomInfo.memberList) do
  638. -- local viewId = app.room:getViewIdByUserId(v.nUserId)
  639. -- if viewId==MJDefine.MyViewId then
  640. -- --我自己则屏蔽触摸事件
  641. -- self.playerHandCards[viewId]:removeTouchEvent()
  642. -- else
  643. -- --显示所有底牌
  644. -- self.playerHandCards[viewId]:removeAllHandCards()
  645. -- self.playerHandCards[viewId]:createOpenHandCards(v.handCards)
  646. -- end
  647. -- end
  648. -- -- self:onGameXiaoJuResponse()
  649. -- self.xiaojuView = MJRoomXiaoJuView:new(roomInfo.isGameOver)
  650. -- self:addChild(self.xiaojuView)
  651. end
  652. self:setBtnSitDownVisible(false)
  653. if onEnd then
  654. onEnd()
  655. end
  656. end
  657. log("2000000000-MJRoomView - self:addCallBack(runOnGameReconnection)" )
  658. self:addCallBack(runOnGameReconnection)
  659. else
  660. -- 游戏未开始
  661. if roomInfo.nStatus and roomInfo.nStatus<MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START then
  662. --self.toolView:enableHosting(false)
  663. local quickStartInfo = roomInfo.quickStartInfo
  664. if quickStartInfo then
  665. if quickStartInfo.tablefaststate == 1 then
  666. local tmpInfo = {}
  667. for uid,status in pairs(quickStartInfo.list) do
  668. table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status})
  669. end
  670. local response = {}
  671. response.pList = tmpInfo
  672. response.timeOut = roomInfo.quickStartInfo.time
  673. self:onBroadcastFaststart({response=response})
  674. else
  675. --self.toolView:showFastStart(true)
  676. end
  677. else
  678. if self._fastRequestView then
  679. self._fastRequestView:removeSelf()
  680. self._fastRequestView = nil
  681. end
  682. --self.toolView:showFastStart(true)
  683. end
  684. end
  685. end
  686. end
  687. function MJRoomView:onClickReady()
  688. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  689. playVoice("res/sound/room/sit.ogg")
  690. self.isTouchCurScene = true
  691. end
  692. -- 邀请好友
  693. function MJRoomView:onClickFriends()
  694. playBtnEffect()
  695. local tt =
  696. {
  697. [0] = "零缺四",
  698. [1] = "一缺三",
  699. [2] = "二缺二",
  700. [3] = "三缺一",
  701. [4] = "满座",
  702. }
  703. if app.room:getMaxPlayerCount()==3 then
  704. tt =
  705. {
  706. [0] = "零缺三",
  707. [1] = "一缺二",
  708. [2] = "二缺一",
  709. [3] = "满座",
  710. }
  711. end
  712. local num = table.nums(app.room.roomInfo.memberList)
  713. local strNum = tt[num]
  714. --根据游戏类型分享
  715. local roomInfo = app.room.roomInfo;
  716. local jsonInfo = json.decode(roomInfo.strGameInfo)
  717. local mjName=getSubGameConfig(app.gameId).gameName or "麻将"
  718. local title = string.format("%s 房号[%s] %s", mjName ,app.room.roomInfo.nShowTableId,strNum) --LHQ_GAME_CONST_WANFA[jsonInfo.gamerule]
  719. --添加俱乐部ID
  720. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  721. title = string.format("%s %sID[%d]", title,PLN.CLUB_NAME, tonumber(app.club_php.clubID))
  722. end
  723. local strGameNum = string.format("%s局", app.room.roomInfo.nTotalGameNum)
  724. local strGameMode = MJWanFa.getWanFaInfo(app.room.roomInfo.strGameInfo)--getLHQRuleStr()
  725. local strNames = ""
  726. local index = 0
  727. for k,v in pairs(app.room.roomInfo.memberList) do
  728. index = index + 1
  729. local userInfo = json.decode(v.userInfo)
  730. local name = getSubStringNickname(userInfo.nickname)
  731. strNames = strNames..name
  732. if index < num then
  733. strNames = strNames..","
  734. end
  735. end
  736. local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames)
  737. print(desc)
  738. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  739. local info = {}
  740. info.scene = "talk"
  741. info.contentType = "url"
  742. info.url = app.config.Setting.appDownloadUrl
  743. info.title = title
  744. info.description = desc
  745. info.image = imagePath
  746. info.imageWidth = 100
  747. app.plugin:shareGame(info)
  748. end
  749. -- 邀请好友
  750. function MJRoomView:onClickFriends2()
  751. playBtnEffect()
  752. local tt = {
  753. [0] = "零缺四",
  754. [1] = "一缺三",
  755. [2] = "二缺二",
  756. [3] = "三缺一",
  757. [4] = "满座",
  758. }
  759. if app.room.roomInfo.nMaxPlayCount==3 then
  760. tt = {
  761. [0] = "零缺三",
  762. [1] = "一缺二",
  763. [2] = "二缺一",
  764. [3] = "满座",
  765. }
  766. end
  767. if app.room.roomInfo.nMaxPlayCount==2 then
  768. tt = {
  769. [0] = "零缺二",
  770. [1] = "一缺一",
  771. [2] = "满座",
  772. }
  773. end
  774. local num = table.nums(app.room.roomInfo.memberList)
  775. local strNum = tt[num]
  776. --根据游戏类型分享
  777. local roomInfo = app.room.roomInfo
  778. local jsonInfo = json.decode(roomInfo.strGameInfo)
  779. local mjName=getSubGameConfig(app.gameId).gameName or "麻将"
  780. local strGameNum = string.format("%s局", app.room.roomInfo.nTotalGameNum)
  781. local title = string.format("%s 房号[%s] %s %s", mjName ,app.room.roomInfo.nShowTableId, strNum, strGameNum) --LHQ_GAME_CONST_WANFA[jsonInfo.gamerule]
  782. --添加俱乐部ID
  783. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  784. title = string.format("%s 亲友圈ID[%d]", title, tonumber(app.club_php.clubID))
  785. end
  786. local strGameMode = MJWanFa.getWanFaInfo(roomInfo.strGameInfo)--getLHQRuleStr()
  787. local strNames = ""
  788. local index = 0
  789. for k,v in pairs(app.room.roomInfo.memberList) do
  790. index = index + 1
  791. local userInfo = json.decode(v.userInfo)
  792. local name = getSubStringNickname(userInfo.nickname)
  793. strNames = strNames..name
  794. if index < num then
  795. strNames = strNames..","
  796. end
  797. end
  798. local desc = string.format("%s \n玩家:%s",strGameMode, strNames)
  799. print(desc)
  800. local info = {}
  801. info.title = title
  802. info.description = desc
  803. info.copyData={type=2}
  804. local view = import("luaScript.Views.Main.ShareView"):new(info)
  805. view:setAnchorPoint(cc.p(0.5, 0.5))
  806. app:showWaitDialog(view)
  807. end
  808. --隐藏微信按钮
  809. function MJRoomView:setWetChatVisible(bVisible)
  810. -- self.toolView.ui.Items.btnInvite:setVisible(bVisible)
  811. -- self.ui.Items.Button_Invite:setVisible(bVisible)
  812. -- if app.room and app.room.roomInfo and table.nums(app.room.roomInfo.memberList) == 4 then
  813. -- self.toolView.ui.Items.Button_Ready:setPositionX(640)
  814. -- self.ui.Items.Button_Invite:setPositionX(640)
  815. -- end
  816. -- self:setInviteClubVisible(bVisible)
  817. -- self:updateButtonPosition()
  818. end
  819. --隐藏准备按钮
  820. function MJRoomView:setBtnSitDownVisible(bVisible)
  821. -- self.toolView.ui.Items.Button_Ready:setVisible(bVisible)
  822. --self.ui.Items.Button_Ready:setVisible(bVisible)
  823. -- self:updateButtonPosition()
  824. end
  825. --设置邀请亲友圈成员显示
  826. function MJRoomView:setInviteClubVisible(bVisible)
  827. if self.ui.Items.Button_Invite_Club then
  828. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  829. self.ui.Items.Button_Invite_Club:setVisible(bVisible)
  830. else
  831. self.ui.Items.Button_Invite_Club:setVisible(false)
  832. end
  833. end
  834. end
  835. function MJRoomView:showStateText()
  836. --游戏没开始状态
  837. if app.room.roomInfo.nGameStartCount <= 0 then
  838. local myUserId = app.room:getMyUserId()
  839. if app.room.roomInfo.nStartGameUid == myUserId then
  840. self.ui.Items.stateText:setText("等待其他玩家加入...");
  841. self.ui.Items.stateTextTime:setText("");
  842. else
  843. local memberInfo = app.room.roomInfo.memberList[app.room.roomInfo.nStartGameUid]
  844. if memberInfo then
  845. local userInfo = json.decode(memberInfo.userInfo)
  846. if not userInfo then
  847. return
  848. end
  849. -- 玩家名字
  850. local nickname = userInfo.nickname
  851. local intro = string.format("等待%s开始游戏",nickname)
  852. self.ui.Items.stateTextTime:setText("");
  853. self.ui.Items.stateText:setText(intro)
  854. end
  855. end
  856. end
  857. end
  858. function MJRoomView:onGameSendCardResponse()
  859. local function runGameSendCardResponse(onEnd)
  860. log("2000000000-MJRoomView - runGameSendCardResponse()" )
  861. -- if self.taiPaiTimer then
  862. -- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.taiPaiTimer)
  863. -- end
  864. --显示指示器
  865. -- local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
  866. -- self:setCircleCardLeftPanelView(true,bankerViewId,19)
  867. --发牌
  868. -- self:createCard(true,app.user.loginInfo.uid,onEnd)
  869. -- print("ding piao:"..table.tostring(app.room.roomInfo.memberList))
  870. --[[for k,v in pairs(app.room.roomInfo.memberList) do
  871. local viewId = app.room:getViewIdByUserId(v.nUserId)
  872. if self.playerHandCards[viewId] then
  873. self.playerHandCards[viewId]:createHandCards(v.handCards)
  874. self.playerHandCards[viewId]:resetHandCards()
  875. end
  876. end
  877. --]]
  878. local myUserId = app.room:getMyUserId()
  879. for k,v in pairs(app.room.roomInfo.memberList) do
  880. local viewId = app.room:getViewIdByUserId(v.nUserId)
  881. if self.playerHandCards[viewId] then
  882. self.playerHandCards[viewId]:createHandCards(v.handCards)
  883. self.playerHandCards[viewId]:resetHandCards()
  884. end
  885. if v.isBaoPai == 1 and myUserId == v.nUserId then
  886. self.playerHandCards[viewId]:showBaoPai()
  887. end
  888. end
  889. local effect=MJAnimationCompnent.CreateGameStart()
  890. self.ui.Items.Layout_Player:addChild(effect,5)
  891. -- MJSound.PlayStartGame()
  892. MJAnimationCompnent.CreateStartSendCards(self.playerHandCards,onEnd)
  893. -- if onEnd then
  894. -- onEnd()
  895. -- end
  896. end
  897. log("2000000000-MJRoomView - addCallBack(runGameSendCardResponse)" )
  898. self:addCallBack(runGameSendCardResponse);
  899. end
  900. -- 广播桌子上所有玩家庄家起手操作
  901. function MJRoomView:onBankerOutCard(data)
  902. --[[ -- 庄家uid
  903. , defVar("nUserId", VT_Int, 0)
  904. -- 庄家操作类型
  905. , defVar("mainOpCode", VT_Short, 0)
  906. --庄家是否需要出牌0不需要 1:需要
  907. , defVar("IsShouldOutCard", VT_UChar, 0)--]]
  908. local function runOnBankerOutCard(onEnd)
  909. -- log("2000000000-MJRoomView - (runOnBankerOutCard)")
  910. -- logE("name = ", data.name)
  911. logE("onBankerOutCard :"..table.tostring(data.response))
  912. -- if not data.response.nUserId then
  913. -- showTooltip("庄家起手操作nUserId is not exist")
  914. -- end
  915. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  916. local card= data.response.card
  917. local operates=data.response.operates
  918. local nSeatId=data.response.nSeatId
  919. if self.playerHandCards[viewId] then
  920. self.playerHandCards[viewId]:onGetCard(operates,card)
  921. end
  922. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  923. self:updateGameNums()
  924. self.direcionView:updateDirection(nSeatId)
  925. if onEnd then
  926. onEnd()
  927. end
  928. end
  929. log("2000000000-MJRoomView - addCallBack(runOnBankerOutCard)")
  930. self:addCallBack(runOnBankerOutCard);
  931. end
  932. function MJRoomView:onQiangGangHu(data)
  933. --[[ -- 庄家uid
  934. , defVar("nUserId", VT_Int, 0)
  935. -- 庄家操作类型
  936. , defVar("mainOpCode", VT_Short, 0)
  937. --庄家是否需要出牌0不需要 1:需要
  938. , defVar("IsShouldOutCard", VT_UChar, 0)--]]
  939. local function runOnQiangGangHu(onEnd)
  940. -- log("2000000000-MJRoomView - (runOnBankerOutCard)")
  941. -- logE("name = ", data.name)
  942. logE("runOnQiangGangHu :"..table.tostring(data.response))
  943. -- if not data.response.nUserId then
  944. -- showTooltip("庄家起手操作nUserId is not exist")
  945. -- end
  946. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  947. local opType=data.response.opType
  948. local opCard= data.response.opCard
  949. local outCardSuccess=MJMessage.OutCardSuccess:new()
  950. -- local operates=VT_Vector(MJMessage.OperateCard)
  951. local operate=MJMessage.OperateCard:new()
  952. operate.opType=opType
  953. operate.opCard=opCard
  954. table.insert(outCardSuccess.operates.Datas,operate)
  955. self.playerHandCards[MJDefine.MyViewId]:showOperate(outCardSuccess.operates,opCard)
  956. -- local operates=data.response.operates
  957. -- local nSeatId=data.response.nSeatId
  958. -- if self.playerHandCards[viewId] then
  959. -- self.playerHandCards[viewId]:onGetCard(operates,card)
  960. -- end
  961. -- self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  962. -- self:updateGameNums()
  963. -- self.direcionView:updateDirection(nSeatId)
  964. if onEnd then
  965. onEnd()
  966. end
  967. end
  968. log("2000000000-MJRoomView - addCallBack(runOnQiangGangHu)")
  969. self:addCallBack(runOnQiangGangHu);
  970. end
  971. --出牌错误
  972. function MJRoomView:onOutCardError(data)
  973. local function runOnOutCardError(onEnd)
  974. logE("MJRoomView:onOutCardError(), response = ", table.tostring(data.response))
  975. log("2000000000-MJRoomView - runOnOutCardError")
  976. --出牌错误主动上报日志
  977. uploadLogs(GAME_ERROR_TYPE.AUTO)
  978. -- --隐藏出牌效果
  979. -- self:setOutCardVisible(false)
  980. -- --恢复出的那张牌的透明度
  981. -- local index = self.ui.Items.ImageView_handTempCard.index
  982. -- self.handCardItem[index]:setOpacity(255)
  983. -- self.bOutCard = true
  984. self:requestReconnect();
  985. if onEnd then
  986. onEnd()
  987. end
  988. end
  989. log("2000000000-MJRoomView - addCallBack(runOnOutCardError)")
  990. self:addCallBack(runOnOutCardError)
  991. end
  992. function MJRoomView:onOutCard(data)
  993. local function runOnOutCard(onEnd)
  994. logE("MJRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  995. log("2000000000-MJRoomView - runOnOutCard")
  996. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  997. -- local card= data.response.card
  998. -- if self.playerHandCards[viewId] then
  999. -- self.playerHandCards[viewId]:createOutCards(card)
  1000. -- end
  1001. if onEnd then
  1002. onEnd()
  1003. end
  1004. end
  1005. log("2000000000-MJRoomView - addCallBack(runOnOutCard)")
  1006. self:addCallBack(runOnOutCard)
  1007. end
  1008. function MJRoomView:onTurnOutCard(data)
  1009. local function runOnTurnOutCard(onEnd)
  1010. logE("MJRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  1011. log("2000000000-MJRoomView - runOnOutCard")
  1012. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  1013. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1014. -- local card= data.response.card
  1015. -- if self.playerHandCards[viewId] then
  1016. -- self.playerHandCards[viewId]:createOutCards(card)
  1017. -- end
  1018. if onEnd then
  1019. onEnd()
  1020. end
  1021. end
  1022. log("2000000000-MJRoomView - addCallBack(runOnTurnOutCard)")
  1023. self:addCallBack(runOnTurnOutCard)
  1024. end
  1025. --出牌成功
  1026. function MJRoomView:onOutCardSuccess(data)
  1027. logE("MJRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  1028. --[[
  1029. -- 出牌用户id
  1030. , defVar("nOutCardUserId", VT_Int, -1)
  1031. -- 出的牌
  1032. , defVar("byOutCard", VT_UChar, -1)
  1033. -- 可以的操作ma
  1034. , defVar("mainOpCode", VT_Short, -1)
  1035. -- 玩家操作
  1036. , defVar("operations", VT_Vector(ChuPaiPlayerOperation), {})--]]
  1037. --local function runOnOutCardSuccess(onEnd)
  1038. log("2000000000-MJRoomView - runOnOutCardSuccess---------")
  1039. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1040. local card= data.response.card
  1041. local operates=data.response.operates
  1042. --local typr = operates.opType
  1043. local function callback()
  1044. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  1045. if onEnd then
  1046. onEnd()
  1047. end
  1048. end
  1049. if self.playerHandCards[viewId] then
  1050. self.playerHandCards[viewId]:onOutCard(card,callback)--onOutCard(data.response,true)
  1051. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId})
  1052. else
  1053. callback()
  1054. end
  1055. --end
  1056. log("2000000000-MJRoomView - addCallBack(runOnOutCardSuccess)")
  1057. --self:addCallBack(runOnOutCardSuccess)
  1058. end
  1059. --用户行为提示
  1060. function MJRoomView:showOperatorTip(viewId,mType)
  1061. local tip = self.allNodes[viewId].tip
  1062. tip:setVisible(true)
  1063. local nUserID = app.room:getUserIdByViewId(viewId)
  1064. playLHQVoiceOperation(mType,nUserID)
  1065. --[[if mType == LHQ_OP_TYPE.OP_TYPE_CANCEL then
  1066. tip:loadTextureFromPlist(LHQ_TIP_FILE.GUO)
  1067. --tip:setVisible(false)
  1068. elseif mType == LHQ_OP_TYPE.OP_TYPE_CHI then
  1069. tip:loadTextureFromPlist(LHQ_TIP_FILE.CHI)
  1070. elseif mType == LHQ_OP_TYPE.OP_TYPE_BI then
  1071. tip:loadTextureFromPlist(LHQ_TIP_FILE.BIPAI)
  1072. elseif mType == LHQ_OP_TYPE.OP_TYPE_PENG then
  1073. tip:loadTextureFromPlist(LHQ_TIP_FILE.PENG)
  1074. elseif mType == LHQ_OP_TYPE.OP_TYPE_MINGWEI then
  1075. tip:loadTextureFromPlist(LHQ_TIP_FILE.MINGWEI)
  1076. elseif mType == LHQ_OP_TYPE.OP_TYPE_ANWEI then
  1077. tip:loadTextureFromPlist(LHQ_TIP_FILE.ANWEI)
  1078. elseif mType == LHQ_OP_TYPE.OP_TYPE_PAO then
  1079. tip:loadTextureFromPlist(LHQ_TIP_FILE.PAO)
  1080. elseif mType == LHQ_OP_TYPE.OP_TYPE_CHONG_PAO then
  1081. tip:loadTextureFromPlist(LHQ_TIP_FILE.CHONGPAO)
  1082. elseif mType == LHQ_OP_TYPE.OP_TYPE_TI then
  1083. tip:loadTextureFromPlist(LHQ_TIP_FILE.TI)
  1084. elseif mType == LHQ_OP_TYPE.OP_TYPE_HU then
  1085. tip:loadTextureFromPlist(LHQ_TIP_FILE.HU)
  1086. tip:setVisible(false)
  1087. end
  1088. tip:setScale(3.0)
  1089. local seq = cc.Sequence:create(cc.ScaleTo:create(0.2,1),cc.DelayTime:create(0.3),cc.CallFunc:create(function ()
  1090. tip:setVisible(false)
  1091. end))
  1092. tip:runAction(seq)--]]
  1093. end
  1094. --操作错误
  1095. function MJRoomView:onOperationError(data)
  1096. local function runOnOperationError(onEnd)
  1097. log("2000000000-MJRoomView - (runOnOperationError)")
  1098. --恢复操作面板
  1099. -- self:touchEatOneCardCallBack()
  1100. if onEnd then
  1101. onEnd()
  1102. end
  1103. end
  1104. log("2000000000-MJRoomView - addCallBack(runOnOperationError)")
  1105. self:addCallBack(runOnOperationError)
  1106. end
  1107. -- 先操作玩家
  1108. function MJRoomView:onOperationFirst(data)
  1109. local function runOnOperationFirst(onEnd)
  1110. log("2000000000-MJRoomView - (runOnOperationFirst)")
  1111. local nUserId = data.response.nUserId
  1112. local viewId = app.room:getViewIdByUserId(nUserId)
  1113. if viewId == self:getMeViewId() then
  1114. --隐藏出牌面板
  1115. self:setOperatorPanelView(false,nil)
  1116. --隐藏吃牌面板
  1117. self:setEatCardView(false)
  1118. end
  1119. if onEnd then
  1120. onEnd()
  1121. end
  1122. end
  1123. log("2000000000-MJRoomView - addCallBack(runOnOperationFirst)")
  1124. self:addCallBack(runOnOperationFirst)
  1125. end
  1126. -- 操作成功
  1127. function MJRoomView:onOperationCodeSuccess(data)
  1128. --[[
  1129. -- 操作者的id
  1130. , defVar("nUserId", VT_Int, -1)
  1131. -- 牌类型
  1132. , defVar("opType", VT_Short, 0)
  1133. -- 操作的牌
  1134. , defVar("opCard", VT_UChar, 0)
  1135. -- -- 操作的牌(只有天胡时 opCard才为0)
  1136. -- , defVar("card", VT_UChar, 0)
  1137. -- 表明操作者他是否要出牌
  1138. , defVar("isNeedOutCard", VT_UChar, 0)
  1139. -- 被操作者座位Id
  1140. , defVar("formSeatId", VT_UChar, -1)
  1141. ]]
  1142. local function runOnOperationSuccess(onEnd)
  1143. log("2000000000-MJRoomView - (runOnOperationSuccess)")
  1144. logE("MJRoomView:onOperationCodeSuccess :"..table.tostring(data.response))
  1145. local response = data.response
  1146. local nUserId = response.nUserId
  1147. local opType = response.opType
  1148. local opCard = response.opCard
  1149. local bIsOutCard = response.isNeedOutCard > 0
  1150. local fromSeatId = response.fromSeatId
  1151. local viewId = app.room:getViewIdByUserId(nUserId)
  1152. local fromViewId=app.room:getViewIdBySeatId(fromSeatId)
  1153. if self.playerHandCards[viewId] then
  1154. --组合一下牌
  1155. local groups={
  1156. self:getChangeGruopDatas({opType=opType,opCard=opCard})
  1157. }
  1158. --删除手中对应的牌
  1159. local deleteCards
  1160. for k,v in pairs(groups) do
  1161. if v.showType==MJDefine.MJGroupType.Peng then
  1162. -- deleteCards={
  1163. -- {card=opCard},
  1164. -- {card=opCard},
  1165. -- }
  1166. self.playerHandCards[viewId]:removeHandCardByNum(opCard,2)
  1167. elseif v.showType==MJDefine.MJGroupType.Chi then
  1168. --TODO:吃的牌怎么删除
  1169. elseif v.showType==MJDefine.MJGroupType.AnGang then
  1170. -- deleteCards={
  1171. -- {card=opCard},
  1172. -- {card=opCard},
  1173. -- {card=opCard},
  1174. -- {card=opCard},
  1175. -- }
  1176. self.playerHandCards[viewId]:removeHandCardByNum(opCard,4)
  1177. else
  1178. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  1179. self.playerHandCards[viewId]:removeHandCardByNum(opCard,1)
  1180. else
  1181. self.playerHandCards[viewId]:removeHandCardByNum(opCard,3)
  1182. end
  1183. -- deleteCards={
  1184. -- {card=opCard},
  1185. -- {card=opCard},
  1186. -- {card=opCard},
  1187. -- }
  1188. end
  1189. end
  1190. -- if deleteCards then
  1191. -- self.playerHandCards[viewId]:removeHandCard(deleteCards)
  1192. -- end
  1193. --删除出去的牌 遍历哪些操作需要删除牌
  1194. for k,v in pairs(MJDefine.MJOperateNeedRemoveCard) do
  1195. if v==opType then
  1196. self.playerHandCards[fromViewId]:removeOutCard(opCard)
  1197. break
  1198. end
  1199. end
  1200. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  1201. self.playerHandCards[viewId]:buGang(opCard)
  1202. else
  1203. self.playerHandCards[viewId]:createGroupCards(groups,fromViewId)
  1204. end
  1205. self.playerHandCards[viewId]:resetHandCards()
  1206. self.playerHandCards[viewId]:hideOperate()
  1207. self.playerHandCards[viewId]:setOutCardEnable(bIsOutCard)
  1208. self.direcionView:updateDirection(app.room:getSeatIdByViewId(viewId))
  1209. end
  1210. --播放动画
  1211. local effect=MJAnimationCompnent.CreateOperareEffect(opType,onEnd)
  1212. if effect then
  1213. self.ui.Items.Layout_Player:addChild(effect)
  1214. effect:setLocalZOrder(1000)
  1215. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1216. else
  1217. if onEnd then
  1218. onEnd()
  1219. end
  1220. end
  1221. --音效
  1222. local userInfo=app.room:getUserInfo(nUserId)
  1223. if userInfo then
  1224. MJSound.PlayOperateSound(userInfo.sex,opType)
  1225. end
  1226. --删除等待操作的显示
  1227. if self.waitOperates and #self.waitOperates>0 then
  1228. for k,v in pairs(self.waitOperates) do
  1229. v:removeFromParent()
  1230. end
  1231. self.waitOperates={}
  1232. end
  1233. -- sprite:setPosition(640,360)
  1234. -- if onEnd then
  1235. -- onEnd()
  1236. -- end
  1237. end
  1238. log("2000000000-MJRoomView - addCallBack(runOnOperationSuccess)")
  1239. self:addCallBack(runOnOperationSuccess)
  1240. end
  1241. -- function MJRoomView:addCallBack(callback)
  1242. -- table.insert(self.callbackQueue, callback)
  1243. -- logE(" #self.callbackQueue:".. #self.callbackQueue)
  1244. -- --高延迟情况下,执行快速播放,15条是没有标准,根据实际调整的
  1245. -- --if #self.callbackQueue >= 15 then
  1246. -- --cc.Director:getInstance():getScheduler():setTimeScale(5.0)
  1247. -- --else
  1248. -- cc.Director:getInstance():getScheduler():setTimeScale(1.0)
  1249. -- --end
  1250. -- local function runFunc()
  1251. -- log("2000000000 - runNextFunc() size = ", #self.callbackQueue )
  1252. -- if #self.callbackQueue <= 0 then
  1253. -- self.callbackRunning = false
  1254. -- return
  1255. -- end
  1256. -- --logE("2000000001 - ", debug.traceback())
  1257. -- local func = self.callbackQueue[1]
  1258. -- table.remove(self.callbackQueue,1)
  1259. -- self.callbackRunning = true
  1260. -- func(function()
  1261. -- self.callbackRunning = false;
  1262. -- runFunc();
  1263. -- end)
  1264. -- end
  1265. -- log("self.callbackRunning:",self.callbackRunning)
  1266. -- if not self.callbackRunning then
  1267. -- runFunc();
  1268. -- end
  1269. -- end
  1270. -- 添加延迟回调事件,delay不传默认为0,但是需注意,排在有delay的后面事件,也会相应的跟着一起间隔
  1271. function MJRoomView:addCallBack(callback, delay)
  1272. local callbackInfo = {
  1273. callback = callback,
  1274. delay = delay or 0
  1275. }
  1276. -- 将回调放在一起管理
  1277. table.insert(self.callbackQueue, callbackInfo)
  1278. logE(" #self.callbackQueue:".. #self.callbackQueue)
  1279. cc.Director:getInstance():getScheduler():setTimeScale(1.0)
  1280. local function runFunc()
  1281. if #self.callbackQueue <= 0 then
  1282. self.callbackRunning = false
  1283. return
  1284. end
  1285. local callbackInfo = self.callbackQueue[1]
  1286. local func = callbackInfo.callback;
  1287. local delay = callbackInfo.delay;
  1288. table.remove(self.callbackQueue,1) -- 执行一个则删除一个回调
  1289. self.callbackRunning = true
  1290. local function runCallback (cb)
  1291. cb(function()
  1292. self.callbackRunning = false;
  1293. runFunc(); -- 然后继续执行下一个回调
  1294. end)
  1295. end
  1296. -- 如果有delay,那么启动全局定时器
  1297. if delay and delay > 0 then
  1298. local entryId = nil;
  1299. entryId = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  1300. runCallback(func);
  1301. if entryId then
  1302. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(entryId);
  1303. end
  1304. end, delay, false);
  1305. else
  1306. runCallback(func);
  1307. end
  1308. end
  1309. log("self.callbackRunning:",self.callbackRunning)
  1310. if not self.callbackRunning then
  1311. runFunc();
  1312. end
  1313. end
  1314. -- 其他玩家坐下成功
  1315. function MJRoomView:onOtherSitDownResponse(data)
  1316. if not data or not data.nSeatShowId then
  1317. return
  1318. end
  1319. -- local nSeatShowId = data.nSeatShowId;
  1320. -- local nUserId = app.room:getUserIdByViewId(nSeatShowId)
  1321. -- self:checkGpsDistance(nUserId,true);
  1322. self:onUserReadyResponse()
  1323. -- 是否显示邀请好友
  1324. self.toolView:updateButton()
  1325. end
  1326. function MJRoomView:onOtherLogoutResponse(data)
  1327. local jushu = app.room.roomInfo.nGameStartCount or 0
  1328. if (not data or not data.nUserId or not data.nSeatShowId) or jushu > 0 then
  1329. return
  1330. end
  1331. local function test(onEnd)
  1332. -- local memberList = app.room.roomInfo.memberList
  1333. -- memberList[data.nUserId] = nil
  1334. self.playerView:updatePlayerInfo(data.nSeatShowId)
  1335. self:onUserReadyResponse()
  1336. --更新GPS
  1337. -- self:updateAllGpsInfo()
  1338. -- self:checkGpsDistance()
  1339. self.toolView:updateButton()
  1340. if self._fastRequestView then
  1341. self._fastRequestView:removeSelf()
  1342. self._fastRequestView = nil
  1343. end
  1344. logE("88888-onOtherLogoutResponse onEnd")
  1345. if onEnd then
  1346. onEnd()
  1347. end
  1348. end
  1349. self:addCallBack(test)
  1350. end
  1351. function MJRoomView:updateGameNums()
  1352. -- 更新当前局数
  1353. -- local roomInfo = app.room.roomInfo
  1354. -- local curCount = roomInfo.nGameStartCount or 0
  1355. -- local str = string.format("局数%d/%d", curCount, roomInfo.nTotalGameNum)
  1356. -- self.ui.Items.Text_JuShu:setText(str)
  1357. --更新牌数
  1358. -- self.ui.Items.Text_CardNum:setText(roomInfo.nLeaveCardNum or 0)
  1359. -- if curCount>0 then
  1360. -- self.ui.Items.ImageView_CardNum:setVisible(false)
  1361. -- self.ui.Items.Layout_GameInfo:setVisible(true)
  1362. -- else
  1363. -- self.ui.Items.ImageView_CardNum:setVisible(false)
  1364. -- self.ui.Items.Layout_GameInfo:setVisible(false)
  1365. -- end
  1366. if self.direcionView then
  1367. self.direcionView:updateGameNums()
  1368. end
  1369. end
  1370. -- 游戏开始
  1371. function MJRoomView:onGameStartResponse()
  1372. local function runGameStartResponse(onEnd)
  1373. log("2000000000-MJRoomView - runGameStartResponse()" )
  1374. --更新背景
  1375. self:changeGameBg(true)
  1376. --隐藏俱乐部
  1377. self:hideClub()
  1378. --重置玩家数据
  1379. self:resetGame()
  1380. self:initHandCardNodes()
  1381. --写入数据
  1382. for k,v in pairs(app.room.roomInfo.memberList) do
  1383. v.nPlayerFlag = 2
  1384. end
  1385. --更新玩家状态状态
  1386. self:onUserReadyResponse()
  1387. self.toolView:updateButton()
  1388. -- 隐藏邀请好友
  1389. -- self:setWetChatVisible(false)
  1390. -- 更新局数
  1391. self:updateGameNums()
  1392. --更新庄家
  1393. self:updateBanker()
  1394. --初始化方位
  1395. self.direcionView:initDirection(self.desktopType)
  1396. self.direcionView:updateDirection(app.room.roomInfo.nBankSeatId)
  1397. --展示洗牌
  1398. local isHaveCallBack = false
  1399. local function call()
  1400. if not isHaveCallBack then
  1401. isHaveCallBack = true
  1402. logD("only one shuffle!!")
  1403. if onEnd then
  1404. onEnd()
  1405. end
  1406. end
  1407. end
  1408. local isFind = self:isHavePlayerShuffle()
  1409. if isFind then
  1410. for k,v in pairs(app.room.roomInfo.shuffleList) do
  1411. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1412. if v.bShuffle == 1 and self.playerHandCards[viewId] then
  1413. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1414. if v.bShuffle == 1 and self.playerHandCards[viewId] then
  1415. MJAnimationCompnent.CreateXiPai(self.ui.Items.Layout_Player,MJDefine.MJXiPaiConfig[viewId].position,call,viewId)
  1416. end
  1417. --[[ local effect = MJAnimationCompnent.CreateXiPai()
  1418. if effect then
  1419. self.ui.Items.Layout_Player:addChild(effect)
  1420. effect:setLocalZOrder(1000)
  1421. effect:setEulerRotation(MJDefine.MJXiPaiConfig[viewId].angle)
  1422. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1423. end--]]
  1424. end
  1425. end
  1426. else
  1427. call()
  1428. end
  1429. -- cc.Device:vibrate(5)
  1430. end
  1431. log("2000000000-MJRoomView - addCallBack(runGameStartResponse)" )
  1432. self:addCallBack(runGameStartResponse);
  1433. end
  1434. --是否有玩家洗牌
  1435. function MJRoomView:isHavePlayerShuffle()
  1436. local isFind = false
  1437. if app.room.roomInfo.shuffleList then
  1438. for k,v in ipairs(app.room.roomInfo.shuffleList) do
  1439. if v.bShuffle == 1 then
  1440. isFind = true
  1441. break
  1442. end
  1443. end
  1444. end
  1445. return isFind
  1446. end
  1447. function MJRoomView:setLiangPaiVisible(bVisible)
  1448. self.ui.Items.Layout_XiaoJu_LiangPai:setVisible(bVisible)
  1449. end
  1450. function MJRoomView:showXiaoJuView()
  1451. self.direcionView:stopAllActions()
  1452. self:setTingCardViewVisible(false)
  1453. if self.xiaojuView then
  1454. self.xiaojuView:removeFromParent()
  1455. end
  1456. local roomInfo = app.room.roomInfo
  1457. -- for k,v in pairs(roomInfo.memberList) do
  1458. -- local viewId = app.room:getViewIdByUserId(v.nUserId)
  1459. -- if self.playerHandCards[viewId] then
  1460. -- if viewId==MJDefine.MyViewId then
  1461. -- --我自己则屏蔽触摸事件
  1462. -- self.playerHandCards[viewId]:removeTouchEvent()
  1463. -- else
  1464. -- if v.result~=MJDefine.MJGameResultType.Win then --没有胡牌的玩家倒牌
  1465. -- --显示所有底牌
  1466. -- self.playerHandCards[viewId]:removeAllHandCards()
  1467. -- self.playerHandCards[viewId]:createOpenHandCards(v.handCards)
  1468. -- end
  1469. -- end
  1470. -- end
  1471. -- end
  1472. self.xiaojuView = MJRoomXiaoJuView:new(self.desktopType)
  1473. self:addChild(self.xiaojuView)
  1474. -- self:runAction(cc.Sequence:create(
  1475. -- cc.DelayTime:create(2),
  1476. -- cc.CallFunc:create(function()
  1477. -- end)
  1478. -- )
  1479. -- )
  1480. end
  1481. --倒牌
  1482. function MJRoomView:showOpenCard()
  1483. local roomInfo = app.room.roomInfo
  1484. for k,v in pairs(roomInfo.memberList) do
  1485. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1486. if viewId and self.playerHandCards[viewId] then
  1487. if viewId==MJDefine.MyViewId then
  1488. -- 我自己则屏蔽触摸事件
  1489. self.playerHandCards[viewId]:removeTouchEvent()
  1490. else
  1491. --倒牌
  1492. self.playerHandCards[viewId]:removeAllHandCards()
  1493. self.playerHandCards[viewId]:createOpenHandCards(v.handCards)
  1494. end
  1495. end
  1496. end
  1497. end
  1498. -- 小局结算
  1499. function MJRoomView:onGameXiaoJuResponse(data)
  1500. local function runGameXiaoJuResponse(onEnd)
  1501. local function callback()
  1502. self:showXiaoJuView()
  1503. if onEnd then
  1504. onEnd()
  1505. end
  1506. end
  1507. local roomInfo = app.room.roomInfo
  1508. local resultInfo=json.decode(roomInfo.strResultInfo)
  1509. self.direcionView:stopAllActions()
  1510. --如果是解散直接return
  1511. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1512. if onEnd then
  1513. onEnd()
  1514. end
  1515. return
  1516. end
  1517. --所有胡牌的人 考虑抢杠胡的问题
  1518. local viewIds={}
  1519. local failViewId=0
  1520. for k,v in pairs(roomInfo.memberList) do
  1521. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1522. if v.result==MJDefine.MJGameResultType.Win then
  1523. table.insert(viewIds,viewId)
  1524. --播放音效
  1525. if viewId==MJDefine.MyViewId then
  1526. MJSound.PlayWinGame()
  1527. end
  1528. elseif v.result==MJDefine.MJGameResultType.Fail then
  1529. failViewId=viewId
  1530. if viewId==MJDefine.MyViewId then
  1531. MJSound.PlayLoseGame()
  1532. end
  1533. end
  1534. end
  1535. self:showOpenCard()
  1536. --被抢杠的人回退补杠
  1537. if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_NORMAL then
  1538. self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard)
  1539. end
  1540. if #viewIds>0 then
  1541. for k,viewId in pairs(viewIds) do
  1542. local effect
  1543. if k == #viewIds then --只有最后播放胡牌动画的回调一次就可以了
  1544. effect=MJAnimationCompnent.CreateHuEffect(callback)
  1545. --音效
  1546. local userInfo=app.room:getUserInfoByViewId(viewId)
  1547. if userInfo then
  1548. if resultInfo.hutype==MJDefine.MJHuType.Zimo then
  1549. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU)
  1550. else
  1551. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU)
  1552. end
  1553. end
  1554. else
  1555. effect=MJAnimationCompnent.CreateHuEffect()
  1556. end
  1557. if effect then
  1558. self.ui.Items.Layout_Player:addChild(effect)
  1559. effect:setLocalZOrder(1000)
  1560. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1561. end
  1562. end
  1563. else
  1564. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  1565. local effect=MJAnimationCompnent.CreateLiuJuEffect(callback)
  1566. self.ui.Items.Layout_Player:addChild(effect)
  1567. effect:setLocalZOrder(1000)
  1568. MJSound.PlayHuangZhuang()
  1569. else
  1570. callback()
  1571. end
  1572. end
  1573. end
  1574. log("2000000000-MJRoomView - addCallBack(runGameXiaoJuResponse)" )
  1575. self:addCallBack(runGameXiaoJuResponse);
  1576. end
  1577. -- 大局结算
  1578. function MJRoomView:onGameDaJuResponse(data)
  1579. local function runGameDaJuResponse(onEnd)
  1580. local roomInfo=app.room.roomInfo
  1581. --如果是解散直接跳转总结算
  1582. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1583. self.direcionView:stopAllActions()
  1584. self:resetGame()
  1585. local view=MJRoomDaJuView:new()
  1586. view:setAnchorPoint(cc.p(0.5, 0.5))
  1587. app:showWaitDialog(view)
  1588. self:showGameOverAward()
  1589. end
  1590. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
  1591. if onEnd then
  1592. onEnd()
  1593. end
  1594. end
  1595. log("2000000000-MJRoomView - addCallBack(runGameDaJuResponse)")
  1596. self:addCallBack(runGameDaJuResponse);
  1597. end
  1598. function MJRoomView:onUserReadyResponse(response)
  1599. -- self:setPlayerVisible(false)
  1600. local uids = {}
  1601. for k,v in pairs(app.room.roomInfo.memberList) do
  1602. local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
  1603. self.playerView:setReadyStatus(nSeatShowId,v.nPlayerFlag == 1)
  1604. self.playerView:updatePlayerInfo(nSeatShowId)
  1605. uids[v.nUserId] = true
  1606. end
  1607. if self.messageView then
  1608. self.messageView:setPlayerUids(uids)
  1609. end
  1610. local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  1611. if response and response.nUserId==nUserId then
  1612. self.toolView:updateButton(true)
  1613. self:resetGame()
  1614. else
  1615. self.toolView:updateButton()
  1616. end
  1617. if response and response.nUserId==nUserId then
  1618. self:resetGame()
  1619. end
  1620. end
  1621. -- 玩家收到解散房间的请求
  1622. function MJRoomView:onDismissResponse(event)
  1623. if not event or not event.response then
  1624. return
  1625. end
  1626. logE("onDismissResponse() response = ", event.response)
  1627. local response = event.response
  1628. --当前时间
  1629. app.room.roomInfo.nDismissStateTime = response.timeLeft
  1630. --总的时间
  1631. app.room.roomInfo.nDismissToTalTime = app.room.roomInfo.nDisbandTimeout
  1632. --显示解散(此标志会影响闹钟时间会冻住)
  1633. app.room.roomInfo.nShowDismiss = true
  1634. if response.operateType == 1 then
  1635. local initiateUserId = response.nUserId
  1636. if response.memberList ~= nil then
  1637. for k,v in pairs(response.memberList) do
  1638. if v.dismissState == 1 then
  1639. initiateUserId = v.nUserId
  1640. end
  1641. end
  1642. end
  1643. --如果上次的解散界面还存在 先发送关闭事件
  1644. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE})
  1645. local view = require("luaScript.Views.Room.RoomDismissView"):new(initiateUserId,app.room.roomInfo.memberList,response.timeLeft)
  1646. view:setAnchorPoint(cc.p(0.5, 0.5))
  1647. app:showWaitDialog(view)
  1648. -- self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  1649. -- if response.memberList ~= nil then --自己发起
  1650. -- for k,v in pairs(response.memberList) do
  1651. -- if v.dismissState == 1 then
  1652. -- local view = MJRoomDismissView:new(v.nUserId);
  1653. -- view:setAnchorPoint(cc.p(0.5, 0.5));
  1654. -- app:showWaitDialog(view);
  1655. -- return
  1656. -- end
  1657. -- end
  1658. -- else --其他收到
  1659. -- local view = MJRoomDismissView:new(response.nUserId);
  1660. -- view:setAnchorPoint(cc.p(0.5, 0.5));
  1661. -- app:showWaitDialog(view);
  1662. -- end
  1663. else --如果不是发起操作则只转发状态给解散界面
  1664. local memberStatus={}
  1665. -- local userId = response.nUserId
  1666. if response.memberList ~= nil then
  1667. for k,v in pairs(response.memberList) do
  1668. table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
  1669. -- if v.dismissState == 1 then
  1670. -- initiateUserId = v.nUserId
  1671. -- end
  1672. end
  1673. else
  1674. table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
  1675. end
  1676. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus});
  1677. end
  1678. end
  1679. --更新庄家
  1680. function MJRoomView:updateBanker()
  1681. --隐藏所有的庄家标志
  1682. -- self:setBankerVisible()
  1683. --只显示当前的庄家座位号
  1684. local nBankerSeatId = app.room.roomInfo.nBankSeatId
  1685. local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
  1686. self.playerView:setBankerVisible(viewId,true)
  1687. -- if self.allNodes[viewId] then
  1688. -- self.allNodes[viewId].banker:setVisible(true)
  1689. -- else
  1690. -- showTooltip("庄家椅子号"..nBankerSeatId.."不匹配")
  1691. -- end
  1692. end
  1693. -- 更新玩家基本信息 : 昵称、头像
  1694. -- index :是玩家展示出来的座位号
  1695. function MJRoomView:updatePlayerInfo(index)
  1696. logE("MJRoomView:updatePlayerInfo() index = ", index)
  1697. local nodes = self.allNodes[index]
  1698. local nUserId = app.room.seatShowList[index]
  1699. local roomInfo = app.room.roomInfo
  1700. local memberInfo = app.room.roomInfo.memberList[nUserId]
  1701. if memberInfo then
  1702. --[[if memberInfo.nPlayerFlag == LHQ_GAME_CONST.LHQ_GAME_CONST_ONLOOKER then
  1703. return
  1704. end--]]
  1705. nodes.player:setVisible(true)
  1706. local userInfo = json.decode(memberInfo.userInfo)
  1707. if not userInfo then
  1708. return
  1709. end
  1710. -- 玩家名字
  1711. local nickname = userInfo.nickname
  1712. nickname = getSubStringNickname(nickname)
  1713. nodes.name:setText(tostring(nickname))
  1714. nodes.score:setText(tostring(memberInfo.nTotalMoney))
  1715. -- 玩家头像
  1716. local nodeHead = nodes.head;
  1717. --先设置默认头像
  1718. local width = nodeHead:getContentSize().width
  1719. setPlayerHeadImage(nUserId, userInfo.headimgurl, nodeHead)
  1720. else
  1721. nodes.player:setVisible(false)
  1722. end
  1723. end
  1724. function MJRoomView:onOtherDroppedResponse(data)
  1725. if not data.response.nUserId then
  1726. return
  1727. end
  1728. local nUserId = data.response.nUserId
  1729. local nOnlineStatus = data.response.nOnlineStatus
  1730. local viewId = app.room:getViewIdByUserId(nUserId)
  1731. self.playerView:setPlayerOffLineVisible(nOnlineStatus == MJDefine.PlayOnlineStatus.offline,viewId)
  1732. end
  1733. function MJRoomView:onUserExitResponseRoom(data)
  1734. local function runUserExitResponseRoom(onEnd)
  1735. log("2000000000-MJRoomView - runUserExitResponseRoom()" )
  1736. local response = data.response
  1737. -- 0: 不退出, 1: 退出
  1738. if response.logoutFlag == 1 then
  1739. --房间号
  1740. local roomid = app.room.roomInfo.nShowTableId
  1741. --app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId,roomid));
  1742. gotoMainView(app.gameId,roomid)
  1743. end
  1744. app.room:dispatchEvent({name = "onUserExitResponseHall"});
  1745. logE("88888-onUserExitResponseRoom onEnd")
  1746. if onEnd then
  1747. onEnd()
  1748. end
  1749. end
  1750. log("2000000000-MJRoomView - addCallBack(runUserExitResponseRoom)" )
  1751. self:addCallBack(runUserExitResponseRoom);
  1752. end
  1753. -- 服务器广播玩家数据发生变化
  1754. function MJRoomView:onGpsChangeResponse(data)
  1755. logD("MJRoomView:onGpsChangeResponse()")
  1756. if not data or not data.nUserId then
  1757. return
  1758. end
  1759. local roomInfo = app.room.roomInfo
  1760. local nUserId = data.nUserId
  1761. logD("MJRoomView:onGpsChangeResponse()", tostring(nUserId))
  1762. self:checkGpsDistance(nUserId,roomInfo.nGameStartCount==0)
  1763. end
  1764. function MJRoomView:initGpsComponent()
  1765. if cc.Application:getInstance():getTargetPlatform() == 0 then
  1766. self.ui.Items.Button_GPS:setVisible(false)
  1767. return
  1768. end
  1769. local versionCode = getAppVersionCode()
  1770. versionCode = tonumber(versionCode) or 0
  1771. logD("MJRoomView:initGpsComponent() versionCode = ", versionCode)
  1772. logD("MJRoomView:initGpsComponent() isReviewVersion = ", isReviewVersion()==true and 1 or 0)
  1773. self.singleComponent = import("luaScript.Views.Room.RoomSinglePowerComponent"):new(self.ui.Items.ImageView_Single,self.ui.Items.LoadingBar_Power)
  1774. if isReviewVersion() then -- or versionCode < 110
  1775. self.ui.Items.Button_GPS:setVisible(false)
  1776. return
  1777. end
  1778. -- 创建 gps 组件
  1779. -- self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponent"):new(self.ui.Items.Button_GPS)
  1780. local function exitRoomCallback()
  1781. local isGameStart = app.room.roomInfo.nGameStartCount > 0
  1782. if isGameStart then
  1783. app.room:requestDismissRoom(1)
  1784. else
  1785. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallLeaveRequest)
  1786. end
  1787. end
  1788. self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(4,self.ui.Items.Button_GPS,exitRoomCallback,exitRoomCallback)
  1789. self:addChild(self.gpsComponent)
  1790. -- GPS 按钮
  1791. self.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView))
  1792. -- 我的GPS数据发生变化时检测是否需要通知服务器
  1793. -- self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate))
  1794. -- self.isInitCheckGps = false
  1795. -- 进入时检测一遍我的GPS数据是否需要更新
  1796. -- self:checkMyGpsNeedUpdate()
  1797. end
  1798. -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新
  1799. -- function MJRoomView:checkMyGpsNeedUpdate(event)
  1800. -- logD("MJRoomView:checkMyGpsNeedUpdate()")
  1801. -- if self.isInitCheckGps and not event then
  1802. -- return
  1803. -- end
  1804. -- self.isInitCheckGps = true
  1805. -- local nMyUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  1806. -- local myMemberInfo = app.room.roomInfo.memberList[nMyUserId]
  1807. -- if myMemberInfo then
  1808. -- local userInfo = json.decode(myMemberInfo.userInfo)
  1809. -- if userInfo then
  1810. -- local gpsInfo = userInfo.gpsInfo
  1811. -- local isNewest = app.user:isGpsInfoNewest(gpsInfo)
  1812. -- logD("MJRoomView:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest))
  1813. -- if not isNewest then
  1814. -- app.room:onGpsChangeRequest();
  1815. -- else
  1816. -- logD("MJRoomView:checkMyGpsNeedUpdate() gpsInfo is newest")
  1817. -- end
  1818. -- else
  1819. -- logD("MJRoomView:checkMyGpsNeedUpdate() userInfo is nil")
  1820. -- end
  1821. -- else
  1822. -- logD("MJRoomView:checkMyGpsNeedUpdate() myMemberInfo is nil")
  1823. -- end
  1824. -- end
  1825. -- 更新所有玩家的信息到GPS组件
  1826. function MJRoomView:updateAllGpsInfo()
  1827. local userInfoList = {}
  1828. for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do
  1829. local nSeatId = memberInfo.nSeatId
  1830. local userInfo = memberInfo.userInfo
  1831. userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
  1832. end
  1833. if self.gpsComponent then
  1834. self.gpsComponent:updateUserInfos(userInfoList)
  1835. end
  1836. end
  1837. -- 检测玩家与其他玩家之间的距离
  1838. -- 如果不传参数,则检测所有玩家相互之间的距离
  1839. -- function MJRoomView:checkGpsDistance(curUserId,isOpenGpsView)
  1840. -- --if app.room.roomInfo.nGameStartCount > 0 then
  1841. -- -- return
  1842. -- --end
  1843. -- self:updateAllGpsInfo()
  1844. -- if self.gpsComponent then
  1845. -- local isDanger = self.gpsComponent:checkGpsDistance(curUserId)
  1846. -- if isDanger and isOpenGpsView then
  1847. -- self:showGpsView()
  1848. -- showTooltip("玩家距离过近或者未开启GPS!")
  1849. -- end
  1850. -- end
  1851. -- end
  1852. -- 显示GPS界面
  1853. function MJRoomView:showGpsView()
  1854. logD("MJRoomView:showGpsView()")
  1855. playBtnEffect()
  1856. local isGameStart = app.room.roomInfo.nGameStartCount > 0
  1857. -- self:updateAllGpsInfo()
  1858. if self.gpsComponent then
  1859. self.gpsComponent:showGpsView(isGameStart)
  1860. end
  1861. end
  1862. function MJRoomView:onTingCardStatus()
  1863. local myUserId=app.user.loginInfo.uid
  1864. local memberList=app.room.roomInfo.memberList
  1865. print("---------onTingCardStatus-----------")
  1866. dump(myUserId)
  1867. dump(memberList[myUserId])
  1868. if memberList[myUserId] then
  1869. local nTingStatus=memberList[myUserId].nTingStatus
  1870. if nTingStatus == MJDefine.MJTingStatus.Ting then
  1871. print("---------onTingCardStatus-----------1")
  1872. self:setChaTingCardViewVisible(true)
  1873. else
  1874. print("---------onTingCardStatus-----------0")
  1875. self:setChaTingCardViewVisible(false)
  1876. end
  1877. end
  1878. end
  1879. function MJRoomView:onTingCardResult(data)
  1880. if data.response.tingType==MJDefine.MJTingType.QuanTing then
  1881. self:setChaTingCardViewVisible(true,{})
  1882. else
  1883. self:setChaTingCardViewVisible(true,data.response.tingCards)
  1884. end
  1885. end
  1886. function MJRoomView:showTing(evet)
  1887. local roomInfo=app.room.roomInfo
  1888. if evet.card and roomInfo.tings and roomInfo.tings[evet.card] then
  1889. self:setTingCardViewVisible(true,roomInfo.tings[evet.card])
  1890. else
  1891. self:setTingCardViewVisible(false)
  1892. end
  1893. end
  1894. function MJRoomView:pushTing()
  1895. local function runPushTing(onEnd)
  1896. log("2000000000-MJRoomView - runPushTing()" )
  1897. if self.playerHandCards[MJDefine.MyViewId] then
  1898. self.playerHandCards[MJDefine.MyViewId]:pushTing()
  1899. end
  1900. if onEnd then
  1901. onEnd()
  1902. end
  1903. end
  1904. log("2000000000-MJRoomView - addCallBack(runPushTing)" )
  1905. self:addCallBack(runPushTing);
  1906. end
  1907. function MJRoomView:onBroadcastFaststart(data)
  1908. local response = data.response
  1909. local remove = false
  1910. if response.nUserId and response.nStatus then
  1911. if response.nStatus == 3 or response.nStatus>4 then
  1912. remove = true
  1913. end
  1914. end
  1915. if not remove then
  1916. for _,v in ipairs(response.pList) do
  1917. if v.nStatus == 3 or v.nStatus>4 then
  1918. remove = true
  1919. end
  1920. end
  1921. end
  1922. if response.timeOut <=0 then remove = true end
  1923. if self._fastRequestView == nil then
  1924. if remove then return "" end
  1925. local requesterId = 0
  1926. for _,v in ipairs(response.pList) do
  1927. if v.nStatus == 1 then
  1928. requesterId = v.nUserId
  1929. end
  1930. end
  1931. if requesterId<=0 then return "" end
  1932. local view = import("mj.luaScript.Views.Room.MJRequestStartView"):new(requesterId)
  1933. view:setAnchorPoint(cc.p(0.5, 0.5))
  1934. view:showItems(response)
  1935. app:showWaitDialog(view)
  1936. self._fastRequestView = view
  1937. else
  1938. if remove then
  1939. local userInfo = app.room.roomInfo.memberList[response.nUserId]
  1940. self._fastRequestView:removeSelf()
  1941. self._fastRequestView = nil
  1942. if userInfo then
  1943. local u = json.decode(userInfo.userInfo)
  1944. local txt = string.format("玩家【%s】拒绝立即开局", u.nickname)
  1945. showTooltip(txt)
  1946. end
  1947. app.room:resetFastInfo()
  1948. --self.toolView:showFastStart(true)
  1949. else
  1950. self._fastRequestView:updateView(response)
  1951. end
  1952. end
  1953. end
  1954. function MJRoomView:onFastStartSucc(data)
  1955. if self._fastRequestView then
  1956. self._fastRequestView:removeSelf()
  1957. self._fastRequestView = nil
  1958. end
  1959. --self.toolView:showFastStart(false)
  1960. self.playerView:setPlayerVisible(false)
  1961. self:updateRoomBaseData()
  1962. end
  1963. function MJRoomView:onWaitOperate(data)
  1964. --等待操作的UID
  1965. local nUserId = data.response.nUserId
  1966. --操作类型
  1967. local opType = data.response.opType
  1968. local viewId = app.room:getViewIdByUserId(nUserId)
  1969. local waitSprite = nil
  1970. if opType==MJDefine.MJOperateType.OPREATE_PENG then
  1971. waitSprite = cc.Sprite:create("mj/res/ui/zy_fangjian/operate/mj_effect_wait_peng.png")
  1972. elseif opType==MJDefine.MJOperateType.OPREATE_ZHIGANG or opType==MJDefine.MJOperateType.OPREATE_BAGANG or opType==MJDefine.MJOperateType.OPREATE_ANGANG then
  1973. waitSprite = cc.Sprite:create("mj/res/ui/zy_fangjian/operate/mj_effect_wait_gang.png")
  1974. elseif opType==MJDefine.MJOperateType.OPREATE_DIANPAOHU or opType==MJDefine.MJOperateType.OPREATE_QIANG_GANG_HU then
  1975. waitSprite = cc.Sprite:create("mj/res/ui/zy_fangjian/operate/mj_effect_wait_hu.png")
  1976. end
  1977. if waitSprite then
  1978. self.ui.Items.Layout_Player:addChild(waitSprite)
  1979. waitSprite:setLocalZOrder(1000)
  1980. waitSprite:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1981. table.insert(self.waitOperates,waitSprite)
  1982. end
  1983. end
  1984. function MJRoomView:bindAllEvent()
  1985. --[[
  1986. 消息分类管理
  1987. ]]
  1988. --用户状态(包括准备,其他玩家进入或者离开通知,离线等)
  1989. self:bindUserStatedMessage()
  1990. --私人场消息(包括解散等)
  1991. self:bindPrivateMessage()
  1992. --游戏消息
  1993. self:bindGameMessage()
  1994. --游戏场景消息
  1995. self:bindGameSceneMessage()
  1996. --更换视图
  1997. -- self:bindEvent(app , MJDefine.MJEvent.ChangeViewType , handler(self , self.onChangeViewType));
  1998. self:bindEvent(app , MJDefine.MJEvent.ChangeViewBG , handler(self , self.onChangeViewBG));
  1999. -- self:bindEvent(app , MJDefine.MJEvent.ChangeChatEnable , handler(self , self.onChangeChatEnable));
  2000. --绑定更换桌布事件
  2001. -- self:bindEvent(app , "onChangeTable" , handler(self , self.onChangeTable));
  2002. --发送道具
  2003. -- self:bindEvent(app.room,"showProp" , handler(self , self.showProp));
  2004. self:bindExtendMessage()
  2005. end
  2006. function MJRoomView:onChangeViewType(event)
  2007. if self.desktopType ~= event.desktopType then
  2008. self.desktopType = event.desktopType
  2009. end
  2010. end
  2011. function MJRoomView:onChangeViewBG(event)
  2012. self:changeGameBg()
  2013. end
  2014. function MJRoomView:onChangeChatEnable()
  2015. if not self.messageView or tolua.isnull(self.messageView) then
  2016. return
  2017. end
  2018. local voiceEnable = tonumber(loadUserInfo("voiceEnable")) or 1
  2019. local propEnable = tonumber(loadUserInfo("propEnable")) or 1
  2020. self.messageView:setVoiceEnabled(voiceEnable==1)
  2021. self.messageView:setPropEnabled(propEnable==1)
  2022. end
  2023. --绑定扩展消息
  2024. function MJRoomView:bindExtendMessage()
  2025. end
  2026. --用户状态消息
  2027. function MJRoomView:bindUserStatedMessage()
  2028. --默认状态
  2029. self:bindEvent(app.room , "defaultState" , handler(self , self.defaultState));
  2030. -- 玩家准备
  2031. self:bindEvent(app.room , MJDefine.MJEvent.UserReadyResponse , handler(self , self.onUserReadyResponse));
  2032. -- 其他玩家进入房间
  2033. self:bindEvent(app.room , MJDefine.MJEvent.OtherSitDownResponse , handler(self , self.onOtherSitDownResponse));
  2034. -- 其他玩家退出房間
  2035. self:bindEvent(app.room , MJDefine.MJEvent.OtherLogoutResponse , handler(self , self.onOtherLogoutResponse));
  2036. -- 其他玩家掉线
  2037. self:bindEvent(app.room , MJDefine.MJEvent.OtherDroppedResponse , handler(self , self.onOtherDroppedResponse));
  2038. -- 用户T出
  2039. self:bindEvent(app.room , MJDefine.MJEvent.UserExitResponseRoom , handler(self , self.onUserExitResponseRoom));
  2040. -- 玩家的GPS信息发生变化
  2041. self:bindEvent(app.room , MJDefine.MJEvent.GpsChangeResponse , handler(self , self.onGpsChangeResponse));
  2042. end
  2043. --私人场消息
  2044. function MJRoomView:bindPrivateMessage()
  2045. -- 玩家收到解散房间的请求
  2046. self:bindEvent(app.room , MJDefine.MJEvent.DismissResponse , handler(self , self.onDismissResponse));
  2047. end
  2048. --游戏消息
  2049. function MJRoomView:bindGameMessage()
  2050. -- 游戏开始
  2051. self:bindEvent(app.room , MJDefine.MJEvent.GameStartResponse , handler(self , self.onGameStartResponse));
  2052. -- 开始给桌子上用户发牌
  2053. self:bindEvent(app.room , MJDefine.MJEvent.GameSendCardResponse , handler(self , self.onGameSendCardResponse));
  2054. -- 系统发给自己可串可哨的消息
  2055. -- self:bindEvent(app.room , "onSystemOperationStart" , handler(self , self.onSystemOperationStart));
  2056. -- 广播桌子上所有玩家庄家起手操作
  2057. self:bindEvent(app.room , MJDefine.MJEvent.BankerOutCard, handler(self , self.onBankerOutCard));
  2058. -- 出牌错误
  2059. self:bindEvent(app.room , MJDefine.MJEvent.OutCardError , handler(self , self.onOutCardError));
  2060. -- 出牌成功
  2061. self:bindEvent(app.room , MJDefine.MJEvent.OutCardSuccess, handler(self , self.onOutCardSuccess));
  2062. self:bindEvent(app.room , MJDefine.MJEvent.TurnOutCard , handler(self , self.onTurnOutCard));
  2063. -- 抢杠胡
  2064. self:bindEvent(app.room , MJDefine.MJEvent.QiangGangHu, handler(self , self.onQiangGangHu));
  2065. -- 弃牌
  2066. self:bindEvent(app.room , MJDefine.MJEvent.OutCardResponse , handler(self , self.onOutCard));
  2067. -- 操作错误
  2068. self:bindEvent(app.room , MJDefine.MJEvent.OperationError, handler(self , self.onOperationError));
  2069. -- 先操作玩家
  2070. -- self:bindEvent(app.room , "onOperationFirst", handler(self , self.onOperationFirst));
  2071. -- 操作成功
  2072. self:bindEvent(app.room , MJDefine.MJEvent.OperationCodeSuccess , handler(self , self.onOperationCodeSuccess));
  2073. -- 听牌
  2074. self:bindEvent(app.room , MJDefine.MJEvent.TingSatus, handler(self , self.onTingCardStatus));
  2075. self:bindEvent(app.room , MJDefine.MJEvent.TingResult, handler(self , self.onTingCardResult));
  2076. self:bindEvent(app.room , MJDefine.MJEvent.ShowTing, handler(self , self.showTing));
  2077. self:bindEvent(app.room , MJDefine.MJEvent.PushTing, handler(self , self.pushTing));
  2078. self:bindEvent(app.room , MJDefine.MJEvent.WaitOperate, handler(self , self.onWaitOperate))
  2079. -- 听牌
  2080. -- self:bindEvent(app.room , "onDaiXing",handler(self , self.onDaiXing));
  2081. --弃胡通知自己
  2082. -- self:bindEvent(app.room , "onQiHuSelfResponese",handler(self , self.onQiHuSelfResponese));
  2083. --弃胡通知其他
  2084. -- self:bindEvent(app.room , "onOtherQiHuTongZhi",handler(self , self.onOtherQiHuTongZhi));
  2085. self:bindEvent(app.room , MJDefine.MJEvent.BraodcastFastStart , handler(self , self.onBroadcastFaststart));
  2086. self:bindEvent(app.room , MJDefine.MJEvent.FastStartSucc , handler(self , self.onFastStartSucc));
  2087. self:bindEvent(app.room , MJDefine.MJEvent.GameXiaoJuResponse , handler(self , self.onGameXiaoJuResponse));
  2088. self:bindEvent(app.room , MJDefine.MJEvent.GameDaJuResponse , handler(self , self.onGameDaJuResponse));
  2089. -- user pass
  2090. self:bindEvent(app.room , MJDefine.MJEvent.USER_PASS, handler(self, self.onUserPassRequest))
  2091. end
  2092. --场景恢复
  2093. function MJRoomView:bindGameSceneMessage()
  2094. local function onEnterRoomSuccess(event)
  2095. if tolua.isnull(self.ui) then
  2096. logE("self.is null")
  2097. return
  2098. end
  2099. local roomInfo = app.room.roomInfo
  2100. local myUserId = app.room:getMyUserId()
  2101. for userId,v in pairs(roomInfo.memberList) do
  2102. local viewId = app.room:getViewIdByUserId(userId)
  2103. --出牌瞬间重连,会先收到重连消息再收到出牌成功,导致多一张牌,这时要在出牌成功那里删一次牌
  2104. if self.playerHandCards[viewId] and v.handCards and type(v.handCards) == 'table' then
  2105. if userId == myUserId then
  2106. local rHandCards = #v.handCards
  2107. local curHandCards = self.playerHandCards[viewId]:getHandCardsNum()
  2108. if curHandCards+1 == rhandCards then
  2109. self.needDeleteOutCard = true
  2110. end
  2111. end
  2112. end
  2113. end
  2114. self:stopAllActions()
  2115. self:defaultState()
  2116. self:onGameReconnection()
  2117. self:startGame()
  2118. end
  2119. app.hall:addEventListener("onEnterRoomSuccess", onEnterRoomSuccess)
  2120. end
  2121. --按钮位置调整
  2122. function MJRoomView:updateButtonPosition()
  2123. if not self.ui.Items.Layout_Button then return end
  2124. --if not self.ui.Items.Button_Invite_Club then return end
  2125. self.ui.Items.Button_Ready:getParent():setVisible(self.ui.Items.Button_Ready:isVisible())
  2126. --self.ui.Items.Button_Invite:getParent():setVisible(self.ui.Items.Button_Invite:isVisible())
  2127. if self.ui.Items.Button_Invite_Club then
  2128. self.ui.Items.Button_Invite_Club:getParent():setVisible(self.ui.Items.Button_Invite_Club:isVisible())
  2129. end
  2130. if self.ui.Items.Layout_Button then
  2131. self.ui.Items.Layout_Button:requestDoLayout()
  2132. self.ui.Items.Layout_Button:doLayout()
  2133. end
  2134. end
  2135. --
  2136. function MJRoomView:onClickInviteClub()
  2137. playBtnEffect()
  2138. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  2139. local roomInfo = app.room.roomInfo;
  2140. if roomInfo and roomInfo.nShowTableId then
  2141. local strInvite = MJFunction.getClubInviteWanFa(roomInfo.gameId or app.gameId, roomInfo)
  2142. local view = import("luaScript.Views.Club.ClubInvite"):new(roomInfo.nShowTableId, strInvite)
  2143. view:setAnchorPoint(cc.p(0.5, 0.5))
  2144. app:showWaitDialog(view)
  2145. end
  2146. end
  2147. end
  2148. --托管状态,服务器下发过操作,客户端隐藏操作界面
  2149. function MJRoomView:onUserPassRequest( data )
  2150. local response = data.response
  2151. if app.room:getMyUserId() == response.nUserId then
  2152. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  2153. end
  2154. end
  2155. -- =========================================== 合并框架新方法 ==============================================
  2156. ---
  2157. -- 根据规则弹出规则,目前每次登陆
  2158. -- @return boolean
  2159. --
  2160. function MJRoomView:getIsNeedShowRule()
  2161. local key = "AutoShowRule_"..app.gameId
  2162. if not app[key] then
  2163. app[key] = true
  2164. return true
  2165. else
  2166. return false
  2167. end
  2168. end
  2169. ---
  2170. -- 清除lua缓存
  2171. -- @return
  2172. --
  2173. function MJRoomView:cleanCache()
  2174. local clearList = {'mj.luaScript', 'mj_hsb.luaScript'};
  2175. local subGameConfig=getSubGameConfig(app.gameId) or {}
  2176. table.insert(clearList, subGameConfig.rootName)
  2177. while (subGameConfig and subGameConfig.fremworkId and subGameConfig.fremworkId > 0) do
  2178. subGameConfig = getSubGameConfig(subGameConfig.fremworkId)
  2179. if not subGameConfig or not subGameConfig.rootName then
  2180. break
  2181. end
  2182. table.insert(clearList, subGameConfig.rootName)
  2183. end
  2184. local preload = package.loaded
  2185. for luaPath, _ in pairs(package.loaded or {}) do
  2186. for __, str in ipairs(clearList or {}) do
  2187. local res = string.find( luaPath, str) or 0
  2188. if res > 0 then
  2189. package.loaded[luaPath] = nil
  2190. end
  2191. end
  2192. end
  2193. end
  2194. -- 分辨率改变回调(针对部分机型切后台后,导致牌数据位置不对(宽高分辨率对调了))
  2195. function MJRoomView:applicationScreenSizeChanged()
  2196. print('MJRoomView:applicationScreenSizeChanged')
  2197. if not self then
  2198. print('MJRoomView:applicationScreenSizeChanged return not self')
  2199. return
  2200. end
  2201. if tolua.isnull(self) then
  2202. print('MJRoomView:applicationScreenSizeChanged return tolua.isnull(self)')
  2203. return
  2204. end
  2205. -- 出现小局不请求重连
  2206. -- if self.xiaojuView and self.xiaojuView:isVisible() then
  2207. -- print('MJRoomView:applicationScreenSizeChanged return self.xiaojuView is showing')
  2208. -- return
  2209. -- end
  2210. local callFunc = function(onEnd)
  2211. if self.playerHandCards[MJDefine.MyViewId].isUseNew3D then
  2212. if self.playerHandCards[MJDefine.MyViewId]:isUseNew3D() then
  2213. MJDefine.loadMJConfig(self.desktopType)
  2214. end
  2215. end
  2216. self:requestReconnect()
  2217. if onEnd then
  2218. onEnd()
  2219. end
  2220. end
  2221. local winSize = cc.Director:getInstance():getWinSize()
  2222. for i, v in pairs(self.playerHandCards) do
  2223. if v:getHandCardPosInitY() > winSize.height then
  2224. self:addCallBack(callFunc)
  2225. break
  2226. end
  2227. end
  2228. end
  2229. -- 请求重连
  2230. function MJRoomView:requestReconnect()
  2231. if not MJDefine then
  2232. return
  2233. end
  2234. if not MJDefine.MJEvent then
  2235. return
  2236. end
  2237. if not MJDefine.MJEvent.GetTableInfo then
  2238. return
  2239. end
  2240. self.ui:sendMsg(app.room,MJDefine.MJEvent.GetTableInfo)
  2241. end
  2242. ---
  2243. -- 显示抽奖界面
  2244. --
  2245. function MJRoomView:showGameOverAward()
  2246. if not (dd and dd.IGameOverAward) then
  2247. return
  2248. end
  2249. self:runDelay(0.1, function ( )
  2250. -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
  2251. dd.IGameOverAward.showAwardView();
  2252. end)
  2253. end
  2254. ---
  2255. -- 检测是否可以解散房间
  2256. -- @param
  2257. -- @return
  2258. --
  2259. function MJRoomView:checkCanDismiss( )
  2260. local onCanDismissCallback = function (info)
  2261. local nUserId = app.room:getMyUserId()
  2262. local roomInfo = app.room.roomInfo or {}
  2263. local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin()
  2264. if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
  2265. canDismiss = false
  2266. end
  2267. self:onCanDismissCallback(canDismiss)
  2268. end
  2269. if dd.IClub.getCanDismiss then
  2270. local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback)
  2271. if canDismiss then
  2272. onCanDismissCallback({canDismiss = canDismiss})
  2273. end
  2274. end
  2275. end
  2276. function MJRoomView:onCanDismissCallback(canDismiss)
  2277. if not self.toolView then
  2278. return
  2279. end
  2280. if self.toolView.ui.Items.Button_Dismiss then
  2281. self.toolView.ui.Items.Button_Dismiss:setEnabled(canDismiss)
  2282. end
  2283. end
  2284. return MJRoomView