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.

2463 line
76 KiB

  1. local RoomView_28 = class("RoomView_28", cc.UIView)
  2. local Functions = require("pk_doudizhu.luaScript.Functions_28")
  3. local defs = require("pk_doudizhu.luaScript.Def_28")
  4. local Messages = require("pk_doudizhu.luaScript.Protocol.ProtocolMessage_28")
  5. local PokerUtil = require('pk_doudizhu.luaScript.Views.Room.newPokerUtil')
  6. local DDZ_New_Effect_Helper = require("pk_doudizhu.luaScript.Views.Room.DDZNewEffectHelper"):new()
  7. local TuoGuanView = require('pk_doudizhu.luaScript.Views.Room.RoomTuoGuanView')
  8. local Card_Move_Up_Down_Time = 0.1 -- 手牌抬起下放动画时间
  9. local Card_Out_Down_Time = 0.15 -- 出牌下放动画时间
  10. local Card_Out_Down_Offset_Y = -5 -- 出牌下放位置
  11. function RoomView_28:ctor()
  12. RoomView_28.super.ctor(self)
  13. self._pokerUtil = nil
  14. self._isCanClickBg = true
  15. end
  16. function RoomView_28:initData()
  17. --事件队列
  18. self.callbackQueue = {}
  19. --手牌间距(越大越密集,越小越稀疏)
  20. self.handCardDif = 110
  21. --默认闹钟时间
  22. self.clockTime = 15
  23. --上家出的牌数据
  24. self.lastData = {}
  25. self:setLastData()
  26. end
  27. function RoomView_28:onEnter()
  28. RoomView_28.super.onEnter(self)
  29. --ui load
  30. local ui = loadUI("pk_doudizhu/res/ui/ui_fangjian/doudizhu_ui_fangjian.ui")
  31. self:addChild(ui)
  32. self.ui = ui
  33. -- 添加合图缓存
  34. self:addloadSpriteFrame()
  35. -- 添加扑克牌型提示文件
  36. self:initPokerUtil()
  37. --初始化属性数据
  38. self:initData()
  39. --初始化所有的玩家节点
  40. self:initPlayerNodes()
  41. --初始化工具层
  42. self:initToolLayer()
  43. -- 初始化GPS组件
  44. self:initGpsComponent()
  45. -- 初始化电量和信号
  46. self:initSingleComponent()
  47. -- 初始化扑克牌
  48. self:initPoker()
  49. --监听事件
  50. self:bindAllEvent()
  51. --显示桌面信息
  52. self:initDeskInfo()
  53. --初始游戏中按钮
  54. self:initGameButtons()
  55. --初始化玩法
  56. self:initGameRule()
  57. --播放音乐
  58. Functions.playMusic()
  59. --先收到8009再初始化的房间(房间还未监听8009事件),所以这里调用重连
  60. self:onGameReconnection()
  61. --恢复协议
  62. self:startGame()
  63. --测试
  64. --self.weaveCardList = self:getTip(self.handCards["" .. self:getMeViewId()])
  65. self:initPlayGameAgain()
  66. end
  67. function RoomView_28:addloadSpriteFrame()
  68. loadSpriteFrameFile("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards.plist")
  69. -- 动画相关
  70. loadSpriteFrameFile("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_shunzi/zy_ddz_CardFX_ShunZi_Sheet1.plist")
  71. loadSpriteFrameFile("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_shunzi/zy_ddz_CardFX_ShunZi_Sheet2.plist")
  72. loadSpriteFrameFile("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_bomb/zy_ddz_CardFX_ZhaDan_Sheet1.plist")
  73. loadSpriteFrameFile("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_liandui/zy_ddz_CardFX_LianDui_Sprite_1.plist")
  74. loadSpriteFrameFile("pk_doudizhu/res/ui/zy_fangjian/doudizhu_player/zy_game_jingbao/ddz_Ani_BJ.plist")
  75. loadSpriteFrameFile('pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/zy_ddz_kingbomb/doudizhu_Ani_KingBomb.plist')
  76. end
  77. function RoomView_28:initPokerUtil()
  78. self._pokerUtil = PokerUtil:new()
  79. end
  80. function RoomView_28:initPoker()
  81. local changePoker = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose
  82. self:onNormalChangePoker({idx=changePoker})
  83. end
  84. function RoomView_28:onClickButtonDismiss( sender )
  85. playBtnEffect()
  86. local function onClickOk()
  87. app.room:requestDismissRoom(1)--发起解散
  88. end
  89. local function onClickCancel()
  90. end
  91. showConfirmDialog("确定要申请解散房间吗?", onClickOk, onClickCancel)
  92. end
  93. function RoomView_28:hideXiangQing(hideAction)
  94. self.xiangQingView.Items.Layout_XiangQing:setVisible(false)
  95. self.xiangQingView.Items.Layout_XQ_content:stopAllActions()
  96. self.xiangQingView.Items.ListView_Xq:setVisible(false)
  97. if hideAction == true then
  98. self.xiangQingView.Items.Layout_XQ_content:setPosition(self.xiangQingViewHidePos)
  99. self.xiangQingView.Items.Button_XiangQing:setVisible(true)
  100. else
  101. self.xiangQingView.Items.Layout_XQ_content:runAction(
  102. cc.Sequence:create(
  103. cc.MoveTo:create(0.35 , self.xiangQingViewHidePos),
  104. cc.CallFunc:create(function()
  105. self.xiangQingView.Items.Button_XiangQing:setVisible(true)
  106. end)
  107. )
  108. )
  109. end
  110. end
  111. function RoomView_28:initGameRule()
  112. self.xiangQingView = loadUI("pk_doudizhu/res/ui/ui_fangjian/doudizhu_ui_wanfa.ui")
  113. self.ui.Items.Layout_RuleView:addChild(self.xiangQingView)
  114. self.xiangQingView.Items.Button_XiangQing:setVisible(false)
  115. self.xiangQingView.Items.Layout_XiangQing:setVisible(true)
  116. local offsetX = 20
  117. self.xiangQingView.Items.Button_XiangQing:setPositionX(self.xiangQingView.Items.Button_XiangQing:getPositionX() + offsetX)
  118. self.xiangQingView.Items.Layout_XQ_content:setPositionX(self.xiangQingView.Items.Layout_XQ_content:getPositionX() + offsetX)
  119. local size = self.xiangQingView.Items.Layout_XQ_content:getContentSize()
  120. self.xiangQingViewShowPos = self.xiangQingView.Items.Layout_XQ_content:getPosition()
  121. self.xiangQingViewHidePos = cc.vec3(self.xiangQingViewShowPos.x,self.xiangQingViewShowPos.y + size.height,self.xiangQingViewShowPos.z)
  122. self.xiangQingView.Items.Button_XiangQing_Back:registerClick(handler(self , self.hideXiangQing))
  123. self.xiangQingView.Items.Layout_XiangQing:registerClick(handler(self , self.hideXiangQing))
  124. self.xiangQingView.Items.Layout_XQ_content:registerClick(handler(self , self.hideXiangQing))
  125. self.xiangQingView.Items.Button_XiangQing:registerClick(function()
  126. playBtnEffect()
  127. self.xiangQingView.Items.Button_XiangQing:setVisible(false)
  128. self.xiangQingView.Items.Layout_XQ_content:stopAllActions()
  129. self.xiangQingView.Items.Layout_XQ_content:runAction(
  130. cc.Sequence:create(
  131. cc.MoveTo:create(0.35 , self.xiangQingViewShowPos),
  132. cc.CallFunc:create(function()
  133. self.xiangQingView.Items.ListView_Xq:setVisible(true)
  134. self.xiangQingView.Items.Layout_XiangQing:setVisible(true)
  135. end)
  136. )
  137. )
  138. end)
  139. self.xiangQingView.Items.ListView_Xq:getVBar():setVisible(false)
  140. local roomInfo = app.room.roomInfo
  141. local ruleAll = Functions.getRuleStr()
  142. local wanfaList = string.split(ruleAll," ")
  143. local listviewSize = self.xiangQingView.Items.ListView_Xq:getContentSize()
  144. for i,v in pairs(wanfaList) do
  145. if v ~= "" and v ~= " " then
  146. local layout=cc.Layout:create()
  147. local wanfaText = cc.Text:createNode()
  148. wanfaText:setDefaults()
  149. local config = wanfaText:getFontConfig()
  150. config.fontSize = 24
  151. config.texColor = cc.c4b(255,192,101,255)
  152. wanfaText:setFontConfig(config)
  153. layout:setSize(cc.size(listviewSize.width,35))
  154. layout:addChild(wanfaText)
  155. wanfaText:setPosition(cc.p(listviewSize.width/2,15))
  156. wanfaText:setString(v)
  157. self.xiangQingView.Items.ListView_Xq:pushBackCustomItem(layout)
  158. end
  159. end
  160. if app.room.roomInfo.nGameStartCount > 0 then
  161. self:hideXiangQing(true)
  162. else
  163. self:runAction(cc.Sequence:create(
  164. cc.DelayTime:create(2),
  165. cc.CallFunc:create(self.hideXiangQing)
  166. ))
  167. end
  168. end
  169. function RoomView_28:defaultState()
  170. --队列初始化
  171. self.callbackQueue = {}
  172. self.callbackRunning = false
  173. --刷新按钮
  174. self:updateButtons()
  175. --刷新用户信息
  176. self:refreshPlayer(true)
  177. --隐藏地主底牌、炸弹等信息
  178. self:setBanderCardsVisible(false)
  179. -- 小结算
  180. if self.XiaoJuView then
  181. self.XiaoJuView:setVisible(false)
  182. end
  183. --是否开局
  184. if app.room.roomInfo.nGameStartCount > 0 then
  185. --隐藏加倍界面
  186. self:setAskBeiVisible(false)
  187. --隐藏叫分界面
  188. self:setAskLoardVisible(false)
  189. --隐藏玩家出牌操作信息
  190. self:hideAllOutCardOperation()
  191. --隐藏界面
  192. for _,v in pairs(app.room.roomInfo.memberList) do
  193. local viewId = app.room:getViewIdByUserId(v.nUserId)
  194. --隐藏桌面加倍标识
  195. self.PlayerView:setTipsVisible("tips_jiabei", false, viewId)
  196. --隐藏桌面叫分标识
  197. self.PlayerView:setTipsVisible("tips_jiaofen", false, viewId)
  198. --隐藏手牌
  199. local handLayout = self.ui.Items["Layout_Hand_" .. viewId]
  200. if handLayout then
  201. handLayout:removeAllChildren()
  202. if self.handCards then
  203. local handCards = self.handCards["" .. viewId]
  204. if handCards then
  205. self.handCards["" .. viewId] = nil
  206. end
  207. end
  208. end
  209. end
  210. end
  211. end
  212. function RoomView_28:onUserExitResponseRoom(data)
  213. local function runUserExitResponseRoom(onEnd)
  214. local response = data.response
  215. --房间号
  216. local roomid = app.room.roomInfo.nShowTableId
  217. app.room.roomInfo.tableOverFlag = response.tableOverFlag
  218. local tableOverFlag = response.tableOverFlag
  219. local nGameStartCount = app.room.roomInfo.nGameStartCount
  220. --长时间未开始强制退出,否则不退出
  221. if tableOverFlag ~= defs.TABLE_OVER_FLAG.TABLE_OVER_LONG_TIME_NO_START and nGameStartCount ~= 0 then
  222. response.logoutFlag = 0
  223. else
  224. response.logoutFlag = 1
  225. end
  226. if tableOverFlag == defs.TABLE_OVER_FLAG.TABLE_OVER_LONG_TIME_NO_START and nGameStartCount > 0 then
  227. -- 如果已经有牌局了,则显示结算界面,不踢到大厅
  228. response.logoutFlag = 0
  229. end
  230. --如果是自己点离开必须退出
  231. if app.room.roomInfo.bQuitRoom then
  232. response.logoutFlag = 1
  233. end
  234. --正常结束不提示,其他都要提示
  235. if tableOverFlag >= defs.TABLE_OVER_FLAG.TABLE_OVER_GROUP_DISBAND then
  236. showTooltip(defs.TABLE_OVER_FLAG_TEXT[tableOverFlag])
  237. end
  238. -- 0: 不退出, 1: 退出
  239. if response.logoutFlag == 1 then
  240. app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.LiuZhou, roomid))
  241. end
  242. app.room:dispatchEvent({name = "onUserExitResponseHall"})
  243. if onEnd then
  244. onEnd()
  245. end
  246. end
  247. self:addCallBack(runUserExitResponseRoom)
  248. end
  249. function RoomView_28:showProp(data)
  250. local response = data.response
  251. logE("RoomView_28:showProp response = "..table.tostring(response))
  252. --ui表现开始
  253. local uidStarId = response.uidStarId
  254. local uidEndId = response.uidEndId
  255. local propId = response.propId
  256. local isQunFa = response.isQunFa
  257. local beginViewId = app.room:getViewIdByUserId(uidStarId)
  258. local endViewId = app.room:getViewIdByUserId(uidEndId)
  259. if not self.allNodes[beginViewId] or not self.allNodes[endViewId]
  260. or not self.allNodes[endViewId].head or not self.allNodes[beginViewId].head then
  261. logE("场景还没初始化完成就收到道具消息果断return!")
  262. return
  263. end
  264. --播放动画
  265. if isQunFa == 1 then
  266. local onLineList = app.room.roomInfo.memberList
  267. for nUserId,v in pairs(onLineList) do
  268. local endViewId = app.room:getViewIdByUserId(nUserId)
  269. if endViewId ~= beginViewId then
  270. self.PropAniManager:playAnimation(self.allNodes[beginViewId].head,self.allNodes[endViewId].head,propId)
  271. end
  272. end
  273. else
  274. self.PropAniManager:playAnimation(self.allNodes[beginViewId].head,self.allNodes[endViewId].head,propId)
  275. end
  276. end
  277. function RoomView_28:initPlayerNodes()
  278. self.PlayerView = import("pk_doudizhu.luaScript.Views.Room.RoomPlayerView_28"):new()
  279. self.ui.Items.Layout_Player:addChild(self.PlayerView)
  280. end
  281. function RoomView_28:refreshPlayer(bVisible, viewId, playerInfo)
  282. if bVisible then
  283. self.PlayerView:updatePlayer(playerInfo, viewId)
  284. else
  285. self.PlayerView:hidePlayer(viewId)
  286. end
  287. local uids = {}
  288. for k,v in pairs(app.room.roomInfo.memberList) do
  289. uids[v.nUserId] = true
  290. end
  291. if self.messageView then
  292. self.messageView:setPlayerUids(uids)
  293. end
  294. end
  295. function RoomView_28:initToolLayer()
  296. --加载工具层
  297. self.toolView = import("pk_doudizhu.luaScript.Views.Room.RoomToolView_28"):new()
  298. self.ui.Items.Layout_Tool:addChild(self.toolView)
  299. --ChatView
  300. self.messageView = require("luaScript.Views.Room.ChatView"):new({chatList = defs.GAME_CHAT_TXT}, self.PlayerView:getChatViewPos(), true)
  301. self.toolView.ui.Items.Layout_ChatView:addChild(self.messageView)
  302. --设置语言
  303. self.messageView:setLanguage(Functions.getCurLanguage() == defs.LANGUAGE_TYPE.PU_TONG_HUA)
  304. --互动表情,语音
  305. self.messageView:setBtnFace(defs.FACE_POS)
  306. self.messageView:setBtnVoice(defs.VOICE_POS)
  307. self.messageView.ui.Items.Button_Face:loadTextureNormal("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png")
  308. self.messageView.ui.Items.Button_Face:loadTexturePressed("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png")
  309. self.messageView.ui.Items.Button_Face:loadTextureDisabled("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_kjy.png")
  310. self.messageView.ui.Items.Button_Voice:loadTextureNormal("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png")
  311. self.messageView.ui.Items.Button_Voice:loadTexturePressed("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png")
  312. self.messageView.ui.Items.Button_Voice:loadTextureDisabled("res/ui/zy_fangjian/RoomMenu/room_menu_3/room_menu3_room_btn_yuyin.png")
  313. --是否屏蔽互动表情
  314. self.messageView:setPropEnabled((tonumber(loadUserInfo("HuDongBiaoQingKG" .. app.gameId)) or 1) == 1)--0关 1开
  315. --是否屏蔽屏蔽语音
  316. self.messageView:setVoiceEnabled((tonumber(loadUserInfo("PingBiYuYinKG" .. app.gameId)) or 1) == 1)--0关 1开
  317. --道具播放管理器
  318. self.PropAniManager = import("luaScript.Tools.PropAniPlayer"):new(self.ui.Items.Layout_Touch)
  319. -- if Functions.getIsForbidVoiceAndProp() then
  320. -- self.messageView:hideBtns()
  321. -- self.messageView:setPropEnabled(false)
  322. -- self.messageView:setVoiceEnabled(false)
  323. -- end
  324. if Functions.getIsForbidFace() then
  325. self.messageView:hideFace()
  326. self.messageView:setPropEnabled(false)
  327. end
  328. if Functions.getIsForbidVoice() then
  329. self.messageView:hideVoice()
  330. self.messageView:setVoiceEnabled(false)
  331. end
  332. end
  333. function RoomView_28:initGpsComponent()
  334. local versionCode = getAppVersionCode()
  335. versionCode = tonumber(versionCode) or 0
  336. logD("RoomView_28:initGpsComponent() versionCode = ", versionCode)
  337. if isReviewVersion() then
  338. self.toolView.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView))
  339. self.toolView.ui.Items.Button_GPS:setVisible(false)
  340. return
  341. end
  342. -- 创建 gps 组件
  343. self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponent"):new()
  344. -- GPS 按钮
  345. self.toolView.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView))
  346. -- 我的GPS数据发生变化时检测是否需要通知服务器
  347. self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate))
  348. -- 进入时检测一遍我的GPS数据是否需要更新
  349. self:checkMyGpsNeedUpdate()
  350. end
  351. -- 初始化电量和信号
  352. function RoomView_28:initSingleComponent()
  353. self.singleComponent = import("luaScript.Views.Room.RoomSinglePowerComponent"):new(self.ui.Items.ImageView_Single, self.ui.Items.LoadingBar_Power);
  354. end
  355. -- 注销电量、网络信号
  356. function RoomView_28:deInitSingleComponent()
  357. if self.singleComponent then
  358. self.singleComponent:exit()
  359. end
  360. end
  361. function RoomView_28:bindAllEvent()
  362. --用户状态(包括准备,其他玩家进入或者离开通知,离线等)
  363. self:bindUserStatedMessage()
  364. --私人场消息(包括解散等)
  365. self:bindPrivateMessage()
  366. --游戏消息
  367. self:bindGameMessage()
  368. --游戏场景消息
  369. self:bindGameSceneMessage()
  370. --绑定更换桌布事件
  371. self:bindEvent(app , "onChangeTable" , handler(self , self.onChangeTable))
  372. --发送道具
  373. self:bindEvent(app.room,"showProp" , handler(self , self.showProp))
  374. --绑定更换语言种类
  375. self:bindEvent(app , "onChangeLanguage" , handler(self , self.onChangeLanguage))
  376. --设置互动表情开关事件
  377. self:bindEvent(app.room,"ontSetPropEnabled" , handler(self , self.ontSetPropEnabled))
  378. --设置语音开关事件
  379. self:bindEvent(app.room,"onSetVoiceEnabled" , handler(self , self.onSetVoiceEnabled))
  380. -- 游戏设置里更换扑克
  381. self:bindEvent(app.room, "ddzNormalEvent_changePoker" , handler(self , self.onNormalChangePoker))
  382. -- 小结算内通知解散
  383. self:bindEvent(app.room, 'onResultInformDisMiss', handler(self, self.onClickButtonDismiss))
  384. -- 托管回复
  385. self:bindEvent(app.room , 'onHostingResponse', handler(self, self.onHostingResponse))
  386. end
  387. function RoomView_28:initDeskInfo()
  388. --设置房间号
  389. self.ui.Items.Text_roomNum:setText("房间号: " .. app.room.roomInfo.nShowTableId)
  390. -- 更新当前局数
  391. self:updateGameNums()
  392. --系统时间
  393. if not app.room.roomInfo.isRecord then
  394. self.ui.Items.Text_systemTime:stopAllActions()
  395. self.ui.Items.Text_systemTime:runActions(
  396. cc.RepeatForever:create(
  397. cc.Sequence:create(
  398. cc.CallFunc:create(function()
  399. self.ui.Items.Text_systemTime:setText(string.format("%s", os.date("%H:%M:%S", os.time())))
  400. end),
  401. cc.DelayTime:create(0.5)
  402. )
  403. )
  404. )
  405. end
  406. --刷新桌面背景和Logo
  407. self:setTableImg(Functions.getDefaultBg())
  408. end
  409. function RoomView_28:startGame()
  410. --起飞
  411. app.net:onMsgResume()
  412. end
  413. function RoomView_28:updateGameNums()
  414. -- 更新当前局数
  415. local roomInfo = app.room.roomInfo
  416. local curCount = roomInfo.nGameStartCount or 0
  417. local str = string.format("%02d / %02d", curCount, roomInfo.nTotalGameNum)
  418. self.ui.Items.Text_JuShu:setText(str)
  419. end
  420. function RoomView_28:onExit()
  421. RoomView_28.super.onExit(self)
  422. self:deInitSingleComponent()
  423. app.room:dispatchEvent({name = "onGameOverResponse"})
  424. stopBGMusic()
  425. self:cleanCache() -- jxtd 记得验证是否要删除
  426. end
  427. -- 清理缓存,用于测试
  428. function RoomView_28:cleanCache()
  429. local preload = package.loaded
  430. for k, v in pairs(package.loaded or {}) do
  431. local res1 = string.find( k, "pk_doudizhu.luaScript") or 0
  432. if res1 > 0 then
  433. package.loaded[k] = nil
  434. end
  435. end
  436. end
  437. -- 其他玩家坐下成功
  438. function RoomView_28:onOtherSitDownResponse(data)
  439. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  440. self:checkGpsDistance(data.response.nUserId)
  441. self:refreshPlayer(true, viewId, app.room.roomInfo.memberList[data.response.nUserId])
  442. self:updateButtons()
  443. if not tolua.isnull(self.quickStartView) then
  444. self.quickStartView:removeView()
  445. self.quickStartView = nil
  446. end
  447. end
  448. function RoomView_28:updateButtons()
  449. local nGameStartCount = app.room.roomInfo.nGameStartCount or 0
  450. if nGameStartCount > 0 then
  451. -- 准备按钮
  452. self.toolView:setReadyVisible(false)
  453. -- 是否显示邀请好友
  454. self.toolView:setInviteVisible(false)
  455. -- 离开按钮
  456. self.toolView:setLeaveEnabled(false)
  457. -- 解散按钮
  458. self.toolView:setDissmissEnabled(true)
  459. -- 显示是否可以解散
  460. self.toolView:checkCanDismiss()
  461. else
  462. local myUserId = app.room:getMyUserId()
  463. -- 是否显示邀请好友
  464. if isReviewVersion() then
  465. self.toolView:setInviteVisible(false)
  466. else
  467. self.toolView:setInviteVisible(table.nums(app.room.roomInfo.memberList) < app.room.roomInfo.nMaxPlayCount)
  468. end
  469. -- 准备按钮
  470. local readyState = app.room.roomInfo.memberList[myUserId].nPlayerFlag or 0
  471. self.toolView:setReadyVisible(readyState == 0)
  472. -- 离开按钮
  473. self.toolView:setLeaveEnabled(true)
  474. -- 解散按钮
  475. local nRoomOwnedUid = app.room.roomInfo.nRoomOwnedUid or 0
  476. self.toolView:setDissmissEnabled(nRoomOwnedUid == app.room:getMyUserId() and (not app.club_php.clubID or (app.club_php.clubID and app.club_php.clubID == 0)))
  477. end
  478. end
  479. function RoomView_28:onOtherDroppedResponse(data)
  480. if not data.response then
  481. return
  482. end
  483. self:setPlayerOffLine(data.response.nOnlineStatus == 0, app.room:getViewIdByUserId(data.response.nUserId))
  484. end
  485. function RoomView_28:setPlayerOffLine(bVisible, viewId, times)
  486. --离线
  487. self.PlayerView:setOffLineVisible(bVisible, viewId)
  488. --[[
  489. if bVisible then
  490. local startTime = os.time()
  491. self.allNodes[viewId].offLine:stopAllActions()
  492. self.allNodes[viewId].offLine:runAction(
  493. cc.RepeatForever:create(
  494. cc.Sequence:create(
  495. cc.CallFunc:create(function()
  496. local endTime = os.time()
  497. local difTime = endTime - startTime + (times or 0)
  498. local timeStr = string.format("%02d : %02d", difTime / 60, difTime % 60)
  499. self.allNodes[viewId].offLineTime:setText(timeStr)
  500. end),
  501. cc.DelayTime:create(1.0)
  502. )
  503. )
  504. )
  505. end
  506. --]]
  507. end
  508. function RoomView_28:onOtherLogoutResponse(data)
  509. self:refreshPlayer(false, data.response.viewId)
  510. self:updateButtons()
  511. end
  512. function RoomView_28:onUserReadyResponse(data)
  513. --自己准备
  514. if app.room:getMyUserId() == data.response.nUserId then
  515. --重置桌面
  516. self:defaultState()
  517. --更新按钮状态
  518. self:updateButtons()
  519. end
  520. --显示准备
  521. self.PlayerView:setReadyVisible(true, app.room:getViewIdByUserId(data.response.nUserId))
  522. end
  523. --用户状态消息
  524. function RoomView_28:bindUserStatedMessage()
  525. --默认状态
  526. self:bindEvent(app.room , "defaultState", handler(self , self.defaultState))
  527. -- 玩家准备
  528. self:bindEvent(app.room , "onUserReadyResponse", handler(self , self.onUserReadyResponse))
  529. -- 其他玩家进入房间
  530. self:bindEvent(app.room , "onOtherSitDownResponse", handler(self , self.onOtherSitDownResponse))
  531. -- 其他玩家退出房間
  532. self:bindEvent(app.room , "onOtherLogoutResponse", handler(self , self.onOtherLogoutResponse))
  533. -- 其他玩家掉线
  534. self:bindEvent(app.room , "onOtherDroppedResponse", handler(self , self.onOtherDroppedResponse))
  535. -- 用户T出
  536. self:bindEvent(app.room , "onUserExitResponseRoom", handler(self , self.onUserExitResponseRoom))
  537. -- 玩家的GPS信息发生变化
  538. self:bindEvent(app.room , "onGpsChangeResponse", handler(self , self.onGpsChangeResponse))
  539. end
  540. --私人场消息
  541. function RoomView_28:bindPrivateMessage()
  542. -- 玩家收到解散房间的请求
  543. self:bindEvent(app.room , "onDismissResponse", handler(self , self.onDismissResponse))
  544. end
  545. --场景恢复
  546. function RoomView_28:bindGameSceneMessage()
  547. app.hall:addEventListener("onEnterRoomSuccess", handler(self , self.onEnterRoomSuccess))
  548. end
  549. function RoomView_28:onEnterRoomSuccess()
  550. if tolua.isnull(self.ui) then
  551. logE("self.is null")
  552. return
  553. end
  554. self:stopAllActions()
  555. self:onGameReconnection()
  556. self:startGame()
  557. end
  558. function RoomView_28:onGameReconnection()
  559. --默认状态
  560. self:defaultState()
  561. --是否开局
  562. if app.room.roomInfo.nGameStartCount > 0 then
  563. --显示剩余手牌
  564. for _,v in pairs(app.room.roomInfo.memberList) do
  565. self.PlayerView:setLeftNumVisible(true, app.room:getViewIdByUserId(v.nUserId), table.nums(v.handCards))
  566. end
  567. --恢复手牌
  568. self:initHandCards(app.room.roomInfo.memberList[app.room:getMyUserId()].handCards, self:getMeViewId())
  569. --叫地主阶段
  570. if app.room.roomInfo.nStatus == defs.GAME_STATUS.ASK_LOARD then
  571. --当前操作位置
  572. self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  573. --显示方位
  574. self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime)
  575. --显示叫分状态
  576. for k,v in pairs(app.room.roomInfo.memberList) do
  577. if v.bAskLoard == 1 then
  578. self.PlayerView:setTipsVisible("tips_jiaofen", true, app.room:getViewIdByUserId(v.nUserId), { askLoard = v.askLoard })
  579. end
  580. end
  581. --是否显示叫分
  582. if self.curViewId == self:getMeViewId() then
  583. self:setAskLoardVisible(true, app.room.roomInfo.opType == 1)
  584. end
  585. --加倍阶段
  586. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.ASK_BEI then
  587. --显示庄家
  588. self.PlayerView:setBankerVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.nBankerId))
  589. --显示加倍状态
  590. for k,v in pairs(app.room.roomInfo.memberList) do
  591. if v.bAskBei == 1 then
  592. self.PlayerView:setTipsVisible("tips_jiabei", true, app.room:getViewIdByUserId(v.nUserId), { askBei = v.askBei })
  593. else
  594. self.PlayerView:setClockVisibel(true, app.room:getViewIdByUserId(v.nUserId), 0)
  595. end
  596. end
  597. --是否显示加倍
  598. local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()]
  599. if myMemberInfo.bAskBei == 0 then
  600. self:setAskBeiVisible(true)
  601. end
  602. --打牌阶段
  603. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.PLAYING then
  604. --当前操作位置
  605. self.curViewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  606. --显示方位
  607. self.PlayerView:setClockVisibel(true, self.curViewId, app.room.roomInfo.currentLeftTime)
  608. --显示庄家
  609. self.PlayerView:setBankerVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.nBankerId))
  610. --最后一手手牌
  611. if app.room:checkUserIDIsInTable(app.room.roomInfo.lastUserId) then
  612. local lastViewId = app.room:getViewIdByUserId(app.room.roomInfo.lastUserId)
  613. self:setOutCardsVisible(true, lastViewId, { cards = app.room.roomInfo.lastCards, opType = app.room.roomInfo.lastCardType })
  614. end
  615. -- 玩家过数据
  616. for k,v in pairs(app.room.roomInfo.memberList) do
  617. -- 显示过
  618. if v.nGuo and v.nGuo == 1 then
  619. self.PlayerView:setTipsVisible("tips_yaobuqi", true, app.room:getViewIdByUserId(v.nUserId))
  620. end
  621. end
  622. --是否显示操作
  623. if self.curViewId == self:getMeViewId() then
  624. self:setOperationVisible(true, app.room.roomInfo.opType)
  625. end
  626. --小局结算阶段
  627. elseif app.room.roomInfo.nStatus == defs.GAME_STATUS.ROUND_OVER then
  628. --服务器会推送一个结算消息
  629. --恢复最后一手出牌
  630. local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()]
  631. if myMemberInfo.nPlayerFlag == 0 then
  632. self:setOutCardsVisible(true, app.room:getViewIdByUserId(app.room.roomInfo.lastUserId), { cards = app.room.roomInfo.lastCards, opType = app.room.roomInfo.lastCardType })
  633. end
  634. end
  635. --显示底牌和底分炸弹情况
  636. if app.room:checkUserIDIsInTable(app.room.roomInfo.nBankerId) and table.nums(app.room.roomInfo.bankerCards) > 0 then
  637. self:setBanderCardsVisible(true, app.room.roomInfo.bankerCards)
  638. end
  639. --是否有人发起解散
  640. self:judgeDissmiss()
  641. end
  642. end
  643. function RoomView_28:setXiaoJuVisible(bVisible, data)
  644. if self.XiaoJuView then
  645. --显示
  646. self.XiaoJuView:setVisible(bVisible)
  647. end
  648. if bVisible then
  649. --显示玩家数据
  650. for _,v in pairs(data.memberList) do
  651. local viewId = app.room:getViewIdByUserId(v.nUserId)
  652. --显示剩余手牌
  653. if v.nUserId ~= app.room:getMyUserId() and v.nUserId ~= data.nWinId then
  654. self:setOutCardsVisible(true, viewId, { cards = v.handCards, maxLen = 10 })
  655. end
  656. --刷新分数
  657. self.PlayerView:updateScore(viewId, v.nTotalScore)
  658. end
  659. --显示小局结算
  660. if not self.XiaoJuView then
  661. function xiaYiJu()
  662. if app.room.roomInfo.isGameOver == 1 then
  663. -- self:goToHall()
  664. self:showDaJu(app.room.roomInfo._GameOverInfo)
  665. else
  666. self.ui:sendMsg(app.room, "callReadyRequest")
  667. end
  668. end
  669. self.XiaoJuView = import("pk_doudizhu.luaScript.Views.Room.RoomXiaoJuView_" .. app.gameId):new(xiaYiJu)
  670. self.ui.Items.Layout_XiaoJu:addChild(self.XiaoJuView)
  671. end
  672. --更新界面数据
  673. self.XiaoJuView:updateView(data)
  674. end
  675. end
  676. function RoomView_28:judgeDissmiss()
  677. local roomInfo = app.room.roomInfo
  678. --解散状态
  679. local uid = 0
  680. local isDismiss = false
  681. for k,v in pairs(roomInfo.memberList) do
  682. local viewId = app.room:getViewIdByUserId(k)
  683. --记录玩家解散状态 0:初始状态, 1:发起解散 2: 同意解散 3:不同意解散
  684. app.room.dismissInfo[k] = v.disbandStatus
  685. --有人发起解散时才显示解散界面
  686. if v.disbandStatus == 1 then
  687. isDismiss = true
  688. uid = k
  689. end
  690. end
  691. --有人发起解散时才显示解散界面
  692. if isDismiss then
  693. local memberList = {}
  694. for nUserId,memberInfo in pairs(roomInfo.memberList) do
  695. if app.room:checkUserIDIsInTable(nUserId) then
  696. memberList[nUserId] = memberInfo
  697. memberList[nUserId].nDisbandStatus = memberInfo.disbandStatus
  698. end
  699. end
  700. local view = import("luaScript.Views.Room.RoomDismissView"):new(uid, memberList, roomInfo.nDismissStateTime)
  701. view:setAnchorPoint(cc.p(0.5, 0.5))
  702. app:showWaitDialog(view)
  703. end
  704. end
  705. function RoomView_28:goToHall()
  706. app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.DouDiZhu))
  707. end
  708. function RoomView_28:leaveRoomRequest()
  709. app.room.roomInfo.bQuitRoom = true
  710. self.ui:sendMsg(app.room, "callLeaveRequest")
  711. end
  712. -- 服务器广播玩家数据发生变化
  713. function RoomView_28:onGpsChangeResponse(data)
  714. logD("RoomView_28:onGpsChangeResponse()")
  715. if not data or not data.nUserId then
  716. return
  717. end
  718. local nUserId = data.nUserId
  719. logD("RoomView_28:onGpsChangeResponse()", tostring(nUserId))
  720. self:checkGpsDistance(nUserId)
  721. end
  722. -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新
  723. function RoomView_28:checkMyGpsNeedUpdate()
  724. logD("RoomView_28:checkMyGpsNeedUpdate()")
  725. local nMyUserId = app.user.loginInfo.uid
  726. local myMemberInfo = app.room.roomInfo.memberList[nMyUserId]
  727. if myMemberInfo then
  728. local userInfo = json.decode(myMemberInfo.userInfo)
  729. if userInfo then
  730. local gpsInfo = userInfo.gpsInfo
  731. local isNewest = app.user:isGpsInfoNewest(gpsInfo)
  732. logD("RoomView_28:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest))
  733. if not isNewest then
  734. app.room:onGpsChangeRequest()
  735. else
  736. logD("RoomView_28:checkMyGpsNeedUpdate() gpsInfo is newest")
  737. end
  738. else
  739. logD("RoomView_28:checkMyGpsNeedUpdate() userInfo is nil")
  740. end
  741. else
  742. logD("RoomView_28:checkMyGpsNeedUpdate() myMemberInfo is nil")
  743. end
  744. end
  745. -- 更新所有玩家的信息到GPS组件
  746. function RoomView_28:updateAllGpsInfo()
  747. local userInfoList = {}
  748. for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do
  749. local nSeatId = memberInfo.nSeatId
  750. local userInfo = memberInfo.userInfo
  751. if userInfo then
  752. userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
  753. end
  754. end
  755. if self.gpsComponent then
  756. self.gpsComponent:updateUserInfos(userInfoList)
  757. end
  758. end
  759. -- 检测玩家与其他玩家之间的距离
  760. -- 如果不传参数,则检测所有玩家相互之间的距离
  761. function RoomView_28:checkGpsDistance(curUserId)
  762. if app.room.roomInfo.nGameStartCount > 0 then
  763. return
  764. end
  765. self:updateAllGpsInfo()
  766. if self.gpsComponent then
  767. self.gpsComponent:checkGpsDistance(curUserId)
  768. end
  769. end
  770. -- 显示GPS界面
  771. function RoomView_28:showGpsView()
  772. logD("RoomView_28:showGpsView()")
  773. local isGameStart = app.room.roomInfo.nGameStartCount > 0
  774. local exitRoomCallback = function()
  775. self.ui:sendMsg(app.room, "callLeaveRequest")
  776. end
  777. local dismissCallback = function()
  778. app.room:requestDismissRoom(1)
  779. end
  780. self:updateAllGpsInfo()
  781. if self.gpsComponent then
  782. self.gpsComponent:showGpsView(app.room.roomInfo.nMaxPlayCount, isGameStart, exitRoomCallback, dismissCallback)
  783. end
  784. end
  785. -- 玩家收到解散房间的请求
  786. function RoomView_28:onDismissResponse(event)
  787. logE("onDismissResponse() response = ", event.response)
  788. if not event or not event.response then
  789. return
  790. end
  791. local response = event.response
  792. --当前时间
  793. app.room.roomInfo.nDismissStateTime = response.timeLeft
  794. --总的时间,服务器没发解散总时间来。那么就和一开始收到的解散剩余时间一致
  795. app.room.roomInfo.nDismissToTalTime = response.timeLeft
  796. --显示解散(此标志会影响闹钟时间会冻住)
  797. app.room.roomInfo.nShowDismiss = true
  798. if response.operateType == 1 then
  799. local memberList = {}
  800. for nUserId,memberInfo in pairs(app.room.roomInfo.memberList) do
  801. if app.room:checkUserIDIsInTable(nUserId) then
  802. memberList[nUserId] = memberInfo
  803. end
  804. end
  805. if response.memberList ~= nil then
  806. for k,v in pairs(response.memberList) do
  807. if v.dismissState == 1 then
  808. local view = import("luaScript.Views.Room.RoomDismissView"):new(v.nUserId, memberList, app.room.roomInfo.nDismissStateTime)
  809. view:setAnchorPoint(cc.p(0.5, 0.5))
  810. app:showWaitDialog(view)
  811. return
  812. end
  813. end
  814. else
  815. local view = import("luaScript.Views.Room.RoomDismissView"):new(response.nUserId, memberList, app.room.roomInfo.nDismissStateTime)
  816. view:setAnchorPoint(cc.p(0.5, 0.5))
  817. app:showWaitDialog(view)
  818. end
  819. else
  820. local memberStatus={}
  821. if response.memberList ~= nil then
  822. for k,v in pairs(response.memberList) do
  823. table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
  824. end
  825. else
  826. table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
  827. end
  828. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus})
  829. end
  830. end
  831. function RoomView_28:addCallBack(callback)
  832. table.insert(self.callbackQueue, callback)
  833. logE(" #self.callbackQueue:".. #self.callbackQueue)
  834. --高延迟情况下,执行快速播放,15条是没有标准,根据实际调整的
  835. --if #self.callbackQueue >= 15 then
  836. --cc.Director:getInstance():getScheduler():setTimeScale(5.0)
  837. --else
  838. cc.Director:getInstance():getScheduler():setTimeScale(1.0)
  839. --end
  840. local function runFunc()
  841. log("2000000000 - runNextFunc() size = ", #self.callbackQueue )
  842. if #self.callbackQueue <= 0 then
  843. self.callbackRunning = false
  844. return
  845. end
  846. local func = self.callbackQueue[1]
  847. table.remove(self.callbackQueue,1)
  848. self.callbackRunning = true
  849. func(function()
  850. self.callbackRunning = false
  851. runFunc()
  852. end)
  853. end
  854. log("self.callbackRunning:",self.callbackRunning)
  855. if not self.callbackRunning then
  856. runFunc()
  857. end
  858. end
  859. function RoomView_28:onChangeTable(data)
  860. self:setTableImg(data.idx)
  861. end
  862. function RoomView_28:onChangeLanguage(data)
  863. local idx = data.idx
  864. if self.messageView then
  865. self.messageView:setLanguage(idx == defs.LANGUAGE_TYPE.PU_TONG_HUA)
  866. end
  867. end
  868. function RoomView_28:setTableImg(idx)
  869. --桌布
  870. self.ui.Items.ImageView_bg:loadTexture(defs.BG_Img[idx] and defs.BG_Img[idx] or defs.BG_Img[1])
  871. self:initLogo()
  872. end
  873. function RoomView_28:initLogo()
  874. if tolua.isnull(self.ui.Items.ImageView_Logo) then
  875. return
  876. end
  877. if not (type(getSubGameRoomLogo) == 'function') then
  878. self.ui.Items.ImageView_Logo:setVisible(false)
  879. return
  880. end
  881. local roomInfo = app.room.roomInfo
  882. local gameInfo = json.decode(roomInfo.strGameInfo or "")
  883. local gamerule = tonumber(gameInfo.gamerule or 1)
  884. roomInfo.gameId = roomInfo.gameId or app.gameId or 0
  885. local logofile = getSubGameRoomLogo(roomInfo.gameId, gamerule)
  886. if logofile then
  887. self.ui.Items.ImageView_Logo:loadTexture(logofile)
  888. self.ui.Items.ImageView_Logo:setVisible(true);
  889. else
  890. self.ui.Items.ImageView_Logo:setVisible(false);
  891. end
  892. --self.ui.Items.ImageView_Logo:setVisible(false)
  893. end
  894. function RoomView_28:ontSetPropEnabled(event)
  895. if self.messageView then
  896. self.messageView:setPropEnabled(event.value == 1)
  897. end
  898. end
  899. function RoomView_28:onSetVoiceEnabled(event)
  900. if self.messageView then
  901. self.messageView:setVoiceEnabled(event.value == 1)
  902. end
  903. end
  904. function RoomView_28:onNormalChangePoker(data)
  905. if data.idx > 2 and data.idx < 1 then
  906. return
  907. end
  908. local temp = {
  909. "pk_doudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards_old.plist",
  910. "pk_doudizhu/res/ui/zy_fangjian/doudizhu_cards/doudizhu_pokerCards.plist",
  911. }
  912. -- 删除缓存重新添加缓存
  913. for i, v in ipairs(temp) do
  914. cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile(v)
  915. end
  916. loadSpriteFrameFile(temp[data.idx])
  917. -- 刷新当前手牌
  918. if self.handCards then
  919. local myHandCardLayout = self.handCards["" .. self:getMeViewId()]
  920. if myHandCardLayout then
  921. for i, v in ipairs(myHandCardLayout) do
  922. if v.refreshCard then
  923. v:refreshCard()
  924. end
  925. end
  926. self:rankHandCards(self:getMeViewId(), false)
  927. end
  928. end
  929. -- 刷新当前出的牌
  930. for _, v in pairs(app.room.roomInfo.memberList) do
  931. local viewId = app.room:getViewIdByUserId(v.nUserId)
  932. local outCardLayout = self.ui.Items["Layout_Out_" .. viewId]
  933. if outCardLayout then
  934. for _, card in ipairs(outCardLayout:getChildren()) do
  935. if card.refreshCard then
  936. card:refreshCard()
  937. end
  938. end
  939. end
  940. end
  941. end
  942. --自己的视图ID
  943. function RoomView_28:getMeViewId()
  944. return defs.VIEW_ID.MY_VIEW_ID
  945. end
  946. function RoomView_28:cmd_0x8104_Resp(data)
  947. function cmd_0x8104_RespEx(onEnd)
  948. playVoice("pk_doudizhu/res/sound/doudizhu_common_began.ogg")
  949. self.PlayerView:setLeftNumVisible(true, -1, 17)
  950. self:setXiaoJuVisible(false, nil)
  951. --更新局数
  952. self:updateGameNums()
  953. --更新按钮状态
  954. self:updateButtons()
  955. --隐藏所有准备
  956. self:setAllReadyVisible(false)
  957. -- 玩家托管状态还原
  958. self:refreshPlayerAIStatus()
  959. if onEnd then
  960. onEnd()
  961. end
  962. end
  963. self:addCallBack(cmd_0x8104_RespEx)
  964. end
  965. --显隐所有准备
  966. function RoomView_28:setAllReadyVisible(bVisible)
  967. for k,v in pairs(app.room.roomInfo.memberList) do
  968. self.PlayerView:setReadyVisible(bVisible, app.room:getViewIdByUserId(v.nUserId))
  969. end
  970. end
  971. function RoomView_28:cmd_0x8105_Resp(data)
  972. function cmd_0x8105_RespEx(onEnd)
  973. --加倍阶段,隐藏叫分相关界面
  974. if data.response.nStatus == defs.GAME_STATUS.ASK_BEI then
  975. self:setAskLoardVisible(false)
  976. for _,v in pairs(app.room.roomInfo.memberList) do
  977. self.PlayerView:setTipsVisible("tips_jiaofen", false, app.room:getViewIdByUserId(v.nUserId))
  978. end
  979. --打牌阶段,隐藏加倍相关界面
  980. elseif data.response.nStatus == defs.GAME_STATUS.PLAYING then
  981. self:setAskBeiVisible(false)
  982. for _,v in pairs(app.room.roomInfo.memberList) do
  983. self.PlayerView:setTipsVisible("tips_jiabei", false, app.room:getViewIdByUserId(v.nUserId))
  984. end
  985. end
  986. if data.response.nStatus == defs.GAME_STATUS.SENDCARDS then
  987. self.PlayerView:setLeftNumVisible(true, -1, 17)
  988. end
  989. if onEnd then
  990. onEnd()
  991. end
  992. end
  993. self:addCallBack(cmd_0x8105_RespEx)
  994. end
  995. function RoomView_28:getCardType(card)
  996. return self._pokerUtil:getCardType(card)
  997. end
  998. function RoomView_28:getCardValue(card)
  999. return self._pokerUtil:getCardValue(card)
  1000. end
  1001. function RoomView_28:setCardUp(card)
  1002. card.isUp = true
  1003. self.selectCards["" .. card.cardNum] = card
  1004. -- card:setPosition(cc.pAdd(card.tarPos, cc.p(0, 35)))
  1005. -- 抬起动画
  1006. card:stopAllActions()
  1007. local moveTo = cc.MoveTo:create(Card_Move_Up_Down_Time, cc.pAdd(card.tarPos, cc.p(0, 28)))
  1008. card:runAction(moveTo)
  1009. end
  1010. function RoomView_28:setCardDown(card)
  1011. card.isUp = false
  1012. -- card:setPosition(card.tarPos)
  1013. -- 下放动画
  1014. card:stopAllActions()
  1015. local moveTo = cc.MoveTo:create(Card_Move_Up_Down_Time, card.tarPos)
  1016. card:runAction(moveTo)
  1017. end
  1018. function RoomView_28:handCardItemRegisterTouchEvent(handCard)
  1019. local nomalColor = cc.c3b(255,255,255)
  1020. local selectColor = cc.c3b(200,200,200)
  1021. function onTouchBegan(touch, event)
  1022. local target = event:getCurrentTarget()
  1023. local locationInNode = target:convertToNodeSpace(touch:getLocation())
  1024. local s = target:getContentSize()
  1025. local rect = cc.rect(0, 0, s.width, s.height)
  1026. if cc.rectContainsPoint(rect, locationInNode) then
  1027. self.touchBeganPos = touch:getLocation()
  1028. target:setColor(selectColor)
  1029. target.isHit = true
  1030. return true
  1031. else
  1032. return false
  1033. end
  1034. end
  1035. function onTouchMoved(touch, event)
  1036. local touchMovePos = touch:getLocation()
  1037. local direction = touchMovePos.x - self.touchBeganPos.x
  1038. local handCards = self.handCards["" .. self:getMeViewId()]
  1039. --灵敏度
  1040. if math.abs(direction) < 5 then
  1041. return
  1042. end
  1043. if handCards then
  1044. for k,v in ipairs(handCards) do
  1045. local needContain = true
  1046. if v.isHit then
  1047. local locationInWorld = v:getParent():convertToWorldSpace(v:getPosition())
  1048. if direction > 0 then
  1049. if touchMovePos.x > locationInWorld.x - v:getContentSize().width / 2 + (v:getContentSize().width - self.handCardDif) then
  1050. needContain = false
  1051. end
  1052. else
  1053. if touchMovePos.x < locationInWorld.x - v:getContentSize().width / 2 then
  1054. needContain = false
  1055. end
  1056. end
  1057. end
  1058. if needContain then
  1059. local cardSize = v:getContentSize()
  1060. local locationInNode = v:convertToNodeSpace(touch:getLocation())
  1061. local rectEx = cc.rect(0, 0, cardSize.width - self.handCardDif, cardSize.height)
  1062. if cc.rectContainsPoint(rectEx, locationInNode) then
  1063. v:setColor(selectColor)
  1064. v.isHit = true
  1065. else
  1066. v:setColor(nomalColor)
  1067. v.isHit = false
  1068. end
  1069. end
  1070. end
  1071. end
  1072. end
  1073. function onTouchEnded(touch, event)
  1074. local handCards = self.handCards["" .. self:getMeViewId()]
  1075. if handCards then
  1076. -- for k,v in ipairs(handCards) do
  1077. -- if v.isHit then
  1078. -- if v.isUp then
  1079. -- self:setCardDown(v)
  1080. -- else
  1081. -- self:setCardUp(v)
  1082. -- end
  1083. -- end
  1084. -- v:setColor(nomalColor)
  1085. -- v.isHit = false
  1086. -- end
  1087. local isAllNormal = true
  1088. for _,card in pairs(handCards) do
  1089. if card then
  1090. if card.isUp then
  1091. isAllNormal = false
  1092. break
  1093. end
  1094. end
  1095. end
  1096. local selectCards = {}
  1097. for k,card in ipairs(handCards) do
  1098. if card.isHit then
  1099. table.insert(selectCards, card.cardNum)
  1100. end
  1101. end
  1102. -- 过滤选择的牌(主动出牌)
  1103. if isAllNormal then
  1104. if #self.lastData.cards <= 0 then
  1105. if self._pokerUtil and self._pokerUtil.getCardInSelectCard then
  1106. selectCards = self._pokerUtil:getCardInSelectCard(selectCards)
  1107. end
  1108. end
  1109. end
  1110. for i, v in ipairs(selectCards) do
  1111. local node = self:getCardNodeByCardValue(v)
  1112. if node then
  1113. if node.isUp then
  1114. self:setCardDown(node)
  1115. else
  1116. self:setCardUp(node)
  1117. end
  1118. node:setColor(nomalColor)
  1119. node.isHit = false
  1120. end
  1121. end
  1122. for i, card in ipairs(handCards) do
  1123. if card.isHit then
  1124. card:setColor(nomalColor)
  1125. card.isHit = false
  1126. end
  1127. end
  1128. end
  1129. end
  1130. -- 创建一个事件监听器
  1131. local listener = cc.EventListenerTouchOneByOne:create()
  1132. --设置穿透属性
  1133. listener:setSwallowTouches(true)
  1134. --添加事件和回调
  1135. listener:registerScriptHandler(onTouchBegan, cc.Handler.EVENT_TOUCH_BEGAN)
  1136. listener:registerScriptHandler(onTouchMoved, cc.Handler.EVENT_TOUCH_MOVED)
  1137. listener:registerScriptHandler(onTouchEnded, cc.Handler.EVENT_TOUCH_ENDED)
  1138. -- 得到事件派发器
  1139. local eventDispatcher = self:getEventDispatcher()
  1140. -- 将监听器注册到派发器中
  1141. eventDispatcher:addEventListenerWithSceneGraphPriority(listener, handCard)
  1142. end
  1143. function RoomView_28:initHandCardItem(card, viewId)
  1144. local switchEx = {}
  1145. local cardType = self:getCardType(card)
  1146. local cardValue = self:getCardValue(card)
  1147. local scaleEx = 0.35
  1148. switchEx["1"] = function()
  1149. -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源
  1150. local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", cardType, cardValue)) -- 新资源
  1151. card:setAnchorPoint(cc.p(1, 1))
  1152. card:setScale(scaleEx)
  1153. return card
  1154. end
  1155. switchEx["2"] = function()
  1156. -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源
  1157. local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", cardType, cardValue)) -- 新资源
  1158. card:setAnchorPoint(cc.p(1, 1))
  1159. card:setScale(scaleEx)
  1160. return card
  1161. end
  1162. switchEx["3"] = function()
  1163. -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源
  1164. local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", cardType, cardValue)) -- 新资源
  1165. card:setAnchorPoint(cc.p(0, 1))
  1166. card:setScale(scaleEx)
  1167. return card
  1168. end
  1169. switchEx["4"] = function()
  1170. -- return cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", cardType, cardValue)) -- 旧资源
  1171. return cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", cardType, cardValue)) -- 新资源
  1172. -- local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", cardType, cardValue)) -- 新资源
  1173. -- card:setScale(scaleEx)
  1174. -- return card
  1175. end
  1176. local initFunc = switchEx["" .. viewId]
  1177. if initFunc then
  1178. local imageCard = initFunc()
  1179. if imageCard then
  1180. imageCard.cardValue = cardValue -- 牌具体值1~13
  1181. imageCard.cardType = cardType -- 牌类型
  1182. imageCard.cardNum = card -- 牌的标准值
  1183. imageCard.refreshCard = function() -- 刷新卡牌
  1184. if card > 0 then
  1185. local cardPng = string.format("ddz_cards_%d_%d.png", cardType, cardValue)
  1186. imageCard:setSpriteFrame(cardPng)
  1187. if imageCard.bankerMark then
  1188. local size = imageCard:getContentSize()
  1189. local offsetX, offsetY = self:getBankTagOffset()
  1190. imageCard.bankerMark:setPosition(cc.p(size.width * 0.72 + offsetX, size.height * 0.78 + offsetY))
  1191. end
  1192. end
  1193. end
  1194. if viewId == self:getMeViewId() then
  1195. self:handCardItemRegisterTouchEvent(imageCard)
  1196. end
  1197. -- 设置为庄家牌
  1198. if self:checkIsBankCard(imageCard.cardNum, viewId) then
  1199. imageCard.isBankCard = true
  1200. end
  1201. end
  1202. logE("initHandCardItem viewId " .. viewId .. "imageCard " .. imageCard.cardNum)
  1203. return imageCard
  1204. end
  1205. end
  1206. function RoomView_28:rankHandCards(viewId, ani)
  1207. local childs = self.handCards["" .. viewId]
  1208. if childs then
  1209. local isBanker = app.room.roomInfo.nBankerId and app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId
  1210. local childsNum = table.nums(childs)
  1211. local xDiff = -30 --x轴调整
  1212. local getPokerChoose = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose
  1213. local cardDif = (getPokerChoose == 1) and 96 or 110
  1214. if childsNum > 17 then -- 使得扑克超过17张的话,让扑克牌组挤一点
  1215. self.handCardDif = cardDif + 3 * (childsNum - 17)
  1216. else
  1217. self.handCardDif = cardDif
  1218. end
  1219. for k,v in ipairs(childs) do
  1220. local maxLen = 12
  1221. local kEx = tonumber(k)
  1222. local floor = math.floor(kEx / maxLen)
  1223. local mod = kEx % maxLen + (kEx >= maxLen and 1 or 0)
  1224. local childScale = v:getScale()
  1225. local childSize = v:getContentSize()
  1226. if viewId == defs.VIEW_ID.MY_VIEW_ID then
  1227. v.tarPos = cc.p(xDiff + (kEx - childsNum / 2) * (childSize.width - self.handCardDif) * childScale.x, childSize.height / 2 * childScale.y)
  1228. elseif viewId == defs.VIEW_ID.TOP_VIEW_ID then
  1229. --设置zOder
  1230. v:setLocalZOrder(maxLen * floor - kEx)
  1231. v.tarPos = cc.p((-1) * mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor)
  1232. elseif viewId == defs.VIEW_ID.LEFT_VIEW_ID then
  1233. v.tarPos = cc.p(mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor)
  1234. elseif viewId == defs.VIEW_ID.RIGHT_VIEW_ID then
  1235. v:setLocalZOrder(maxLen * floor - kEx)
  1236. v.tarPos = cc.p((-1) * mod * (childSize.width - self.handCardDif) * childScale.x, (-1) * childSize.height * childScale.y * 0.5 * floor)
  1237. end
  1238. --庄家标识
  1239. if isBanker then
  1240. if v.isBankCard then
  1241. if v.bankerMark then
  1242. v.bankerMark:setVisible(true)
  1243. else
  1244. v.bankerMark = cc.Sprite:create(string.format("pk_doudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_bankerCardMark.png"))
  1245. local offsetX, offsetY = self:getBankTagOffset()
  1246. if app.room.roomInfo.isRecord then
  1247. if viewId ~= self:getMeViewId() then
  1248. offsetY = offsetY - 1.5
  1249. end
  1250. end
  1251. v.bankerMark:setPosition(cc.p(childSize.width * 0.72 + offsetX, childSize.height * 0.78 + offsetY))
  1252. v:addChild(v.bankerMark)
  1253. end
  1254. end
  1255. end
  1256. if ani then
  1257. v:stopAllActions()
  1258. v:runAction(cc.MoveTo:create(0.15, v.tarPos))
  1259. else
  1260. v:setPosition(v.tarPos)
  1261. end
  1262. end
  1263. end
  1264. end
  1265. function RoomView_28:initHandCards(handCards, viewId)
  1266. local handLayout = self.ui.Items["Layout_Hand_" .. viewId]
  1267. --手牌
  1268. self.handCards = self.handCards or {}
  1269. --选中的牌
  1270. self.selectCards = self.selectCards or {}
  1271. if handLayout then
  1272. handLayout:removeAllChildren()
  1273. --排序手牌
  1274. table.sort(handCards.Datas, function(a, b)
  1275. local cardValueA = self:getCardValue(a.card)
  1276. local cardValueB = self:getCardValue(b.card)
  1277. return cardValueA > cardValueB or cardValueA == cardValueB and self:getCardType(a.card) > self:getCardType(b.card)
  1278. end)
  1279. for k,v in ipairs(handCards.Datas) do
  1280. local imageCard = self:initHandCardItem(v.card, viewId)
  1281. if imageCard then
  1282. handLayout:addChild(imageCard)
  1283. end
  1284. end
  1285. self.handCards["" .. viewId] = handLayout:getChildren()
  1286. end
  1287. self:rankHandCards(viewId)
  1288. end
  1289. function RoomView_28:fapaiAni(onEnd)
  1290. self._isCanClickBg = false
  1291. local handCards = self.handCards["" .. self:getMeViewId()]
  1292. if not handCards then
  1293. logE("RoomView_28 fapaiAni error")
  1294. if onEnd then
  1295. onEnd()
  1296. end
  1297. end
  1298. for k,v in ipairs(handCards) do
  1299. v:setPosition(cc.pAdd(v.tarPos, cc.p(1280, 0)))
  1300. v:runAction(
  1301. cc.Sequence:create(
  1302. cc.DelayTime:create(0.03 * tonumber(k)),
  1303. cc.MoveTo:create(0, v.tarPos),
  1304. cc.CallFunc:create(function()
  1305. --playVoice("pk_doudizhu/res/sound/doudizhu_common_fapai.ogg")
  1306. if tonumber(k) == table.nums(handCards) then
  1307. self._isCanClickBg = true
  1308. if onEnd then
  1309. onEnd()
  1310. end
  1311. end
  1312. end)
  1313. )
  1314. )
  1315. end
  1316. end
  1317. function RoomView_28:cmd_0x8106_Resp(data)
  1318. function cmd_0x8106_Resp(onEnd)
  1319. local handCards = app.room.roomInfo.memberList[app.room:getMyUserId()].handCards
  1320. self:initHandCards(handCards, self:getMeViewId())
  1321. if table.nums(handCards) == 20 then
  1322. local bankerCards = {}
  1323. for _,v in ipairs(app.room.roomInfo.bankerCards) do
  1324. table.insert(bankerCards, v.card)
  1325. end
  1326. --从手牌中上升地主牌
  1327. self:setHandCardsUp(self:getMeViewId(), bankerCards)
  1328. if onEnd then
  1329. onEnd()
  1330. end
  1331. else
  1332. self:fapaiAni(onEnd)
  1333. end
  1334. end
  1335. self:addCallBack(cmd_0x8106_Resp)
  1336. end
  1337. function RoomView_28:setAskLoardVisible(bVisible, biJiao)
  1338. self.ui.Items.Layout_Ask_Loard:setVisible(bVisible)
  1339. if bVisible then
  1340. local curAskLoard = app.room.roomInfo.curAskLoard or 0
  1341. for i = 0, 3 do
  1342. local askLoardBtn = self.ui.Items["Button_Ask_Loard_F_" .. i]
  1343. if askLoardBtn then
  1344. if biJiao then
  1345. askLoardBtn:setEnabled(i == 3)
  1346. else
  1347. askLoardBtn:setEnabled(not (i ~= 0 and i <= curAskLoard))
  1348. end
  1349. end
  1350. end
  1351. self.ui.Items.Layout_Ask_Loard_Buttons:requestDoLayout()
  1352. self.ui.Items.Layout_Ask_Loard_Buttons:doLayout()
  1353. end
  1354. end
  1355. function RoomView_28:setAskBeiVisible(bVisible)
  1356. self.ui.Items.Layout_Ask_Bei:setVisible(bVisible)
  1357. end
  1358. function RoomView_28:setOperationVisible(bVisible, opType)
  1359. self.ui.Items.Layout_Operation:setVisible(bVisible)
  1360. if bVisible then
  1361. -- opType: 0要不起(没有可压牌), 1可要可不要, 2必须出(轮到自己了)
  1362. if opType == 1 then
  1363. -- 这种风格是,全程没有变灰的按钮,直接就隐藏掉
  1364. self.ui.Items.Layout_Operation_BuChu:setVisible(bVisible)
  1365. self.ui.Items.Layout_Operation_TiShi:setVisible(bVisible)
  1366. self.ui.Items.Layout_Operation_ChuPai:setVisible(bVisible)
  1367. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(not bVisible)
  1368. -- 这种风格是,有变灰的按钮,不可点击,下面同理
  1369. --[[
  1370. self.ui.Items.Button_Operation_BuChu:setEnabled(bVisible)
  1371. self.ui.Items.Button_Operation_TiShi:setEnabled(bVisible)
  1372. self.ui.Items.Button_Operation_ChuPai:setEnabled(bVisible)
  1373. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false)
  1374. ]]
  1375. elseif opType == 2 then
  1376. self:setLastData()
  1377. self.ui.Items.Layout_Operation_BuChu:setVisible(not bVisible)
  1378. self.ui.Items.Layout_Operation_TiShi:setVisible(not bVisible) -- 轮到自己回合,提示按钮隐藏
  1379. self.ui.Items.Layout_Operation_ChuPai:setVisible(bVisible)
  1380. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(not bVisible)
  1381. --[[
  1382. self.ui.Items.Button_Operation_BuChu:setEnabled(not bVisible)
  1383. self.ui.Items.Button_Operation_TiShi:setEnabled(bVisible)
  1384. self.ui.Items.Button_Operation_ChuPai:setEnabled(bVisible)
  1385. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false)
  1386. ]]
  1387. else
  1388. self.ui.Items.Layout_Operation_BuChu:setVisible(not bVisible)
  1389. self.ui.Items.Layout_Operation_TiShi:setVisible(not bVisible)
  1390. self.ui.Items.Layout_Operation_ChuPai:setVisible(not bVisible)
  1391. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(bVisible)
  1392. --[[
  1393. self.ui.Items.Button_Operation_BuChu:setEnabled(bVisible)
  1394. self.ui.Items.Button_Operation_TiShi:setEnabled(not bVisible)
  1395. self.ui.Items.Button_Operation_ChuPai:setEnabled(not bVisible)
  1396. self.ui.Items.Layout_Operation_YaoBuQi:setVisible(false)
  1397. ]]
  1398. end
  1399. self.ui.Items.Layout_Operation_Buttons:requestDoLayout()
  1400. self.ui.Items.Layout_Operation_Buttons:doLayout()
  1401. --检测提示
  1402. self.tiShiCount = 1
  1403. local handCards = self.handCards["" .. self:getMeViewId()]
  1404. local handCardsValueTable = {} -- 玩家手牌值表
  1405. local lastDataValueTable = {} -- 上个牌数据值表
  1406. for i, v in pairs(handCards) do
  1407. table.insert(handCardsValueTable, v.cardNum)
  1408. end
  1409. for i, v in pairs(self.lastData.cards) do
  1410. table.insert(lastDataValueTable, v.cardNum)
  1411. end
  1412. -- 判断是否可以一手出完牌
  1413. if self._pokerUtil:checkIsCanOneOutCard(handCardsValueTable, lastDataValueTable) then
  1414. --self:setOperationVisible(false)
  1415. self:runAction(
  1416. cc.Sequence:create(
  1417. cc.DelayTime:create(0.5),
  1418. cc.CallFunc:create(function ()
  1419. self:setHandCardsUp(self:getMeViewId(), handCardsValueTable)
  1420. self:chuPai()
  1421. end)
  1422. )
  1423. )
  1424. end
  1425. -- 牌型提示
  1426. if self.ui.Items.Layout_Operation_TiShi:isVisible() then
  1427. self.weaveCardList = self:getTip(handCardsValueTable, lastDataValueTable)
  1428. end
  1429. end
  1430. end
  1431. function RoomView_28:setHandCardsUp(viewId, cards)
  1432. --下降所有牌
  1433. self:setAllHandCardDown(self:getMeViewId())
  1434. --上升指定牌
  1435. if self.handCards and cards then
  1436. local handCards = self.handCards["" .. viewId]
  1437. if handCards then
  1438. for k,v in ipairs(cards) do
  1439. for _,v2 in ipairs(handCards) do
  1440. if v == v2.cardNum then
  1441. self:setCardUp(v2)
  1442. end
  1443. end
  1444. end
  1445. end
  1446. end
  1447. end
  1448. function RoomView_28:setAllHandCardDown(viewId)
  1449. if self.handCards then
  1450. local handCards = self.handCards["" .. viewId]
  1451. if handCards then
  1452. for _,v in ipairs(handCards) do
  1453. self:setCardDown(v)
  1454. end
  1455. end
  1456. end
  1457. end
  1458. function RoomView_28:initGameButtons()
  1459. --桌面
  1460. self.ui.Items.ImageView_bg:registerClick(function()
  1461. --测试
  1462. --self:chuPai()
  1463. --self:tiShi()
  1464. --self:fapaiAni()
  1465. if not self._isCanClickBg then
  1466. return
  1467. end
  1468. --下降所有牌
  1469. self:setAllHandCardDown(self:getMeViewId())
  1470. end)
  1471. --叫分
  1472. self.ui.Items.Layout_Ask_Loard:setVisible(false)
  1473. for i = 0, 3 do
  1474. local button = self.ui.Items["Button_Ask_Loard_F_" .. i]
  1475. if button then
  1476. button:registerClick(function()
  1477. playBtnEffect()
  1478. app.room:sendAskLoard(i)
  1479. end)
  1480. end
  1481. end
  1482. --加倍
  1483. self.ui.Items.Layout_Ask_Bei:setVisible(false)
  1484. for i = 0, 1 do
  1485. local button = self.ui.Items["Button_Ask_Bei_" .. i]
  1486. if button then
  1487. button:registerClick(function()
  1488. playBtnEffect()
  1489. app.room:sendAskBei(i)
  1490. end)
  1491. end
  1492. end
  1493. --要不起,不出,提示,出牌
  1494. self.ui.Items.Layout_Operation:setVisible(false)
  1495. self.ui.Items.Button_Operation_YaoBuQi:registerClick(function()
  1496. playBtnEffect()
  1497. app.room:sendOperation({opType = 0, cards = {}})
  1498. end)
  1499. self.ui.Items.Button_Operation_BuChu:registerClick(function()
  1500. playBtnEffect()
  1501. app.room:sendOperation({opType = 0, cards = {}})
  1502. end)
  1503. self.ui.Items.Button_Operation_TiShi:registerClick(handler(self, self.tiShi))
  1504. self.ui.Items.Button_Operation_ChuPai:registerClick(handler(self, self.chuPai))
  1505. end
  1506. function RoomView_28:getCardsType(cards)
  1507. return self._pokerUtil:getCardsType(cards)
  1508. end
  1509. function RoomView_28:getTip(cards, lastData)
  1510. if cards and cards[1] and type(cards[1]) == 'userdata' then
  1511. logD('亲!现在调用getTip,cards数据是要传牌值,不是card节点啦!!!')
  1512. return
  1513. end
  1514. return self._pokerUtil:getTip(cards, lastData)
  1515. end
  1516. function RoomView_28:tiShi()
  1517. playBtnEffect()
  1518. if self.weaveCardList and table.nums(self.weaveCardList) > 0 then
  1519. function tiShiEx()
  1520. local weaveList = self.weaveCardList[self.tiShiCount]
  1521. if weaveList then
  1522. self:setHandCardsUp(self:getMeViewId(), weaveList)
  1523. self.tiShiCount = self.tiShiCount + 1
  1524. else
  1525. self.tiShiCount = 1
  1526. tiShiEx()
  1527. end
  1528. end
  1529. tiShiEx()
  1530. else
  1531. app.room:sendOperation({opType = 0, cards = {}})
  1532. end
  1533. end
  1534. function RoomView_28:chuPai()
  1535. playBtnEffect()
  1536. local handCards = self.handCards["" .. self:getMeViewId()]
  1537. if not handCards then
  1538. logE("RoomView_28 chuPai error handCards is null")
  1539. end
  1540. --获取点中的牌
  1541. local cards = {}
  1542. local cardsEx = {}
  1543. for k,v in ipairs(handCards) do
  1544. if v:isVisible() and v.isUp then
  1545. table.insert(cards, v.cardNum)
  1546. table.insert(cardsEx, v)
  1547. end
  1548. end
  1549. --local typeEx = self:getCardsType(cardsEx)
  1550. --logE("RoomView_28 chuPai type : " .. table.tostring(cardsEx))
  1551. logE("RoomView_28 chuPai type : " .. table.tostring(cards))
  1552. app.room:sendOperation({opType = 1, cards = cards})
  1553. end
  1554. function RoomView_28:cmd_0x8108_Resp(data)
  1555. function cmd_0x8108_RespEx(onEnd)
  1556. --当前操作玩家
  1557. self.curViewId = app.room:getViewIdByUserId(data.response.nUserId)
  1558. --显示闹钟
  1559. self.PlayerView:setClockVisibel(true, self.curViewId, data.response.leftTime)
  1560. --显示叫分
  1561. if self.curViewId == self:getMeViewId() then
  1562. self:setAskLoardVisible(true, data.response.mustBanker == 1)
  1563. end
  1564. if onEnd then
  1565. onEnd()
  1566. end
  1567. end
  1568. self:addCallBack(cmd_0x8108_RespEx)
  1569. end
  1570. function RoomView_28:cmd_0x8109_Resp(data)
  1571. function cmd_0x8109_RespEx(onEnd)
  1572. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1573. --隐藏叫分界面
  1574. self:setAskLoardVisible(false)
  1575. --隐藏闹钟
  1576. self.PlayerView:setClockVisibel(false, viewId)
  1577. --显示叫分
  1578. self.PlayerView:setTipsVisible("tips_jiaofen", true, viewId, {askLoard = data.response.askLoard})
  1579. --播放音效
  1580. Functions.playVoice("jiaofen", data.response.askLoard, self.PlayerView:getPlayerData("sex", viewId))
  1581. if onEnd then
  1582. onEnd()
  1583. end
  1584. end
  1585. self:addCallBack(cmd_0x8109_RespEx)
  1586. end
  1587. function RoomView_28:setBankerAskLoard()
  1588. self.ui.Items.Text_AskLoard:setText(app.room.roomInfo.curAskLoard or 0)
  1589. end
  1590. function RoomView_28:setCurZhaDanNum()
  1591. self.ui.Items.Text_ZhaDan:setText(app.room.roomInfo.nBombs or 0)
  1592. end
  1593. function RoomView_28:setBanderCardsVisible(bVisible, bankerCards)
  1594. self.ui.Items.Layout_BankerInfo:setVisible(bVisible)
  1595. if bVisible then
  1596. for k,v in ipairs(bankerCards) do
  1597. local card = self.ui.Items["Image_BankerCard_" .. k]
  1598. if card then
  1599. -- card:loadTexture(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 旧资源
  1600. card:loadTexture(string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card)), 1) -- 新资源
  1601. end
  1602. end
  1603. self:setCurZhaDanNum()
  1604. self:setBankerAskLoard()
  1605. end
  1606. end
  1607. function RoomView_28:cmd_0x810a_Resp(data)
  1608. function cmd_0x810a_RespEx(onEnd)
  1609. self:runAction(
  1610. cc.Sequence:create(
  1611. cc.DelayTime:create(1.0),
  1612. cc.CallFunc:create(function()
  1613. local viewId = app.room:getViewIdByUserId(data.response.nBankerId)
  1614. --显示剩余手牌
  1615. self.PlayerView:setLeftNumVisible(true, viewId, 20)
  1616. --显示庄家
  1617. self.PlayerView:setBankerVisible(true, viewId)
  1618. --显示底牌和底分炸弹情况
  1619. self:setBanderCardsVisible(true, data.response.bankerCards)
  1620. -- 底牌显示的时候,即叫分结束,此时把叫分分数隐藏
  1621. self:setAllTipsVisible()
  1622. if onEnd then
  1623. onEnd()
  1624. end
  1625. end)
  1626. )
  1627. )
  1628. end
  1629. self:addCallBack(cmd_0x810a_RespEx)
  1630. end
  1631. function RoomView_28:setAllTipsVisible(bVisible)
  1632. for k,v in pairs(app.room.roomInfo.memberList) do
  1633. self.PlayerView:setTipsVisible("tips_jiaofen", false, app.room:getViewIdByUserId(v.nUserId))
  1634. end
  1635. end
  1636. function RoomView_28:cmd_0x810c_Resp(data)
  1637. function cmd_0x810c_RespEx(onEnd)
  1638. --显示加倍
  1639. self:setAskBeiVisible(true)
  1640. local function endCallback(viewId)
  1641. if Functions.getIsAutoAskBeiAfterTimeout() then
  1642. if viewId == self:getMeViewId() then
  1643. app.room:sendAskBei(0)
  1644. end
  1645. end
  1646. end
  1647. --显示闹钟
  1648. for k,v in pairs(app.room.roomInfo.memberList) do
  1649. self.PlayerView:setClockVisibel(true, app.room:getViewIdByUserId(v.nUserId), data.response.leftTime, endCallback)
  1650. end
  1651. if onEnd then
  1652. onEnd()
  1653. end
  1654. end
  1655. self:addCallBack(cmd_0x810c_RespEx)
  1656. end
  1657. function RoomView_28:cmd_0x810d_Resp(data)
  1658. function cmd_0x810d_RespEx(onEnd)
  1659. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  1660. --隐藏加倍操作界面
  1661. if viewId == self:getMeViewId() then
  1662. self:setAskBeiVisible(false)
  1663. self:setAllHandCardDown(viewId)
  1664. end
  1665. --隐藏闹钟
  1666. self.PlayerView:setClockVisibel(false, viewId)
  1667. --显示加倍状态
  1668. self.PlayerView:setTipsVisible("tips_jiabei", true, viewId, { askBei = data.response.askBei })
  1669. --播放音效
  1670. Functions.playVoice("jiabei", data.response.askBei, self.PlayerView:getPlayerData("sex", viewId))
  1671. self:runAction(
  1672. cc.Sequence:create(
  1673. cc.DelayTime:create(0.5),
  1674. cc.CallFunc:create(function()
  1675. if onEnd then
  1676. onEnd()
  1677. end
  1678. end)
  1679. )
  1680. )
  1681. end
  1682. self:addCallBack(cmd_0x810d_RespEx)
  1683. end
  1684. function RoomView_28:hideAllOutCardOperation()
  1685. --隐藏玩家出牌操作信息
  1686. for _,v in pairs(app.room.roomInfo.memberList) do
  1687. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1688. --隐藏玩家的出牌
  1689. self:setOutCardsVisible(false, viewId)
  1690. --隐藏玩家的操作
  1691. self.PlayerView:setTipsVisible("tips_yaobuqi", false, viewId)
  1692. end
  1693. end
  1694. function RoomView_28:cmd_0x810e_Resp(data)
  1695. function cmd_0x810e_RespEx(onEnd)
  1696. --当前操作玩家
  1697. self.curViewId = app.room:getViewIdByUserId(data.response.nUserId)
  1698. local delayTime = 0
  1699. if data.response.opType == 2 then -- 如果是所有玩家都操作不要,即本家必须出牌
  1700. delayTime = 0.4
  1701. end
  1702. self:runAction(cc.Sequence:create(
  1703. cc.DelayTime:create(delayTime),
  1704. cc.CallFunc:create(function()
  1705. --隐藏玩家出牌操作信息
  1706. if data.response.opType == 2 then
  1707. self:hideAllOutCardOperation()
  1708. else
  1709. --隐藏玩家的出牌
  1710. self:setOutCardsVisible(false, self.curViewId)
  1711. --隐藏玩家的操作
  1712. self.PlayerView:setTipsVisible("tips_yaobuqi", false, self.curViewId)
  1713. end
  1714. --显示闹钟
  1715. self.PlayerView:setClockVisibel(true, self.curViewId, self.clockTime)
  1716. --显示操作
  1717. if self.curViewId == self:getMeViewId() then
  1718. self:setOperationVisible(true, data.response.opType)
  1719. end
  1720. if onEnd then
  1721. onEnd()
  1722. end
  1723. end)
  1724. ))
  1725. end
  1726. self:addCallBack(cmd_0x810e_RespEx)
  1727. end
  1728. function RoomView_28:cmd_0x810f_Resp(data)
  1729. function cmd_0x810f_RespEx(onEnd)
  1730. local errorMessage = {
  1731. [1] = "轮次错误",
  1732. [2] = "牌型错误",
  1733. [3] = "出牌错误",
  1734. }
  1735. --下降所有手牌
  1736. self:setAllHandCardDown(self.getMeViewId())
  1737. --显示错误信息
  1738. showTooltip(errorMessage[data.response.errorType] or "出牌错误")
  1739. if onEnd then
  1740. onEnd()
  1741. end
  1742. end
  1743. self:addCallBack(cmd_0x810f_RespEx)
  1744. end
  1745. function RoomView_28:setLastData(viewId, data)
  1746. if viewId and data then
  1747. local cardsEx = {}
  1748. local cardsValueTable = {}
  1749. for k,v in ipairs(data.cards) do
  1750. table.insert(cardsEx, { cardNum = v.card, cardValue = self:getCardValue(v.card), cardType = self:getCardType(v.card) })
  1751. table.insert(cardsValueTable, v.card)
  1752. end
  1753. local lastDataEx = self:getCardsType(cardsValueTable)
  1754. if lastDataEx then
  1755. for k,v in pairs(lastDataEx) do
  1756. self.lastData[k] = v
  1757. end
  1758. end
  1759. self.lastData.cards = cardsEx
  1760. self.lastData.viewId = viewId
  1761. --播放音效
  1762. Functions.playVoice("chupai", self.lastData, self.PlayerView:getPlayerData("sex", viewId))
  1763. else
  1764. self.lastData = {
  1765. min = 0,
  1766. cards = {},
  1767. viewId = 0,
  1768. cardType = 0,
  1769. }
  1770. end
  1771. end
  1772. function RoomView_28:setOutCardsVisible(bVisible, viewId, data)
  1773. logE("RoomView_28 setOutCardsVisible data : ".. table.toString(data))
  1774. local outCardsLayout = self.ui.Items["Layout_Out_" .. viewId]
  1775. if outCardsLayout then
  1776. outCardsLayout:setVisible(bVisible)
  1777. if bVisible then
  1778. outCardsLayout:removeAllChildren()
  1779. if data.opType == 0 then
  1780. self.PlayerView:setTipsVisible("tips_yaobuqi", true, viewId)
  1781. --播放音效
  1782. Functions.playVoice("buyao", 0, self.PlayerView:getPlayerData("sex", viewId))
  1783. else
  1784. if not data.maxLen then
  1785. self:setLastData(viewId, data)
  1786. end
  1787. self:initOutCardItem(outCardsLayout, viewId, data)
  1788. end
  1789. end
  1790. end
  1791. end
  1792. function RoomView_28:initOutCardItem(outCardsLayout, viewId, data)
  1793. local cardScale = 0.5
  1794. local cardsLen = table.nums(data.cards)
  1795. local isBanker = app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId
  1796. for k,v in ipairs(data.cards) do
  1797. -- local card = cc.Sprite:create(string.format("pk/res/ui/zy_fangjian/pk_cards/pk_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 旧资源
  1798. local card = cc.Sprite:createWithSpriteFrameName(string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))) -- 新资源
  1799. if card then
  1800. -- 设置为庄家牌
  1801. if self:checkIsBankCard(v.card, viewId) then
  1802. card.isBankCard = true
  1803. end
  1804. local kEx = tonumber(k)
  1805. card:setScale(cardScale)
  1806. outCardsLayout:addChild(card)
  1807. local cardSize = card:getContentSize()
  1808. if viewId == 1 then
  1809. --左对齐
  1810. if data.maxLen then
  1811. local floor = math.floor(kEx / data.maxLen)
  1812. local mod = kEx % data.maxLen + (kEx >= data.maxLen and 1 or 0)
  1813. --设置zOder
  1814. card:setLocalZOrder(data.maxLen * floor - kEx)
  1815. card:setPosition(cc.p((-1) * mod * (cardSize.width - self.handCardDif) * cardScale, (-1) * cardSize.height * cardScale * 0.5 * floor))
  1816. else
  1817. --设置zOder
  1818. card:setLocalZOrder(cardsLen - kEx)
  1819. card:setPosition(cc.p((-1) * kEx * (cardSize.width - self.handCardDif) * cardScale, 0))
  1820. end
  1821. elseif viewId == 3 then
  1822. --右对齐
  1823. if data.maxLen then
  1824. local floor = math.floor(kEx / data.maxLen)
  1825. local mod = kEx % data.maxLen + (kEx >= data.maxLen and 1 or 0)
  1826. card:setPosition(cc.p(mod * (cardSize.width - self.handCardDif) * cardScale, (-1) * cardSize.height * cardScale * 0.5 * floor))
  1827. else
  1828. card:setPosition(cc.p(kEx * (cardSize.width - self.handCardDif) * cardScale, 0))
  1829. end
  1830. else
  1831. --居中
  1832. card:setPosition(cc.p((kEx - cardsLen / 2) * (cardSize.width - self.handCardDif) * cardScale, 0))
  1833. end
  1834. --庄家标识
  1835. if isBanker then
  1836. if card.isBankCard then
  1837. if card.bankerMark then
  1838. card.bankerMark:setVisible(true)
  1839. else
  1840. card.bankerMark = cc.Sprite:create(string.format("pk_doudizhu/res/ui/zy_fangjian/doudizhu_desk/doudizhu_desk_bankerCardMark.png"))
  1841. local offsetX, offsetY = self:getBankTagOffset()
  1842. card.bankerMark:setPosition(cc.p(cardSize.width * 0.72 + offsetX, cardSize.height * 0.7835 + offsetY))
  1843. card:addChild(card.bankerMark)
  1844. end
  1845. end
  1846. end
  1847. card:stopAllActions()
  1848. local moveTo = cc.MoveBy:create(Card_Out_Down_Time, cc.p(0, Card_Out_Down_Offset_Y))
  1849. card:runAction(moveTo)
  1850. -- 添加刷新牌的方法
  1851. card.refreshCard = function() -- 刷新卡牌
  1852. if v.card > 0 then
  1853. local cardPng = string.format("ddz_cards_%d_%d.png", self:getCardType(v.card), self:getCardValue(v.card))
  1854. card:setSpriteFrame(cardPng)
  1855. if card.bankerMark then
  1856. local size = card:getContentSize()
  1857. local offsetX, offsetY = self:getBankTagOffset()
  1858. card.bankerMark:setPosition(cc.p(size.width * 0.72 + offsetX, size.height * 0.7835 + offsetY))
  1859. end
  1860. end
  1861. end
  1862. else
  1863. logE("RoomView_28 initOutCardItem error".. table.toString(v))
  1864. end
  1865. end
  1866. --播放动画
  1867. if #self.lastData.cards > 0 then
  1868. local cardsEx = outCardsLayout:getChildren()
  1869. if #cardsEx > 0 then
  1870. local effect = nil
  1871. if self.lastData.cardType == defs.CARD_TYPE.SHUNZI then --顺子
  1872. -- effect = createAnimationByPlist("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_shunzi.plist", "shunzi%d.png", 1, 17, -1)
  1873. effect = DDZ_New_Effect_Helper:getShunziNew()
  1874. elseif self.lastData.cardType == defs.CARD_TYPE.SHUANGSHUN then --连对
  1875. -- effect = createAnimationByPlist("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_liandui.plist", "liandui%d.png", 1, 8, -1)
  1876. effect = DDZ_New_Effect_Helper:getLianduiNew()
  1877. elseif self.lastData.cardType == defs.CARD_TYPE.SANSHUN then --飞机
  1878. -- effect = createAnimationByPlist("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1)
  1879. effect = DDZ_New_Effect_Helper:getPlanNew()
  1880. elseif self.lastData.cardType == defs.CARD_TYPE.AIRPLANE_SINGLE then --飞机
  1881. -- effect = createAnimationByPlist("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1)
  1882. effect = DDZ_New_Effect_Helper:getPlanNew()
  1883. elseif self.lastData.cardType == defs.CARD_TYPE.AIRPLANE_DUAD then --飞机
  1884. -- effect = createAnimationByPlist("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_feiji.plist", "feiji%d.png", 1, 16, -1)
  1885. effect = DDZ_New_Effect_Helper:getPlanNew()
  1886. elseif self.lastData.cardType == defs.CARD_TYPE.BOMB then --炸弹
  1887. -- effect = createAnimationByPlist("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_zhadan.plist", "zhadan%d.png", 1, 17, -1)
  1888. effect = DDZ_New_Effect_Helper:getBombNew()
  1889. elseif self.lastData.cardType == defs.CARD_TYPE.BOMB_KING then --王炸
  1890. -- effect = createAnimationByPlist("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_zhadan.plist", "zhadan%d.png", 1, 17, -1)
  1891. effect = DDZ_New_Effect_Helper:getKingBombNew()
  1892. end
  1893. if effect then
  1894. effect:setScale(0.7)
  1895. effect:setPosition(cardsEx[toint(#cardsEx / 2)]:getPosition())
  1896. outCardsLayout:addChild(effect, 100)
  1897. if effect.onEnter and type(effect.onEnter)=='function' then
  1898. effect:onEnter()
  1899. end
  1900. end
  1901. end
  1902. end
  1903. end
  1904. function RoomView_28:deleteHandCards(viewId, cards, doAni)
  1905. local handCards = self.handCards["" .. viewId]
  1906. if handCards then
  1907. for k,v in ipairs(cards) do
  1908. logE("handCards v.card " .. v.card)
  1909. for k2,v2 in ipairs(handCards) do
  1910. logE("handCards v2.cardNum " .. v2.cardNum)
  1911. if v2.cardNum == v.card then
  1912. v2:removeFromParent()
  1913. table.remove(handCards, k2)
  1914. break
  1915. end
  1916. end
  1917. end
  1918. self:rankHandCards(viewId, doAni)
  1919. end
  1920. end
  1921. -- 根据牌的标准值获取手牌节点
  1922. function RoomView_28:getCardNodeByCardValue(cardValue)
  1923. if self.handCards and cardValue then
  1924. local handCards = self.handCards["" .. self:getMeViewId()]
  1925. if handCards then
  1926. for _,cardNode in ipairs(handCards) do
  1927. if cardValue == cardNode.cardNum then
  1928. return cardNode
  1929. end
  1930. end
  1931. end
  1932. end
  1933. end
  1934. -- 判断是否是庄家牌
  1935. function RoomView_28:checkIsBankCard(card, viewId)
  1936. if not app.room.roomInfo.bankerCards then
  1937. return false
  1938. end
  1939. -- 只要是庄家,庄家的牌都显示为地主
  1940. local isBanker = app.room.roomInfo.nBankerId and app.room.roomInfo.nBankerId > 0 and app.room:getViewIdByUserId(app.room.roomInfo.nBankerId) == viewId
  1941. return isBanker
  1942. -- 只有3张底牌显示
  1943. -- local temp = {}
  1944. -- for _,v in ipairs(app.room.roomInfo.bankerCards) do
  1945. -- table.insert(temp, v.card)
  1946. -- end
  1947. -- for i, v in ipairs(temp) do
  1948. -- if card == v then
  1949. -- return true
  1950. -- end
  1951. -- end
  1952. -- return false
  1953. end
  1954. -- 获得庄家标记偏移值
  1955. function RoomView_28:getBankTagOffset()
  1956. local getPokerChoose = tonumber(loadUserInfo("ddz_setting_poker")) or defs.Default_Poker_Choose
  1957. local offsetX = (getPokerChoose == 1) and 0 or 3
  1958. local offsetY = (getPokerChoose == 1) and 1 or -1.2
  1959. return offsetX, offsetY
  1960. end
  1961. function RoomView_28:cmd_0x8110_Resp(data)
  1962. function cmd_0x8110_RespEx(onEnd)
  1963. --隐藏玩家信息
  1964. if data.response.opType == 1 then
  1965. self:hideAllOutCardOperation()
  1966. end
  1967. --操作位置
  1968. local opViewId = app.room:getViewIdByUserId(data.response.nUserId)
  1969. --显示剩余手牌
  1970. self.PlayerView:setLeftNumVisible(true, opViewId, data.response.leftNum)
  1971. --隐藏操作
  1972. self:setOperationVisible(false)
  1973. --隐藏闹钟
  1974. self.PlayerView:setClockVisibel(false, opViewId)
  1975. --显示出牌
  1976. self:setOutCardsVisible(true, opViewId, {cards = data.response.cards, opType = data.response.opType})
  1977. --删除手牌
  1978. if opViewId == self:getMeViewId() then
  1979. self:deleteHandCards(opViewId, data.response.cards, true)
  1980. end
  1981. if onEnd then
  1982. onEnd()
  1983. end
  1984. end
  1985. self:addCallBack(cmd_0x8110_RespEx)
  1986. end
  1987. function RoomView_28:cmd_0x8111_Resp(data)
  1988. function cmd_0x8111_RespEx(onEnd)
  1989. --设置底分
  1990. self:setBankerAskLoard()
  1991. --设置炸弹数
  1992. self:setCurZhaDanNum()
  1993. if onEnd then
  1994. onEnd()
  1995. end
  1996. end
  1997. self:addCallBack(cmd_0x8111_RespEx)
  1998. end
  1999. function RoomView_28:cmd_0x8112_Resp(data)
  2000. function cmd_0x8112_RespEx(onEnd)
  2001. --显示春天动画
  2002. -- 去除春天动画
  2003. -- if data.response.nSpring == 1 then
  2004. -- local effect = createAnimationByPlist("pk_doudizhu/res/ui/zy_fangjian/doudizhu_cardsAni/doudizhu_spring.plist", "spring%d.png", 1, 22, -1)
  2005. -- if effect then
  2006. -- playVoice("pk_doudizhu/res/sound/doudizhu_common_spring.ogg")
  2007. -- effect:setPosition(cc.p(640, 360))
  2008. -- self:addChild(effect)
  2009. -- end
  2010. -- end
  2011. self:runAction(
  2012. cc.Sequence:create(
  2013. -- cc.DelayTime:create(1.0),
  2014. cc.DelayTime:create(1.3),
  2015. cc.CallFunc:create(function()
  2016. --隐藏界面
  2017. local winViewId = app.room:getViewIdByUserId(data.response.nWinId)
  2018. for _,v in pairs(app.room.roomInfo.memberList) do
  2019. local viewId = app.room:getViewIdByUserId(v.nUserId)
  2020. if viewId ~= winViewId then
  2021. --出牌界面
  2022. self:setOutCardsVisible(false, viewId)
  2023. end
  2024. --闹钟界面
  2025. self.PlayerView:setClockVisibel(false, viewId)
  2026. end
  2027. --显示小局结算
  2028. self:setXiaoJuVisible(true, data.response)
  2029. if onEnd then
  2030. onEnd()
  2031. end
  2032. end)
  2033. )
  2034. )
  2035. end
  2036. self:addCallBack(cmd_0x8112_RespEx)
  2037. end
  2038. function RoomView_28:showDaJu(data)
  2039. if not self.daJuView then
  2040. self.daJuView = import("pk_doudizhu.luaScript.Views.Room.RoomDaJuView_28"):new(data)
  2041. -- self.ui.Items.Layout_DaJu:addChild(self.daJuView)
  2042. self.daJuView:setAnchorPoint(cc.p(0.5, 0.5))
  2043. app:showWaitDialog(self.daJuView);
  2044. end
  2045. --更新界面
  2046. self.daJuView:updateView(data)
  2047. self:showGameOverAward()
  2048. end
  2049. function RoomView_28:cmd_0x8113_Resp(data)
  2050. function cmd_0x8113_RespEx(onEnd)
  2051. if self.tuoguanView then
  2052. self:showTuoGuan(false)
  2053. end
  2054. local isShow_XiaoJu = (self.XiaoJuView and self.XiaoJuView:isVisible()) or false
  2055. -- 如果之前没显示过小结算,或者是解散导致的结束,直接显示大结算
  2056. if not isShow_XiaoJu or app.room.roomInfo._stopFlag == 9 then
  2057. --隐藏小局结算
  2058. self:setXiaoJuVisible(false)
  2059. --显示总结算
  2060. self:showDaJu(data.response)
  2061. end
  2062. --关闭结算界面
  2063. app.room:dispatchEvent({ name = GAME_EVENT.DISSMISS_CLOSE })
  2064. if onEnd then
  2065. onEnd()
  2066. end
  2067. end
  2068. self:addCallBack(cmd_0x8113_RespEx)
  2069. end
  2070. function RoomView_28:cmd_0x8114_Resp(data)
  2071. function cmd_0x8114_RespEx(onEnd)
  2072. --重置桌面
  2073. self:defaultState()
  2074. if onEnd then
  2075. onEnd()
  2076. end
  2077. end
  2078. self:addCallBack(cmd_0x8114_RespEx)
  2079. end
  2080. ---
  2081. -- 初始化大结算再来一局
  2082. -- @return
  2083. --
  2084. function RoomView_28:initPlayGameAgain()
  2085. local strGameInfo = app.room.roomInfo.strGameInfo
  2086. local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0
  2087. if not isInClub then
  2088. logD("RoomView_28.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局");
  2089. return
  2090. end
  2091. local clubGameInfo = json.decode(strGameInfo) or {}
  2092. if not clubGameInfo.ruleid then
  2093. logD("RoomView_28.initPlayGameAgain", "游戏包间id不存在,不能再来一局");
  2094. return
  2095. end
  2096. dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid)
  2097. end
  2098. -- 托管通知
  2099. function RoomView_28:onHostingResponse( data )
  2100. local function onHostingResponseEx(onEnd)
  2101. local response = data.response
  2102. -- 如果是我,则显示托管layout界面
  2103. if response.nUserId == app.room:getMyUserId() then
  2104. if response.status == 1 then --托管状态
  2105. self:showTuoGuan(true)
  2106. elseif response.status == 0 then--取消托管状态
  2107. self:showTuoGuan(false)
  2108. end
  2109. end
  2110. local isTuoGuan = response.status == 1
  2111. local viewId = app.room:getViewIdByUserId(response.nUserId)
  2112. self.PlayerView:showTuoGuanByViewId(viewId, isTuoGuan)
  2113. if onEnd then
  2114. onEnd()
  2115. end
  2116. end
  2117. self:addCallBack(onHostingResponseEx)
  2118. end
  2119. --显示隐藏托管
  2120. function RoomView_28:showTuoGuan(isShow)
  2121. if not self.tuoguanView then
  2122. self.tuoguanView = TuoGuanView:new()
  2123. self:addChild(self.tuoguanView)
  2124. self.tuoguanView:setVisible(false)
  2125. end
  2126. self.tuoguanView:setVisible(isShow)
  2127. end
  2128. function RoomView_28:refreshPlayerAIStatus()
  2129. for _,v in pairs(app.room.roomInfo.memberList) do
  2130. local isTuoGuan = v.AIStatus == 1
  2131. print('RoomView_28:refreshPlayerAIStatus', v.nUserId, isTuoGuan)
  2132. self.PlayerView:showTuoGuanByViewId(app.room:getViewIdByUserId(v.nUserId), isTuoGuan)
  2133. end
  2134. end
  2135. --游戏消息
  2136. function RoomView_28:bindGameMessage()
  2137. self:bindEvent(app.room , "cmd_0x8104_Resp", handler(self , self.cmd_0x8104_Resp))
  2138. self:bindEvent(app.room , "cmd_0x8105_Resp", handler(self , self.cmd_0x8105_Resp))
  2139. self:bindEvent(app.room , "cmd_0x8106_Resp", handler(self , self.cmd_0x8106_Resp))
  2140. self:bindEvent(app.room , "cmd_0x8108_Resp", handler(self , self.cmd_0x8108_Resp))
  2141. self:bindEvent(app.room , "cmd_0x8109_Resp", handler(self , self.cmd_0x8109_Resp))
  2142. self:bindEvent(app.room , "cmd_0x810a_Resp", handler(self , self.cmd_0x810a_Resp))
  2143. self:bindEvent(app.room , "cmd_0x810c_Resp", handler(self , self.cmd_0x810c_Resp))
  2144. self:bindEvent(app.room , "cmd_0x810d_Resp", handler(self , self.cmd_0x810d_Resp))
  2145. self:bindEvent(app.room , "cmd_0x810e_Resp", handler(self , self.cmd_0x810e_Resp))
  2146. self:bindEvent(app.room , "cmd_0x810f_Resp", handler(self , self.cmd_0x810f_Resp))
  2147. self:bindEvent(app.room , "cmd_0x8110_Resp", handler(self , self.cmd_0x8110_Resp))
  2148. self:bindEvent(app.room , "cmd_0x8111_Resp", handler(self , self.cmd_0x8111_Resp))
  2149. self:bindEvent(app.room , "cmd_0x8112_Resp", handler(self , self.cmd_0x8112_Resp))
  2150. self:bindEvent(app.room , "cmd_0x8113_Resp", handler(self , self.cmd_0x8113_Resp))
  2151. self:bindEvent(app.room , "cmd_0x8114_Resp", handler(self , self.cmd_0x8114_Resp))
  2152. end
  2153. ---
  2154. -- 显示抽奖界面
  2155. --
  2156. function RoomView_28:showGameOverAward()
  2157. if not (dd and dd.IGameOverAward) then
  2158. return
  2159. end
  2160. self:runDelay(0.1, function ( )
  2161. -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
  2162. dd.IGameOverAward.showAwardView();
  2163. end)
  2164. end
  2165. return RoomView_28