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

1294 行
41 KiB

  1. local MJRoomToolView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView")
  2. local MJRoomMessageView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomMessageView")
  3. local MJRoomPlayerView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView")
  4. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  5. local MJHandCardView=MJFramework.MJImport("mj.luaScript.Views.Game.MJHandCardView")
  6. local MJRoomXiaoJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomXiaoJuView")
  7. local MJRoomDaJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView")
  8. local MJRoomDismissView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDismissView")
  9. local MJRoomDirection=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection")
  10. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  11. local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  12. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  13. local MJAnimationCompnent=MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent")
  14. local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
  15. local MJSound=MJFramework.MJImport("mj.luaScript.MJSound")
  16. local MJRoomView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomView")
  17. local hongzhongRoomView = class("hongzhongRoomView", MJRoomView)
  18. local zhongNiaoTime=1.33
  19. function hongzhongRoomView:loadUi()
  20. local ui = loadUI("hongzhong/res/ui_fangjian/hongzhong_ui_fangjian.ui")
  21. self.ui = ui
  22. self:addChild(ui)
  23. if isReviewVersion() then
  24. self.ui.Items.Layout_3:setVisible(false)
  25. self.ui.Items.Layout_4:setVisible(false)
  26. end
  27. end
  28. function hongzhongRoomView:ctor()
  29. hongzhongRoomView.super.ctor(self)
  30. local defaultValue = tostring(loadUserInfo("hongzhong_mj_color")) or "2d"
  31. if defaultValue == "" then
  32. defaultValue = "2d"
  33. saveUserInfo("hongzhong_mj_color", defaultValue)
  34. end
  35. self.desktopType = defaultValue
  36. MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
  37. end
  38. function hongzhongRoomView:onEnter()
  39. hongzhongRoomView.super.onEnter(self)
  40. -- self:test()
  41. -- self:onGameXiaoJuResponse()
  42. -- self:showPiao()
  43. self.ui.Items.Text_Rule:setVisible(false)
  44. self:doSound()
  45. --记录3D位置
  46. -- self:init3DPos()
  47. --初始化详情
  48. self:initGameRule()
  49. --更换桌布
  50. self:bindEvent(app , MJDefine.MJEvent.ChangeTableBg , handler(self , self.onChangeTableBg));
  51. end
  52. function hongzhongRoomView:onExit()
  53. hongzhongRoomView.super.onExit(self)
  54. self:cleanCache()
  55. end
  56. function hongzhongRoomView:cleanCache()
  57. local preload = package.loaded
  58. for k, v in pairs(package.loaded or {}) do
  59. local res1 = string.find( k, "mj.luaScript") or 0
  60. local res2 = string.find( k, "hongzhong.luaScript") or 0
  61. if res1 > 0 or res2 > 0 then
  62. print("cleanCache-------"..k)
  63. package.loaded[k] = nil
  64. end
  65. end
  66. end
  67. ---
  68. -- 更新房间基础数据
  69. -- @return
  70. --
  71. function hongzhongRoomView:updateRoomBaseData (...)
  72. hongzhongRoomView.super.updateRoomBaseData(self, ...)
  73. -- 更新房间号
  74. local roomInfo = app.room.roomInfo;
  75. self.ui.Items.Text_roomNum:setText(tostring(roomInfo.nShowTableId));
  76. end
  77. --更换桌布(同维度)
  78. function hongzhongRoomView:onChangeTableBg()
  79. local defaultValue = tonumber(loadUserInfo("hongzhong_mj_desktop_group")) or 2
  80. local bgData = MJDefine.CHANGE_GAME_BG[defaultValue]
  81. if self.curDeskType==MJDefine.DesktopType.TwoD or self.curDeskType==MJDefine.DesktopType.TwoDGold then
  82. self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
  83. else
  84. self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
  85. end
  86. end
  87. function hongzhongRoomView:initView()
  88. hongzhongRoomView.super.initView(self)
  89. if not self.messageView or tolua.isnull(self.messageView) then
  90. return
  91. end
  92. --互动表情
  93. local faceKG = tonumber(loadUserInfo("hongzhongHuDongBiaoQingKG")) or 1--0关 1开
  94. --屏蔽语音
  95. local voiceKG = tonumber(loadUserInfo("hongzhongPingBiYuYinKG")) or 1--0关 1开
  96. self.messageView:setPropEnabled(faceKG == 1)
  97. self.messageView:setVoiceEnabled(voiceKG == 1)
  98. self.messageView:setBtnFace(nil,"mj_btn_face2.png")
  99. self.messageView:setBtnVoice(nil,"mj_btn_voice2.png")
  100. end
  101. function hongzhongRoomView:onUserReadyResponse(response)
  102. hongzhongRoomView.super.onUserReadyResponse(self, response)
  103. self:updateReady()
  104. local roomInfo = app.room.roomInfo
  105. local isShow = roomInfo.nGameStartCount <= 0
  106. local memberInfo = app.room.roomInfo.memberList[app.user.loginInfo.uid]
  107. if memberInfo then
  108. self.ui.Items.Button_Ready:getParent():setVisible(memberInfo.nPlayerFlag == 0 and isShow)
  109. self.ui.Items.Layout_Button:requestDoLayout()
  110. self.ui.Items.Layout_Button:doLayout()
  111. end
  112. end
  113. function hongzhongRoomView:updateReady()
  114. local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  115. if app.room.roomInfo.nGameStartCount > 0 then
  116. self.toolView.ui.Items.Button_Leave:setEnabled(false)
  117. self:setBtnSitDownVisible(false)
  118. else
  119. self.toolView.ui.Items.Button_Leave:setEnabled(true)
  120. end
  121. if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= nUserId then
  122. self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
  123. else
  124. self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
  125. end
  126. self:checkCanDismiss()
  127. end
  128. --[[
  129. --初始记录一些位置,切换2D桌面时需要移动一些位置,记录这些需要移动元素的位置
  130. function hongzhongRoomView:init3DPos()
  131. --游戏顶部信息
  132. self.topBgPos = self.ui.Items.ImageView_top_bg:getPosition()
  133. self.layoutGameInfoPos = self.ui.Items.Layout_GameInfo:getPosition()
  134. self.layoutRoomInfoPos = self.ui.Items.Layout_RoomInfo:getPosition()
  135. self.Text_JuShuPos = self.ui.Items.Text_JuShu:getPosition()
  136. self.Text_TimePos = self.ui.Items.Text_Time:getPosition()
  137. self.btn_baoJianPos = self.ui.Items.Button_Club:getPosition()
  138. --菜单按钮
  139. self.toolMenuBtnPos = self.toolView.ui.Items.Button_Menu:getPosition()
  140. --菜单展开按钮
  141. self.toolMenuLayoutPos = self.toolView.ui.Items.Layout_Menu:getPosition()
  142. --菜单展开按钮背景
  143. self.toolMenuBgPos = self.toolView.ui.Items.ImageView_menubg:getPosition()
  144. --聊天语音按钮
  145. self.messgaeBtnFacePos = self.messageView.ui.Items.Button_Face:getPosition()
  146. self.messgaeBtnVoicePos = self.messageView.ui.Items.Button_Voice:getPosition()
  147. self.playerNodePos = {}
  148. for i=1,4 do
  149. if self.playerView.allNodes[i].player then
  150. self.playerNodePos[i] = self.playerView.allNodes[i].player:getPosition()
  151. end
  152. end
  153. -- self.chatRecordPos = self.messageView.ui.Items.Button_Record:getPosition()
  154. -- self.chatFacePos = self.messageView.ui.Items.Button_Face:getPosition()
  155. self.tingPos = self.ui.Items.Layout_Ting_Tip_Card_Panel:getPosition()
  156. self.gpsPos = self.ui.Items.Button_GPS:getPosition()
  157. self:changeGameBg()
  158. self.ui.Items.Button_GPS:setVisible(true)
  159. end
  160. function hongzhongRoomView:changePosToAdapt2D()
  161. self.ui.Items.ImageView_top_bg:setVisible(false)
  162. self.ui.Items.Layout_GameInfo:setPositionY(self.layoutGameInfoPos.y-15)
  163. self.ui.Items.Layout_RoomInfo:setPositionY(self.layoutRoomInfoPos.y-15)
  164. --self.ui.Items.Text_JuShu:setPositionX(self.Text_JuShuPos.x+20)
  165. self.ui.Items.Text_Time:setPosition(cc.p(5,40))
  166. self.toolView.ui.Items.btnMenu:setPosition(cc.p(self.toolMenuBtnPos.x-10,self.toolMenuBtnPos.y - 10))
  167. self.toolView.ui.Items.Layout_Menu:setPosition(cc.p(self.toolMenuLayoutPos.x-10,self.toolMenuLayoutPos.y+10))
  168. self.ui.Items.Button_Club:setPosition(cc.p(self.btn_baoJianPos.x-10,self.btn_baoJianPos.y + 25))
  169. self.toolView.ui.Items.ImageView_menubg:setPosition(cc.p(self.toolMenuBgPos.x+10,self.toolMenuBgPos.y+15))
  170. self.messageView.ui.Items.Button_Voice:setPosition(cc.p(self.messgaeBtnVoicePos.x - 5,self.messgaeBtnVoicePos.y - 20))
  171. self.messageView.ui.Items.Button_Face:setPosition(cc.p(self.messgaeBtnFacePos.x - 5,self.messgaeBtnFacePos.y - 20))
  172. self.playerView.allNodes[1].player:setPositionX(self.playerNodePos[1].x-8)
  173. self.playerView.allNodes[2].player:setPositionY(self.playerNodePos[2].y-7)
  174. self.playerView.allNodes[3].player:setPositionX(self.playerNodePos[3].x+8)
  175. self.playerView.allNodes[4].player:setPosition(cc.p(self.playerNodePos[4].x+8,self.playerNodePos[4].y+10))
  176. -- self.messageView.ui.Items.Button_Record:setPositionX(self.chatRecordPos.x-10)
  177. -- self.messageView.ui.Items.Button_Face:setPositionX(self.chatFacePos.x-10)
  178. self.ui.Items.Layout_Ting_Tip_Card_Panel:setPositionY(self.tingPos.y+10)
  179. self.ui.Items.Button_GPS:setPositionY(self.gpsPos.y-2)
  180. end
  181. function hongzhongRoomView:changePosToAdapt3D()
  182. self.ui.Items.ImageView_top_bg:setVisible(false)
  183. self.ui.Items.Layout_GameInfo:setPositionY(self.layoutGameInfoPos.y)
  184. self.ui.Items.Layout_RoomInfo:setPositionY(self.layoutRoomInfoPos.y)
  185. self.ui.Items.Text_JuShu:setPositionX(self.Text_JuShuPos.x)
  186. self.ui.Items.Text_Time:setPosition(self.Text_TimePos)
  187. self.toolView.ui.Items.btnMenu:setPosition(self.toolMenuBtnPos)
  188. self.toolView.ui.Items.Layout_Menu:setPosition(self.toolMenuLayoutPos)
  189. self.messageView.ui.Items.Button_Voice:setPosition(cc.p(self.messgaeBtnVoicePos.x ,self.messgaeBtnVoicePos.y - 20))
  190. self.messageView.ui.Items.Button_Face:setPosition(cc.p(self.messgaeBtnFacePos.x ,self.messgaeBtnFacePos.y - 20))
  191. self.ui.Items.Button_Club:setPositionY(self.btn_baoJianPos.y + 22)
  192. self.toolView.ui.Items.ImageView_menubg:setPosition(self.toolMenuBgPos)
  193. self.playerView.allNodes[1].player:setPositionX(self.playerNodePos[1].x)
  194. self.playerView.allNodes[2].player:setPositionY(self.playerNodePos[2].y)
  195. self.playerView.allNodes[3].player:setPositionX(self.playerNodePos[3].x)
  196. self.playerView.allNodes[4].player:setPosition(self.playerNodePos[4])
  197. -- self.messageView.ui.Items.Button_Record:setPositionX(self.chatRecordPos.x)
  198. -- self.messageView.ui.Items.Button_Face:setPositionX(self.chatFacePos.x)
  199. self.ui.Items.Layout_Ting_Tip_Card_Panel:setPositionY(self.tingPos.y)
  200. self.ui.Items.Button_GPS:setPositionY(self.gpsPos.y)
  201. end]]
  202. function hongzhongRoomView:updateGameNums()
  203. -- 更新当前局数
  204. local roomInfo = app.room.roomInfo
  205. local curCount = roomInfo.nGameStartCount or 0
  206. --local str = string.format("牌局:%d/%d", curCount, roomInfo.nTotalGameNum)
  207. --local str = string.format("牌局: /%02d", roomInfo.nTotalGameNum)
  208. local str = string.format("牌局: /%02d", roomInfo.nTotalGameNum)
  209. local str1 = string.format("%02d", curCount)
  210. self.ui.Items.Text_JuShu:setText(str)
  211. self.ui.Items.Text_curJuShu:setText(str1)
  212. --更新牌数
  213. self.ui.Items.Text_CardNum:setText(roomInfo.nLeaveCardNum or 0)
  214. if curCount>0 then
  215. self.ui.Items.Layout_GameInfo:setVisible(true)
  216. else
  217. self.ui.Items.Layout_GameInfo:setVisible(false)
  218. end
  219. self:updateInviteButtonState()
  220. self:updateInviteClubButtonState()
  221. self:updateReadyButtonState()
  222. end
  223. function hongzhongRoomView:initGameButton()
  224. hongzhongRoomView.super.initGameButton(self)
  225. -- 邀请好友
  226. self.ui.Items.Button_Invite:registerClick(handler(self , self.onClickFriends2))
  227. -- 准备
  228. self.ui.Items.Button_Ready:registerClick(handler(self , self.onClickReady))
  229. -- 亲友圈邀请
  230. self.ui.Items.Button_Invite_Club:registerClick(handler(self , self.onClickInviteClub))
  231. -- 包间
  232. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  233. self.ui.Items.Button_Club:setVisible(true)
  234. --切换回俱乐部
  235. self.ui.Items.Button_Club:registerClick(handler(self, self.onClickBaoJian))
  236. else
  237. self.ui.Items.Button_Club:setVisible(false)
  238. end
  239. end
  240. function hongzhongRoomView:doSound()--1 普通话 2 长沙话
  241. local defaultValue = tonumber(loadUserInfo("hongzhong_mj_sound")) or 1
  242. saveUserInfo("hongzhong_mj_sound", defaultValue)
  243. MJSound.setSoundType(defaultValue)
  244. end
  245. function hongzhongRoomView:loadTextureCache()
  246. hongzhongRoomView.super.loadTextureCache(self)
  247. loadSpriteFrameFile("hongzhong/res/zy_fangjian/hl_old_mj.plist")
  248. loadSpriteFrameFile("hongzhong/res/zy_fangjian/hl_old_mj_2d.plist")
  249. cc.SpriteFrameCache:getInstance():addSpriteFramesWithFile("hongzhong/res/zy_fangjian/mj_piao_fen.plist")
  250. end
  251. function hongzhongRoomView:bindExtendMessage()
  252. --下飘
  253. self:bindEvent(app.room , MJDefine.MJEvent.XiaPiaoTime , handler(self , self.onXiaPiaoTime))
  254. self:bindEvent(app.room , MJDefine.MJEvent.XiaPiaoResponse , handler(self , self.onXiaPiaoResponse))
  255. -- 玩家请求快速开始广播
  256. self:bindEvent(app.room, MJDefine.MJEvent.BraodcastFastStart, handler(self, self.onBroadcastFaststart))
  257. -- 快速开始成功
  258. self:bindEvent(app.room, MJDefine.MJEvent.FastStartSucc, handler(self, self.onFastStartSucc))
  259. -- 托管
  260. self:bindEvent(app.room , MJDefine.MJEvent.HostingRequest, handler(self, self.onHostingRequest))
  261. -- user pass
  262. self:bindEvent(app.room , MJDefine.MJEvent.USER_PASS, handler(self, self.onUserPassRequest))
  263. --设置互动表情开关事件
  264. self:bindEvent(app.room,"ontSetPropEnabled" , handler(self , self.ontSetPropEnabled));
  265. --设置语音开关事件
  266. self:bindEvent(app.room,"onSetVoiceEnabled" , handler(self , self.onSetVoiceEnabled));
  267. --切换视图
  268. self:bindEvent(app, MJDefine.MJEvent.ChangeViewType, handler(self, self.onChangeViewType))
  269. end
  270. function hongzhongRoomView:onChangeViewType(event)
  271. hongzhongRoomView.super.onChangeViewType(self,event)
  272. self:loadTextureCache()
  273. MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
  274. self:changeGameBg(true)
  275. self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo)
  276. end
  277. function hongzhongRoomView:ontSetPropEnabled(event)
  278. -- local idx = event.value
  279. if self.messageView then
  280. self.messageView:setPropEnabled(event.value == 1)
  281. end
  282. end
  283. function hongzhongRoomView:onSetVoiceEnabled(event)
  284. -- local idx = event.value
  285. if self.messageView then
  286. self.messageView:setVoiceEnabled(event.value == 1)
  287. end
  288. end
  289. function hongzhongRoomView:onXiaPiaoTime(event)
  290. local roomInfo=app.room.roomInfo
  291. local t=roomInfo.nPiaoLeftTime
  292. self.direcionView:updateDirection(roomInfo.memberList[app.room:getMyUserId()].nSeatId)
  293. self.direcionView:runShotTime(MJDefine.MyViewId,t)
  294. self:showPiao()
  295. --倒计时
  296. -- self.ui.Items.Text_Time:setString(string.format("%02d",t))
  297. -- self:stopAllActions()
  298. -- self:runAction(cc.RepeatForever:create(
  299. -- cc.Sequence:create(
  300. -- cc.DelayTime:create(1),
  301. -- cc.CallFunc:create(function()
  302. -- t=t-1
  303. -- if t<0 then
  304. -- t=0
  305. -- self:hidePiao()
  306. -- self:stopAllActions()
  307. -- end
  308. -- -- self.ui.Items.Text_Time:setString(string.format("%02d",t))
  309. -- end)
  310. -- )
  311. -- ))
  312. end
  313. function hongzhongRoomView:onXiaPiaoResponse(event)
  314. local nUserId=event.nUserId
  315. if nUserId==app.room:getMyUserId() then
  316. self:hidePiao()
  317. end
  318. -- self:updatePiao()
  319. local roomInfo=app.room.roomInfo
  320. local memberList=roomInfo.memberList
  321. for k,v in pairs(memberList) do
  322. if v.nPiaoNum then
  323. local viewId = app.room:getViewIdByUserId(k)
  324. logD("hongzhongRoomView:onXiaPiaoResponse: viewId="..viewId.." nPiaoNum="..v.nPiaoNum)
  325. self:updatePiao(viewId,v.nPiaoNum)
  326. end
  327. end
  328. end
  329. function hongzhongRoomView:test()
  330. self.playerHandCards={}
  331. self.playerHandCards[MJDefine.MyViewId] = MJHandCardView:new(MJDefine.MyViewId)
  332. self:addChild(self.playerHandCards[MJDefine.MyViewId])
  333. self.playerView = MJRoomPlayerView:new()
  334. self:addChild(self.playerView)
  335. end
  336. function hongzhongRoomView:showPiao()
  337. local roomInfo=app.room.roomInfo
  338. local gameInfo=json.decode(roomInfo.strGameInfo)
  339. if not gameInfo.piaotype or tonumber(gameInfo.piaotype)==0 then return end
  340. --飘风分数
  341. local piaoFen={
  342. 1,2,3,5
  343. -- [0] = {},
  344. -- [2]={1,2,3},
  345. -- [3]={2,3,5},
  346. }
  347. self:hidePiao()
  348. local ui=loadUI("hongzhong/res/ui_fangjian/hongzhong_ui_piao.ui")
  349. self:addChild(ui)
  350. self.piao=ui
  351. ui.Items.Button_BuPiao:registerClick(function()
  352. playBtnEffect()
  353. self:hidePiao()
  354. local request = MJMessage.XiaPiao:new()
  355. request.nPiaoNum = 0
  356. self.ui:sendMsg(app.room,MJDefine.MJEvent.XiaPiao,request)
  357. end)
  358. for i=1,4 do
  359. -- local piaoNum=
  360. ui.Items["Button_Piao_"..i]:registerClick(function()
  361. playBtnEffect()
  362. self:hidePiao()
  363. local request = MJMessage.XiaPiao:new()
  364. request.nPiaoNum = piaoFen[i]
  365. logD("nPiaoNum="..request.nPiaoNum)
  366. self.ui:sendMsg(app.room,MJDefine.MJEvent.XiaPiao,request)
  367. end)
  368. end
  369. end
  370. function hongzhongRoomView:hidePiao()
  371. if self.piao then
  372. self.piao:removeFromParent()
  373. self.piao=nil
  374. end
  375. end
  376. function hongzhongRoomView:updatePiao(viewId,piaoNum)
  377. local roomInfo=app.room.roomInfo
  378. local gameInfo=json.decode(roomInfo.strGameInfo)
  379. if not gameInfo.piaotype or tonumber(gameInfo.piaotype)==0 then return end
  380. if not piaoNum or piaoNum==-1 then return end
  381. local head=self.playerView:getHead(viewId)
  382. if not head.piao then
  383. local piao = cc.Sprite:createWithSpriteFrameName("mj_img_piao_fen_flag.png")
  384. head:addChild(piao)
  385. piao:setPosition(25,41)
  386. head.piao=piao
  387. local labNum = cc.Text:createNode()
  388. labNum:setDefaults()
  389. local config = labNum:getFontConfig()
  390. config.fontSize = 18
  391. config.texColor = cc.c4b(254,247,183,255)
  392. config.outlineSize = 1
  393. config.effectColor = cc.c4b(64,42,172,255)
  394. labNum:setFontConfig(config)
  395. piao:addChild(labNum)
  396. labNum:setAnchorPoint(cc.p(0.5,0.5))
  397. labNum:setPosition(cc.p(20,42))
  398. -- labNum:setString("飘 "..piaoNum)
  399. labNum:setRotation(7.1)
  400. head.piaoNum=labNum
  401. end
  402. if piaoNum==0 then
  403. head.piaoNum:setString("不飘")
  404. else
  405. head.piaoNum:setString("飘 "..piaoNum)
  406. end
  407. -- head.piao:loadTexture("3d/mj_dir_3d_2_down.png",cc.TextureResType.plistType)
  408. end
  409. --中鸟展示
  410. function hongzhongRoomView:showZhongNiaoView(cards,viewIds,callback)
  411. local ui=loadUI("mj/res/ui/ui_animation/mj_zhong_niao.ui")
  412. self:addChild(ui)
  413. ui.Items.Layout_Content:setSize(cc.size(#cards*100,ui.Items.Layout_Content:getContentSize().height))
  414. -- ui.Items.Layout_Content:requestDoLayout()
  415. -- ui.Items.Layout_Content:doLayout()
  416. local scale=0.7
  417. local pad=10
  418. local mjWidth=87*scale
  419. local x=(ui.Items.Layout_Content:getContentSize().width-#cards*(mjWidth+pad))/2+mjWidth/2
  420. for k,v in pairs(cards) do
  421. local light=cc.Sprite:createWithSpriteFrameName("bird/mj_animation_bird_bg_light.png")
  422. ui.Items.Layout_Content:addChild(light)
  423. light:setPosition(x,ui.Items.Layout_Content:getContentSize().height/2)
  424. light:runAction(cc.RotateTo:create(zhongNiaoTime,30))
  425. light:setScale(1.2)
  426. local mj=MJ:new(v,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
  427. mj:setScale(scale)
  428. ui.Items.Layout_Content:addChild(mj,1)
  429. mj:setPosition(x,ui.Items.Layout_Content:getContentSize().height/2)
  430. x=x+mjWidth+pad
  431. end
  432. ui.Items.Layout_Content:playClip("start",function()
  433. if callback then
  434. callback()
  435. end
  436. ui:removeFromParent()
  437. end)
  438. local head=self.playerView:getHead(viewIds[1])
  439. local pos=head:getPosition()
  440. pos=head:convertToWorldSpace(pos)
  441. if pos.x<640 then
  442. ui:setPosition(cc.p(pos.x+ui.Items.Layout_Content:getContentSize().width/2+50,pos.y-40))
  443. else
  444. ui:setPosition(cc.p(pos.x-ui.Items.Layout_Content:getContentSize().width/2-50,pos.y-40))
  445. end
  446. end
  447. --鸟飞行动画
  448. function hongzhongRoomView:showNiaoAniamtion(viewIds,callback)
  449. local size = self:getContentSize()
  450. local bird=cc.Sprite:createWithSpriteFrameName("bird/mj_animation_bird.png")
  451. bird:setPosition(size.width / 2,size.height / 2)
  452. self:addChild(bird)
  453. local head=self.playerView:getHead(viewIds[1])
  454. local function showLight()
  455. local light=cc.Sprite:createWithSpriteFrameName("bird/mj_animation_bird_head_light.png")
  456. head:addChild(light)
  457. light:setPosition(head:getContentSize().width/2,head:getContentSize().height/2)
  458. light:runAction(cc.Sequence:create(
  459. cc.DelayTime:create(zhongNiaoTime),
  460. -- cc.CallFunc:create(function()
  461. -- if callback then callback() end
  462. -- end),
  463. cc.RemoveSelf:create()
  464. ))
  465. end
  466. local pos=head:getPosition()
  467. pos=head:convertToWorldSpace(pos)
  468. if pos.x<bird:getPositionX() then
  469. bird:setFlippedX(true)
  470. end
  471. local actions={
  472. cc.MoveTo:create(0.5,pos),
  473. cc.CallFunc:create(function()
  474. showLight()
  475. -- self:showZhongNiaoView()
  476. if callback then callback() end
  477. end),
  478. cc.RemoveSelf:create(),
  479. }
  480. bird:runAction(cc.Sequence:create(actions))
  481. end
  482. --抓鸟展示
  483. function hongzhongRoomView:showNiaoView(cards,callback)
  484. MJSound.PlayZhaNiao()
  485. local ui=loadUI("mj/res/ui/ui_animation/mj_niao.ui")
  486. self:addChild(ui)
  487. local size = self:getContentSize()
  488. ui:setPosition(size.width / 2,size.height / 2)
  489. local mjWidth=87
  490. local pad=5
  491. local x=(ui.Items.Layout_Content:getContentSize().width-#cards*(mjWidth+pad))/2+mjWidth/2
  492. for k,v in pairs(cards) do
  493. local mj=MJ:new(v,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
  494. ui.Items.Layout_Content:addChild(mj)
  495. mj:setPosition(x,ui.Items.Layout_Content:getContentSize().height/2)
  496. x=x+mjWidth+pad
  497. end
  498. ui.Items.Layout_Content:playClip("start",function()
  499. if callback then
  500. callback()
  501. end
  502. ui:removeFromParent()
  503. end)
  504. end
  505. function hongzhongRoomView:onGameReconnection()
  506. hongzhongRoomView.super.onGameReconnection(self)
  507. local roomInfo = app.room.roomInfo
  508. for k,v in pairs(roomInfo.memberList) do
  509. local viewId = app.room:getViewIdByUserId(v.nUserId)
  510. self:updatePiao(viewId,v.nPiaoNum)
  511. local extInfo = roomInfo.extJson or ""
  512. if extInfo and type(extInfo)=='table' and extInfo[tostring(v.nUserId)] then
  513. local info = extInfo[tostring(v.nUserId)]
  514. local host = info.hosted or 0--托管状态
  515. local isTuoGuan = host == 1;
  516. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  517. end
  518. end
  519. -- 游戏开始后才有
  520. if roomInfo.nStatus and roomInfo.nStatus>=MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START and roomInfo.nStatus<MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  521. self.toolView:showTuoGuan(app.room.roomInfo.hosting == 1)
  522. self.toolView:showFastStart(false)
  523. else
  524. --self.toolView:enableHosting(false)
  525. local quickStartInfo = app.room.roomInfo.quickStartInfo
  526. if quickStartInfo then
  527. if quickStartInfo.tablefaststate == true then
  528. local tmpInfo = {}
  529. for uid,status in pairs(quickStartInfo.list) do
  530. table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status})
  531. end
  532. local response = {}
  533. response.pList = tmpInfo
  534. response.timeOut = app.room.roomInfo.quickStartInfo.time
  535. self:onBroadcastFaststart({response=response})
  536. else
  537. self.toolView:showFastStart(true)
  538. end
  539. else
  540. self.toolView:showFastStart(true)
  541. end
  542. end
  543. if roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  544. local resultInfo=json.decode(roomInfo.strResultInfo)
  545. --所有胡牌的人 考虑抢杠胡的问题
  546. local viewIds={}
  547. local failViewId=0
  548. for k,v in pairs(roomInfo.memberList) do
  549. local viewId = app.room:getViewIdByUserId(v.nUserId)
  550. if v.result==MJDefine.MJGameResultType.Win then
  551. table.insert(viewIds,viewId)
  552. elseif v.result==MJDefine.MJGameResultType.Fail then
  553. failViewId=viewId
  554. end
  555. end
  556. local zhaniaocards=string.ltrim(resultInfo.zhaniaocards)
  557. local tabZhaniaocards=string.split(zhaniaocards," ")
  558. if resultInfo.zhaniaocards=="" then
  559. tabZhaniaocards={}
  560. end
  561. self:outNiaoCards(viewIds,failViewId,tabZhaniaocards)
  562. end
  563. end
  564. -- 小局结算
  565. function hongzhongRoomView:onGameXiaoJuResponse(data)
  566. local function runGameXiaoJuResponse(onEnd)
  567. local roomInfo = app.room.roomInfo
  568. local resultInfo=json.decode(roomInfo.strResultInfo)
  569. self.direcionView:stopAllActions()
  570. --如果是解散直接return
  571. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  572. if onEnd then
  573. onEnd()
  574. end
  575. return
  576. end
  577. --所有胡牌的人 考虑抢杠胡的问题
  578. local viewIds={}
  579. local failViewId=0
  580. for k,v in pairs(roomInfo.memberList) do
  581. local viewId = app.room:getViewIdByUserId(v.nUserId)
  582. if v.result==MJDefine.MJGameResultType.Win then
  583. table.insert(viewIds,viewId)
  584. --播放音效
  585. if viewId==MJDefine.MyViewId then
  586. MJSound.PlayWinGame()
  587. end
  588. elseif v.result==MJDefine.MJGameResultType.Fail then
  589. failViewId=viewId
  590. if viewId==MJDefine.MyViewId then
  591. MJSound.PlayLoseGame()
  592. end
  593. end
  594. end
  595. self:showOpenCard()
  596. if app.room.roomInfo.hosting then
  597. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  598. end
  599. --被抢杠的人回退补杠
  600. if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_NORMAL then
  601. self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard)
  602. end
  603. -- local zhaniaocards=string.ltrim(resultInfo.zhaniaocards)
  604. local tabZhaniaocards=MJFunction.convertToCards(resultInfo.zhaniaocards)--string.split(zhaniaocards," ")
  605. -- if resultInfo.zhaniaocards=="" then
  606. -- tabZhaniaocards={}
  607. -- end
  608. -- local zhongniaocards=string.ltrim(resultInfo.zhongniaocards)
  609. local tabZhongniaocards=MJFunction.convertToCards(resultInfo.zhongniaocards)--string.split(zhongniaocards," ")
  610. -- if resultInfo.zhongniaocards=="" then --and #tabZhongniaocards>0 then
  611. -- tabZhongniaocards={}
  612. -- end
  613. self:outNiaoCards(viewIds,failViewId,tabZhaniaocards)
  614. local function callback()
  615. self:showXiaoJuView()
  616. if onEnd then
  617. onEnd()
  618. end
  619. end
  620. local function zhongNiao()
  621. self:showZhongNiaoView(tabZhongniaocards,viewIds,callback)
  622. end
  623. local function niaoFly()
  624. if #tabZhongniaocards>0 then
  625. self:showNiaoAniamtion(viewIds,zhongNiao)
  626. else
  627. callback()
  628. end
  629. end
  630. local function niaoCallBack()
  631. if #tabZhaniaocards>0 then
  632. self:showNiaoView(tabZhaniaocards,niaoFly)
  633. else
  634. callback()
  635. end
  636. end
  637. if #viewIds>0 then
  638. for k,viewId in pairs(viewIds) do
  639. local effect
  640. if k == #viewIds then --只有最后播放胡牌动画的回调一次就可以了
  641. effect=MJAnimationCompnent.CreateHuEffect(niaoCallBack)
  642. local userInfo=app.room:getUserInfoByViewId(viewId)
  643. if userInfo then
  644. --音效
  645. local resultInfo=json.decode(roomInfo.strResultInfo)
  646. if resultInfo.hutype==MJDefine.MJHuType.Zimo then --1为自摸
  647. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU)
  648. else
  649. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU)
  650. end
  651. end
  652. else
  653. effect=MJAnimationCompnent.CreateHuEffect()
  654. end
  655. if effect then
  656. self:addChild(effect)
  657. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  658. end
  659. end
  660. else
  661. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  662. local effect=MJAnimationCompnent.CreateLiuJuEffect(callback)
  663. self:addChild(effect)
  664. MJSound.PlayHuangZhuang()
  665. else
  666. callback()
  667. end
  668. end
  669. end
  670. -- runGameXiaoJuResponse()
  671. log("2000000000-hongzhongRoomView - addCallBack(runGameXiaoJuResponse)" )
  672. self:addCallBack(runGameXiaoJuResponse);
  673. end
  674. function hongzhongRoomView:outNiaoCards(viewIds,failViewId,niaoCards)
  675. if #niaoCards==0 then return end
  676. --把鸟牌放入出牌区域
  677. local outNiaoCards={}
  678. for k,v in pairs(niaoCards) do
  679. table.insert(outNiaoCards,{card=v})
  680. end
  681. local outCards={}
  682. if #viewIds>1 then
  683. if self.playerHandCards[failViewId] then
  684. self.playerHandCards[failViewId]:createOutCards(outNiaoCards)
  685. outCards=self.playerHandCards[failViewId].outCards
  686. end
  687. elseif #viewIds==1 then
  688. local viewId=viewIds[1]
  689. if self.playerHandCards[viewId] then
  690. self.playerHandCards[viewId]:createOutCards(outNiaoCards)
  691. outCards=self.playerHandCards[viewId].outCards
  692. end
  693. end
  694. for i=#outCards,#outCards-#outNiaoCards+1,-1 do
  695. if outCards[i] then
  696. outCards[i]:setStatus(MJDefine.MJStatus.Disable)
  697. end
  698. end
  699. end
  700. function hongzhongRoomView:onFastStartSucc( data )
  701. if self._fastRequestView and not tolua.isnull(self._fastRequestView) then
  702. self._fastRequestView:removeSelf()
  703. self._fastRequestView = nil
  704. end
  705. self.toolView:showFastStart(false)
  706. self.playerView:setPlayerVisible(false)
  707. self:updateRoomBaseData()
  708. end
  709. -- 服务器广播快速开始
  710. function hongzhongRoomView:onBroadcastFaststart( data )
  711. local response = data.response
  712. local remove = false
  713. if response.nUserId and response.nStatus then
  714. if response.nStatus == 3 or response.nStatus>4 then
  715. remove = true
  716. end
  717. end
  718. if not remove then
  719. for _,v in ipairs(response.pList) do
  720. if v.nStatus == 3 or v.nStatus>4 then
  721. remove = true
  722. end
  723. end
  724. end
  725. if response.timeOut <=0 then remove = true end
  726. if self._fastRequestView == nil then
  727. if remove then return "" end
  728. local requesterId = 0
  729. for _,v in ipairs(response.pList) do
  730. if v.nStatus == 1 then
  731. requesterId = v.nUserId
  732. end
  733. end
  734. if requesterId<=0 then return "" end
  735. local view = import("hongzhong.luaScript.Views.Room.hongzhongRequestStartView"):new(requesterId)
  736. view:setAnchorPoint(cc.p(0.5, 0.5))
  737. view:showItems(response)
  738. app:showWaitDialog(view)
  739. self._fastRequestView = view
  740. else
  741. if remove then
  742. local userInfo = app.room.roomInfo.memberList[response.nUserId]
  743. self._fastRequestView:removeSelf()
  744. self._fastRequestView = nil
  745. if userInfo then
  746. local u = json.decode(userInfo.userInfo)
  747. local txt = string.format("玩家【%s】拒绝立即开局", u.nickname)
  748. showTooltip(txt)
  749. end
  750. app.room:resetFastInfo()
  751. self.toolView:showFastStart(true)
  752. else
  753. self._fastRequestView:updateView(response)
  754. end
  755. end
  756. end
  757. function hongzhongRoomView:onOtherSitDownResponse( data )
  758. hongzhongRoomView.super.onOtherSitDownResponse(self, data)
  759. -- fast start
  760. self.toolView:showFastStart(true)
  761. self:updateInviteButtonState()
  762. self:updateInviteClubButtonState()
  763. end
  764. function hongzhongRoomView:onOtherLogoutResponse(data)
  765. hongzhongRoomView.super.onOtherLogoutResponse(self, data)
  766. local function showFastStart( onEnd )
  767. -- fast start
  768. self.toolView:showFastStart(true)
  769. self:updateInviteButtonState()
  770. self:updateInviteClubButtonState()
  771. if not tolua.isnull(self._fastRequestView) then
  772. self._fastRequestView:removeFromParent()
  773. self._fastRequestView = nil
  774. end
  775. if onEnd and type(onEnd)=='function' then onEnd() end
  776. end
  777. self:addCallBack(showFastStart)
  778. end
  779. function hongzhongRoomView:onHostingRequest( data )
  780. local response = data.response
  781. if app.room:isMyself(response.nUserId) then
  782. if response.status == 1 then --托管状态
  783. self.toolView:showTuoGuan(true)
  784. if not tolua.isnull(self.firstTingTipsView) then
  785. self.firstTingTipsView:killSelf()
  786. self.firstTingTipsView = nil
  787. end
  788. elseif response.status == 0 then--取消托管状态
  789. self.toolView:showTuoGuan(false)
  790. end
  791. end
  792. local isTuoGuan = response.status == 1;
  793. local viewId = app.room:getViewIdByUserId(response.nUserId)
  794. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  795. end
  796. -- 发牌
  797. function hongzhongRoomView:onGameSendCardResponse()
  798. hongzhongRoomView.super.onGameSendCardResponse(self)
  799. local function showHosting( onEnd )
  800. self.toolView:showTuoGuan(app.room.roomInfo.hosting==1)
  801. if onEnd and type(onEnd)=='function' then onEnd() end
  802. end
  803. self:addCallBack(showHosting)
  804. end
  805. function hongzhongRoomView:onUserPassRequest( data )
  806. local response = data.response
  807. if app.room:isMyself(response.nUserId) then
  808. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  809. end
  810. end
  811. --更换背景
  812. function hongzhongRoomView:changeGameBg()
  813. local defaultValue = tonumber(loadUserInfo("hongzhong_mj_desktop_group")) or 1
  814. local bgData = MJDefine.CHANGE_GAME_BG[defaultValue]
  815. --更换2D桌面
  816. if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold then
  817. self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
  818. --[[
  819. if self.topBgPos then
  820. self:changePosToAdapt2D()
  821. end
  822. ]]
  823. else
  824. self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
  825. --[[
  826. if self.topBgPos then
  827. self:changePosToAdapt3D()
  828. end
  829. ]]
  830. end
  831. --记录当前的桌布类型(2d/3d)
  832. self.curDeskType = self.desktopType
  833. end
  834. --显示查听的牌
  835. function hongzhongRoomView:setChaTingCardViewVisible(bVisible,tingCards)
  836. end
  837. function hongzhongRoomView:onTingCardStatus()
  838. local myUserId=app.user.loginInfo.uid
  839. local memberList=app.room.roomInfo.memberList
  840. if memberList[myUserId] then
  841. local nTingStatus=memberList[myUserId].nTingStatus
  842. if nTingStatus == MJDefine.MJTingStatus.Ting then
  843. print("---------onTingCardStatus-----------1")
  844. -- self:setChaTingCardViewVisible(true)
  845. -- self:setTingCardViewVisible(true, )
  846. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  847. else
  848. print("---------onTingCardStatus-----------0")
  849. -- self:setChaTingCardViewVisible(false)
  850. self:setTingCardViewVisible(false)
  851. end
  852. end
  853. end
  854. function hongzhongRoomView:onTingCardResult(data)
  855. if data.response.tingType==MJDefine.MJTingType.QuanTing then
  856. else
  857. self:setTingCardViewVisible(true, data.response.tingCards)
  858. end
  859. end
  860. function hongzhongRoomView:showTing(evet)
  861. local roomInfo=app.room.roomInfo
  862. if evet.card and roomInfo.tings and roomInfo.tings[evet.card] then
  863. self:setTingCardViewVisible(true,roomInfo.tings[evet.card])
  864. else
  865. --self:setTingCardViewVisible(false)
  866. end
  867. end
  868. function hongzhongRoomView:onClickBaoJian()
  869. playBtnEffect()
  870. openClub();
  871. end
  872. function hongzhongRoomView:initGameRule()
  873. self.xiangQingView = loadUI("mj/res/ui/ui_fangjian/mj_fangjian_xiangqing2.ui")
  874. self:addChild(self.xiangQingView)
  875. self.xiangQingView.Items.Button_XiangQing:setVisible(false)
  876. --[[--先摆放初始化位置
  877. local pos = self.xiangQingView.Items.Layout_XQ_content:getPosition()
  878. self.xiangQingView.Items.Layout_XQ_content:setPosition(cc.p(pos.x + 27, pos.y + 26))
  879. --记录当前所在位置
  880. self.xqContentPos = self.xiangQingView.Items.Layout_XQ_content:getPosition()
  881. --记录玩法详情框大小
  882. self.xqContentSize = self.xiangQingView.Items.Layout_XQ_content:getContentSize()
  883. --移动至指定位置
  884. self.xiangQingView.Items.Button_XiangQing:runAction(cc.MoveTo:create(0, cc.p(250, 702)))
  885. --顺时针旋转90度
  886. self.xiangQingView.Items.Button_XiangQing:setEulerRotation(cc.vec3(180,180,90))
  887. --逆时针旋转90度
  888. self.xiangQingView.Items.Button_XiangQing_Back:setEulerRotation(cc.vec3(-180,-180,-270))--]]
  889. self.xiangQingView.Items.Layout_XiangQing:registerClick(handler(self , self.hideXiangQing))
  890. self.xiangQingView.Items.Layout_XiangQing:setVisible(true)
  891. self.xiangQingView.Items.Layout_XQ_content:registerClick(handler(self , self.hideXiangQing))
  892. self.xiangQingView.Items.Button_XiangQing_Back:registerClick(handler(self , self.hideXiangQing))
  893. self.xiangQingView.Items.Button_XiangQing:registerClick(handler(self, self.showXiangQing))
  894. self.xiangQingView.Items.ListView_Xq:getVBar():setVisible(false)
  895. local listviewSize = self.xiangQingView.Items.ListView_Xq:getContentSize()
  896. local roomInfo = app.room.roomInfo
  897. local ruleAll = MJWanFa.getWanFaInfo(roomInfo.strGameInfo)
  898. local wanfaList = string.split(ruleAll," ")
  899. for i,v in pairs(wanfaList) do
  900. if v ~= "" then
  901. local layout=cc.Layout:create()
  902. local wanfaText = cc.Text:createNode()
  903. wanfaText:setDefaults()
  904. local config = wanfaText:getFontConfig()
  905. config.fontSize = 24
  906. config.texColor = cc.c4b(255,192,101,255)
  907. wanfaText:setFontConfig(config)
  908. layout:setSize(cc.size(listviewSize.width,35))
  909. layout:addChild(wanfaText)
  910. wanfaText:setPosition(cc.p(listviewSize.width/2,15))
  911. wanfaText:setString(v)
  912. self.xiangQingView.Items.ListView_Xq:pushBackCustomItem(layout)
  913. end
  914. end
  915. if app.room.roomInfo.nGameStartCount > 0 or (not self:getIsNeedShowRule()) then
  916. --self.xiangQingView.Items.Layout_XQ_content:setPositionY(self.xqContentPos.y + self.xqContentSize.height + 47)
  917. self.xiangQingView.Items.Layout_XQ_content:setVisible(false)
  918. self.xiangQingView.Items.Button_XiangQing:setVisible(true)
  919. self.xiangQingView.Items.Layout_XiangQing:setVisible(false)
  920. self.xiangQingView.Items.ListView_Xq:setVisible(false)
  921. end
  922. end
  923. function hongzhongRoomView:showXiangQing()
  924. playBtnEffect()
  925. self.xiangQingView.Items.Button_XiangQing:setVisible(false)
  926. self.xiangQingView.Items.Layout_XiangQing:setVisible(true)
  927. self.xiangQingView.Items.ListView_Xq:setVisible(true)
  928. self.xiangQingView.Items.Layout_XQ_content:setVisible(true)
  929. --[[--执行动画时,先停止当前所有动画
  930. self.xiangQingView.Items.Layout_XQ_content:stopAllActions()
  931. --显示时,直接移动到初始化位置
  932. local action = cc.Sequence:create(
  933. cc.MoveTo:create(0.4 , cc.p(self.xqContentPos.x, self.xqContentPos.y)),
  934. cc.CallFunc:create(function()
  935. self.xiangQingView.Items.Layout_XiangQing:setVisible(true)
  936. self.xiangQingView.Items.ListView_Xq:setVisible(true)
  937. end)
  938. )
  939. self.xiangQingView.Items.Layout_XQ_content:runAction(action)--]]
  940. end
  941. function hongzhongRoomView:hideXiangQing()
  942. self.xiangQingView.Items.Layout_XiangQing:setVisible(false)
  943. self.xiangQingView.Items.Layout_XQ_content:setVisible(false)
  944. self.xiangQingView.Items.Button_XiangQing:setVisible(true)
  945. --[[self.xiangQingView.Items.Layout_XQ_content:stopAllActions()
  946. --隐藏时,在初始位置基础上加上整个layout的高度,再加上从layout顶部到屏幕边缘线位置,一般为固定值
  947. local movePosY = self.xqContentPos.y + (self.xqContentSize.height + 47)
  948. local action = cc.Sequence:create(
  949. cc.CallFunc:create(function ()
  950. self.xiangQingView.Items.ListView_Xq:setVisible(false)
  951. end),
  952. cc.MoveTo:create(0.4 , cc.p(self.xqContentPos.x, movePosY)),
  953. cc.CallFunc:create(function()
  954. self.xiangQingView.Items.Button_XiangQing:setVisible(true)
  955. end)
  956. )
  957. self.xiangQingView.Items.Layout_XQ_content:runAction(action)--]]
  958. end
  959. ---
  960. -- 刷新邀请按钮状态
  961. --
  962. function hongzhongRoomView:updateInviteButtonState()
  963. local roomInfo = app.room.roomInfo
  964. local curMemberNum = table.nums(roomInfo.memberList)
  965. --没有坐满
  966. local isNotSitFull = curMemberNum < roomInfo.nMaxPlayCount
  967. --更新邀请按钮
  968. self.ui.Items.Button_Invite:getParent():setVisible(isNotSitFull)
  969. if isReviewVersion() then
  970. self.ui.Items.Button_Invite:getParent():setVisible(false)
  971. end
  972. if self.ui.Items.Layout_Button then
  973. self.ui.Items.Layout_Button:requestDoLayout()
  974. self.ui.Items.Layout_Button:doLayout()
  975. end
  976. end
  977. ---
  978. -- 刷新亲友圈按钮状态
  979. --
  980. function hongzhongRoomView:updateInviteClubButtonState()
  981. local roomInfo = app.room.roomInfo
  982. local isShow = roomInfo.nGameStartCount <= 0 and app.club_php.clubID and app.club_php.clubID ~= 0
  983. if not self.ui.Items.Button_Invite_Club then
  984. return
  985. end
  986. self.ui.Items.Button_Invite_Club:getParent():setVisible(isShow)
  987. if isShow then
  988. -- 如果当前显示,则判断人数满了没有,满了则不再显示
  989. local curMemberNum = table.nums(roomInfo.memberList)
  990. --没有坐满
  991. local isNotSitFull = curMemberNum < roomInfo.nMaxPlayCount
  992. --更新邀请按钮
  993. self.ui.Items.Button_Invite_Club:getParent():setVisible(isNotSitFull)
  994. end
  995. local roomInfo = app.room.roomInfo or {}
  996. local gameId = roomInfo.gameId or app.gameId
  997. local gameConfig = getSubGameConfig(gameId)
  998. if gameConfig.isOpenClubInvite == false then
  999. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  1000. end
  1001. if isReviewVersion() then
  1002. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  1003. end
  1004. if self.ui.Items.Layout_Button then
  1005. self.ui.Items.Layout_Button:requestDoLayout()
  1006. self.ui.Items.Layout_Button:doLayout()
  1007. end
  1008. end
  1009. ---
  1010. -- 刷新按钮状态
  1011. --
  1012. function hongzhongRoomView:updateReadyButtonState()
  1013. local roomInfo = app.room.roomInfo
  1014. local isShow = roomInfo.nGameStartCount <= 0
  1015. self.ui.Items.Button_Ready:getParent():setVisible(isShow)
  1016. if self.ui.Items.Layout_Button then
  1017. self.ui.Items.Layout_Button:requestDoLayout()
  1018. self.ui.Items.Layout_Button:doLayout()
  1019. end
  1020. end
  1021. function hongzhongRoomView:initChatView()
  1022. end
  1023. --出牌成功
  1024. function hongzhongRoomView:onOutCardSuccess(data)
  1025. local function runOnOutCardSuccess(onEnd)
  1026. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1027. local card= data.response.card
  1028. local operates=data.response.operates
  1029. local function callback()
  1030. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  1031. if viewId == MJDefine.MyViewId then
  1032. if app.room.roomInfo.hosting == 1 then
  1033. self.playerHandCards[viewId]:setTing(false)
  1034. end
  1035. end
  1036. if onEnd then
  1037. onEnd()
  1038. end
  1039. end
  1040. if self.playerHandCards[viewId] then
  1041. self.playerHandCards[viewId]:onOutCard(card,callback)--onOutCard(data.response,true)
  1042. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId})
  1043. else
  1044. callback()
  1045. end
  1046. end
  1047. log("2000000000-hongzhongRoomView - addCallBack(runOnOutCardSuccess)")
  1048. self:addCallBack(runOnOutCardSuccess)
  1049. end
  1050. -- 本家出牌时不会收到出牌成功的,置灰收到弃牌。所以如果收到此消息时,当前手牌还是保持可出状态,说明出牌的时候导致了问题,需要重新删牌
  1051. function hongzhongRoomView:onOutCard(data)
  1052. local function runOnOutCard(onEnd)
  1053. logE("hongzhongRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  1054. log("2000000000-hongzhongRoomView - runOnOutCard")
  1055. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1056. -- local card= data.response.card
  1057. -- if self.playerHandCards[viewId] then
  1058. -- self.playerHandCards[viewId]:createOutCards(card)
  1059. -- end
  1060. local data = data.response
  1061. if data.nUserId == app.room:getMyUserId() then
  1062. local myCardLength = self.playerHandCards[MJDefine.MyViewId]:getHandCardsNum()
  1063. if self.needDeleteOutCard or myCardLength % 3 == 2 then
  1064. print('self.needDeleteOutCard', self.needDeleteOutCard)
  1065. print('myCardLength', myCardLength)
  1066. logD(string.format("hongzhongRoomView:onOutCard 手牌有问题,当前长度是 %s, 需要出的牌是%s ", myCardLength, data.card))
  1067. self.playerHandCards[MJDefine.MyViewId]:onOutCard(data.card)
  1068. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value=data.card,viewId=MJDefine.MyViewId})
  1069. end
  1070. end
  1071. if onEnd then
  1072. onEnd()
  1073. end
  1074. end
  1075. log("2000000000-hongzhongRoomView - addCallBack(runOnOutCard)")
  1076. self:addCallBack(runOnOutCard)
  1077. end
  1078. return hongzhongRoomView