Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

825 lignes
26 KiB

  1. local RoomView = class("luzhouguiRoomView_Coin", require("mj_luzhougui.luaScript.Views.Room.luzhouguiRoomView"))
  2. require("luaScript.Views.Room.RoomFunctions")
  3. local MJRoomToolView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView")
  4. local MJRoomMessageView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomMessageView")
  5. local MJRoomPlayerView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView")
  6. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  7. local MJHandCardView=MJFramework.MJImport("mj_luzhougui.luaScript.Coin.luzhouguiHandCardView_Coin")
  8. local MJRoomXiaoJuView=MJFramework.MJImport("mj_luzhougui.luaScript.Coin.luzhouguiRoomXiaoJuView_Coin")
  9. local MJRoomDaJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView")
  10. local MJRoomDismissView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDismissView")
  11. local MJRoomDirection=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection")
  12. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  13. local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  14. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  15. local MJAnimationCompnent=MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent")
  16. local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
  17. local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
  18. local CoinFunctions = import("luaScript.Views.Coin.Util.CoinFunctions")
  19. local CoinData = import("luaScript.Views.Coin.Data.CoinData")
  20. local CoinGameLogic = import("luaScript.Views.Coin.CoinGameLogic")
  21. function RoomView:ctor()
  22. RoomView.super.ctor(self)
  23. --监听礼券数据
  24. self:bindEvent(app.hall, "couponsAdd" , handler(self, self.changeLiquan))
  25. --获取礼券数量和所需局数
  26. self:bindEvent(app, "getLiquanNumSuccess" , handler(self, self.LiquanNum))
  27. --兑换成功
  28. self:bindEvent(app.phpShop , "exchangeCoinSuccess" , handler(self , self.onDuiHuanCoin))
  29. --开局后后台推送的信息
  30. self:bindEvent(app.room , "onGameInfoChange" , handler(self , self.onGameInfoChange))
  31. -- 托管
  32. self:bindEvent(app.room , MJDefine.MJEvent.HostingRequest, handler(self, self.onHostingRequest))
  33. end
  34. function RoomView:onEnter()
  35. RoomView.super.onEnter(self)
  36. if not tolua.isnull(self.xiangQingView) then
  37. self.xiangQingView:removeFromParent()
  38. self.xiangQingView = nil
  39. end
  40. end
  41. function RoomView:loadUi()
  42. RoomView.super.loadUi(self)
  43. end
  44. function RoomView:initToolView()
  45. RoomView.super.initToolView(self)
  46. end
  47. function RoomView:initChatView()
  48. -- 添加语音相关的界面
  49. self.messageView = require("luaScript.Views.CoinRoom.CoinChatView"):new({ chatList = MJDefine.MJChatTxt, faceList = MJDefine.MJFaceConfig }, self.headInfos, true)
  50. self.coinTool.Items.Layout_1:addChild(self.messageView)
  51. --这里其实没什么用
  52. --self.messageView:setBtnFace(cc.p(1236,348),"room_room_img_face.png")
  53. self.messageView:setBtnVoice(cc.p(1236,257),"room_room_img_voice.png")
  54. --捷语按钮
  55. self.messageView:setBtnFace(cc.p(1236, 237), "mj_btn_face2.png")
  56. end
  57. function RoomView:onGameInfoChange(data)
  58. local gameInfo = json.decode(data.response.Datas.gameInfoChange)
  59. for k,v in pairs(gameInfo) do
  60. if tonumber(k) == tonumber(app.room:getMyUserId()) then
  61. app.user.loginInfo.curJingbiNum = tonumber(v.nTotalMoney)
  62. end
  63. local memberInfo = app.room.roomInfo.memberList[tonumber(k)]
  64. if memberInfo then
  65. memberInfo.nTotalMoney = v.nTotalMoney
  66. self.playerView:updatePlayerInfo(app.room:getViewIdByUserId(memberInfo.nUserId))
  67. end
  68. end
  69. end
  70. function RoomView:initHandCardNodes()
  71. --玩家手牌相关
  72. if MJDefine.MJRoomPlayerSitConfig[app.room.roomInfo.nMaxPlayCount] then
  73. for k,v in pairs(MJDefine.MJRoomPlayerSitConfig[app.room.roomInfo.nMaxPlayCount]) do
  74. if self.playerHandCards[v] then
  75. self.playerHandCards[v]:removeFromParent()
  76. end
  77. self.playerHandCards[v] = MJHandCardView:new(v,self.desktopType)
  78. self.ui.Items.Layout_Player:addChild(self.playerHandCards[v],v)
  79. end
  80. end
  81. end
  82. function RoomView:defaultState()
  83. RoomView.super.defaultState(self)
  84. self.headInfos = {}
  85. for k,v in pairs(self.playerView.allNodes) do
  86. local pos = cc.pAdd(v.player:getPosition(),cc.p(38,66))
  87. table.insert(self.headInfos,{headPos=pos})
  88. end
  89. --初始化金币场Tool
  90. self:initCoinTool()
  91. --礼券数
  92. self.add_coupons = 0
  93. --设置房间等级
  94. self.coinTool.Items.Text_CoinLevel:setText(string.format("%d人%s", app.room.roomInfo.nMaxPlayCount, CoinFunctions.getLevelDisplayText(app.room.roomInfo.serverLevel)))
  95. --设置底分
  96. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  97. self.coinTool.Items.Text_BaseScore:setText(string.format("底分%s", gameInfo.baseScore or 50))
  98. --设置底分
  99. --隐藏桌面信息
  100. --self.ui.Items.ImageView_8:setVisible(false)
  101. self.ui.Items.Layout_GameInfoPanel:setVisible(false)
  102. --隐藏菜单按钮
  103. self.toolView.ui.Items.Button_Menu:setVisible(false)
  104. self.toolView.ui.Items.Layout_Button:setVisible(false)
  105. --隐藏语音按钮
  106. --self.messageView:setBtnVoiceVisible(false)
  107. --隐藏GPS按钮
  108. self.ui.Items.Button_GPS:setVisible(false)
  109. --隐藏快速成局按钮
  110. self.toolView.ui.Items.Button_FastStart:setOpacity(0)
  111. self.toolView.showFastStart = function()
  112. self.toolView.ui.Items.Button_fastStart:setVisible(false)
  113. end
  114. self.toolView.ui.Items.Button_Rule:setVisible(false)
  115. self.toolView.ui.Items.Button_Rule:setOpacity(0)
  116. self.toolView.ui.Items.Layout_Rule:setVisible(false)
  117. self.toolView.ui.Items.Layout_Rule:setOpacity(0)
  118. self:showTuoGuan(false)
  119. --隐藏玩法详情
  120. self:hideXiangQing(false)
  121. --隐藏托管icon
  122. self:hideAllTuoGuanIcon()
  123. --设置菜单的离开按钮状态
  124. self.coinTool.Items.Button_Leave:setEnabled(not isPlaying)
  125. self.coinTool.Items.Button_ChangeTable:setEnabled(not isPlaying)
  126. --记录正在匹配中文字初始位置
  127. if not self.fontPos then
  128. self.fontPos = {}
  129. for i = 1,3 do
  130. local imgNode = string.format("ImageView_font_%d", i)
  131. self.fontPos[i] = self.coinTool.Items[imgNode]:getPosition()
  132. end
  133. end
  134. --默认准备
  135. self:onClickReady()
  136. app.waitDialogManager:closeWaitNetworkDialog()
  137. end
  138. --隐藏托管icon
  139. function RoomView:hideAllTuoGuanIcon()
  140. --隐藏托管
  141. for i = 1, 4 do
  142. if self.playerView["tuoguanicon" .. i] then
  143. self.playerView["tuoguanicon" .. i]:setVisible(false)
  144. end
  145. end
  146. end
  147. --GPS屏蔽
  148. function RoomView:checkGpsDistance()
  149. end
  150. --GPS屏蔽
  151. function RoomView:updateAllGpsInfo()
  152. end
  153. --兑换金币成功
  154. function RoomView:onDuiHuanCoin(eventData)
  155. local myMemberInfo = app.room.roomInfo.memberList[app.room:getMyUserId()]
  156. if myMemberInfo then
  157. myMemberInfo.nTotalMoney = tonumber(eventData.response.gold)
  158. end
  159. if self.playerView then
  160. self.playerView:updatePlayerInfo(app.room:getViewIdByUserId(app.room:getMyUserId()))
  161. end
  162. end
  163. --准备
  164. function RoomView:onClickReady(notPlayEffect)
  165. RoomView.super.onClickReady(self, true)
  166. --准备阶段隐藏 贴鬼碰/杠和自动对齐
  167. self.ui.Items.Layout_WanFa:setVisible(false)
  168. self:playPipeiAction()
  169. end
  170. --礼券数
  171. function RoomView:changeLiquan(eventData)
  172. self.add_coupons = eventData.attr.add_coupons
  173. end
  174. --游戏开始
  175. function RoomView:onGameStartResponse()
  176. RoomView.super.onGameStartResponse(self)
  177. --停止匹配动画
  178. self:stopPipeiAction()
  179. --设置菜单的离开按钮状态
  180. self.coinTool.Items.Button_Leave:setEnabled(false)
  181. self.coinTool.Items.Button_ChangeTable:setEnabled(false)
  182. self:hideDirectionZJ()
  183. end
  184. --隐藏方向盘两旁的剩余张数和局数
  185. function RoomView:hideDirectionZJ()
  186. if self.direcionView.ui and self.direcionView.ui.Items.ImageView_1 then
  187. self.direcionView.ui.Items.ImageView_1:setVisible(false)
  188. self.direcionView.ui.Items.ImageView_2:setVisible(false)
  189. end
  190. if self.direcionView.ui and self.direcionView.ui.Items.ImageView_3 then
  191. self.direcionView.ui.Items.ImageView_3:setVisible(false)
  192. self.direcionView.ui.Items.ImageView_4:setVisible(false)
  193. end
  194. end
  195. --初始化金币场Tool
  196. function RoomView:initCoinTool()
  197. if not tolua.isnull(self.coinTool) then
  198. self.coinTool:removeFromParent()
  199. self.coinTool = nil
  200. end
  201. --加载金币场Tool
  202. self.coinTool = loadUI("mj_luzhougui/res/ui_fangjian/mj_luzhou_coinTool.ui")
  203. self:addChild(self.coinTool)
  204. --设置时间
  205. self.coinTool.Items.Text_SystemTime:runAction(
  206. cc.RepeatForever:create(
  207. cc.Sequence:create(
  208. cc.CallFunc:create(function()
  209. self.coinTool.Items.Text_SystemTime:setText(getTimeString3())
  210. end),
  211. cc.DelayTime:create(1.0)
  212. )
  213. )
  214. )
  215. --获取金币
  216. self.coinTool.Items.Button_HuoQuJinBi:registerClick(handler(self , self.onClickHuoQuJinBi))
  217. --礼券
  218. self.coinTool.Items.Layout_LiQuan_Close:setVisible(false)
  219. self.coinTool.Items.Layout_LiQuan_Close:registerClick(function()
  220. self.coinTool.Items.Layout_liquan:playClip("moveBack")
  221. self.coinTool.Items.Layout_LiQuan_Close:setVisible(false)
  222. end)
  223. self.coinTool.Items.Button_liquan:registerClick(handler(self , self.onClickLiquan))
  224. self.coinTool.Items.Button_liquan:setVisible(false)
  225. self.coinTool.Items.Layout_liquan:setVisible(false)
  226. --设置默认值
  227. --app.php:requestGetLiquan(app.gameId, app.room.roomInfo.serverLevel)
  228. local liquanInfo = {
  229. [11] = { need = 3, prize = 2 },
  230. [12] = { need = 3, prize = 2 },
  231. [21] = { need = 3, prize = 8 },
  232. [22] = { need = 3, prize = 8 },
  233. [31] = { need = 3, prize = 15 },
  234. [32] = { need = 3, prize = 15 },
  235. }
  236. -- --获取礼券所需局数
  237. -- self.leftJushu = self.leftJushu or liquanInfo[tonumber(app.room.roomInfo.serverLevel)].need
  238. -- --奖励礼券数
  239. -- self.getLiquan = self.getLiquan or liquanInfo[tonumber(app.room.roomInfo.serverLevel)].prize
  240. -- --刷新界面
  241. -- self.coinTool.Items.Text_jushu:setText(self.leftJushu)
  242. -- self.coinTool.Items.Text_liquan:setText(self.getLiquan)
  243. --礼券信息收回
  244. --self:onClickLiquan(true)
  245. --隐藏剩余牌提示
  246. self.coinTool.Items.Image_CardNumBg:setVisible(false)
  247. --菜单按钮
  248. self.coinTool.Items.Button_Menu:registerClick(function()
  249. playBtnEffect()
  250. self.coinTool.Items.Layout_Menu:setVisible(not self.coinTool.Items.Layout_Menu:isVisible())
  251. end)
  252. --隐藏菜单界面
  253. self.coinTool.Items.Layout_Menu:setVisible(false)
  254. self.coinTool.Items.Layout_Menu:registerClick(function()
  255. self.coinTool.Items.Layout_Menu:setVisible(not self.coinTool.Items.Layout_Menu:isVisible())
  256. end)
  257. --菜单的设置按钮
  258. self.coinTool.Items.Button_Set:registerClick(function()
  259. self.toolView:onClickSet()
  260. end)
  261. --菜单的离开按钮
  262. self.coinTool.Items.Button_Leave:registerClick(function()
  263. if app.room.roomInfo.nGameStartCount == 0 then
  264. --每次如果有礼券赠送,则会主动请求一次剩余局数和礼券数量
  265. if app.room.roomInfo.isGameOver == true then
  266. runInNextFrame(function()
  267. setShowCountAll(false)
  268. self.toolView:onClickLeave()
  269. self:backToCoinHall()
  270. end)
  271. return
  272. --[[
  273. local function clickOk()
  274. runInNextFrame(function()
  275. setShowCountAll(false)
  276. self.toolView:onClickLeave()
  277. self:backToCoinHall()
  278. end)
  279. end
  280. local function clickCancel()
  281. end
  282. showConfirmDialog(
  283. string.format("再打%d局送%d礼券,是否退出?", tonumber(self.leftJushu or 0), tonumber(self.getLiquan or 0)),
  284. clickOk,
  285. clickCancel
  286. )
  287. ]]
  288. else
  289. setShowCountAll(false)
  290. self.toolView:onClickLeave()
  291. self:backToCoinHall()
  292. end
  293. end
  294. end)
  295. --换桌
  296. self.coinTool.Items.Button_ChangeTable:registerClick(function()
  297. playBtnEffect()
  298. app.room.roomInfo.changeTable = true
  299. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallLeaveRequest)
  300. local gameData = CoinData.getInstance():getGameData() or {}
  301. local ruleList = gameData.ruleList or {}
  302. local gameId = tonumber(app.gameId)
  303. local gameRuleInfo = ruleList[gameId]
  304. if gameRuleInfo then
  305. local serverLevel = app.room.roomInfo.serverLevel
  306. local minServerLevel = 10
  307. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  308. gameInfo.gamerule = gameInfo.gamerule or 1
  309. minServerLevel = minServerLevel + tonumber(gameInfo.gamerule)
  310. local minCoinInfo = gameRuleInfo["" .. minServerLevel]
  311. local curCoinInfo = gameRuleInfo["" .. serverLevel]
  312. if tonumber(app.user.loginInfo.curJingbiNum) < tonumber(minCoinInfo.min_money) or
  313. tonumber(app.user.loginInfo.curJingbiNum) >= tonumber(curCoinInfo.min_money)
  314. then
  315. CoinGameLogic.requestEnterCoinGame(gameId, gameInfo.gamerule, serverLevel, tonumber(curCoinInfo.min_money))
  316. else
  317. CoinGameLogic.requestEnterCoinGame(gameId, gameInfo.gamerule)
  318. end
  319. else
  320. CoinData.getInstance():requestGameServerConfig()
  321. end
  322. end)
  323. --托管按钮
  324. self.coinTool.Items.Button_TuoGuan:registerClick(function()
  325. playBtnEffect()
  326. local request = MJMessage.HostingRequest:new()
  327. request.nUserId = 0
  328. request.status = 1 --1托管 0取消托管
  329. self.ui:sendMsg(app.room, MJDefine.MJEvent.HostingRequest, request)
  330. end)
  331. --取消托管
  332. self.coinTool.Items.Button_guoguan:registerClick(function()
  333. playBtnEffect()
  334. local request = MJMessage.HostingRequest:new()
  335. request.nUserId = 0
  336. request.status = 0 --1托管 0取消托管
  337. --app.room.roomInfo.hosting = 0
  338. self.ui:sendMsg(app.room, MJDefine.MJEvent.HostingRequest, request)
  339. end)
  340. --玩法界面
  341. self:initXiangQing()
  342. end
  343. --获取金币
  344. function RoomView:onClickHuoQuJinBi()
  345. playBtnEffect()
  346. local view = import("luaScript.Views.Main.RechargeView"):new(STORE_TYPE.CHANGE_COIN, false, true)
  347. view:setAnchorPoint(cc.p(0.5, 0.5))
  348. app:showWaitDialog(view)
  349. end
  350. --礼券
  351. function RoomView:onClickLiquan(notPlayEffect)
  352. if notPlayEffect ~= true then
  353. playBtnEffect()
  354. end
  355. if self.coinTool.Items.Layout_liquan:getScaleX() < 1 then
  356. app.php:requestGetLiquan(app.gameId, app.room.roomInfo.serverLevel)
  357. self.coinTool.Items.Layout_liquan:playClip("moveTo")
  358. self.coinTool.Items.Layout_LiQuan_Close:setVisible(true)
  359. else
  360. self.coinTool.Items.Layout_liquan:playClip("moveBack")
  361. self.coinTool.Items.Layout_LiQuan_Close:setVisible(false)
  362. end
  363. end
  364. -- 小局结算
  365. function RoomView:onGameXiaoJuResponse(data)
  366. --设置停留
  367. setShowCountAll(true)
  368. --自动离开
  369. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallLeaveRequest)
  370. --停止方位时间
  371. self.direcionView:stopAllActions()
  372. --self.direcionView:cleanDirectionTimer()
  373. --隐藏托管
  374. self:showTuoGuan(false)
  375. --隐藏托管icon
  376. self:hideAllTuoGuanIcon()
  377. --设置菜单的离开按钮状态
  378. self.coinTool.Items.Button_Leave:setEnabled(true)
  379. self.coinTool.Items.Button_ChangeTable:setEnabled(true)
  380. --隐藏听牌
  381. self:setTingCardViewVisible(false)
  382. RoomView.super.onGameXiaoJuResponse(self, data)
  383. end
  384. --显示隐藏托管
  385. function RoomView:showTuoGuan(vis)
  386. if not tolua.isnull(self.toolView) then
  387. self.toolView:showTuoGuan(vis)
  388. end
  389. self.coinTool.Items.Layout_tuoguan:setVisible(false)
  390. self:setTieGuiAndDisableIt(vis)
  391. -- if vis and true == vis then
  392. -- --是否托管标识
  393. -- --[[self.isTuoGuan = true
  394. -- if self.playerHandCards[MJDefine.MyViewId] then
  395. -- self.playerHandCards[MJDefine.MyViewId]:removeTouchEventOnly()
  396. -- end--]]
  397. -- self.coinTool.Items.Button_TuoGuan:setEnabled(false)
  398. -- else
  399. -- --[[if self.playerHandCards[MJDefine.MyViewId] and self.isTuoGuan then
  400. -- self.isTuoGuan = nil
  401. -- self.playerHandCards[MJDefine.MyViewId]:initTouchEvent()
  402. -- end--]]
  403. -- self.coinTool.Items.Button_TuoGuan:setEnabled(true)
  404. -- end
  405. end
  406. --设置贴鬼碰杠且不可点
  407. function RoomView:setTieGuiAndDisableIt(able)
  408. if able then
  409. if self.ui.Items.CheckBox_TieGui then
  410. self.ui.Items.CheckBox_TieGui:setSelectedState(true)
  411. saveUserInfo("luzhou_mj_tiegui", 1)
  412. MJDefine.isTieGui = true
  413. end
  414. else
  415. end
  416. self.ui.Items.CheckBox_TieGui:setTouchEnabled(not able)
  417. self.ui.Items.CheckBox_Automatic:setTouchEnabled(not able)
  418. end
  419. -- 显示小局结算
  420. function RoomView:showXiaoJuView()
  421. --获取最新礼券
  422. --app.php:requestGetLiquan(app.gameId, app.room.roomInfo.serverLevel)
  423. --停止方位时间
  424. self.direcionView:stopAllActions()
  425. --self.direcionView:cleanDirectionTimer()
  426. --刷新分数
  427. for _,v in pairs(app.room.roomInfo.memberList) do
  428. self.playerView:updatePlayerInfo(app.room:getViewIdByUserId(v.nUserId))
  429. end
  430. --显示小局结算
  431. if self.xiaojuView then
  432. self.xiaojuView:removeFromParent()
  433. end
  434. self.xiaojuView = MJRoomXiaoJuView:new(self.add_coupons)
  435. self:addChild(self.xiaojuView)
  436. end
  437. --隐藏微信
  438. function RoomView:setWetChatVisible(bVisible)
  439. RoomView.super.setWetChatVisible(self, false)
  440. end
  441. --更新牌数
  442. function RoomView:updateGameNums()
  443. if self.coinTool then
  444. self.coinTool.Items.Image_CardNumBg:setVisible(true)
  445. self.coinTool.Items.Text_CardNum:setText(app.room.roomInfo.nLeaveCardNum or 0)
  446. end
  447. end
  448. --初始化法详情
  449. function RoomView:initXiangQing()
  450. local size = self.coinTool.Items.Layout_XQ_content:getContentSize()
  451. self.xiangQingViewShowPos = self.coinTool.Items.Layout_XQ_content:getPosition()
  452. self.xiangQingViewHidePos = cc.vec3(self.xiangQingViewShowPos.x, self.xiangQingViewShowPos.y + size.height, self.xiangQingViewShowPos.z)
  453. self.coinTool.Items.ListView_Xq:getVBar():setVisible(false)
  454. self.coinTool.Items.Button_XiangQing:registerClick(handler(self , self.showXiangQing))
  455. self.coinTool.Items.Layout_XQ_content:registerClick(handler(self , self.hideXiangQing))
  456. self.coinTool.Items.Button_XiangQing_Back:registerClick(handler(self , self.hideXiangQing))
  457. self.coinTool.Items.Button_XiangQing_Close:registerClick(handler(self , self.hideXiangQing))
  458. --self.coinTool.Items.Layout_XiangQing:setVisible(false)
  459. local roomInfo = app.room.roomInfo
  460. local listviewSize = self.coinTool.Items.ListView_Xq:getContentSize()
  461. local wanfaList = {"80颗(5颗起胡)", "12鬼", "报叫", "过张升番可胡", "听牌提示", "一炮多响头家庄"}
  462. table.insert(wanfaList, 1, roomInfo.nMaxPlayCount .. "人")
  463. for i,v in pairs(wanfaList) do
  464. if v ~= "" and v ~= " " then
  465. local layout=cc.Layout:create()
  466. local wanfaText = cc.Text:createNode()
  467. wanfaText:setDefaults()
  468. local config = wanfaText:getFontConfig()
  469. config.fontSize = 24
  470. config.texColor = cc.c4b(255, 192, 101, 255)
  471. wanfaText:setFontConfig(config)
  472. layout:setSize(cc.size(listviewSize.width, 40))
  473. layout:addChild(wanfaText)
  474. wanfaText:setPosition(cc.p(listviewSize.width / 2, 15))
  475. wanfaText:setString(v)
  476. self.coinTool.Items.ListView_Xq:pushBackCustomItem(layout)
  477. end
  478. end
  479. end
  480. --显示法详情
  481. function RoomView:showXiangQing(doAction)
  482. self.coinTool.Items.Button_XiangQing:setVisible(false)
  483. self.coinTool.Items.Layout_XQ_content:stopAllActions()
  484. if doAction then
  485. playBtnEffect()
  486. self.coinTool.Items.Layout_XQ_content:runAction(
  487. cc.Sequence:create(
  488. cc.MoveTo:create(0.35 , self.xiangQingViewShowPos),
  489. cc.CallFunc:create(function()
  490. self.coinTool.Items.ListView_Xq:setVisible(true)
  491. self.coinTool.Items.Button_XiangQing_Close:setVisible(true)
  492. end)
  493. )
  494. )
  495. else
  496. self.coinTool.Items.ListView_Xq:setVisible(true)
  497. self.coinTool.Items.Button_XiangQing_Close:setVisible(true)
  498. self.coinTool.Items.Layout_XQ_content:setPosition(self.xiangQingViewShowPos)
  499. end
  500. end
  501. --隐玩法详情
  502. function RoomView:hideXiangQing(doAction)
  503. self.coinTool.Items.Button_XiangQing_Close:setVisible(false)
  504. self.coinTool.Items.Layout_XQ_content:stopAllActions()
  505. self.coinTool.Items.ListView_Xq:setVisible(false)
  506. if doAction then
  507. playBtnEffect()
  508. self.coinTool.Items.Layout_XQ_content:runAction(
  509. cc.Sequence:create(
  510. cc.MoveTo:create(0.35 , self.xiangQingViewHidePos),
  511. cc.CallFunc:create(function()
  512. self.coinTool.Items.Button_XiangQing:setVisible(true)
  513. end)
  514. )
  515. )
  516. else
  517. self.coinTool.Items.Button_XiangQing:setVisible(true)
  518. self.coinTool.Items.Layout_XQ_content:setPosition(self.xiangQingViewHidePos)
  519. end
  520. end
  521. --托管
  522. function RoomView:onHostingRequest(data)
  523. --RoomView.super.onHostingRequest(self, data)
  524. local response = data.response
  525. if app.room:getMyUserId() == response.nUserId then
  526. if response.status == 1 then --托管状态
  527. self:showTuoGuan(true)
  528. self.coinTool.Items.Button_TuoGuan:setEnabled(false)
  529. if not tolua.isnull(self.firstTingTipsView) then
  530. self.firstTingTipsView:killSelf()
  531. self.firstTingTipsView = nil
  532. end
  533. elseif response.status == 0 then--取消托管状态
  534. self:showTuoGuan(false)
  535. self.coinTool.Items.Button_TuoGuan:setEnabled(true)
  536. end
  537. end
  538. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  539. if self.playerView and viewId then
  540. if data.response.status == 1 then --托管状态
  541. if not self.playerView["tuoguanicon" .. viewId] then
  542. local tuoguanicon = cc.ImageView:createNode()
  543. tuoguanicon:loadTexture("res/ui/zy_jinbichang/coin_game/coin_game_tuoguanicon.png")
  544. --重新计算大小
  545. local headSize = self.playerView.allNodes[viewId].head:getContentSize()
  546. local tuoguanSize = tuoguanicon:getContentSize()
  547. tuoguanicon:setAutoSize(false)
  548. tuoguanicon:setSize(cc.size(headSize.width, headSize.width / tuoguanSize.width * tuoguanSize.height))
  549. --重新位置
  550. local posEx = self.headInfos[viewId].headPos
  551. posEx = cc.p(posEx.x, posEx.y - headSize.height / 2 + tuoguanicon:getSize().height / 2 - 1)
  552. tuoguanicon:setPosition(posEx)
  553. --添加节点
  554. self.playerView:addChild(tuoguanicon)
  555. --保存引用
  556. self.playerView["tuoguanicon" .. viewId] = tuoguanicon
  557. end
  558. self.playerView["tuoguanicon" .. viewId]:setVisible(true)
  559. else --取消托管状态
  560. if self.playerView["tuoguanicon" .. viewId] then
  561. self.playerView["tuoguanicon" .. viewId]:setVisible(false)
  562. end
  563. end
  564. end
  565. end
  566. --重连
  567. function RoomView:onGameReconnection()
  568. RoomView.super.onGameReconnection(self)
  569. local roomInfo = app.room.roomInfo
  570. if roomInfo.nGameStartCount > 0 then
  571. --停止正在匹配中动画
  572. self:stopPipeiAction()
  573. --设置菜单的离开按钮状态
  574. self.coinTool.Items.Button_Leave:setEnabled(false)
  575. self.coinTool.Items.Button_ChangeTable:setEnabled(false)
  576. else
  577. --正在匹配中动画
  578. self.ui.Items.Layout_WanFa:setVisible(false)
  579. local myMemberInfo = roomInfo.memberList[app.room:getMyUserId()]
  580. if myMemberInfo.nPlayerFlag == 1 then
  581. self:playPipeiAction()
  582. end
  583. end
  584. if roomInfo.nStatus ~= MJDefine.GameStatus.GAME_STATUS_ROUND_OVER then
  585. --显示托管
  586. for k,v in pairs(roomInfo.memberList) do
  587. self:onHostingRequest({ response = { nUserId = k, status = (v.hosted or 0) }})
  588. end
  589. else
  590. --隐藏托管
  591. self:showTuoGuan(false)
  592. end
  593. self:hideDirectionZJ()
  594. end
  595. --正在匹配中动画
  596. function RoomView:playPipeiAction()
  597. --先暂停之前的
  598. self:stopPipeiAction()
  599. --显示动画
  600. self.coinTool.Items.Layout_action:setVisible(true)
  601. local index = 1
  602. local function fontAction(idx)
  603. local seq = cc.Sequence:create(
  604. cc.MoveTo:create(0.3,cc.p(self.fontPos[idx].x, self.fontPos[idx].y + 10)),
  605. cc.CallFunc:create(function ()
  606. idx = idx + 1
  607. if idx > 3 then
  608. idx = 1
  609. end
  610. local imgNode = string.format("ImageView_font_%d", idx)
  611. self.coinTool.Items[imgNode]:runAction(fontAction(idx))
  612. end),
  613. cc.MoveTo:create(0.3,cc.p(self.fontPos[idx].x, self.fontPos[idx].y))
  614. )
  615. return seq
  616. end
  617. self.coinTool.Items.ImageView_font_1:runAction(fontAction(index))
  618. end
  619. --停止正在匹配中动画
  620. function RoomView:stopPipeiAction()
  621. self.coinTool.Items.Layout_action:setVisible(false)
  622. for i = 1,3 do
  623. local imgNode = string.format("ImageView_font_%d", i)
  624. self.coinTool.Items[imgNode]:stopAllActions()
  625. --重新设置文字位置,回归原位
  626. self.coinTool.Items[imgNode]:setPosition(self.fontPos[i])
  627. end
  628. end
  629. --获取礼券数量和所需局数返回
  630. function RoomView:LiquanNum(event)
  631. if not event then
  632. return
  633. end
  634. if event.result then
  635. if event.result.need then
  636. --所需局数
  637. self.leftJushu = tonumber(event.result.need)
  638. self.coinTool.Items.Text_jushu:setText(self.leftJushu)
  639. end
  640. if event.result.prize then
  641. --可获得礼券数
  642. self.getLiquan = tonumber(event.result.prize)
  643. self.coinTool.Items.Text_liquan:setText(self.getLiquan)
  644. end
  645. end
  646. end
  647. --- RoomView:backToCoinHall 返回金币场大厅
  648. function RoomView:backToCoinHall()
  649. local data = {
  650. gameId = app.gameId,
  651. isCoin = true
  652. }
  653. app:gotoView(import("luaScript.Views.Main.MainView"):new(data))
  654. end
  655. -- 发牌
  656. function RoomView:onGameSendCardResponse()
  657. RoomView.super.onGameSendCardResponse(self)
  658. local function showHosting( onEnd )
  659. if app.room.roomInfo.hosting then
  660. self:showTuoGuan(app.room.roomInfo.hosting==1)
  661. self.coinTool.Items.Button_TuoGuan:setEnabled(app.room.roomInfo.hosting==0)
  662. end
  663. if onEnd and type(onEnd)=='function' then onEnd() end
  664. end
  665. self:addCallBack(showHosting)
  666. end
  667. -- 出牌成功
  668. function RoomView:onOutCardSuccess(data)
  669. local function runOnOutCardSuccess(onEnd)
  670. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  671. local card= data.response.card
  672. local operates=data.response.operates
  673. local typr = operates.opType
  674. if operates and table.nums(operates)>0 then
  675. self.operates = operates
  676. else
  677. self.operates = {}
  678. end
  679. local function callback()
  680. self.playerHandCards[MJDefine.MyViewId].handOutCard = nil
  681. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  682. if onEnd then
  683. onEnd()
  684. end
  685. end
  686. if self.playerHandCards[viewId] then
  687. if viewId==MJDefine.MyViewId then
  688. local player = app.room.roomInfo.memberList[data.response.nUserId]
  689. self.playerHandCards[viewId]:setTing(false)
  690. if player.isBaoPai==1 and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId then --点击爆牌的时候 前端已经打出牌 要判断上次出牌的人是不是自己 避免重复出牌
  691. self.playerHandCards[viewId]:onOutCard(card,callback)
  692. --音效
  693. local userInfo=app.room:getUserInfoByViewId(viewId)
  694. if userInfo then
  695. MJSound.PlayMJSound(userInfo.sex,card)
  696. end
  697. elseif app.room.roomInfo.hosting and app.room.roomInfo.hosting == 1 then
  698. self.playerHandCards[viewId]:hideOperate()
  699. if self.playerHandCards[viewId].handOutCard then
  700. self.playerHandCards[viewId].handOutCard = nil
  701. callback()
  702. else
  703. self.playerHandCards[viewId]:onOutCard(card,callback)
  704. --音效
  705. local userInfo=app.room:getUserInfoByViewId(viewId)
  706. if userInfo then
  707. MJSound.PlayMJSound(userInfo.sex,card)
  708. end
  709. end
  710. else
  711. --self.playerHandCards[viewId]:onOutCard(card,callback)
  712. callback()
  713. self.playerHandCards[MJDefine.MyViewId]:lockHongZhong(false)
  714. end
  715. else
  716. self.playerHandCards[viewId]:onOutCard(card,callback)
  717. end
  718. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId})
  719. else
  720. callback()
  721. end
  722. app.room.roomInfo.lastOutViewId = viewId
  723. end
  724. self:addCallBack(runOnOutCardSuccess)
  725. end
  726. function RoomView:onWaitOperate(data)
  727. RoomView.super.onWaitOperate(self,data)
  728. --等待操作的UID
  729. local nUserId = data.response.nUserId
  730. local viewId = app.room:getViewIdByUserId(nUserId)
  731. if MJDefine.MyViewId == viewId then--自己预操作了,隐藏操作按钮
  732. self.playerHandCards[viewId]:hideOperate()
  733. end
  734. end
  735. return RoomView