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.

2798 lines
86 KiB

  1. require("luaScript.Views.Room.RoomFunctions")
  2. local MJRoomToolView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView")
  3. local MJRoomMessageView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomMessageView")
  4. local MJRoomPlayerView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView")
  5. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  6. local MJHandCardView=MJFramework.MJImport("mj.luaScript.Views.Game.MJHandCardView")
  7. local MJRoomXiaoJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomXiaoJuView")
  8. local MJRoomDaJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView")
  9. local MJRoomDismissView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDismissView")
  10. local MJRoomDirection=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection")
  11. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  12. local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  13. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  14. local MJAnimationCompnent=MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent")
  15. local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
  16. local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
  17. local MJRoomView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomView")
  18. local zigong7zRoomView = class("zigong7zRoomView", cc.UIView)
  19. local zhongNiaoTime = 1.33
  20. local HU_EFFECT_TAG = 100
  21. -- 组件相关
  22. local GPS_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_GPS_Component'
  23. local Single_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_Single_Component'
  24. local RoomInfo_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_RoomHeadInfo_Component'
  25. local LastCardTip_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_LastCardTip_Component'
  26. local Reconnect_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_Reconnect_Component'
  27. local Operate_Component = 'mj_zigong7z.luaScript.Views.Component.zigong7z_Operate_Component'
  28. function zigong7zRoomView:ctor()
  29. zigong7zRoomView.super.ctor(self)
  30. -- value
  31. self.ui = nil
  32. self._gps = nil
  33. self._singleComponent = nil
  34. self._roomHeadInfo = nil
  35. self._lastCardTip = nil
  36. self._ruleView = nil
  37. self._reconnnet = nil
  38. self._operateComponent = nil
  39. self.playerHandCards={} -- 玩家牌局面板
  40. self.operates = {}
  41. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then -- viewType只保存2d 3d类型 mj_desktop_2d_mjType保存2d麻将类型
  42. local value = loadUserInfo("mj_desktop_2d_mjType")
  43. local value = loadUserInfo("mj_zg_desktop_2d_mjType")
  44. if value=="" or not value then
  45. value = MJDefine.DesktopType.ThreeD
  46. saveUserInfo("mj_desktop_2d_mjType", value)
  47. saveUserInfo("mj_zg_desktop_2d_mjType", value)
  48. end
  49. self.desktopType = value
  50. else
  51. self.desktopType = app.systemSetting.info.viewType
  52. end
  53. cc.Director:getInstance():getEventDispatcher():addEventListenerWithFixedPriority(
  54. cc.EventListenerCustom:create("applicationScreenSizeChanged" , handler(self, self.applicationScreenSizeChanged)), 1
  55. )
  56. MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
  57. end
  58. -- 加载ui
  59. function zigong7zRoomView:loadUi()
  60. local ui = loadUI("mj_zigong7z/res/ui_fangjian/mj_zigong_roomView.ui")
  61. self.ui = ui
  62. self:addChild(ui)
  63. end
  64. function zigong7zRoomView:onEnter()
  65. zigong7zRoomView.super.onEnter(self)
  66. self:loadUi() -- 加载UI
  67. self:initAllComponent() -- 加载所有组件
  68. self:loadTextureCache() --加载纹理缓存
  69. self:defaultState() -- 默认状态
  70. self:bindAllEvent() --监听事件
  71. self:onGameReconnection() -- 初始化重连(如果有重连则会回复重连状态)
  72. self:initDefaultValue()
  73. self:startGame() -- 游戏开始
  74. end
  75. -- 初始化所有组件
  76. function zigong7zRoomView:initAllComponent()
  77. self:initRoomHeadInfo() -- 初始化桌面信息面板
  78. self:initGpsComponent() -- 初始化GPS组件
  79. self:initSingleComponent() -- 初始化电池和信号组件
  80. self:initDirectionComponent() -- 初始化方位组件
  81. self:initToolComponent() -- 初始化工具组件
  82. self:initPlayerComponent() -- 初始化玩家组件
  83. self:initRuleComponent() -- 初始化规则面板
  84. self:initLastCardTipsComponent() -- 初始化剩余牌提示面板
  85. self:initOperateComponent() -- 初始化操作界面组件
  86. self:initReconnectComponent() -- 初始化重连组件
  87. self:initDefaultView() --初始化默认视图
  88. self:initPlayGameAgain() -- 初始化大解散再来一局按钮
  89. self:checkCanDismiss() -- 检查是否可以解散房间
  90. end
  91. -- 初始化默认值
  92. function zigong7zRoomView:initDefaultValue()
  93. self:setCheckDefault() -- 设置是否贴鬼杠和是否自动对齐
  94. self:changeWaterMark() -- 水印
  95. MJSound.PlayGameBGM() -- 启动BGM
  96. self:doSound() -- 设置语言
  97. end
  98. -- 初始化信息面板
  99. function zigong7zRoomView:initRoomHeadInfo()
  100. local roomHeadInfo = require(RoomInfo_Component):new()
  101. self:addChild(roomHeadInfo)
  102. self._roomHeadInfo = roomHeadInfo
  103. end
  104. -- 初始化GPS组件
  105. function zigong7zRoomView:initGpsComponent()
  106. if self._isReplay then
  107. return
  108. end
  109. local gps = require(GPS_Component):new()
  110. self:addChild(gps)
  111. self._gps = gps
  112. end
  113. -- 初始化信号和电量组件
  114. function zigong7zRoomView:initSingleComponent()
  115. local single = require(Single_Component):new()
  116. self:addChild(single)
  117. self._singleComponent = single
  118. end
  119. -- 初始化方位组件
  120. function zigong7zRoomView:initDirectionComponent()
  121. self.direcionView = MJRoomDirection:new(self.desktopType)
  122. self.ui.Items.Layout_Player:addChild(self.direcionView)
  123. self.direcionView:setVisible(false) -- 隐藏中间内容
  124. end
  125. -- 初始化剩余牌提示面板
  126. function zigong7zRoomView:initLastCardTipsComponent()
  127. self._lastCardTip = require(LastCardTip_Component):new()
  128. self.ui.Items.Layout_Player:addChild(self._lastCardTip)
  129. self:setLastCardTipVisible()
  130. end
  131. -- 初始化操作界面组件
  132. function zigong7zRoomView:initOperateComponent()
  133. self._operateComponent = require(Operate_Component):new(self, self.desktopType)
  134. self:addChild(self._operateComponent)
  135. end
  136. -- 初始化重连组件
  137. function zigong7zRoomView:initReconnectComponent()
  138. local reconnect = import(Reconnect_Component):new(self)
  139. self._reconnect = reconnect
  140. end
  141. -- 初始化工具组件
  142. function zigong7zRoomView:initToolComponent()
  143. self.toolView = MJRoomToolView:new()
  144. self:addChild(self.toolView)
  145. end
  146. -- 初始化玩家组件
  147. function zigong7zRoomView:initPlayerComponent()
  148. self.playerView = MJRoomPlayerView:new()
  149. self.toolView:addLayoutToChatLayer(self.playerView)
  150. end
  151. -- 默认试图
  152. function zigong7zRoomView:initDefaultView()
  153. self:startSysTime()
  154. self:onChangeChatEnable() -- 聊天
  155. self:changeGameBg() -- 背景
  156. self:initGameButton() --初始化游戏事件按钮
  157. end
  158. -- 系统时间启动
  159. function zigong7zRoomView:startSysTime()
  160. if self._roomHeadInfo then
  161. self._roomHeadInfo:setTime(MJFunction.getTimeString())
  162. end
  163. if not self.Time then
  164. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  165. if self._roomHeadInfo then
  166. self._roomHeadInfo:setTime(MJFunction.getTimeString())
  167. end
  168. end,1.0,false)
  169. end
  170. end
  171. -- 初始化规则弹框
  172. function zigong7zRoomView:initRuleComponent()
  173. if self._ruleView then
  174. return
  175. end
  176. local RuleViewClass = MJFramework.MJImport("mj.luaScript.Views.Room.MJRuleViewVertical")
  177. local ruleView = RuleViewClass:new()
  178. self:addChild(ruleView);
  179. local roomInfo = app.room.roomInfo or {}
  180. local ruleList = MJWanFa.getWanFaInfoTab(roomInfo.strGameInfo, roomInfo.nTotalGameNum)
  181. ruleView:setRuleList(ruleList or {})
  182. ruleView:setBtnRuleOffset(60, nil);
  183. self._ruleView = ruleView
  184. end
  185. function zigong7zRoomView:onExit()
  186. zigong7zRoomView.super.onExit(self)
  187. if self.Time then
  188. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  189. end
  190. if self.taiPaiTimer then
  191. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.taiPaiTimer)
  192. end
  193. if self._singleComponent then
  194. self._singleComponent:exit()
  195. end
  196. app.room:dispatchEvent({name=MJDefine.MJEvent.DismissClose});
  197. stopBGMusic()
  198. self:cleanCache()
  199. end
  200. -- 清理缓存
  201. function zigong7zRoomView:cleanCache()
  202. local preload = package.loaded
  203. for k, v in pairs(package.loaded or {}) do
  204. local res1 = string.find( k, "mj.luaScript") or 0
  205. local res2 = string.find( k, "mj_zigong7z.luaScript") or 0
  206. if res1 > 0 or res2 > 0 then
  207. package.loaded[k] = nil
  208. end
  209. end
  210. end
  211. -- 设置语言 1 普通话 2 方言
  212. function zigong7zRoomView:doSound()
  213. local cacheLan = "mj_language"..(MJDefine.GameID or app.gameId)
  214. local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2
  215. saveUserInfo(cacheLan,defaultValue)
  216. MJSound.setSoundType(defaultValue)
  217. end
  218. function zigong7zRoomView:setCheckDefault()
  219. MJDefine.isAutomatic = true
  220. end
  221. -- 一键截屏
  222. function zigong7zRoomView:onClickButtonShot( sender )
  223. playBtnEffect()
  224. showScreenShot()
  225. end
  226. --隐藏俱乐部
  227. function zigong7zRoomView:hideClub()
  228. -- self.ui.Items.Button_Club:setVisible(false)
  229. if self.clubView and not tolua.isnull(self.clubView) then
  230. self.clubView:removeFromParent()
  231. self.clubView=nil
  232. end
  233. end
  234. --更换桌布(同维度)
  235. function zigong7zRoomView:changeGameBg(isUpdateViewType)
  236. if isUpdateViewType then
  237. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色
  238. local value = loadUserInfo("mj_zg_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD
  239. if value=="" or not value then
  240. value = MJDefine.DesktopType.TwoD
  241. saveUserInfo("mj_zg_desktop_2d_mjType", value)
  242. end
  243. logD("changeGameBg value:"..value)
  244. self.desktopType = value
  245. else
  246. self.desktopType = app.systemSetting.info.viewType
  247. end
  248. self:loadTextureCache()
  249. logD("changeGameBg"..self.desktopType)
  250. end
  251. local defaultValue = tonumber(loadUserInfo("zigong_mj_desktop_group")) or 1
  252. local bgData = MJDefine.CHANGE_GAME_BG[defaultValue]
  253. if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold then
  254. self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
  255. else
  256. self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
  257. end
  258. end
  259. function zigong7zRoomView:defaultState()
  260. --队列初始化
  261. self.callbackQueue = {}
  262. self.callbackRunning = false
  263. self.playerView:setOffLineVisible(false)
  264. self.playerView:setPlayerVisible(false)
  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:resetGame()
  272. end
  273. function zigong7zRoomView:loadTextureCache()
  274. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile("res/ui/zy_fangjian/RoomMenu/RoomMenu2.plist")
  275. local mjRes = MJDefine.MJRes[self.desktopType]
  276. if mjRes then
  277. for k,v in pairs(mjRes) do
  278. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile(v)
  279. end
  280. end
  281. loadSpriteFrameFile("mj_zigong7z/res/zy_fangjian/zigong_operateEffect.plist")
  282. loadSpriteFrameFile("mj_zigong7z/res/zy_fangjian/effect_guangxiao.plist")
  283. loadSpriteFrameFile("mj_zigong7z/res/zy_fangjian/effect_guafeng.plist")
  284. loadSpriteFrameFile("mj_zigong7z/res/zy_fangjian/effect_xiayu.plist")
  285. end
  286. -- 初始化游戏按钮
  287. function zigong7zRoomView:initGameButton()
  288. --点击空白
  289. self.ui.Items.Layout_Touch:registerClick(nil,function()
  290. -- 隐藏个人信息
  291. self.playerView:removePlayerInfoView()
  292. self.toolView:setMenuVisible(false)
  293. self._operateComponent:hideOperateItem()
  294. self.toolView:hideRule()
  295. self:setTingCardViewVisible(false);
  296. end)
  297. --隐藏听牌模板
  298. self.ui.Items.Item_Ting:setVisible(false)
  299. self.ui.Items.Button_Ting_Info:setVisible(false);
  300. self.ui.Items.Button_Ting_Info:registerClick(handler(self, self.onBtnTingInfoClicked))
  301. -- 聊天按钮
  302. -- self.toolView:setButtonFacePos(cc.p(1208*g_radio_x,(322+25)*g_radio_y))
  303. -- self.toolView:setButtonVoicePos(cc.p(1208*g_radio_x,(237+30)*g_radio_y))
  304. end
  305. --通知庄家可以爆牌
  306. function zigong7zRoomView:onBankerBaoPai(data)
  307. local function runBankerBaoPai(onEnd)
  308. local myUserId = app.room:getMyUserId()
  309. local viewId = app.room:getViewIdByUserId(myUserId)
  310. if data.response.nUserId == myUserId then
  311. self:showBaoJiao()
  312. self.playerHandCards[viewId]:setOutCardEnable(false)
  313. end
  314. if onEnd then
  315. onEnd()
  316. end
  317. end
  318. self:addCallBack(runBankerBaoPai)
  319. end
  320. --广播玩家爆牌
  321. function zigong7zRoomView:onBaoPai(data)
  322. if data.response.isBaoPai == 1 then
  323. local effect=MJAnimationCompnent.CreateBaoEffect()
  324. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  325. local myUserId = app.room:getMyUserId()
  326. local userInfo=app.room:getUserInfoByViewId(viewId)
  327. --爆牌音效
  328. MJSound.PlayBaoSound(userInfo.sex)
  329. if effect then
  330. self.ui.Items.Layout_Player:addChild(effect)
  331. effect:setLocalZOrder(1000)
  332. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  333. end
  334. if myUserId == data.response.nUserId then
  335. self.playerHandCards[viewId]:lockHandCard(true)
  336. -- self.playerHandCards[viewId]:setOutCardEnable(false)
  337. else
  338. --self.playerHandCards[viewId]:setOutCardEnable(true)
  339. end
  340. self.playerView:playBaoAnim(viewId)
  341. elseif data.response.isBaoPai == 2 then--博自摸
  342. local effect=MJAnimationCompnent.CreateBoZiMoEffect()
  343. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  344. local myUserId = app.room:getMyUserId()
  345. local userInfo=app.room:getUserInfoByViewId(viewId)
  346. --爆牌音效
  347. MJSound.PlayBaoSound(userInfo.sex)
  348. if effect then
  349. self.ui.Items.Layout_Player:addChild(effect)
  350. effect:setLocalZOrder(1000)
  351. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  352. end
  353. if myUserId == data.response.nUserId then
  354. self.playerHandCards[viewId]:lockHandCard(true)
  355. else
  356. end
  357. self.playerView:showBoZiMo(viewId,true)
  358. end
  359. if app.room:getMyUserId() == data.response.nUserId then
  360. self:hideBaoJiao()
  361. if (data.response.isBaoPai == 1 or data.response.isBaoPai == 2) then
  362. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  363. if gameInfo.tingpai > 0 then
  364. self.ui.Items.Button_Ting_Info:setVisible(true);
  365. app.room.roomInfo.memberList[data.response.nUserId].nTingStatus = MJDefine.MJTingStatus.Ting;
  366. end
  367. end
  368. end
  369. end
  370. function zigong7zRoomView:onGameSendCardResponse()
  371. --发牌的时候清除桌面上的飘
  372. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  373. local function runGameSendCardResponse(onEnd)
  374. log("2000000000-zigong7zRoomView - runGameSendCardResponse()" )
  375. --走过重连标志值为false
  376. self.isRunGameReconnection = false
  377. self:hidePiao()
  378. local myUserId = app.room:getMyUserId()
  379. for k,v in pairs(app.room.roomInfo.memberList) do
  380. local viewId = app.room:getViewIdByUserId(v.nUserId)
  381. if self.playerHandCards[viewId] then
  382. self.playerHandCards[viewId]:createHandCards(v.handCards)
  383. self.playerHandCards[viewId]:resetHandCards()
  384. end
  385. if v.isBaoPai == 1 and myUserId == v.nUserId then
  386. --self.playerHandCards[viewId]:showBaoPai()
  387. self:showBaoJiao()
  388. end
  389. end
  390. -- local effect=MJAnimationCompnent.CreateGameStart()
  391. -- self.ui.Items.Layout_Player:addChild(effect,5)
  392. -- MJSound.PlayStartGame()
  393. MJAnimationCompnent.CreateStartSendCards(self.playerHandCards,onEnd)
  394. -- if onEnd then
  395. -- onEnd()
  396. -- end
  397. self.toolView:showTuoGuan(app.room.roomInfo.hosting==1)
  398. end
  399. log("2000000000-zigong7zRoomView - addCallBack(runGameSendCardResponse)" )
  400. self:addCallBack(runGameSendCardResponse);
  401. end
  402. function zigong7zRoomView:onUserReadyResponse(response)
  403. -- self:setPlayerVisible(false)
  404. local uids = {}
  405. for k,v in pairs(app.room.roomInfo.memberList) do
  406. local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
  407. self.playerView:setReadyStatus(nSeatShowId,v.nPlayerFlag == 1)
  408. self.playerView:updatePlayerInfo(nSeatShowId)
  409. uids[v.nUserId] = true
  410. end
  411. if self.messageView then
  412. self.messageView:setPlayerUids(uids)
  413. end
  414. local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  415. if response and response.nUserId==nUserId then
  416. self.toolView:updateButton(true)
  417. self:resetGame()
  418. else
  419. self.toolView:updateButton()
  420. end
  421. if response and response.nUserId==nUserId then
  422. self:resetGame()
  423. end
  424. local myUserId = app.room:getMyUserId()
  425. if response and response.nUserId==myUserId then
  426. self.playerView:clearBao()
  427. self.playerView:clearAllPiao()
  428. self.playerView:clearAllBoZiMo()
  429. app.room.roomInfo.luoboCards = nil
  430. -- local roomInfo = app.room.roomInfo
  431. -- for k,v in pairs(roomInfo.memberList) do
  432. -- self.ui.Items.Layout_Player:removeChildByTag(HU_EFFECT_TAG)
  433. -- end
  434. end
  435. self.ui.Items.Button_Ting_Info:setVisible(false);
  436. end
  437. -- 广播桌子上所有玩家庄家起手操作 这里其实是发牌
  438. function zigong7zRoomView:onBankerOutCard(data)
  439. --[[ -- 庄家uid
  440. , defVar("nUserId", VT_Int, 0)
  441. -- 庄家操作类型
  442. , defVar("mainOpCode", VT_Short, 0)
  443. --庄家是否需要出牌0不需要 1:需要
  444. , defVar("IsShouldOutCard", VT_UChar, 0)--]]
  445. local function runOnBankerOutCard(onEnd)
  446. logE("zigong7zRoomView onBankerOutCard :"..table.tostring(data.response))
  447. -- if not data.response.nUserId then
  448. -- showTooltip("庄家起手操作nUserId is not exist")
  449. -- end
  450. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  451. local card= data.response.card
  452. local operates=data.response.operates
  453. local nSeatId=data.response.nSeatId
  454. -- app.room.roomInfo.outCardUserId = data.response.nUserId
  455. if self.playerHandCards[viewId] then
  456. self.playerHandCards[viewId]:onGetCard(operates,card)
  457. end
  458. --先清除所有操作按钮
  459. self._operateComponent:hideOperateItem()
  460. self._operateComponent:showOperate(operates,card,true)
  461. if viewId == MJDefine.MyViewId then
  462. self.ui.Items.Button_Ting_Info:setVisible(false)
  463. if operates and table.nums(operates)>0 then
  464. self.operates = operates
  465. else
  466. self.operates = {}
  467. end
  468. if self.playerHandCards[MJDefine.MyViewId] then
  469. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  470. local player = app.room.roomInfo.memberList[data.response.nUserId]
  471. if player and (player.isBaoPai==1 or player.isBaoPai == 2) then
  472. self.playerHandCards[MJDefine.MyViewId]:lockHandCard(true)
  473. end
  474. end
  475. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  476. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  477. -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  478. local curHandCards = self.playerHandCards[viewId]:getHandCardsNum()
  479. if curHandCards%3 ~= 2 then--抓了牌之后,手牌不正确,主动重连一下
  480. app.room.roomInfo.requestGetTableInfo = true
  481. self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
  482. end
  483. end
  484. self:showGuideTip(viewId == MJDefine.MyViewId)
  485. -- local myUserId = app.room:getMyUserId()
  486. -- if data.response.nUserId == myUserId then
  487. -- if self.playerHandCards[MJDefine.MyViewId] then
  488. -- self.playerHandCards[MJDefine.MyViewId]:pushTing()
  489. -- end
  490. -- end
  491. self:updateGameNums()
  492. self.direcionView:updateDirection(nSeatId)
  493. if onEnd then
  494. onEnd()
  495. end
  496. end
  497. log("2000000000-zigong7zRoomView - addCallBack(runOnBankerOutCard)")
  498. self:addCallBack(runOnBankerOutCard);
  499. end
  500. function zigong7zRoomView:onTurnOutCard(data)
  501. local function runOnTurnOutCard(onEnd)
  502. logE("zigong7zRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  503. log("2000000000-MJRoomView - runOnOutCard")
  504. if app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId then
  505. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  506. end
  507. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  508. -- local card= data.response.card
  509. -- if self.playerHandCards[viewId] then
  510. -- self.playerHandCards[viewId]:createOutCards(card)
  511. -- end
  512. if onEnd then
  513. onEnd()
  514. end
  515. end
  516. log("2000000000-MJRoomView - addCallBack(runOnTurnOutCard)")
  517. self:addCallBack(runOnTurnOutCard)
  518. end
  519. --出牌成功
  520. function zigong7zRoomView:onOutCardSuccess(data)
  521. logE("zigong7zRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  522. local function runOnOutCardSuccess(onEnd)
  523. log("2000000000-zigong7zRoomView - runOnOutCardSuccess---------")
  524. -- app.room.roomInfo.outCardUserId = data.response.nUserId
  525. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  526. local card= data.response.card
  527. local operates=data.response.operates
  528. local typr = operates.opType
  529. if operates and table.nums(operates)>0 then
  530. self.operates = operates
  531. else
  532. self.operates = {}
  533. end
  534. local function callback()
  535. -- app.room.roomInfo.lastOutViewId = nil
  536. self._operateComponent:showOperate(operates,card)
  537. if onEnd then
  538. onEnd()
  539. end
  540. end
  541. -- self.lastOutCard = card
  542. if self.playerHandCards[viewId] then
  543. --(viewId~=MJDefine.MyViewId or player.isBaoPai == 1) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId
  544. if viewId==MJDefine.MyViewId then
  545. local player = app.room.roomInfo.memberList[data.response.nUserId]
  546. self.playerHandCards[viewId]:setTing(false)
  547. local curHandCards = self.playerHandCards[viewId]:getHandCardsNum() or 0
  548. if ((player.isBaoPai==1 or player.isBaoPai==2) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId) or app.room.roomInfo.hosting == 1 then --点击爆牌的时候 前端已经打出牌 要判断上次出牌的人是不是自己 避免重复出牌
  549. self.playerHandCards[viewId]:onOutCard(card,callback)
  550. --音效
  551. local userInfo=app.room:getUserInfoByViewId(viewId)
  552. if userInfo then
  553. MJSound.PlayMJSound(userInfo.sex,card)
  554. end
  555. elseif self.needDeleteOutCard and true == self.needDeleteOutCard then
  556. self.needDeleteOutCard = nil
  557. uploadLogs("mjduopai")
  558. self.playerHandCards[viewId]:onOutCard(card,callback)
  559. elseif self.isRunGameReconnection and true ==self.isRunGameReconnection and curHandCards%3 == 2 then--重连后,手牌是可以出牌的,则删除一张牌
  560. self.playerHandCards[viewId]:onOutCard(card,callback)
  561. else
  562. callback()
  563. end
  564. self.isRunGameReconnection = false
  565. local gameInfo = json.decode(app.room.roomInfo.strGameInfo);
  566. if gameInfo.tingpai > 0 then
  567. self._isOutCardTingCheck = true;
  568. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  569. end
  570. self:setGuideView(false)
  571. else
  572. self.playerHandCards[viewId]:onOutCard(card,callback)
  573. end
  574. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId})
  575. else
  576. callback()
  577. end
  578. app.room.roomInfo.lastOutViewId = viewId
  579. end
  580. log("2000000000-zigong7zRoomView - addCallBack(runOnOutCardSuccess)")
  581. self:addCallBack(runOnOutCardSuccess)
  582. end
  583. --已经发送了过操作,此时就算再勾选贴鬼碰,也不会显示操作
  584. function zigong7zRoomView:onSendGuo()
  585. --发牌重置,主要用于贴鬼碰/杠
  586. MJDefine.isSendGuo = false
  587. self.operates = {}
  588. end
  589. -- 操作成功
  590. function zigong7zRoomView:onOperationCodeSuccess(data)
  591. local function runOnOperationSuccess(onEnd)
  592. local response = data.response
  593. local nUserId = response.nUserId
  594. local opType = response.opType
  595. local opCard = response.opCard
  596. local bIsOutCard = response.isNeedOutCard > 0
  597. local fromSeatId = response.fromSeatId
  598. local redNum = response.redNum
  599. local viewId = app.room:getViewIdByUserId(nUserId)
  600. local fromViewId = app.room:getViewIdBySeatId(fromSeatId)
  601. local opSeatId = app.room:getSeatIdByViewId(viewId)
  602. local fromUserId = app.room:getUserIdBySeatId(fromSeatId)
  603. if self.playerHandCards[viewId] then
  604. --组合一下牌
  605. local groups={
  606. self:getChangeGruopDatas({opType=opType, opCard=opCard, redNum = redNum, targetSeatId=opSeatId, opUserId=fromUserId})
  607. }
  608. --删除手中对应的牌
  609. local deleteCards
  610. for k,v in pairs(groups) do
  611. if v.showType==MJDefine.MJGroupType.Peng then
  612. self.playerHandCards[viewId]:removeHandCardByNum(opCard,2,v.redNum)
  613. elseif v.showType==MJDefine.MJGroupType.Chi then
  614. --TODO:吃的牌删除两张
  615. elseif v.showType==MJDefine.MJGroupType.AnGang
  616. or v.showType==MJDefine.MJGroupType.MAnGang then
  617. self.playerHandCards[viewId]:removeHandCardByNum(opCard,4,v.redNum)
  618. else
  619. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  620. self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.redNum)
  621. else
  622. self.playerHandCards[viewId]:removeHandCardByNum(opCard,3,v.redNum)
  623. end
  624. end
  625. end
  626. --删除出去的牌 遍历哪些操作需要删除牌
  627. for k,v in pairs(MJDefine.MJOperateNeedRemoveCard) do
  628. if v==opType then
  629. self.playerHandCards[fromViewId]:removeOutCard(opCard)
  630. break
  631. end
  632. end
  633. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  634. self.playerHandCards[viewId]:buGang(opCard,redNum)
  635. else
  636. self.playerHandCards[viewId]:createGroupCards(groups)--创建显示的牌
  637. end
  638. self.playerHandCards[viewId]:resetHandCards()
  639. self._operateComponent:hideOperate()
  640. self.playerHandCards[viewId]:setOutCardEnable(bIsOutCard)
  641. self:showGuideTip(viewId == MJDefine.MyViewId)
  642. self.direcionView:updateDirection(app.room:getSeatIdByViewId(viewId))
  643. end
  644. local function guafengxiayuEffect()
  645. local effect
  646. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  647. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) then
  648. effect=MJAnimationCompnent.createGuaFengEffect()
  649. MJSound.PlayWindSound()
  650. elseif (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  651. effect=MJAnimationCompnent.createXiaYuEffect()
  652. MJSound.PlayRainSound()
  653. end
  654. if effect then
  655. self.ui.Items.Layout_Player:addChild(effect)
  656. effect:setLocalZOrder(1000)
  657. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  658. end
  659. end
  660. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  661. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) or (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  662. guafengxiayuEffect()
  663. else
  664. --播放动画
  665. local effect=MJAnimationCompnent.CreateOperareEffect(opType)--,onEnd)
  666. if effect then
  667. self.ui.Items.Layout_Player:addChild(effect)
  668. effect:setLocalZOrder(1000)
  669. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  670. -- else
  671. -- if onEnd then
  672. -- onEnd()
  673. -- end
  674. end
  675. end
  676. --音效
  677. local userInfo=app.room:getUserInfo(nUserId)
  678. if userInfo then
  679. MJSound.PlayOperateSound(userInfo.sex,opType)
  680. end
  681. if viewId == MJDefine.MyViewId then
  682. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  683. self:setTingCardViewVisible(false)
  684. self.ui.Items.Button_Ting_Info:setVisible(false)
  685. self.operates={}
  686. end
  687. --删除等待操作的显示
  688. if self.waitOperates and #self.waitOperates>0 then
  689. for k,v in pairs(self.waitOperates) do
  690. v:removeFromParent()
  691. end
  692. self.waitOperates={}
  693. end
  694. --[[if viewId == MJDefine.MyViewId and opType==MJDefine.MJOperateType.OPREATE_PENG then
  695. local cards = {opCard}
  696. self.playerHandCards[viewId]:cardEnabled(cards, true)
  697. end--]]
  698. -- 取消操作按钮
  699. self._operateComponent:hideOperate()
  700. -- 操作完后,隐藏手势
  701. self:showGuideTip(false)
  702. if onEnd then
  703. onEnd()
  704. end
  705. end
  706. self:addCallBack(runOnOperationSuccess)
  707. end
  708. function zigong7zRoomView:test()
  709. self.playerHandCards={}
  710. self.playerHandCards[MJDefine.MyViewId] = MJHandCardView:new(MJDefine.MyViewId)
  711. self:addChild(self.playerHandCards[MJDefine.MyViewId])
  712. self.playerView = MJRoomPlayerView:new()
  713. self:addChild(self.playerView)
  714. end
  715. --飘状态停止
  716. function zigong7zRoomView:stopDirection()
  717. self.direcionView:stopAllActions()
  718. self.direcionView.ui.Items.ImageView_Dir_Down:setVisible(false)
  719. self.direcionView.ui.Items.ImageView_Dir_Up:setVisible(false)
  720. self.direcionView.ui.Items.ImageView_Dir_Left:setVisible(false)
  721. self.direcionView.ui.Items.ImageView_Dir_Right:setVisible(false)
  722. self.direcionView.ui.Items.Text_Time:setString(string.format("%02d",0))
  723. self.direcionView.ui.Items.Text_Leave_Card_Num:setText("72")
  724. end
  725. function zigong7zRoomView:onGameReconnection()
  726. if self._isReplay then
  727. return
  728. end
  729. --更新房间基础数据
  730. local roomInfo = app.room.roomInfo;
  731. self:updateRoomBaseData()
  732. self.toolView:updateButton()
  733. --显示离线状态
  734. for k,v in pairs(roomInfo.memberList) do
  735. local viewId = app.room:getViewIdByUserId(k)
  736. local nOffLineState = v.nOnlineStatus
  737. self.playerView:setPlayerOffLineVisible(nOffLineState ~= MJDefine.PlayerOnlineStatus.Online,viewId)
  738. end
  739. --断线重连
  740. if roomInfo.nGameStartCount > 0 then
  741. if self._fastRequestView then
  742. self._fastRequestView:removeSelf()
  743. self._fastRequestView = nil
  744. end
  745. local function runOnGameReconnection(onEnd)
  746. self._reconnect:checkCode(onEnd)
  747. end
  748. log("2000000000-MJRoomView - self:addCallBack(runOnGameReconnection)" )
  749. self:addCallBack(runOnGameReconnection)
  750. else
  751. -- 游戏未开始
  752. if roomInfo.nStatus and roomInfo.nStatus<MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START then
  753. --self.toolView:enableHosting(false)
  754. local quickStartInfo = roomInfo.quickStartInfo
  755. if quickStartInfo then
  756. if quickStartInfo.tablefaststate == 1 then
  757. local tmpInfo = {}
  758. for uid,status in pairs(quickStartInfo.list) do
  759. table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status})
  760. end
  761. local response = {}
  762. response.pList = tmpInfo
  763. response.timeOut = roomInfo.quickStartInfo.time
  764. self:onBroadcastFaststart({response=response})
  765. else
  766. --self.toolView:showFastStart(true)
  767. end
  768. else
  769. if self._fastRequestView then
  770. self._fastRequestView:removeSelf()
  771. self._fastRequestView = nil
  772. end
  773. --self.toolView:showFastStart(true)
  774. end
  775. end
  776. end
  777. end
  778. function zigong7zRoomView:getChangeGruopDatas(g)
  779. local opType=g.opType
  780. local showType=MJDefine.MJOperateToGroupType[g.opType]
  781. local opCard=g.opCard
  782. local redNum = g.redNum
  783. local fromViewId = nil
  784. local targetSeatId = g.targetSeatId--操作位置座位号
  785. local fromUserId = g.opUserId or g.fromUserId --触发操作玩家
  786. local fromViewId1 = app.room:getViewIdByUserId(fromUserId)
  787. if fromUserId<=0 or not targetSeatId then
  788. else
  789. fromViewId = app.room:transPos( targetSeatId, app.room:getSeatIdByUserId(fromUserId))
  790. --判断是否是对面玩家,对面玩家的话要做一次翻转
  791. local opViewId = app.room:getViewIdBySeatId(targetSeatId)
  792. if opViewId == 2 then --对面
  793. if fromViewId==1 then fromViewId = 3
  794. elseif fromViewId==3 then fromViewId = 1 end
  795. end
  796. --三人玩只有上下家
  797. if app.room:getMaxPlayerCount()==3 and fromViewId==2 then fromViewId = 3 end
  798. if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
  799. if showType == MJDefine.MJGroupType.Peng then
  800. fromViewId = 2
  801. else
  802. fromViewId = 4
  803. end
  804. end
  805. end
  806. --组合一下牌
  807. local group={
  808. opType=opType,
  809. showType=showType,
  810. values={},
  811. opCard = opCard,
  812. redNum = redNum,
  813. fromViewId = fromViewId,
  814. fromViewId1 = fromViewId1,--真正的来源viewID
  815. }
  816. if MJDefine.MJGroupType.Chi==showType then
  817. elseif MJDefine.MJGroupType.Peng==showType then
  818. group.values={opCard,opCard,opCard}
  819. else
  820. group.values={opCard,opCard,opCard,opCard}
  821. end
  822. return group
  823. end
  824. -- 小局结算
  825. function zigong7zRoomView:onGameXiaoJuResponse(data)
  826. local function runGameXiaoJuResponse(onEnd)
  827. if not tolua.isnull(self.firstTingTipsView) then
  828. self.firstTingTipsView:killSelf()
  829. self.firstTingTipsView = nil
  830. end
  831. -- 取消操作按钮
  832. self._operateComponent:hideOperate()
  833. local roomInfo = app.room.roomInfo
  834. self.direcionView:stopAllActions()
  835. self.operates = {}
  836. self:setTingCardViewVisible(false)
  837. app.room:resetTings()
  838. app.room:cleanTingStatus()
  839. --如果是解散直接return
  840. --[[if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  841. if onEnd then
  842. onEnd()
  843. end
  844. return
  845. end --]]
  846. --所有胡牌的人 考虑抢杠胡的问题
  847. local viewIds={}
  848. local failViewId=0
  849. for k,v in pairs(roomInfo.memberList) do
  850. local viewId = app.room:getViewIdByUserId(v.nUserId)
  851. if v.result>0 then
  852. table.insert(viewIds,viewId)
  853. --处理掉huCard, 不加入手牌
  854. --播放音效
  855. if viewId==MJDefine.MyViewId then
  856. --MJSound.PlayWinGame()
  857. end
  858. if v.result==MJDefine.MJGameHuType.HU_DIANPAO then
  859. failViewId = app.room:getViewIdBySeatId(v.dpSeatId)
  860. end
  861. end
  862. end
  863. self:showOpenCard()
  864. for k,v in pairs(roomInfo.memberList) do
  865. local viewId = app.room:getViewIdByUserId(v.nUserId)
  866. if viewId and self.playerHandCards[viewId] then
  867. if viewId==MJDefine.MyViewId then
  868. else
  869. --倒牌
  870. if v.huCard and v.huCard ~= 0 then
  871. self.playerHandCards[viewId]:createOpenHandCards(v.huCard)
  872. self.playerHandCards[viewId]:moveLastOpenCard()
  873. end
  874. end
  875. end
  876. end
  877. --被抢杠的人回退补杠
  878. -- if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_NORMAL then
  879. -- self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard)
  880. -- end
  881. local function callback()
  882. self:showXiaoJuView()
  883. if onEnd then
  884. onEnd()
  885. end
  886. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  887. end
  888. local function luoboNumCallBack()
  889. local strGameInfo = json.decode(app.room.roomInfo.strGameInfo)
  890. if strGameInfo.luobonum and strGameInfo.luobonum > 0 then
  891. local index = 1
  892. for k,v in pairs(roomInfo.memberList) do
  893. local viewId = app.room:getViewIdByUserId(v.nUserId)
  894. local effect
  895. if index == app.room.roomInfo.nMaxPlayCount then
  896. effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboNum,callback)
  897. else
  898. effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboNum)
  899. end
  900. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  901. local offsetX, offsetY = self:getLuoBoOffset(viewId)
  902. effect:setPosition(pos.x + offsetX, pos.y + offsetY)
  903. self.ui.Items.Layout_Effect_luobo_Lable:addChild(effect)
  904. index = index + 1
  905. end
  906. else
  907. callback()
  908. end
  909. end
  910. local luoboCards = roomInfo.luoboCards
  911. local function luoboCallBack()
  912. if luoboCards and #luoboCards>0 then
  913. local luoNum = #luoboCards
  914. --加一个黑底
  915. local layer = cc.LayerColor:create(cc.c4b(0,0,0,120))
  916. layer:setAnchorPoint(cc.p(0.5,0.5))
  917. layer:ignoreAnchorPointForPosition(false)
  918. local tPos = self.ui.Items.ImageView_Logo:getPosition()
  919. local tLuoBoPos = {
  920. [1] = {[1] = cc.p(tPos.x,360-40)},
  921. [2] = {[1] = cc.p(tPos.x-50,360),[2] = cc.p(tPos.x+50,360)},
  922. }
  923. layer:setPosition(cc.p(getWinSize().width/2,getWinSize().height/2))
  924. self.ui.Items.Layout_Effect_luobo:addChild(layer)
  925. for i,v in pairs(luoboCards) do
  926. local effect
  927. if i == #luoboCards then
  928. effect = MJAnimationCompnent.CreateLoBoEffect(v,self.desktopType,luoboNumCallBack)
  929. else
  930. effect = MJAnimationCompnent.CreateLoBoEffect(v,self.desktopType)
  931. end
  932. if MJDefine.LuoBoPos[luoNum] and MJDefine.LuoBoPos[luoNum][i] then
  933. effect:setPosition(tLuoBoPos[luoNum][i])
  934. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  935. end
  936. end
  937. else
  938. self:runDelay(1.0,function()
  939. callback()
  940. end)
  941. end
  942. end
  943. if #viewIds>0 then
  944. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  945. self:runDelay(1.0,function()
  946. callback()
  947. end)
  948. else
  949. luoboCallBack()
  950. end
  951. local userInfo=app.room:getUserInfo(app.room:getMyUserId())
  952. if userInfo then --拔萝卜音效
  953. end
  954. else
  955. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  956. local effect=MJAnimationCompnent.CreateLiuJuEffect(callback)
  957. self.ui.Items.Layout_Player:addChild(effect)
  958. effect:setLocalZOrder(1000)
  959. MJSound.PlayHuangZhuang()
  960. else
  961. callback()
  962. end
  963. end
  964. end
  965. self:addCallBack(runGameXiaoJuResponse);
  966. end
  967. -- 显示小局结算
  968. function zigong7zRoomView:showXiaoJuView()
  969. self.direcionView:stopAllActions()
  970. self:setTingCardViewVisible(false)
  971. if self.xiaojuView then
  972. self.xiaojuView:removeFromParent()
  973. end
  974. local roomInfo = app.room.roomInfo
  975. self.xiaojuView = MJRoomXiaoJuView:new(self.desktopType)
  976. self:addChild(self.xiaojuView)
  977. end
  978. function zigong7zRoomView:setTingCardViewVisible(bVisible,tingCards)
  979. log("setTingCardViewVisible :"..table.tostring(tingCards))
  980. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(bVisible)
  981. -- self.ui.Items.ListView_Ting:removeAllItems()
  982. -- self.ui.Items.ListView_Ting:getHBar():setVisible(false)
  983. self.ui.Items.ListView_Ting:removeAllChildren()
  984. -- self.ui.Items.Item_Ting:setVisible(false)
  985. -- self.toolView:setVisible(false)
  986. if not tingCards then return end
  987. local count = #tingCards
  988. local row = math.ceil(count/5) --几行
  989. self.ui.Items.ListView_Ting:setSize(cc.size(670,80*row))
  990. self.ui.Items.Layout_Ting_Tip_Card_Panel:setSize(cc.size(row>1 and 786 or count*134+116,80*row+40))
  991. self.ui.Items.ImageView_Ting:setPositionY(self.ui.Items.Layout_Ting_Tip_Card_Panel:getContentSize().height-60)
  992. for k,v in pairs(tingCards) do
  993. local item = self.ui.Items.Item_Ting:getCopied()
  994. item:setVisible(true)
  995. local items = getUIItems(item)
  996. items.Text_Num:setString(v.count.."张")
  997. items.Text_Fan:setString(v.fanshu.."番")
  998. local mj=MJ:new(v.card,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
  999. mj:setPosition(cc.p(20,30))
  1000. mj:setScale(0.5)
  1001. items.Node:addChild(mj)
  1002. self.ui.Items.ListView_Ting:addChild(item)
  1003. end
  1004. self.ui.Items.ListView_Ting:requestDoLayout()
  1005. self.ui.Items.ListView_Ting:doLayout()
  1006. end
  1007. --显示查听的牌
  1008. function zigong7zRoomView:setChaTingCardViewVisible(bVisible,tingCards)
  1009. end
  1010. function zigong7zRoomView:onTingCardStatus()
  1011. local myUserId=app.user.loginInfo.uid
  1012. local memberList=app.room.roomInfo.memberList
  1013. if memberList[myUserId] then
  1014. local nTingStatus=memberList[myUserId].nTingStatus
  1015. if nTingStatus == MJDefine.MJTingStatus.Ting then
  1016. print("---------onTingCardStatus-----------1 "..myUserId)
  1017. -- self:setChaTingCardViewVisible(true)
  1018. -- self:setTingCardViewVisible(true, )
  1019. --self._isTingStateChanged = true--防止出现听牌提示闪一下的bug
  1020. --self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1021. self.ui.Items.Button_Ting_Info:setVisible(true);
  1022. else
  1023. print("---------onTingCardStatus-----------0 "..myUserId)
  1024. -- self:setChaTingCardViewVisible(false)
  1025. self:setTingCardViewVisible(false)
  1026. self.ui.Items.Button_Ting_Info:setVisible(false);
  1027. end
  1028. end
  1029. end
  1030. function zigong7zRoomView:onTingCardResult(data)
  1031. print("---------听牌结果-------------")
  1032. if data.response.tingType==MJDefine.MJTingType.QuanTing then
  1033. -- self:setChaTingCardViewVisible(true,{})
  1034. else
  1035. if self._isOutCardTingCheck then
  1036. self._isOutCardTingCheck = false
  1037. local count = table.nums(data.response.tingCards);
  1038. local isTing = count > 0;
  1039. self.ui.Items.Button_Ting_Info:setVisible(isTing);
  1040. self:setTingCardViewVisible(false, data.response.tingCards)
  1041. else
  1042. self:setTingCardViewVisible(true, data.response.tingCards)
  1043. end
  1044. end
  1045. end
  1046. function zigong7zRoomView:showTing(evet)
  1047. local roomInfo=app.room.roomInfo
  1048. -- if evet.card and roomInfo.tings and roomInfo.tings[evet.card] then
  1049. -- self:setTingCardViewVisible(true,roomInfo.tings[evet.card])
  1050. -- else
  1051. -- self:setTingCardViewVisible(false)
  1052. -- end
  1053. if evet.card and roomInfo.tings and #roomInfo.tings>0 then
  1054. local isTing = false
  1055. for k,v in pairs(roomInfo.tings) do
  1056. if evet.card==v.outCard then
  1057. self:setTingCardViewVisible(true,v.tingCards)
  1058. isTing = true
  1059. end
  1060. end
  1061. if not isTing then
  1062. self:setTingCardViewVisible(false)
  1063. end
  1064. else
  1065. self:setTingCardViewVisible(false)
  1066. end
  1067. end
  1068. function zigong7zRoomView:pushTing()
  1069. local function runPushTing(onEnd)
  1070. if self.playerHandCards[MJDefine.MyViewId] then
  1071. self.playerHandCards[MJDefine.MyViewId]:pushTing()
  1072. end
  1073. if onEnd then
  1074. onEnd()
  1075. end
  1076. end
  1077. self:addCallBack(runPushTing);
  1078. end
  1079. function zigong7zRoomView:onHuResponse(data)
  1080. local function runHuResponse(onEnd)
  1081. local response = data.response
  1082. logD('有人胡牌了', table.tostring(response))
  1083. local function callback()
  1084. self:playHuAni(response)
  1085. if onEnd then
  1086. onEnd()
  1087. end
  1088. end
  1089. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1090. local userInfo=app.room:getUserInfoByViewId(viewId)
  1091. --先播放胡牌动画和音效,再显示胡牌顺序
  1092. local effect = MJAnimationCompnent.CreateHuEffect(response.huType,callback)
  1093. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1094. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU)
  1095. -- effect=MJAnimationCompnent.CreateHuEffect("zimo",callback)
  1096. -- elseif response.huType == MJDefine.MJGameHuType.HU_QIANGGANG then
  1097. else
  1098. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU)
  1099. -- effect=MJAnimationCompnent.CreateHuEffect("hu",callback)
  1100. -- --点炮显示
  1101. end
  1102. if effect then
  1103. self.ui.Items.Layout_Effect:addChild(effect)
  1104. effect:setTag(HU_EFFECT_TAG)
  1105. effect:setLocalZOrder(1000)
  1106. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1107. end
  1108. --删除等待操作的显示
  1109. if self.waitOperates and #self.waitOperates>0 then
  1110. for k,v in pairs(self.waitOperates) do
  1111. v:removeFromParent()
  1112. end
  1113. self.waitOperates={}
  1114. end
  1115. if response.huType==MJDefine.MJGameHuType.HU_DIANPAO and response.curOpType ~= 1 then
  1116. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1117. --点炮胡或抢杠胡,胡牌类型都是发 点炮胡
  1118. if response.isQiangGng > 0 then
  1119. local huCard = response.huCard == 65 and response.redRealCard or response.huCard --如果胡的牌是红中 用真实的牌 否则用胡的牌
  1120. -- logD("isQiangGng huCard:"..huCard)
  1121. --抢杠胡
  1122. self.playerHandCards[viewId]:onGetCard(nil,huCard)
  1123. --被抢杠的人回退补杠
  1124. self.playerHandCards[failViewId]:retoreBuGang(huCard,1)
  1125. --[[elseif response.isGspHu and response.isGspHu > 0 then
  1126. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  1127. if gameInfo.dianganghua == 1 then
  1128. dghDianPao = true
  1129. --点杠炮(选择的点杠花)时手上已经有杠的牌 不需要再加一张胡的牌
  1130. else
  1131. self.playerHandCards[viewId]:onGetCard(nil,response.huCard)
  1132. --将胡的牌收走
  1133. self.playerHandCards[failViewId]:removeOutCard(response.huCard)
  1134. end--]]
  1135. else
  1136. self.playerHandCards[viewId]:onGetCard(nil,response.huCard)
  1137. --将胡的牌收走
  1138. self.playerHandCards[failViewId]:removeOutCard(response.huCard)
  1139. end
  1140. --放炮动画
  1141. effect=MJAnimationCompnent.CreateDianPaoEffect()
  1142. self.ui.Items.Layout_Effect:addChild(effect)
  1143. effect:setLocalZOrder(1000)
  1144. effect:setPosition(self.playerHandCards[failViewId]:getAnimationPostion())
  1145. if failViewId==MJDefine.MyViewId and app.room.roomInfo.lastOutViewId==MJDefine.MyViewId then --修改点炮的人连续二次出牌 不删除牌
  1146. app.room.roomInfo.lastOutViewId = nil
  1147. end
  1148. --此处仅做保留,没有实际意义
  1149. elseif response.huType==MJDefine.MJGameHuType.HU_QIANGGANG then
  1150. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1151. if response.redRealCard > 0 then
  1152. --抢杠胡时,胡牌的人将胡的牌加入手中
  1153. self.playerHandCards[viewId]:onGetCard(nil,response.redRealCard)
  1154. --被抢杠的人回退补杠
  1155. self.playerHandCards[failViewId]:retoreBuGang(response.redRealCard,1)
  1156. end
  1157. end
  1158. if response.nUserId == app.room:getMyUserId() then
  1159. self.playerHandCards[viewId]:setOutCardEnable(false)
  1160. self:setTingCardViewVisible(false)
  1161. self.playerHandCards[viewId]:setTing(false)
  1162. else
  1163. -- 其他人胡了倒牌
  1164. local handCards = {}
  1165. for k,v in pairs(self.playerHandCards[viewId]:getHandCardNodes() or {}) do
  1166. table.insert(handCards,{card = v.value or v:getValue()})
  1167. end
  1168. if response.huType==MJDefine.MJGameHuType.HU_ZIMO or response.curOpType == 1 then --如果是自摸胡 把最后一张替换为胡的牌或点杠花点炮
  1169. handCards[#handCards] = {card = response.huCard}
  1170. end
  1171. self.playerHandCards[viewId]:removeAllHandCards()
  1172. dump(handCards, '胡牌handCards....')
  1173. self.playerHandCards[viewId]:createOpenHandCards(handCards)
  1174. self.playerHandCards[viewId]:moveLastOpenCard()
  1175. end
  1176. self._operateComponent:hideOperate()
  1177. end
  1178. self:addCallBack(runHuResponse);
  1179. end
  1180. function zigong7zRoomView:playHuAni(response)
  1181. local strGameInfo = json.decode(app.room.roomInfo.strGameInfo)
  1182. local effect = MJAnimationCompnent.CreateHuOrderEffect(response.huType,response.huOrder)
  1183. -- if response.huType == 1 then
  1184. -- effect=MJAnimationCompnent.CreateHuOrderEffect("zimo",response.huOrder)
  1185. -- else
  1186. -- effect=MJAnimationCompnent.CreateHuOrderEffect("hu",response.huOrder)
  1187. -- end
  1188. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1189. if effect then
  1190. self.ui.Items.Layout_Effect:addChild(effect)
  1191. effect:setTag(HU_EFFECT_TAG)
  1192. effect:setLocalZOrder(1000)
  1193. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  1194. local offsetX, offsetY = self:getHuFlagOffset(viewId)
  1195. effect:setPosition(pos.x + offsetX, pos.y + offsetY)
  1196. end
  1197. end
  1198. function zigong7zRoomView:onQiangDuanOperates(data)
  1199. local function runOnQiangDuanOperates(onEnd)
  1200. logD("zigong7zRoomView:runOnQiangDuanOperates")
  1201. local response = data.response
  1202. if response.operates and self.playerHandCards[MJDefine.MyViewId] then
  1203. self._operateComponent:showOperate(operates)
  1204. end
  1205. if onEnd then
  1206. onEnd()
  1207. end
  1208. end
  1209. logD("zigong7zRoomView:onQiangDuanOperates")
  1210. self:addCallBack(runOnQiangDuanOperates)
  1211. end
  1212. --游戏消息
  1213. function zigong7zRoomView:bindExtendMessage()
  1214. self:bindEvent(app.room , MJDefine.MJEvent.OutCardTings, handler(self , self.pushTing));
  1215. self:bindEvent(app.room , MJDefine.MJEvent.HuResponse, handler(self , self.onHuResponse))
  1216. self:bindEvent(app.room , MJDefine.MJEvent.BaoPaiResponse, handler(self , self.onBaoPai))
  1217. self:bindEvent(app.room , MJDefine.MJEvent.BankerBaoPai, handler(self , self.onBankerBaoPai))
  1218. self:bindEvent(app.room , MJDefine.MJEvent.SendGuo, handler(self , self.onSendGuo))
  1219. self:bindEvent(app.room , MJDefine.MJEvent.QiangDuanOperates, handler(self , self.onQiangDuanOperates))
  1220. self:bindEvent(app , MJDefine.MJEvent.ChangeLanguage , handler(self , self.doSound))
  1221. self:bindEvent(app.room , MJDefine.MJEvent.StartPiao, handler(self , self.onStartPiao))
  1222. self:bindEvent(app.room , MJDefine.MJEvent.PiaoResponse, handler(self , self.onPiaoResponse))
  1223. self:bindEvent(app, MJDefine.MJEvent.ChangeViewType, handler(self, self.onEventChangeViewType ))
  1224. -- 托管
  1225. self:bindEvent(app.room , MJDefine.MJEvent.HostingRequest, handler(self, self.onHostingRequest))
  1226. self:bindEvent(app , MJDefine.MJEvent.HeadShowHighLight , handler(self , self.onHeadShowHighLight)) -- 头像显示高亮
  1227. self:bindEvent(app.room , MJDefine.MJEvent.HideOperateLayer , handler(self , self.onHideOperateLayer)) -- 隐藏操作界面
  1228. self:bindEvent(app.room , MJDefine.MJEvent.HideGuideTip , handler(self , self.onHideGuideTip)) -- 隐藏手势提示
  1229. end
  1230. function zigong7zRoomView:clean()
  1231. self.playerView:init()
  1232. -- --默认状态
  1233. self:defaultState()
  1234. app.room:resetRoomInfo()
  1235. self:setBtnSitDownVisible(false)
  1236. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  1237. --
  1238. self._gameoverview = nil
  1239. end
  1240. function zigong7zRoomView:updateReady()
  1241. local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  1242. if app.room.roomInfo.nGameStartCount > 0 then
  1243. self.toolView:setButtonLeaveEnable(false)
  1244. self:setBtnSitDownVisible(false)
  1245. else
  1246. self.toolView:setButtonLeaveEnable(true)
  1247. end
  1248. if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= nUserId then
  1249. self.toolView:setButtonToolEnable(false)
  1250. else
  1251. self.toolView:setButtonToolEnable(true)
  1252. end
  1253. self:checkCanDismiss()
  1254. end
  1255. -- 游戏开始
  1256. function zigong7zRoomView:onGameStartResponse()
  1257. local function runGameStartResponse(onEnd)
  1258. log("2000000000-MJRoomView - runGameStartResponse()" )
  1259. --更新背景
  1260. self:changeGameBg(true)
  1261. --隐藏俱乐部
  1262. self:hideClub()
  1263. --重置玩家数据
  1264. self:resetGame()
  1265. self:initHandCardNodes()
  1266. --写入数据
  1267. for k,v in pairs(app.room.roomInfo.memberList) do
  1268. v.nPlayerFlag = 2
  1269. end
  1270. --更新玩家状态状态
  1271. self:onUserReadyResponse()
  1272. self.toolView:updateButton()
  1273. -- 隐藏邀请好友
  1274. -- self:setWetChatVisible(false)
  1275. -- 更新局数
  1276. self:updateGameNums()
  1277. --更新庄家
  1278. self:updateBanker()
  1279. -- 显示剩余牌
  1280. self:setLastCardTipVisible(true)
  1281. --初始化方位
  1282. self.direcionView:initDirection(self.desktopType)
  1283. self.direcionView:updateDirection(app.room.roomInfo.nBankSeatId)
  1284. if onEnd then
  1285. onEnd()
  1286. end
  1287. -- cc.Device:vibrate(5)
  1288. end
  1289. log("2000000000-MJRoomView - addCallBack(runGameStartResponse)" )
  1290. self:addCallBack(runGameStartResponse);
  1291. self._gameoverview = nil
  1292. end
  1293. -- 大局结算
  1294. function zigong7zRoomView:onGameDaJuResponse(data)
  1295. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  1296. if self._gameoverview then
  1297. return
  1298. end
  1299. if app.room.roomInfo.needJieSuanInfo == 1 then--显示总结算
  1300. self:showGameOverResult(data.response)
  1301. else
  1302. --[[local roomInfo=app.room.roomInfo
  1303. --如果是解散直接跳转总结算
  1304. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1305. self:showGameOverResult(data.response)
  1306. end --]]
  1307. local roomInfo=app.room.roomInfo
  1308. local isNoCard = false--没有手牌
  1309. for i,player in pairs(roomInfo.memberList) do
  1310. if type(player.handCards) == 'table' and #player.handCards <= 0 then
  1311. local a = #player.handCards
  1312. isNoCard = true
  1313. break
  1314. end
  1315. end
  1316. if isNoCard then
  1317. self:showGameOverResult(data.response)
  1318. end
  1319. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE})
  1320. end
  1321. end
  1322. -- 大局结算
  1323. function zigong7zRoomView:showGameOverResult(data)
  1324. if self._gameoverview ~= nil then
  1325. return
  1326. end
  1327. self.direcionView:stopAllActions()
  1328. self:resetGame()
  1329. local view=MJRoomDaJuView:new(data)
  1330. view:setAnchorPoint(cc.p(0.5, 0.5))
  1331. app:showWaitDialog(view)
  1332. self._gameoverview = view
  1333. self:showGameOverAward()
  1334. end
  1335. -- 显示抽奖界面
  1336. function zigong7zRoomView:showGameOverAward()
  1337. if not (dd and dd.IGameOverAward) then
  1338. return
  1339. end
  1340. self:runDelay(0.1, function ( )
  1341. -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
  1342. dd.IGameOverAward.showAwardView();
  1343. end)
  1344. end
  1345. function zigong7zRoomView:onOtherLogoutResponse(data)
  1346. -- local jushu = app.room.roomInfo.nGameStartCount or 0
  1347. if (not data or not data.nUserId or not data.nSeatShowId) then
  1348. return
  1349. end
  1350. local function test(onEnd)
  1351. self.playerView:updatePlayerInfo(data.nSeatShowId)
  1352. self:onUserReadyResponse()
  1353. --更新GPS
  1354. --self:updateAllGpsInfo()
  1355. --self:checkGpsDistance()
  1356. -- 是否显示邀请好友
  1357. self.toolView:updateButton()
  1358. if self._fastRequestView then
  1359. self._fastRequestView:removeSelf()
  1360. self._fastRequestView = nil
  1361. end
  1362. logE("88888-onOtherLogoutResponse onEnd")
  1363. if onEnd then
  1364. onEnd()
  1365. end
  1366. end
  1367. self:addCallBack(test)
  1368. end
  1369. function zigong7zRoomView:resetGame()
  1370. logE("===========重置游戏数据===============")
  1371. self.direcionView:setVisible(false)
  1372. -- self.playerView:setOperatorTipVisible(false)
  1373. self:setTingCardViewVisible(false)
  1374. self:setChaTingCardViewVisible(false)
  1375. self:setGuideView(false)
  1376. self:showGuideTip(false)
  1377. self:setLastCardTipVisible(false)
  1378. for k,v in pairs(self.playerHandCards) do
  1379. v:removeFromParent()
  1380. end
  1381. self.playerHandCards={}
  1382. if self.xiaojuView then
  1383. self.xiaojuView:removeFromParent()
  1384. self.xiaojuView=nil
  1385. end
  1386. --隐藏工具界面 详情
  1387. -- if self.toolView.ui.Items.ImageView_Rule_bg then
  1388. -- self.toolView.ui.Items.ImageView_Rule_bg:setVisible(false)
  1389. -- end
  1390. --操作码
  1391. -- self.operationLocalCode = 0
  1392. -- self.isMoPaiOperator = false
  1393. -- self.isGameOver = false
  1394. -- self.isTianHu = false
  1395. -- self.isGodHand = false
  1396. -- --重置开招次数
  1397. -- for i = 1,4 do
  1398. -- -- self.playerZhao[i] = 0
  1399. -- end
  1400. self.ui.Items.Layout_Effect:removeAllChildren()
  1401. self.ui.Items.Layout_Effect_luobo_Lable:removeAllChildren()
  1402. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  1403. self.playerView:clearBao()
  1404. self.playerView:clearAllPiao()
  1405. self.playerView:clearAllBoZiMo()
  1406. self.playerView:setPlayerHeadLight() -- 清空头像光
  1407. self.playerView:setPlayerClock() -- 清空头像闹钟
  1408. end
  1409. function zigong7zRoomView:showPiao()
  1410. self:stopDirection()
  1411. self.playerView:setPlayerHeadLight() -- 清空头像光
  1412. self.playerView:setPlayerClock() -- 清空头像闹钟
  1413. local roomInfo=app.room.roomInfo
  1414. local gameInfo=json.decode(roomInfo.strGameInfo)
  1415. if not gameInfo.piaomode or tonumber(gameInfo.piaomode)==0 then return end
  1416. self:hidePiao()
  1417. local ui=loadUI("mj_zigong7z/res/ui_fangjian/mj_zigong_piao.ui")
  1418. self.ui.Items.Layout_Player:addChild(ui)
  1419. self.piao=ui
  1420. ui.Items.Button_BuPiao:registerClick(function()
  1421. playBtnEffect()
  1422. self:hidePiao()
  1423. local request = MJMessage.PiaoRequest:new()
  1424. request.isPiao = 0
  1425. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
  1426. end)
  1427. ui.Items.Button_Piao:registerClick(function()
  1428. playBtnEffect()
  1429. self:hidePiao()
  1430. local request = MJMessage.PiaoRequest:new()
  1431. request.isPiao = 1
  1432. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
  1433. end)
  1434. end
  1435. function zigong7zRoomView:hidePiao()
  1436. if self.piao then
  1437. self.piao:removeFromParent()
  1438. self.piao=nil
  1439. end
  1440. end
  1441. --显示飘操作按钮
  1442. function zigong7zRoomView:onStartPiao(response)
  1443. local function runPiao(onEnd)
  1444. logD("zigong7zRoomView:onStartPiao")
  1445. self:showPiao()
  1446. if onEnd then
  1447. onEnd()
  1448. end
  1449. end
  1450. logD("zigong7zRoomView:runPiao")
  1451. self:addCallBack(runPiao)
  1452. end
  1453. --飘结果
  1454. function zigong7zRoomView:onPiaoResponse(response)
  1455. local function runonPiaoResponse(onEnd)
  1456. logD("zigong7zRoomView:runonPiaoResponse")
  1457. local data = response.response
  1458. local userId = data.nUserId--操作的玩家
  1459. local playersPiaostate = data.playerPiaoState--所有玩家的飘状态
  1460. if playersPiaostate then
  1461. for i,v in pairs(playersPiaostate) do
  1462. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1463. local myUserId = app.room:getMyUserId()
  1464. local userInfo=app.room:getUserInfoByViewId(viewId)
  1465. if myUserId == data.nUserId then
  1466. else
  1467. end
  1468. self.playerView:showPiao(viewId,v.piaostate==1)
  1469. if v.piaostate==1 and userId == v.nUserId then
  1470. --飘音效
  1471. MJSound.PlayPiaoSound(userInfo.sex)
  1472. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1473. if effect then
  1474. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  1475. effect:setLocalZOrder(1000)
  1476. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1477. end
  1478. end
  1479. end
  1480. else
  1481. local viewId = app.room:getViewIdByUserId(userId)
  1482. self.playerView:showPiao(viewId,data.piaostate==1)
  1483. if data.piaostate and data.piaostate == 1 then
  1484. --飘音效
  1485. local userInfo=app.room:getUserInfoByViewId(viewId)
  1486. MJSound.PlayPiaoSound(userInfo.sex)
  1487. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1488. if effect then
  1489. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  1490. effect:setLocalZOrder(1000)
  1491. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1492. end
  1493. end
  1494. end
  1495. if onEnd then
  1496. onEnd()
  1497. end
  1498. end
  1499. logD("zigong7zRoomView:runonPiaoResponse--------")
  1500. self:addCallBack(runonPiaoResponse)
  1501. end
  1502. function zigong7zRoomView:showBaoJiao()
  1503. self:hideBaoJiao()
  1504. local ui=loadUI("mj_zigong7z/res/ui_fangjian/mj_zigong_baojiao.ui")
  1505. self:addChild(ui)
  1506. self.baojiao=ui
  1507. ui.Items.Button_bozimo:registerClick(function()
  1508. playBtnEffect()
  1509. self:hideBaoJiao()
  1510. local request = MJMessage.BaoPaiRequest:new()
  1511. request.isBaoPai = 2
  1512. logD(request.isBaoPai,"发送爆:2")
  1513. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  1514. end)
  1515. ui.Items.Button_Bao:registerClick(function()
  1516. playBtnEffect()
  1517. self:hideBaoJiao()
  1518. local request = MJMessage.BaoPaiRequest:new()
  1519. request.isBaoPai = 1
  1520. logD(request.isBaoPai,"发送爆:1")
  1521. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  1522. end)
  1523. ui.Items.Button_guo:registerClick(function()
  1524. playBtnEffect()
  1525. self:hideBaoJiao()
  1526. local request = MJMessage.BaoPaiRequest:new()
  1527. request.isBaoPai = 0
  1528. logD(request.isBaoPai,"发送爆:0")
  1529. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  1530. end)
  1531. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  1532. if gameInfo.baojiao then
  1533. ui.Items.Button_Bao:setVisible(gameInfo.baojiao == 1);
  1534. end
  1535. if gameInfo.specrule then
  1536. local bozimo = getNumBand(gameInfo.specrule, 0x0002) > 0
  1537. ui.Items.Button_bozimo:setVisible(bozimo);
  1538. end
  1539. ui.Items.Layout_baojiao:requestDoLayout()
  1540. ui.Items.Layout_baojiao:doLayout();
  1541. end
  1542. function zigong7zRoomView:hideBaoJiao()
  1543. if self.baojiao then
  1544. self.baojiao:removeFromParent()
  1545. self.baojiao=nil
  1546. end
  1547. end
  1548. function zigong7zRoomView:onBtnTingInfoClicked( )
  1549. playBtnEffect()
  1550. if self.ui.Items.Layout_Ting_Tip_Card_Panel:isVisible() then
  1551. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false)
  1552. else
  1553. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1554. end
  1555. end
  1556. function zigong7zRoomView:onChangeChatEnable()
  1557. if not self.messageView or tolua.isnull(self.messageView) then
  1558. return
  1559. end
  1560. local voiceEnable = tonumber(loadUserInfo("zigongPingBiYuYinKG")) or 1
  1561. local propEnable = tonumber(loadUserInfo("zigongHuDongBiaoQingKG")) or 1
  1562. self.messageView:setVoiceEnabled(voiceEnable==1)
  1563. self.messageView:setPropEnabled(propEnable==1)
  1564. end
  1565. function zigong7zRoomView:onEventChangeViewType(data)
  1566. MJDefine.MJConfig = MJDefine.loadMJConfig()
  1567. self:changeGameBg(true)
  1568. app.room.roomInfo.requestGetTableInfo = true
  1569. self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
  1570. end
  1571. function zigong7zRoomView:onHostingRequest( data )
  1572. local response = data.response
  1573. if response.nUserId == app.user.loginInfo.uid then
  1574. if response.status == 1 then --托管状态
  1575. self.toolView:showTuoGuan(true)
  1576. elseif response.status == 0 then--取消托管状态
  1577. self.toolView:showTuoGuan(false)
  1578. end
  1579. end
  1580. local isTuoGuan = response.status == 1;
  1581. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1582. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  1583. if isTuoGuan then
  1584. self:hidePiao()
  1585. self:hideBaoJiao()
  1586. end
  1587. end
  1588. function zigong7zRoomView:bindAllEvent()
  1589. --[[
  1590. 消息分类管理
  1591. ]]
  1592. --用户状态(包括准备,其他玩家进入或者离开通知,离线等)
  1593. self:bindUserStatedMessage()
  1594. --私人场消息(包括解散等)
  1595. self:bindPrivateMessage()
  1596. --游戏消息
  1597. self:bindGameMessage()
  1598. --游戏场景消息
  1599. self:bindGameSceneMessage()
  1600. --更换视图
  1601. -- self:bindEvent(app , MJDefine.MJEvent.ChangeViewType , handler(self , self.onChangeViewType));
  1602. self:bindEvent(app , MJDefine.MJEvent.ChangeViewBG , handler(self , self.changeGameBg));
  1603. -- self:bindEvent(app , MJDefine.MJEvent.ChangeChatEnable , handler(self , self.onChangeChatEnable));
  1604. --绑定更换桌布事件
  1605. -- self:bindEvent(app , "onChangeTable" , handler(self , self.onChangeTable));
  1606. --发送道具
  1607. -- self:bindEvent(app.room,"showProp" , handler(self , self.showProp));
  1608. self:bindExtendMessage()
  1609. end
  1610. -- 开始游戏,起飞
  1611. function zigong7zRoomView:startGame()
  1612. app.net:onMsgResume()
  1613. end
  1614. --更换水印,不同平台水印不同,在子游戏配置里面配置图片
  1615. function zigong7zRoomView:changeWaterMark()
  1616. self:initLogo()
  1617. end
  1618. -- 水印
  1619. function zigong7zRoomView:initLogo()
  1620. if tolua.isnull(self.ui.Items.ImageView_Logo) then return end
  1621. if not (type(getSubGameRoomLogo) == 'function') then--大厅不支持此方法,则隐藏logo
  1622. self.ui.Items.ImageView_Logo:setVisible(false);
  1623. return
  1624. end
  1625. local roomInfo = app.room.roomInfo
  1626. local gameInfo = json.decode(roomInfo.strGameInfo or "")
  1627. local gamerule = tonumber(gameInfo.gamerule or 1)
  1628. roomInfo.gameId = roomInfo.gameId or MJDefine.GameID or 0
  1629. local logofile = getSubGameRoomLogo(roomInfo.gameId,gamerule)
  1630. if logofile then
  1631. self.ui.Items.ImageView_Logo:loadTexture(logofile)
  1632. self.ui.Items.ImageView_Logo:setVisible(true);
  1633. else
  1634. self.ui.Items.ImageView_Logo:setVisible(false);
  1635. end
  1636. end
  1637. -- 初始化大结算再来一局
  1638. function zigong7zRoomView:initPlayGameAgain()
  1639. local strGameInfo = app.room.roomInfo.strGameInfo
  1640. local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0
  1641. if not isInClub then
  1642. logD("IPlayGameAgain.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局");
  1643. return
  1644. end
  1645. local clubGameInfo = json.decode(strGameInfo) or {}
  1646. if not clubGameInfo.ruleid then
  1647. logD("IPlayGameAgain.initPlayGameAgain", "游戏包间id不存在,不能再来一局");
  1648. return
  1649. end
  1650. dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid)
  1651. end
  1652. -- 检测是否可以解散房间
  1653. function zigong7zRoomView:checkCanDismiss( )
  1654. local onCanDismissCallback = function (info)
  1655. local nUserId = app.room:getMyUserId()
  1656. local roomInfo = app.room.roomInfo or {}
  1657. local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin()
  1658. if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
  1659. canDismiss = false
  1660. end
  1661. self:onCanDismissCallback(canDismiss)
  1662. end
  1663. if dd.IClub.getCanDismiss then
  1664. local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback)
  1665. if canDismiss then
  1666. onCanDismissCallback({canDismiss = canDismiss})
  1667. end
  1668. end
  1669. end
  1670. function zigong7zRoomView:onCanDismissCallback(canDismiss)
  1671. if not self.toolView then
  1672. return
  1673. end
  1674. if self.toolView:getIsHaveButtonDismiss() then
  1675. self.toolView:setButtonToolEnable(canDismiss)
  1676. end
  1677. end
  1678. --用户状态消息
  1679. function zigong7zRoomView:bindUserStatedMessage()
  1680. --默认状态
  1681. self:bindEvent(app.room , "defaultState" , handler(self , self.defaultState));
  1682. -- 玩家准备
  1683. self:bindEvent(app.room , MJDefine.MJEvent.UserReadyResponse , handler(self , self.onUserReadyResponse));
  1684. -- 其他玩家进入房间
  1685. self:bindEvent(app.room , MJDefine.MJEvent.OtherSitDownResponse , handler(self , self.onOtherSitDownResponse));
  1686. -- 其他玩家退出房間
  1687. self:bindEvent(app.room , MJDefine.MJEvent.OtherLogoutResponse , handler(self , self.onOtherLogoutResponse));
  1688. -- 其他玩家掉线
  1689. self:bindEvent(app.room , MJDefine.MJEvent.OtherDroppedResponse , handler(self , self.onOtherDroppedResponse));
  1690. -- 用户T出
  1691. self:bindEvent(app.room , MJDefine.MJEvent.UserExitResponseRoom , handler(self , self.onUserExitResponseRoom));
  1692. -- 玩家的GPS信息发生变化
  1693. self:bindEvent(app.room , MJDefine.MJEvent.GpsChangeResponse , handler(self , self.onGpsChangeResponse));
  1694. end
  1695. --私人场消息
  1696. function zigong7zRoomView:bindPrivateMessage()
  1697. -- 玩家收到解散房间的请求
  1698. self:bindEvent(app.room , MJDefine.MJEvent.DismissResponse , handler(self , self.onDismissResponse));
  1699. end
  1700. --游戏消息
  1701. function zigong7zRoomView:bindGameMessage()
  1702. -- 游戏开始
  1703. self:bindEvent(app.room , MJDefine.MJEvent.GameStartResponse , handler(self , self.onGameStartResponse));
  1704. -- 开始给桌子上用户发牌
  1705. self:bindEvent(app.room , MJDefine.MJEvent.GameSendCardResponse , handler(self , self.onGameSendCardResponse));
  1706. -- 系统发给自己可串可哨的消息
  1707. -- self:bindEvent(app.room , "onSystemOperationStart" , handler(self , self.onSystemOperationStart));
  1708. -- 广播桌子上所有玩家庄家起手操作
  1709. self:bindEvent(app.room , MJDefine.MJEvent.BankerOutCard, handler(self , self.onBankerOutCard));
  1710. -- 出牌错误
  1711. self:bindEvent(app.room , MJDefine.MJEvent.OutCardError , handler(self , self.onOutCardError));
  1712. -- 出牌成功
  1713. self:bindEvent(app.room , MJDefine.MJEvent.OutCardSuccess, handler(self , self.onOutCardSuccess));
  1714. self:bindEvent(app.room , MJDefine.MJEvent.TurnOutCard , handler(self , self.onTurnOutCard));
  1715. -- 抢杠胡
  1716. self:bindEvent(app.room , MJDefine.MJEvent.QiangGangHu, handler(self , self.onQiangGangHu));
  1717. -- 弃牌
  1718. self:bindEvent(app.room , MJDefine.MJEvent.OutCardResponse , handler(self , self.onOutCard));
  1719. -- 操作错误
  1720. self:bindEvent(app.room , MJDefine.MJEvent.OperationError, handler(self , self.onOperationError));
  1721. -- 先操作玩家
  1722. -- self:bindEvent(app.room , "onOperationFirst", handler(self , self.onOperationFirst));
  1723. -- 操作成功
  1724. self:bindEvent(app.room , MJDefine.MJEvent.OperationCodeSuccess , handler(self , self.onOperationCodeSuccess));
  1725. -- 听牌
  1726. self:bindEvent(app.room , MJDefine.MJEvent.TingSatus, handler(self , self.onTingCardStatus));
  1727. self:bindEvent(app.room , MJDefine.MJEvent.TingResult, handler(self , self.onTingCardResult));
  1728. self:bindEvent(app.room , MJDefine.MJEvent.ShowTing, handler(self , self.showTing));
  1729. self:bindEvent(app.room , MJDefine.MJEvent.PushTing, handler(self , self.pushTing));
  1730. self:bindEvent(app.room , MJDefine.MJEvent.WaitOperate, handler(self , self.onWaitOperate))
  1731. -- 听牌
  1732. -- self:bindEvent(app.room , "onDaiXing",handler(self , self.onDaiXing));
  1733. --弃胡通知自己
  1734. -- self:bindEvent(app.room , "onQiHuSelfResponese",handler(self , self.onQiHuSelfResponese));
  1735. --弃胡通知其他
  1736. -- self:bindEvent(app.room , "onOtherQiHuTongZhi",handler(self , self.onOtherQiHuTongZhi));
  1737. self:bindEvent(app.room , MJDefine.MJEvent.BraodcastFastStart , handler(self , self.onBroadcastFaststart));
  1738. self:bindEvent(app.room , MJDefine.MJEvent.FastStartSucc , handler(self , self.onFastStartSucc));
  1739. self:bindEvent(app.room , MJDefine.MJEvent.GameXiaoJuResponse , handler(self , self.onGameXiaoJuResponse));
  1740. self:bindEvent(app.room , MJDefine.MJEvent.GameDaJuResponse , handler(self , self.onGameDaJuResponse));
  1741. -- user pass
  1742. self:bindEvent(app.room , MJDefine.MJEvent.USER_PASS, handler(self, self.onUserPassRequest))
  1743. end
  1744. --场景恢复
  1745. function zigong7zRoomView:bindGameSceneMessage()
  1746. local function onEnterRoomSuccess(event)
  1747. if tolua.isnull(self.ui) then
  1748. logE("self.is null")
  1749. return
  1750. end
  1751. local roomInfo = app.room.roomInfo
  1752. local myUserId = app.room:getMyUserId()
  1753. for userId,v in pairs(roomInfo.memberList) do
  1754. local viewId = app.room:getViewIdByUserId(userId)
  1755. --出牌瞬间重连,会先收到重连消息再收到出牌成功,导致多一张牌,这时要在出牌成功那里删一次牌
  1756. if self.playerHandCards[viewId] and v.handCards and type(v.handCards) == 'table' then
  1757. if userId == myUserId then
  1758. local rHandCards = #v.handCards
  1759. local curHandCards = self.playerHandCards[viewId]:getHandCardsNum()
  1760. if curHandCards+1 == rhandCards then
  1761. self.needDeleteOutCard = true
  1762. end
  1763. end
  1764. end
  1765. end
  1766. self:stopAllActions()
  1767. self:defaultState()
  1768. self:onGameReconnection()
  1769. self:startGame()
  1770. end
  1771. app.hall:addEventListener("onEnterRoomSuccess", onEnterRoomSuccess)
  1772. end
  1773. function zigong7zRoomView:onFastStartSucc(data)
  1774. if self._fastRequestView then
  1775. self._fastRequestView:removeSelf()
  1776. self._fastRequestView = nil
  1777. end
  1778. --self.toolView:showFastStart(false)
  1779. self.playerView:setPlayerVisible(false)
  1780. self:updateRoomBaseData()
  1781. end
  1782. --更新房间基础数据
  1783. function zigong7zRoomView:updateRoomBaseData()
  1784. --初始化背景
  1785. -- local idx2 = tonumber(loadUserInfo("lhqgameBgPicture")) or 4
  1786. -- self:setTableImg(idx2)
  1787. --初始化方言
  1788. -- local languageType = tonumber(loadUserInfo("lhqLanguageType")) or LHQ_GAME_LANGUAGE_TYPE.FANG_YAN
  1789. -- setLHQCurLanguage(languageType)
  1790. local roomInfo = app.room.roomInfo;
  1791. -- 房间号
  1792. self._roomHeadInfo:setRoomNum(tostring(roomInfo.nShowTableId))
  1793. --局数
  1794. self:updateGameNums()
  1795. --房间玩法
  1796. self.toolView:updateRule()
  1797. -- local ruleAll = MJWanFa.getWanFaInfo(roomInfo.strGameInfo)--getLHQRuleStr();
  1798. -- self.ui.Items.Text_Rule:setText(ruleAll)
  1799. --local heght=self.ui.Items.Text_Rule:getContentSize().height+20
  1800. --self.ui.Items.Layout_Rule:setSize(cc.size(self.ui.Items.Layout_Rule:getContentSize().width,self.ui.Items.Text_Rule:getContentSize().height))
  1801. -- self.ui.Items.Layout_Rule:doLayout()
  1802. self:onUserReadyResponse()
  1803. for i = 1,6 do
  1804. self.playerView:updatePlayerInfo(i)
  1805. end
  1806. self.toolView:updateButton()
  1807. -- -- 是否显示邀请好友
  1808. -- self:setWetChatVisible(table.nums(app.room.roomInfo.memberList) < app.room.roomInfo.nMaxPlayCount)
  1809. -- if isReviewVersion() then
  1810. -- self:setWetChatVisible(false);
  1811. -- end
  1812. -- -- 更新玩家手牌列表时,按需显示
  1813. -- if app.room.roomInfo.nGameStartCount > 0 then
  1814. -- self:setWetChatVisible(false)
  1815. -- --self:setBtnSitDownVisible(false)
  1816. -- end
  1817. end
  1818. -- 分辨率改变回调(针对部分机型切后台后,导致牌数据位置不对(宽高分辨率对调了))
  1819. function zigong7zRoomView:applicationScreenSizeChanged()
  1820. print('zigong7zRoomView:applicationScreenSizeChanged')
  1821. if not self then
  1822. print('zigong7zRoomView:applicationScreenSizeChanged return not self')
  1823. return
  1824. end
  1825. if tolua.isnull(self) then
  1826. print('zigong7zRoomView:applicationScreenSizeChanged return tolua.isnull(self)')
  1827. return
  1828. end
  1829. -- 出现小局不请求重连
  1830. -- if self.xiaojuView and self.xiaojuView:isVisible() then
  1831. -- print('zigong7zRoomView:applicationScreenSizeChanged return self.xiaojuView is showing')
  1832. -- return
  1833. -- end
  1834. local callFunc = function(onEnd)
  1835. if self.playerHandCards[MJDefine.MyViewId].isUseNew3D then
  1836. if self.playerHandCards[MJDefine.MyViewId]:isUseNew3D() then
  1837. MJDefine.loadMJConfig(self.desktopType)
  1838. end
  1839. end
  1840. self:requestReconnect()
  1841. if onEnd then
  1842. onEnd()
  1843. end
  1844. end
  1845. local winSize = cc.Director:getInstance():getWinSize()
  1846. for i, v in pairs(self.playerHandCards) do
  1847. if v:getHandCardPosInitY() > winSize.height then
  1848. self:addCallBack(callFunc)
  1849. break
  1850. end
  1851. end
  1852. end
  1853. -- 其他玩家坐下成功
  1854. function zigong7zRoomView:onOtherSitDownResponse(data)
  1855. if not data or not data.nSeatShowId then
  1856. return
  1857. end
  1858. -- local nSeatShowId = data.nSeatShowId;
  1859. -- local nUserId = app.room:getUserIdByViewId(nSeatShowId)
  1860. -- self:checkGpsDistance(nUserId,true);
  1861. self:onUserReadyResponse()
  1862. -- 是否显示邀请好友
  1863. self.toolView:updateButton()
  1864. end
  1865. function zigong7zRoomView:onOtherDroppedResponse(data)
  1866. if not data.response.nUserId then
  1867. return
  1868. end
  1869. local nUserId = data.response.nUserId
  1870. local nOnlineStatus = data.response.nOnlineStatus
  1871. local viewId = app.room:getViewIdByUserId(nUserId)
  1872. self.playerView:setPlayerOffLineVisible(nOnlineStatus == MJDefine.PlayOnlineStatus.offline,viewId)
  1873. end
  1874. function zigong7zRoomView:onUserExitResponseRoom(data)
  1875. local function runUserExitResponseRoom(onEnd)
  1876. log("2000000000-MJRoomView - runUserExitResponseRoom()" )
  1877. local response = data.response
  1878. -- 0: 不退出, 1: 退出
  1879. if response.logoutFlag == 1 then
  1880. --房间号
  1881. local roomid = app.room.roomInfo.nShowTableId
  1882. --app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId,roomid));
  1883. gotoMainView(app.gameId,roomid)
  1884. end
  1885. app.room:dispatchEvent({name = "onUserExitResponseHall"});
  1886. logE("88888-onUserExitResponseRoom onEnd")
  1887. if onEnd then
  1888. onEnd()
  1889. end
  1890. end
  1891. log("2000000000-MJRoomView - addCallBack(runUserExitResponseRoom)" )
  1892. self:addCallBack(runUserExitResponseRoom);
  1893. end
  1894. -- 服务器广播玩家数据发生变化
  1895. function zigong7zRoomView:onGpsChangeResponse(data)
  1896. logD("zigong7zRoomView:onGpsChangeResponse()")
  1897. if not data or not data.nUserId then
  1898. return
  1899. end
  1900. local roomInfo = app.room.roomInfo
  1901. local nUserId = data.nUserId
  1902. logD("zigong7zRoomView:onGpsChangeResponse()", tostring(nUserId))
  1903. self:checkGpsDistance(nUserId,roomInfo.nGameStartCount==0)
  1904. end
  1905. -- 玩家收到解散房间的请求
  1906. function zigong7zRoomView:onDismissResponse(event)
  1907. if not event or not event.response then
  1908. return
  1909. end
  1910. logE("onDismissResponse() response = ", event.response)
  1911. local response = event.response
  1912. --当前时间
  1913. app.room.roomInfo.nDismissStateTime = response.timeLeft
  1914. --总的时间
  1915. app.room.roomInfo.nDismissToTalTime = app.room.roomInfo.nDisbandTimeout
  1916. --显示解散(此标志会影响闹钟时间会冻住)
  1917. app.room.roomInfo.nShowDismiss = true
  1918. if response.operateType == 1 then
  1919. local initiateUserId = response.nUserId
  1920. if response.memberList ~= nil then
  1921. for k,v in pairs(response.memberList) do
  1922. if v.dismissState == 1 then
  1923. initiateUserId = v.nUserId
  1924. end
  1925. end
  1926. end
  1927. --如果上次的解散界面还存在 先发送关闭事件
  1928. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE})
  1929. local view = require("luaScript.Views.Room.RoomDismissView"):new(initiateUserId,app.room.roomInfo.memberList,response.timeLeft)
  1930. view:setAnchorPoint(cc.p(0.5, 0.5))
  1931. app:showWaitDialog(view)
  1932. -- self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  1933. -- if response.memberList ~= nil then --自己发起
  1934. -- for k,v in pairs(response.memberList) do
  1935. -- if v.dismissState == 1 then
  1936. -- local view = MJRoomDismissView:new(v.nUserId);
  1937. -- view:setAnchorPoint(cc.p(0.5, 0.5));
  1938. -- app:showWaitDialog(view);
  1939. -- return
  1940. -- end
  1941. -- end
  1942. -- else --其他收到
  1943. -- local view = MJRoomDismissView:new(response.nUserId);
  1944. -- view:setAnchorPoint(cc.p(0.5, 0.5));
  1945. -- app:showWaitDialog(view);
  1946. -- end
  1947. else --如果不是发起操作则只转发状态给解散界面
  1948. local memberStatus={}
  1949. -- local userId = response.nUserId
  1950. if response.memberList ~= nil then
  1951. for k,v in pairs(response.memberList) do
  1952. table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
  1953. -- if v.dismissState == 1 then
  1954. -- initiateUserId = v.nUserId
  1955. -- end
  1956. end
  1957. else
  1958. table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
  1959. end
  1960. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus});
  1961. end
  1962. end
  1963. --出牌错误
  1964. function zigong7zRoomView:onOutCardError(data)
  1965. local function runOnOutCardError(onEnd)
  1966. logE("zigong7zRoomView:onOutCardError(), response = ", table.tostring(data.response))
  1967. log("2000000000-MJRoomView - runOnOutCardError")
  1968. --出牌错误主动上报日志
  1969. uploadLogs(GAME_ERROR_TYPE.AUTO)
  1970. -- --隐藏出牌效果
  1971. -- self:setOutCardVisible(false)
  1972. -- --恢复出的那张牌的透明度
  1973. -- local index = self.ui.Items.ImageView_handTempCard.index
  1974. -- self.handCardItem[index]:setOpacity(255)
  1975. -- self.bOutCard = true
  1976. self:requestReconnect();
  1977. if onEnd then
  1978. onEnd()
  1979. end
  1980. end
  1981. log("2000000000-MJRoomView - addCallBack(runOnOutCardError)")
  1982. self:addCallBack(runOnOutCardError)
  1983. end
  1984. function zigong7zRoomView:onQiangGangHu(data)
  1985. --[[ -- 庄家uid
  1986. , defVar("nUserId", VT_Int, 0)
  1987. -- 庄家操作类型
  1988. , defVar("mainOpCode", VT_Short, 0)
  1989. --庄家是否需要出牌0不需要 1:需要
  1990. , defVar("IsShouldOutCard", VT_UChar, 0)--]]
  1991. local function runOnQiangGangHu(onEnd)
  1992. -- log("2000000000-MJRoomView - (runOnBankerOutCard)")
  1993. -- logE("name = ", data.name)
  1994. logE("runOnQiangGangHu :"..table.tostring(data.response))
  1995. -- if not data.response.nUserId then
  1996. -- showTooltip("庄家起手操作nUserId is not exist")
  1997. -- end
  1998. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1999. local opType=data.response.opType
  2000. local opCard= data.response.opCard
  2001. local outCardSuccess=MJMessage.OutCardSuccess:new()
  2002. -- local operates=VT_Vector(MJMessage.OperateCard)
  2003. local operate=MJMessage.OperateCard:new()
  2004. operate.opType=opType
  2005. operate.opCard=opCard
  2006. table.insert(outCardSuccess.operates.Datas,operate)
  2007. self._operateComponent:showOperate(outCardSuccess.operates,opCard)
  2008. -- local operates=data.response.operates
  2009. -- local nSeatId=data.response.nSeatId
  2010. -- if self.playerHandCards[viewId] then
  2011. -- self.playerHandCards[viewId]:onGetCard(operates,card)
  2012. -- end
  2013. -- self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  2014. -- self:updateGameNums()
  2015. -- self.direcionView:updateDirection(nSeatId)
  2016. if onEnd then
  2017. onEnd()
  2018. end
  2019. end
  2020. log("2000000000-MJRoomView - addCallBack(runOnQiangGangHu)")
  2021. self:addCallBack(runOnQiangGangHu);
  2022. end
  2023. function zigong7zRoomView:onOutCard(data)
  2024. local function runOnOutCard(onEnd)
  2025. logE("zigong7zRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  2026. log("2000000000-MJRoomView - runOnOutCard")
  2027. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  2028. -- local card= data.response.card
  2029. -- if self.playerHandCards[viewId] then
  2030. -- self.playerHandCards[viewId]:createOutCards(card)
  2031. -- end
  2032. if onEnd then
  2033. onEnd()
  2034. end
  2035. end
  2036. log("2000000000-MJRoomView - addCallBack(runOnOutCard)")
  2037. self:addCallBack(runOnOutCard)
  2038. end
  2039. --操作错误
  2040. function zigong7zRoomView:onOperationError(data)
  2041. local function runOnOperationError(onEnd)
  2042. log("2000000000-MJRoomView - (runOnOperationError)")
  2043. --恢复操作面板
  2044. -- self:touchEatOneCardCallBack()
  2045. if onEnd then
  2046. onEnd()
  2047. end
  2048. end
  2049. log("2000000000-MJRoomView - addCallBack(runOnOperationError)")
  2050. self:addCallBack(runOnOperationError)
  2051. end
  2052. function zigong7zRoomView:onWaitOperate(data)
  2053. --等待操作的UID
  2054. local nUserId = data.response.nUserId
  2055. --操作类型
  2056. local opType = data.response.opType
  2057. local viewId = app.room:getViewIdByUserId(nUserId)
  2058. local waitSprite = nil
  2059. if opType==MJDefine.MJOperateType.OPREATE_PENG then
  2060. waitSprite = cc.Sprite:create("mj/res/ui/zy_fangjian/operate/mj_effect_wait_peng.png")
  2061. elseif opType==MJDefine.MJOperateType.OPREATE_ZHIGANG or opType==MJDefine.MJOperateType.OPREATE_BAGANG or opType==MJDefine.MJOperateType.OPREATE_ANGANG then
  2062. waitSprite = cc.Sprite:create("mj/res/ui/zy_fangjian/operate/mj_effect_wait_gang.png")
  2063. elseif opType==MJDefine.MJOperateType.OPREATE_DIANPAOHU or opType==MJDefine.MJOperateType.OPREATE_QIANG_GANG_HU then
  2064. waitSprite = cc.Sprite:create("mj/res/ui/zy_fangjian/operate/mj_effect_wait_hu.png")
  2065. end
  2066. if waitSprite then
  2067. self.ui.Items.Layout_Player:addChild(waitSprite)
  2068. waitSprite:setLocalZOrder(1000)
  2069. waitSprite:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  2070. table.insert(self.waitOperates,waitSprite)
  2071. end
  2072. end
  2073. function zigong7zRoomView:onBroadcastFaststart(data)
  2074. local response = data.response
  2075. local remove = false
  2076. if response.nUserId and response.nStatus then
  2077. if response.nStatus == 3 or response.nStatus>4 then
  2078. remove = true
  2079. end
  2080. end
  2081. if not remove then
  2082. for _,v in ipairs(response.pList) do
  2083. if v.nStatus == 3 or v.nStatus>4 then
  2084. remove = true
  2085. end
  2086. end
  2087. end
  2088. if response.timeOut <=0 then remove = true end
  2089. if self._fastRequestView == nil then
  2090. if remove then return "" end
  2091. local requesterId = 0
  2092. for _,v in ipairs(response.pList) do
  2093. if v.nStatus == 1 then
  2094. requesterId = v.nUserId
  2095. end
  2096. end
  2097. if requesterId<=0 then return "" end
  2098. local view = import("mj.luaScript.Views.Room.MJRequestStartView"):new(requesterId)
  2099. view:setAnchorPoint(cc.p(0.5, 0.5))
  2100. view:showItems(response)
  2101. app:showWaitDialog(view)
  2102. self._fastRequestView = view
  2103. else
  2104. if remove then
  2105. local userInfo = app.room.roomInfo.memberList[response.nUserId]
  2106. self._fastRequestView:removeSelf()
  2107. self._fastRequestView = nil
  2108. if userInfo then
  2109. local u = json.decode(userInfo.userInfo)
  2110. local txt = string.format("玩家【%s】拒绝立即开局", u.nickname)
  2111. showTooltip(txt)
  2112. end
  2113. app.room:resetFastInfo()
  2114. --self.toolView:showFastStart(true)
  2115. else
  2116. self._fastRequestView:updateView(response)
  2117. end
  2118. end
  2119. end
  2120. --托管状态,服务器下发过操作,客户端隐藏操作界面
  2121. function zigong7zRoomView:onUserPassRequest( data )
  2122. local response = data.response
  2123. if app.room:getMyUserId() == response.nUserId then
  2124. self._operateComponent:hideOperate()
  2125. end
  2126. end
  2127. -- 添加延迟回调事件,delay不传默认为0,但是需注意,排在有delay的后面事件,也会相应的跟着一起间隔
  2128. function zigong7zRoomView:addCallBack(callback, delay)
  2129. local callbackInfo = {
  2130. callback = callback,
  2131. delay = delay or 0
  2132. }
  2133. -- 将回调放在一起管理
  2134. table.insert(self.callbackQueue, callbackInfo)
  2135. logE(" #self.callbackQueue:".. #self.callbackQueue)
  2136. cc.Director:getInstance():getScheduler():setTimeScale(1.0)
  2137. local function runFunc()
  2138. if #self.callbackQueue <= 0 then
  2139. self.callbackRunning = false
  2140. return
  2141. end
  2142. local callbackInfo = self.callbackQueue[1]
  2143. local func = callbackInfo.callback;
  2144. local delay = callbackInfo.delay;
  2145. table.remove(self.callbackQueue,1) -- 执行一个则删除一个回调
  2146. self.callbackRunning = true
  2147. local function runCallback (cb)
  2148. cb(function()
  2149. self.callbackRunning = false;
  2150. runFunc(); -- 然后继续执行下一个回调
  2151. end)
  2152. end
  2153. -- 如果有delay,那么启动全局定时器
  2154. if delay and delay > 0 then
  2155. local entryId = nil;
  2156. entryId = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  2157. runCallback(func);
  2158. if entryId then
  2159. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(entryId);
  2160. end
  2161. end, delay, false);
  2162. else
  2163. runCallback(func);
  2164. end
  2165. end
  2166. log("self.callbackRunning:",self.callbackRunning)
  2167. if not self.callbackRunning then
  2168. runFunc();
  2169. end
  2170. end
  2171. --隐藏提示界面
  2172. function zigong7zRoomView:setGuideView(bVisible)
  2173. self.ui.Items.Layout_tips:setVisible(bVisible)
  2174. if bVisible then
  2175. self.ui.Items.ImageView_3:playClip("tip")
  2176. end
  2177. end
  2178. -- 初始化手牌界面
  2179. function zigong7zRoomView:initHandCardNodes()
  2180. if MJDefine.MJRoomPlayerSitConfig[app.room:getMaxPlayerCount()] then
  2181. for k,v in pairs(MJDefine.MJRoomPlayerSitConfig[app.room:getMaxPlayerCount()]) do
  2182. if self.playerHandCards[v] then
  2183. self.playerHandCards[v]:removeFromParent()
  2184. end
  2185. self.playerHandCards[v] = MJHandCardView:new(v,self.desktopType)
  2186. self.ui.Items.Layout_Player:addChild(self.playerHandCards[v],v)
  2187. end
  2188. end
  2189. end
  2190. -- 获得手牌界面
  2191. function zigong7zRoomView:getHandCardNodesByViewId(viewId)
  2192. return self.playerHandCards[viewId]
  2193. end
  2194. function zigong7zRoomView:updateGameNums()
  2195. -- 更新当前局数
  2196. -- local roomInfo = app.room.roomInfo
  2197. -- local curCount = roomInfo.nGameStartCount or 0
  2198. -- local str = string.format("局数%d/%d", curCount, roomInfo.nTotalGameNum)
  2199. -- self.ui.Items.Text_JuShu:setText(str)
  2200. --更新牌数
  2201. -- self.ui.Items.Text_CardNum:setText(roomInfo.nLeaveCardNum or 0)
  2202. -- if curCount>0 then
  2203. -- self.ui.Items.ImageView_CardNum:setVisible(false)
  2204. -- self.ui.Items.Layout_GameInfo:setVisible(true)
  2205. -- else
  2206. -- self.ui.Items.ImageView_CardNum:setVisible(false)
  2207. -- self.ui.Items.Layout_GameInfo:setVisible(false)
  2208. -- end
  2209. local roomInfo = app.room.roomInfo
  2210. if self.direcionView then
  2211. self.direcionView:updateGameNums()
  2212. end
  2213. if self._lastCardTip then
  2214. self._lastCardTip:setLastCardCount(roomInfo.nLeaveCardNum or 0)
  2215. end
  2216. if self._roomHeadInfo then
  2217. self._roomHeadInfo:setRoundCount(roomInfo.nGameStartCount, roomInfo.nTotalGameNum)
  2218. end
  2219. end
  2220. --更新庄家
  2221. function zigong7zRoomView:updateBanker()
  2222. --隐藏所有的庄家标志
  2223. -- self:setBankerVisible()
  2224. --只显示当前的庄家座位号
  2225. local nBankerSeatId = app.room.roomInfo.nBankSeatId
  2226. local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
  2227. self.playerView:setBankerVisible(viewId,true)
  2228. -- if self.allNodes[viewId] then
  2229. -- self.allNodes[viewId].banker:setVisible(true)
  2230. -- else
  2231. -- showTooltip("庄家椅子号"..nBankerSeatId.."不匹配")
  2232. -- end
  2233. end
  2234. --隐藏准备按钮
  2235. function zigong7zRoomView:setBtnSitDownVisible(bVisible)
  2236. -- self.toolView.ui.Items.Button_Ready:setVisible(bVisible)
  2237. --self.ui.Items.Button_Ready:setVisible(bVisible)
  2238. -- self:updateButtonPosition()
  2239. end
  2240. --倒牌
  2241. function zigong7zRoomView:showOpenCard()
  2242. local roomInfo = app.room.roomInfo
  2243. for k,v in pairs(roomInfo.memberList) do
  2244. local viewId = app.room:getViewIdByUserId(v.nUserId)
  2245. if viewId and self.playerHandCards[viewId] then
  2246. if viewId==MJDefine.MyViewId then
  2247. -- 我自己则屏蔽触摸事件
  2248. self.playerHandCards[viewId]:removeTouchEvent()
  2249. else
  2250. --倒牌
  2251. self.playerHandCards[viewId]:removeAllHandCards()
  2252. self.playerHandCards[viewId]:createOpenHandCards(v.handCards)
  2253. end
  2254. end
  2255. end
  2256. end
  2257. -- 胡标记偏移位置
  2258. function zigong7zRoomView:getHuFlagOffset(viewId)
  2259. local offset = {
  2260. [MJDefine.PlayerViewType.My] = {x = 0, y = 0},
  2261. [MJDefine.PlayerViewType.LeftUp] = {x = 0, y = 0},
  2262. [MJDefine.PlayerViewType.LeftDown] = {x = 0, y = 0},
  2263. [MJDefine.PlayerViewType.Top] = {x = 0, y = 0},
  2264. [MJDefine.PlayerViewType.RightUp] = {x = 0, y = 0},
  2265. [MJDefine.PlayerViewType.RightDown] = {x = 0, y = 0},
  2266. }
  2267. if offset[viewId] then
  2268. return offset[viewId].x, offset[viewId].y
  2269. else
  2270. return 0, 0
  2271. end
  2272. end
  2273. --显示高亮头像
  2274. function zigong7zRoomView:onHeadShowHighLight(response)
  2275. if not response then return end
  2276. local data = response.response
  2277. if not data then return end
  2278. self.playerView:setPlayerHeadLight(data.viewId, true)
  2279. self.playerView:setPlayerClock(data.viewId, true, 30) -- 清空头像闹钟
  2280. end
  2281. -- 手势提示
  2282. function zigong7zRoomView:showGuideTip(isShow)
  2283. if self._isReplay then
  2284. self.ui.Items.Layout_tips:setVisible(false)
  2285. return
  2286. end
  2287. local isShow = isShow or false
  2288. self.ui.Items.Layout_tips:setVisible(isShow)
  2289. local startPos = cc.p(97, 67)
  2290. if isShow then
  2291. local moveBy = cc.MoveBy:create(0.5, cc.p(0, 80))
  2292. local callfunc = cc.CallFunc:create(function()
  2293. self.ui.Items.ImageView_3:setPosition(startPos)
  2294. end)
  2295. local delay = cc.DelayTime:create(1)
  2296. local seq = cc.Sequence:create(moveBy, delay, callfunc)
  2297. local rep = cc.RepeatForever:create(seq)
  2298. self.ui.Items.ImageView_3:runAction(rep)
  2299. else
  2300. self.ui.Items.ImageView_3:stopAllActions()
  2301. self.ui.Items.ImageView_3:setPosition(startPos)
  2302. end
  2303. local is3D = self:getDeskopType() == MJDefine.DesktopType.ThreeD
  2304. self.ui.Items.ImageView_1:setVisible(not is3D)
  2305. self.ui.Items.ImageView_2:setVisible(not is3D)
  2306. self.ui.Items.ImageView_3:setVisible(is3D)
  2307. end
  2308. -- 获得方位组件
  2309. function zigong7zRoomView:getDirectionView()
  2310. return self.direcionView
  2311. end
  2312. -- 获得桌子类型
  2313. function zigong7zRoomView:getDeskopType()
  2314. return self.desktopType
  2315. end
  2316. -- 获得玩家面板
  2317. function zigong7zRoomView:getPlayerView()
  2318. return self.playerView
  2319. end
  2320. -- 设置正在重连属性
  2321. function zigong7zRoomView:setRunningReconnect(bool)
  2322. self.isRunGameReconnection = bool
  2323. end
  2324. -- 获得特效面板
  2325. function zigong7zRoomView:getEffectLayer()
  2326. return self.ui.Items.Layout_Effect
  2327. end
  2328. -- 获得萝卜特效面板
  2329. function zigong7zRoomView:getEffectLuoboLayer()
  2330. return self.ui.Items.Layout_Effect_luobo
  2331. end
  2332. -- 获得听按钮
  2333. function zigong7zRoomView:getButtonTingInfo()
  2334. return self.ui.Items.Button_Ting_Info
  2335. end
  2336. -- 设置操作数据
  2337. function zigong7zRoomView:setOperates(data)
  2338. self.operates = data or {}
  2339. end
  2340. -- 获得工具层
  2341. function zigong7zRoomView:getToolView()
  2342. return self.toolView
  2343. end
  2344. -- 隐藏操作界面
  2345. function zigong7zRoomView:onHideOperateLayer()
  2346. if not self._operateComponent then
  2347. return
  2348. end
  2349. self._operateComponent:hideOperateLayer()
  2350. end
  2351. -- 获得操作界面
  2352. function zigong7zRoomView:getOperateComponent()
  2353. return self._operateComponent
  2354. end
  2355. -- 萝卜标记偏移位置
  2356. function zigong7zRoomView:getLuoBoOffset(viewId)
  2357. local offset = {
  2358. [MJDefine.PlayerViewType.My] = {x = -500, y = -100},
  2359. [MJDefine.PlayerViewType.LeftUp] = {x = 0, y = -60},
  2360. [MJDefine.PlayerViewType.LeftDown] = {x = 0, y = -60},
  2361. [MJDefine.PlayerViewType.Top] = {x = 100, y = 100},
  2362. [MJDefine.PlayerViewType.RightUp] = {x = 0, y = -60},
  2363. [MJDefine.PlayerViewType.RightDown] = {x = 0, y = -60},
  2364. }
  2365. if offset[viewId] then
  2366. return offset[viewId].x, offset[viewId].y
  2367. else
  2368. return 0, 0
  2369. end
  2370. end
  2371. -- 获得是否回放
  2372. function zigong7zRoomView:getIsReplay()
  2373. return self._isReplay or false
  2374. end
  2375. -- 设置剩余牌显示
  2376. function zigong7zRoomView:setLastCardTipVisible(bool)
  2377. self._lastCardTip:setVisible(bool or false)
  2378. end
  2379. -- 隐藏手势提示界面
  2380. function zigong7zRoomView:onHideGuideTip()
  2381. self:showGuideTip(false)
  2382. end
  2383. -- 请求重连
  2384. function zigong7zRoomView:requestReconnect()
  2385. if not MJDefine then
  2386. return
  2387. end
  2388. if not MJDefine.MJEvent then
  2389. return
  2390. end
  2391. if not MJDefine.MJEvent.GetTableInfo then
  2392. return
  2393. end
  2394. self.ui:sendMsg(app.room,MJDefine.MJEvent.GetTableInfo)
  2395. end
  2396. return zigong7zRoomView