-- xx : 2018 3 27 -- 跑得快主界面 local PdkDef = require("luaScript.SubGameDefine.PDKDefine") local PdkPlayerNode = require("pk_paodekuai.luaScript.Views.Room.Node.PdkPlayerNode") local PdkCardNode = require("pk_paodekuai.luaScript.Views.Room.Node.PdkCardNode") local PdkRoomViewConfig = require("pk_paodekuai.luaScript.Views.Room.PdkRoomViewConfig") local PdkEffectHelper = require("pk_paodekuai.luaScript.Views.Room.PdkEffectHelper"):new() local ETS = PdkRoomViewConfig.EffectType local PdkSoundHelper = require("pk_paodekuai.luaScript.Views.Room.PdkSoundHelper"):new() local RoomGpsComponent = require("luaScript.Views.Room.RoomGpsComponent") require("luaScript.Views.Room.RoomFunctions") local PdkMessage = require("pk_paodekuai.luaScript.Protocol.PdkMessage") local PdkFunctions = require("pk_paodekuai.luaScript.PdkFunctions") -- 默认选择值 local CENTER_X=640*g_radio_x local CENTER_Y=360*g_radio_y local PdkRoomView = class("PdkRoomView", cc.UIView) function PdkRoomView:ctor(params) PdkRoomView.super.ctor(self) -- 玩家节点 self._playerNodes = {} -- 自己手牌集合 self._selfCards = {} -- 玩家出牌集合 self._showCards = {{},{},{}} -- 点击选择的牌 self._selectCards = {} -- 上一次出牌viewPos self._lastOutPos = 0 -- 上一次出牌类型 self._lastOutType = 0 -- 上一次出牌,用于提示 self._lastCards = {} -- 排序轮次用 self._turnsQueue = {} -- 快速开始界面 self.fastStartRequestView = nil self.ui = loadUI("pk_paodekuai/res/ui/ui_room/ui_pdk_gameview.ui") self:addChild(self.ui) self.panelMenu = self.ui.Items.Layout_Menu self.cardRoot = self.ui.Items.cardRoot self.imgOtherCards = self.ui.Items.ImageView_other self.txtOtherCards = self.ui.Items.Text_otherNum self:showOtherCards(false) loadSpriteFrameFile("pk_paodekuai/res/ui/zy_game/zy_room_add.plist") self:initChatView() self:initUi() self:showMenu(false) self:showTurnBtn(false) self:setRoomInfo(app.room:getRoomInfo()) loadSpriteFrameFile("pk_paodekuai/res/ui/zy_game/zy_pdk_cards.plist") loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/zy_pdk_effect.plist") loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/zy_pdk_effect_bomb.plist") loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/zy_pdk_effect_shunziliandui.plist") loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/zy_pdk_effect_plan.plist") loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/pdk_effect_spring2.plist") loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/pdk_effect_fspring.plist") -- local gameInfo = app.room:getRoomInfo().nGameInfo local data = json.decode(gameInfo) local rule = tonumber(data.specialRule) -- 是否选择三不带全 self.ruleIsNotEnough = true--getNumBand(rule, 0x0008)>0 -- 炸弹可拆 self.ruleIsChaiBomb = getNumBand(rule, 0x0004)>0 -- 是否选择4带3 self.ruleIsFAT = getNumBand(rule, 0x0002)>0 -- 玩法模式 经典 15张 self.ruleType = tonumber(data.gamerule) -- 是否选择扎鸟 self.ruleZhaniao = getNumBand(rule, 0x0001)>0 -- self.functionQueue = require("luaScript.Tools.FunctionQueue"):new() end --[[ GAME_STATE_INIT =0, --//游戏准备状态 GAME_STATE_SEND_HAND_CARD =1, --//发牌 GAME_STATE_OUT_CARD =2, --//打牌 GAME_STATE_ROUND_OVER =3, --//游戏一局结束 GAME_STATE_GAME_OVER =4, --//游戏结束 ]] function PdkRoomView:onEnter() PdkRoomView.super.onEnter() local roomInfo = app.room:getRoomInfo() if roomInfo.nGameStartCount > 0 then setShowCountAll(true) end PokerUtil = require("pk_paodekuai.luaScript.Views.Room.PokerUtil"):new({isChai=self.ruleIsChaiBomb, isFAT=self.ruleIsFAT}) self:bindEvents() self:addTouchesListener() local roomInfo = app.room:getRoomInfo() if roomInfo.recoverItem then local recoverData = roomInfo.recoverItem self:recover(recoverData) else --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0) end -- GPS组件 self:initGpsComponent() local changeDesk = tonumber(loadUserInfo("pdk_setting_bg_idx")) or 3 self:onNormalChangeDesktop({idx=changeDesk}) PdkSoundHelper:playBgMusic() --定时器 local roomInfo = app.room:getRoomInfo() self.ui.Items.systemTime:setText(string.format("%s", os.date("%y-%m-%d %H:%M:%S", os.time()) ) ) if not self.Time then self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function() local roomInfo = app.room:getRoomInfo() self.ui.Items.systemTime:setText(string.format("%s", os.date("%y-%m-%d %H:%M:%S", os.time()) ) ) end,1.0,false) end if app.room.isReconnection == true then --断线重连 self:isShowFastStartView() end self:checkCanDismiss() -- if self.chatView and PdkFunctions.isForbidProp() then -- self.chatView:hideBtns() -- end -- todo if self.chatView and PdkFunctions.isForbidProp() then self.chatView:hideFace() end if self.chatView and PdkFunctions.isForbidVoice() then self.chatView:hideVoice() end end function PdkRoomView:onExit() self.fastStartRequestView = nil setShowCountAll(false) if self.Time then cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time) self.Time = nil end for _,node in pairs(self._playerNodes) do if node then node:setTurn(false) end end PokerUtil = nil app.room:cleanCache() stopBGMusic() self:cleanCache() end function PdkRoomView:cleanCache() local preload = package.loaded for k, v in pairs(package.loaded or {}) do local res1 = string.find( k, "pk.luaScript") or 0 local res2 = string.find( k, "pk_paodekuai.luaScript") or 0 if res1 > 0 or res2 > 0 then package.loaded[k] = nil end end end function PdkRoomView:addFunction( func ) if self.functionQueue then self.functionQueue:addFunction(func) else func() end end function PdkRoomView:initChatView() local children = self.panelMenu:getParent():getChildByTag(99) if children then children:removeFromParent() end local winSize = cc.Director:getInstance():getWinSize() local designSize = cc.p(1280,720) local radis_x = winSize.width / designSize.x local radis_y = winSize.height / designSize.y local messageList = PdkDef.ChatMessages local headInfos = {} if app.room:getRoomInfo().nMaxPlayCount == 2 then headInfos[1] = {headPos = cc.p((62)/designSize.x * winSize.width, 111/designSize.y * winSize.height), voiceDir = 2} headInfos[2] = {headPos = cc.p((1224-25)/designSize.x * winSize.width, 500/designSize.y * winSize.height), voiceDir = 1} elseif app.room:getRoomInfo().nMaxPlayCount == 3 then headInfos[1] = {headPos = cc.p((62)/designSize.x * winSize.width, 111/designSize.y * winSize.height), voiceDir = 2} headInfos[2] = {headPos = cc.p((1224-25)/designSize.x * winSize.width, 500/designSize.y * winSize.height), voiceDir = 1} headInfos[3] = {headPos = cc.p((62+25)/designSize.x * winSize.width, 500/designSize.y * winSize.height), voiceDir = 2} end local showBtn = true; self.chatView = import("luaScript.Views.Room.ChatView"):new(messageList, headInfos, showBtn) --self.chatView:setLanguage(false) self.chatView:setLocalZOrder(99) self.chatView:setTag(99) self.chatView:setBtnFace(cc.p(0.9411563, 0.3730273),"room_menu3_room_btn_kjy.png") self.chatView:setBtnVoice(cc.p(0.9411563, 0.2163281),"room_menu3_room_btn_yuyin.png") self.panelMenu:getParent():addChild(self.chatView) local pdkHuDongBiaoQingKG = tonumber(loadUserInfo("pdkHuDongBiaoQingKG")) or 1 local pdkPingBiYuYinKG = tonumber(loadUserInfo("pdkPingBiYuYinKG")) or 1 self.chatView:setPropEnabled(pdkHuDongBiaoQingKG == 1) self.chatView:setVoiceEnabled(pdkPingBiYuYinKG == 1) -- if PdkFunctions.isForbidProp() and self.chatView then -- self.chatView:hideBtns() -- self.chatView:setPropEnabled(false) -- self.chatView:setVoiceEnabled(false) -- end -- todo if self.chatView and PdkFunctions.isForbidProp() then self.chatView:hideFace() end if self.chatView and PdkFunctions.isForbidVoice() then self.chatView:hideVoice() end end function PdkRoomView:resetRoundData( ) -- 上一次出牌viewPos self._lastOutPos = 0 -- 上一次出牌类型 self._lastOutType = 0 self._lastCards = {} self.lastOutFlag = -1 -- self:showTurnBtn(false) self:cleanSelfCards() self:cleanShowCards() self:showOtherCards(false) -- 清空玩家时钟 for _,v in pairs(self._playerNodes) do v:setTurn(false) end self._resultMsg = nil self:showRstComfirm(false) end function PdkRoomView:getMode() if app.room:getRoomInfo().nMaxPlayCount == 2 then return 0 elseif app.room:getRoomInfo().nMaxPlayCount == 3 then return 1 end return 1 end function PdkRoomView:initUi() self.ui.Items.btnMenu:registerClick(handler(self , self.onClickButtonMenu)) self.ui.Items.Button_Leave:registerClick(handler(self , self.onClickButtonLeave)) self.ui.Items.Button_Dismiss:registerClick(handler(self , self.onClickButtonDismiss)) self.ui.Items.Button_Set:registerClick(handler(self , self.onClickButtonSetting)) -- self.ui.Items.Button_updateLog:registerClick(handler(self , self.onClickButtonUlog)) self.ui.Items.Button_Ready:registerClick(handler(self , self.onClickButtonReady)) self.ui.Items.Button_Ready.oPos = self.ui.Items.Button_Ready:getPosition() self.ui.Items.Button_invite:registerClick(handler(self , self.onClickButtonInvite)) self.ui.Items.Button_invite.oPos = self.ui.Items.Button_invite:getPosition() self.ui.Items.Layout_7:registerClick(handler(self , self.onClickMenuOut)) self.ui.Items.Button_rule:registerClick(handler(self, self.onClickButtonDetails)) self.ui.Items.Button_Copy:registerClick(handler(self, self.onClickCopy)) -- self.ui.Items.btnDetail:registerClick(handler(self , self.onClickButtonDetails)) self.ui.Items.Button_tip:registerClick(handler(self , self.onClickButtonTip)) self.ui.Items.Button_out:registerClick(handler(self , self.onClickButtonOut)) self.ui.Items.Button_not_out:registerClick(handler(self , self.onClickButtonNotOut)) --邀请俱乐部成员 self.ui.Items.Button_Invite_Club:registerClick(handler(self , self.onClickInviteClub)) -- self.ui.Items.btnShot:registerClick(handler(self , self.onClickButtonShot)) -- 小局结算展示按钮 self._btnComfirm = self.ui.Items.Button_RstComfirm self._btnComfirm:registerClick(handler(self , self.onClickButtonRstComfirm)) self:showRstComfirm(false) self.ui.Items.imgTip:setVisible(false) self.ui.Items.imgTip:setOpacity(0) self.ui.Items.imgTip:setLocalZOrder(200) self.ui.Items.btnShowClub:registerClick(handler(self , self.onClickButtonShowClub)) if app.club_php.clubID and app.club_php.clubID~=0 then self.ui.Items.btnShowClub:setVisible(true) self.ui.Items.Button_Invite_Club:setVisible(true) else self.ui.Items.btnShowClub:setVisible(false) self.ui.Items.Button_Invite_Club:setVisible(false) end local roomInfo = app.room:getRoomInfo() --快速开始按钮 self.ui.Items.Button_fastStart:registerClick(handler(self, self.onClickFastStart)) if roomInfo.nGameStartCount and roomInfo.nGameStartCount <= 0 then --游戏未开始 self:showFastStart(true) else self:showFastStart(false) end --添加玩家节点 local players = app.room:getPlayers() for _, info in pairs(players) do self:addPlayerNode( info ) end -- local myself = app.room:getMyself() if myself.playFlag>=1 then self:showSitdownBtn(false) else self:showSitdownBtn(true) end -- 水印 --[[local gameInfo = roomInfo.nGameInfo local data = json.decode(gameInfo) local logostr = "" if tonumber(data.gamerule) == PdkDef.GameTypes.Normal then logostr = "pdk_img_logo_jingdian.png" else logostr = "pdk_img_logo_swz.png" end self.ui.Items.ImageView_logo:loadTexture(logostr, 1)--]] self:initLogo(1) if not isReviewVersion() and self.gpsComponent then --self.gpsComponent:updateUserInfos(app.room:getUserInfoList()) end self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum() ~= roomInfo.nMaxPlayCount) self:updateButtonPosition() -- if not self.LeavePos then self.LeavePos = self.ui.Items.Button_Leave:getPosition() self.DisbandPos = self.ui.Items.Button_Dismiss:getPosition() self.SettingPos = self.ui.Items.Button_Set:getPosition() self.RulePos = self.ui.Items.Button_rule:getPosition() end -- self:showMenu(false, true) self.ui.Items.Layout_Rule:setVisible(false) self.ui.Items.Layout_7:setVisible(false) self.ui.Items.Text_Rule:setVisible(false) --self.ui.Items.btnMenu:setVisible(false) self.ui.Items.Layout_Menu_1:setVisible(false) self.ui.Items.Layout_Menu_1:setLocalZOrder(199) if roomInfo.nGameStartCount and roomInfo.nGameStartCount > 0 then self.ui.Items.Layout_Rule:setVisible(false) else self.ui.Items.Layout_Rule:setVisible(true) self.ui.Items.Button_rule:setVisible(false) self.ui.Items.Layout_7:setVisible(true) self.ui.Items.Layout_Rule:runAction(cc.Sequence:create( cc.DelayTime:create(2), cc.CallFunc:create(function() self.ui.Items.Layout_Rule:setVisible(false) self.ui.Items.Button_rule:setVisible(true) end))) end local bar = self.ui.Items.ListView:getVBar() -- bar:setPositionX(220) bar:setVisible(false) end function PdkRoomView:onClickInviteClub() playBtnEffect() if app.club_php.clubID and app.club_php.clubID ~= 0 then local roomInfo = app.room:getRoomInfo() local strInvite = PdkRoomViewConfig.getSimpleInviteStr(app.gameId, roomInfo) local view = import("luaScript.Views.Club.ClubInvite"):new(roomInfo.nTableId, strInvite) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end -- 弹出小结算展示按钮 function PdkRoomView:showRstComfirm( is ) self._btnComfirm:setVisible(is==true) end -- 设置房间信息 function PdkRoomView:setRoomInfo( info ) self.ui.Items.roomNum:setString(string.format("房号: %06d", info.nTableId)) self.ui.Items.Label_JuShu:setString(string.format("%02d/%02d局", info.nGameStartCount or 0, info.nTotalGameNum or 0)) --设置规则信息 -- local ruleInfo = json.decode(info.nGameInfo) --房间规则不会中途变化,不用多次更新 if not self.isHadupdateRule then self.isHadupdateRule = true else return end self.ui.Items.ListView:removeAllChildren() self.ui.Items.ListView:setAutoSize(true) local rules = PdkRoomViewConfig.getWanfaTab(info.nGameInfo) for k,v in pairs(rules) do local text = self.ui.Items.Text_Rule:getCopied() text:setVisible(true) text:setString(v) self.ui.Items.ListView:addChild(text) end end --[[更新房间局数信息--]] function PdkRoomView:updateRoomInfo(startCount, totalCount) local roomInfo = app.room:getRoomInfo() roomInfo.nGameStartCount = startCount roomInfo.nTotalGameNum = totalCount end -- 显示操作按钮 function PdkRoomView:showTurnBtn( is, isShowPass ) --获取开房参数 local roomInfo = app.room:getRoomInfo() local gameInfo = roomInfo.nGameInfo or "" local ruleInfo = json.decode(gameInfo) --是否选择了AAA可为炸弹 local isChoiceAAA = false --是否选择了3必带2 local isChoice3dai2 = false if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0080)>0 then isChoiceAAA = true end if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0200)>0 then isChoice3dai2 = true end if is then--倒计时 --最后一手牌 local cards = self:getHandCards() local ttp = PokerUtil:checkType(cards) if (ttp==ETS.THREE_AND_ONE or ttp==ETS.THREE) and (not isChoice3dai2) then--归并3带2 ttp = ETS.THREE_AND_TWO end local function __delay( onEnd ) self.ui:runDelay(1, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end local function __lastOut(onEnd) self:resetSelect() app.room:requestOutCards(cards) if onEnd and type(onEnd)=='function' then onEnd() end end local bombs = PokerUtil:getAllBomb(cards, isChoiceAAA)--有炸弹就不自动打出去 if self._lastOutType==ttp then if ttp==ETS.LIAN_DUI or ttp==ETS.SHUN_ZI then--最后一手牌顺子连对保证牌数相等 if #self._lastCards==#cards then self:addFunction(__lastOut) return end elseif ttp==ETS.AIRPLANE and #bombs <= 0 then--最后一手飞机校验 if #self._lastCards>=#cards then self:addFunction(__lastOut) return end else--防止炸弹拆开成3带2打出去 if self._lastCards~=ETS.BOMB then local bombs = PokerUtil:getAllBomb(cards, isChoiceAAA)--有炸弹就不自动打出去 if #self._lastCards>=#cards and #bombs<=0 then self:addFunction(__lastOut) return end else if #self._lastCards>=#cards then self:addFunction(__lastOut) return end end end elseif self._lastOutType==0 then local can, handCards = self:checkOnceOut() if can then self:addFunction(__delay) self:addFunction(__lastOut) return end end else -- showTooltip("---------------------------------showBtn false") end --是否选择了可不要 if ruleInfo and ruleInfo.allowPass and ruleInfo.allowPass == 1 then --开房参数设置为可不要时,才显示不要按钮 self.ui.Items.Layout_not_out:setVisible(true) self.ui.Items.Button_not_out:setVisible(is==true) if not self.errorOut then--出牌错误的情况下,不改变不出按钮的状态 if isShowPass ~= nil and isShowPass == false then --针对每一局开始发完牌后,庄家不能操作不要按钮 self.ui.Items.Button_not_out:setBright(false) else self.ui.Items.Button_not_out:setBright(true) end else self.errorOut = nil end else self.ui.Items.Layout_not_out:setVisible(false) end --解散按钮状态 if roomInfo.nGameStartCount == 0 and not app.room:isMyself(roomInfo.nRoomOwnedUid) then --未开始,且自己不是房主,则解散按钮不可点击 self.ui.Items.Button_Dismiss:setEnabled(false) else self.ui.Items.Button_Dismiss:setEnabled(true) end self:checkCanDismiss() self.ui.Items.Layout_operating_menus:requestDoLayout() self.ui.Items.Layout_operating_menus:doLayout() self.ui.Items.Button_tip:setVisible(is==true) self.ui.Items.Button_out:setVisible(is==true) -- 自动提示 if self._lastOutType>0 and is then local cards = self._lastCards if cards and #cards>0 then local handCards = self:getHandCards() local result = PokerUtil:getTip(handCards, cards) if result and #result > 0 then --local result2 = PokerUtil:getOnlyTip(handCards, cards) --if result2 then --有且只有一种提示 自动弹出牌 -- self:tipCards(clone(result2)) --end else result = {} end -- 计算不能出的牌 local canotOuts = {} local tp = self._lastOutType if tp == ETS.SINGLE_CARD then local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) for _,v in pairs(bombs) do table.insert(result, 1, v) end canotOuts = PokerUtil:leftSingleCards(handCards, result) elseif tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI or tp == ETS.THREE_AND_TWO or tp == ETS.FOUR_AND_THREE or tp == ETS.AIRPLANE then local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) for _,v in pairs(bombs) do table.insert(result, 1, v) end if tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI then --飞机带的牌可以随意 canotOuts = PokerUtil:leftCardsEx(handCards, result) end elseif tp == ETS.BOMB then end if #canotOuts>0 then self:downCanotOuts(canotOuts, true) end if result and #result > 0 then local result2 = PokerUtil:getOnlyTip(handCards, cards) if result2 then --有且只有一种提示 自动弹出牌 self:tipCards(clone(result2[1].cid and result2 or result2[1])) end end end end end function PdkRoomView:showMenu( is, flag ) -- self.ui.Items.btnMenu.show = is==true -- if flag then -- self.panelMenu:setVisible(is==true) -- return -- end -- if is==true then -- self.panelMenu:setVisible(is==true) -- local actime = 0.08 -- local leavAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.LeavePos), cc.FadeIn:create(actime)) } -- local disbandAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.DisbandPos), cc.FadeIn:create(actime)) } -- local settingAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.SettingPos), cc.FadeIn:create(actime)) } -- local uplogAc = {cc.Spawn:create(cc.MoveTo:create(actime, self.RulePos), cc.FadeIn:create(actime)) } -- self.ui.Items.Button_Leave:runAction(cc.Sequence:create(leavAc)) -- self.ui.Items.Button_Dismiss:runAction(cc.Sequence:create(disbandAc)) -- self.ui.Items.Button_Set:runAction(cc.Sequence:create(settingAc)) -- self.ui.Items.Button_rule:runAction(cc.Sequence:create(uplogAc)) -- else -- local oPos = self.ui.Items.btnMenu:getPosition() -- local actime = 0.08 -- local leavAc = cc.MoveTo:create(actime, oPos) -- self.ui.Items.Button_Leave:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime))) -- self.ui.Items.Button_Dismiss:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime))) -- self.ui.Items.Button_Set:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime))) -- self.ui.Items.Button_rule:runAction(cc.Sequence:create(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)), cc.CallFunc:create(function() self.panelMenu:setVisible(is==true) end))) -- end end -- 是否显示准备按钮 function PdkRoomView:showSitdownBtn( is ) if self._isGameOver and true == self._isGameOver then return end self.ui.Items.Button_Ready:setVisible(is == true) local playerNum = app.room:getPlayerNum() if playerNum ~= app.room:getRoomInfo().nMaxPlayCount then--房间人数未满 self.ui.Items.Button_invite:setVisible(true) -- local invitePos = self.ui.Items.Button_invite:getPosition() -- if is then -- self.ui.Items.Button_invite:runAction(cc.MoveTo:create(0.2, self.ui.Items.Button_invite.oPos)) -- self.ui.Items.Button_Ready:runAction(cc.MoveTo:create(0.2, self.ui.Items.Button_Ready.oPos)) -- else -- if invitePos.x < 10 then -- self.ui.Items.Button_invite:stopAllActions() -- self.ui.Items.Button_invite:setPosition(self.ui.Items.Button_invite.oPos) -- self.ui.Items.Button_invite:runAction(cc.MoveTo:create(0.2, cc.p(10, invitePos.y))) -- end -- end else -- local readyPos = self.ui.Items.Button_Ready:getPosition() -- self.ui.Items.Button_Ready:stopAllActions() -- self.ui.Items.Button_Ready:runAction(cc.MoveTo:create(0.2, cc.p(10, readyPos.y))) end self:updateInviteClubButton() self:updateButtonPosition() end function PdkRoomView:updateButtonPosition() self.ui.Items.Button_Ready:getParent():setVisible(self.ui.Items.Button_Ready:isVisible()) self.ui.Items.Button_invite:getParent():setVisible(self.ui.Items.Button_invite:isVisible()) self.ui.Items.Button_Invite_Club:getParent():setVisible(self.ui.Items.Button_Invite_Club:isVisible()) local roomInfo = app.room.roomInfo or {} local gameId = roomInfo.gameId or app.gameId local gameConfig = getSubGameConfig(gameId) if gameConfig.isOpenClubInvite == false then self.ui.Items.Button_Invite_Club:getParent():setVisible(false) end if isReviewVersion() then self.ui.Items.Button_invite:getParent():setVisible(false) self.ui.Items.Button_Invite_Club:getParent():setVisible(false) end self.ui.Items.Layout_Button:requestDoLayout() self.ui.Items.Layout_Button:doLayout() end function PdkRoomView:onClickButtonShowClub( sender ) playBtnEffect() if IS_USER_NEW_CLUB then openClub() else local clubList = app.club_php.clubList if clubList and table.nums(clubList) > 0 then --房间号 local roomInfo = app.room:getRoomInfo() if roomInfo then --创建房间时传入的桌子下标 local infoT = json.decode(roomInfo.nGameInfo) self.clubView = import("luaScript.Views.Club.ClubTable"):new(clubList[app.club_php.clubID], infoT.tableIdx) self.clubView:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(self.clubView) end else --未找到茶馆列表数据时,请求茶馆列表(可能是断线重连) app.club_php:getClubList(); end end end function PdkRoomView:onClickButtonRstComfirm( sender ) playBtnEffect() -- 小结算 local showFunc = function (msg) for _,node in pairs(self._playerNodes) do node:cleanScore() end if msg then local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkGameResultView"):new(msg) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end showFunc(self._resultMsg) end -- 三人玩打开GPS --[[function PdkRoomView:onClickButtonGps( sender ) playBtnEffect() local isStart = app.room:getRoomInfo().nGameStartCount>0 local exitFunc = function () local isStart = app.room:getRoomInfo().nGameStartCount>0 if isStart then app.room:requestDismissRoom(1)--发起解散 else self.ui:sendMsg(app.room, "callLeaveRequest")--离开房间 end end local dismissFunc = function () app.room:requestDismissRoom(1)--发起解散 end -- self.gpsComponent:showGpsView(app.room:getRoomInfo().nMaxPlayCount, isStart, exitFunc, dismissFunc) local playerlist = app.room:getUserInfoList() if not isReviewVersion() and self.gpsComponent then self.gpsComponent:updateUserInfos(playerlist) self.gpsComponent:showGpsView(3, isStart, exitFunc, exitFunc) end end--]] -- 显示GPS界面 function PdkRoomView:showGpsView() if self.isRecordScene then return end--回放场景直接return logD("PdkRoomView:showGpsView()") playBtnEffect() local isGameStart = app.room:getRoomInfo().nGameStartCount > 0 if self.gpsComponent then self.gpsComponent:showGpsView(isGameStart) end end -- 玩家点击房间详情 function PdkRoomView:onClickButtonDetails( sender ) playBtnEffect() self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible()) self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Rule:isVisible()) self.ui.Items.Button_rule:setVisible(not self.ui.Items.Layout_Rule:isVisible()) -- self:showMenu(false, true) -- local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkGameDetailView"):new(app.room:getRoomInfo().nGameInfo) -- view:setAnchorPoint(cc.p(0.5, 0.5)) -- app:showWaitDialog(view) end -- 一键截屏 function PdkRoomView:onClickButtonShot( sender ) playBtnEffect() showScreenShot() end function PdkRoomView:onClickButtonMenu( sender ) playBtnEffect() --self:showMenu(not sender.show) self.ui.Items.Layout_Menu_1:setVisible(not self.ui.Items.Layout_Menu_1:isVisible()) self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Menu_1:isVisible()) end function PdkRoomView:onClickMenuOut( sender ) -- self:showMenu(false) self.ui.Items.Layout_Rule:setVisible(false) self.ui.Items.Layout_7:setVisible(false) self.ui.Items.Layout_Menu_1:setVisible(false) self.ui.Items.Button_rule:setVisible(true) end function PdkRoomView:onClickButtonLeave( sender ) playBtnEffect() self:showMenu(false, true) self.ui:sendMsg(app.room, "callLeaveRequest") end function PdkRoomView:onClickButtonDismiss( sender ) playBtnEffect() local function onClickOk() self:showMenu(false, true) app.room:requestDismissRoom(1)--发起解散 end local function onClickCancel() end showConfirmDialog("确定要申请解散房间吗?", onClickOk, onClickCancel) end function PdkRoomView:onClickButtonSetting( sender ) playBtnEffect() self:showMenu(false, true) local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkSettingView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function PdkRoomView:onClickButtonUlog( sender ) playBtnEffect() self:showMenu(false, true) local view = import("luaScript.Views.Room.UplogView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function PdkRoomView:onClickButtonTip( sender, tag, tipShow ) playBtnEffect() --获取开房参数 local roomInfo = app.room:getRoomInfo() local gameInfo = roomInfo.nGameInfo or "" local ruleInfo = json.decode(gameInfo) --是否选择了AAA可为炸弹 local isChoiceAAA = false if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0080)>0 then isChoiceAAA = true end --出牌提示 local cards = self._lastCards if cards and #cards>0 then local tp = PokerUtil:checkType(cards) if tp >= ETS.NONE then return nil end -- showTooltip("提示牌型: " .. PokerUtil:getTypeString(tp)) local handCards = self:getHandCards() if #handCards<=0 then return false end if tp == ETS.SINGLE_CARD then if sender._tipCards and #sender._tipCards>0 then local tmp = sender._tipCards[#sender._tipCards] if tmp[1] and type(tmp[1])=='table' then self:tipCards(clone(tmp)) else self:tipCards({clone(tmp)}) end table.remove(sender._tipCards, #sender._tipCards) if #sender._tipCards <= 0 then sender._tipCards = nil end else local result = PokerUtil:getTip(handCards, cards) if result and #result > 0 then else result = {} end -- 判断下家是否报单 local node = self:getPlayerNodeVpos(2) if node then if node:isAlarm() then local max = result[1] for _,v in ipairs(result) do if v.val > max.val then max = v end end result = {max} end end local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) local cds = {} for _,v in pairs(bombs) do table.insert(result, 1, v) end if #result <= 0 then return end sender._tipCards = clone(result) local tmp = sender._tipCards[#sender._tipCards] if tag then if #result>=1 then if tmp[1] and type(tmp[1])=='table' then self:tipCards(clone(tmp)) else self:tipCards({clone(tmp)}) end table.remove(sender._tipCards, #sender._tipCards) end else if tmp[1] and type(tmp[1])=='table' then self:tipCards(clone(tmp)) else self:tipCards({clone(tmp)}) end table.remove(sender._tipCards, #sender._tipCards) end end elseif tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI or tp == ETS.THREE_AND_TWO or tp == ETS.FOUR_AND_THREE or tp == ETS.AIRPLANE then if sender._tipCards and #sender._tipCards>0 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) if #sender._tipCards <= 0 then sender._tipCards = nil end else local result = PokerUtil:getTip(handCards, cards) if result and #result > 0 then else result = {} end local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) for _,v in pairs(bombs) do table.insert(result, 1, v) end if #result <= 0 then return end sender._tipCards = clone(result) if tag then if #result >= 1 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end else self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end end elseif tp == ETS.BOMB then if sender._tipCards and #sender._tipCards>0 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) if #sender._tipCards <= 0 then sender._tipCards = nil end else local result = PokerUtil:getTip(handCards, cards) if result and #result > 0 then else return end sender._tipCards = clone(result) if tag then if #result >= 1 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end else self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end end else return nil end else--没有牌,第一手提示 local handCards = self:getHandCards() if sender._tipCards and #sender._tipCards>0 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) if #sender._tipCards <= 0 then sender._tipCards = nil end else local result = PokerUtil:getFirstTip(handCards) if result and #result > 0 then else return end sender._tipCards = clone(result) self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end end end -- 变暗不能出的牌 function PdkRoomView:downCanotOuts(canotOuts, isTouch) for _,v in pairs(canotOuts) do local node = self:getCardNode(v) if node then node:setNormal() node:setNormalColor() node:setNoTouch(isTouch) end end local tmp = {} for _,v in pairs(self._selectCards) do if v:isDown() then table.insert(tmp, v) end end self._selectCards = tmp end --出牌 function PdkRoomView:onClickButtonOut( sender ) playBtnEffect() local cards = self:getSelected() if #cards <= 0 then return showTooltip("请选择要出的牌") else local isThreeA = false local tp = PokerUtil:checkType(cards) local gameInfo = app.room:getRoomInfo().nGameInfo or "" local ruleInfo = json.decode(gameInfo) --是否选择了AAA为炸弹 if ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0080) > 0 then if PokerUtil:isAAA(cards) then tp = ETS.BOMB isThreeA = true end end if tp >=100 then return showTooltip("选择的牌型错误") end if self._lastCards and #self._lastCards>0 then self._lastOutType = PokerUtil:checkType(self._lastCards) end --检测炸弹是否可拆(不可拆要做检测) if not self.ruleIsChaiBomb then if PokerUtil:isChaiBombs(self:getHandCards(), cards) then return showTooltip("炸弹不可拆开") end end if not isThreeA and (tp == ETS.THREE_AND_ONE or tp == ETS.THREE) then--归并三带二 tp = ETS.THREE_AND_TWO end if self._lastOutType==tp or self._lastOutType==0 or tp==ETS.BOMB then -- 检测下家是否报单 --获取自己的座位数据 local myself = app.room:getMyself() local pdata = app.room:getPlayerVpos(myself.viewPos) logD("PdkRoomView:onClickButtonOut pdata = "..table.tostring(pdata)) local node = self:getPlayerNode(pdata.userId) local isAlarm = node:isAlarm() if isAlarm and #cards==1 and tp==ETS.SINGLE_CARD then -- 判断是否是最大单张 if PokerUtil:isMaxCard(self:getHandCards(), cards[1]) then app.room:requestOutCards(cards) else return showTooltip("报单必须出最大牌") end else if self._lastOutType==ETS.SHUN_ZI and tp==ETS.SHUN_ZI and #self._lastCards~=#cards then--限制顺子牌张数 return showTooltip("顺子牌张数错误") end -- 判断顺子的大小 if self._lastCards==ETS.SHUN_ZI then pokerSortPdkCards(cards) local _, minVal = pokerParse(self._lastCards[1]) if cards[1].val <= minVal then return showTooltip("出牌选择错误") end end app.room:requestOutCards(cards) end else return showTooltip("选择的牌型错误") end end end function PdkRoomView:onClickButtonNotOut( sender ) local cards = {} app.room:requestOutCards(cards) end function PdkRoomView:onClickButtonReady( sender ) playBtnEffect() self.ui:sendMsg(app.room, "callReadyRequestPdk") end function PdkRoomView:getInviteData() local strNames = "" local index = 0 local num = app.room:getPlayerNum() for k,v in pairs(app.room:getPlayers()) do index = index + 1 local name = getSubStringNickname(v.nickname) strNames = strNames..name if index < num then strNames = strNames.."," end end local roomInfo = app.room:getRoomInfo() local invitePtr = PdkRoomViewConfig.InviteConfig[roomInfo.nMaxPlayCount][num]--几缺几 local strGameMode = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo) local strGameNum = string.format("%s局", roomInfo.nTotalGameNum) local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames) print("pdk_invite : ",desc) local title = string.format("经典跑得快 房号[%s] %s", roomInfo.nTableId, invitePtr ) if app.club_php.clubID and app.club_php.clubID~=0 then title = string.format("%s %sID[%d]", title,(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME), tonumber(app.club_php.clubID)) end print("pdk_invite : ", title) return title,desc end --邀请好友 function PdkRoomView:onClickButtonInvite( sender ) playBtnEffect() --[[local strNames = "" local index = 0 local num = app.room:getPlayerNum() for k,v in pairs(app.room:getPlayers()) do index = index + 1 local name = getSubStringNickname(v.nickname) strNames = strNames..name if index < num then strNames = strNames.."," end end local roomInfo = app.room:getRoomInfo() local invitePtr = PdkRoomViewConfig.InviteConfig[roomInfo.nMaxPlayCount][num]--几缺几 local strGameMode = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo) local strGameNum = string.format("%s局", roomInfo.nTotalGameNum) local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames) print("pdk_invite : ",desc) local title = string.format("欢乐跑得快 房号[%s] %s", roomInfo.nTableId, invitePtr ) if app.club_php.clubID and app.club_php.clubID~=0 then title = string.format("%s 茶馆ID[%d]", title, tonumber(app.club_php.clubID)) end print("pdk_invite : ", title)--]] local title,desc = self:getInviteData() local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png" --[[ local info = {} info.scene = "talk" info.contentType = "url" info.url = app.config.Setting.appDownloadUrl info.title = title info.description = desc info.image = imagePath info.imageWidth = 100 app.plugin:shareGame(info)--]] local info = {} info.title = title info.description = desc info.copyData={type=2} local view = import("luaScript.Views.Main.ShareView"):new(info) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function PdkRoomView:onClickCopy() playBtnEffect() local title,desc = self:getInviteData() local clubData = "" if app.club_php.clubID and app.club_php.clubID ~= 0 then local clubName = "" local clubList = app.club_php.clubList if clubList and table.nums(clubList) > 0 then clubName = clubList[tonumber(app.club_php.clubID)].clubName; end clubData = string.format((app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME).."名:%s \n", clubName) end local tishi = "复制信息打开游戏将自动入座\n<仅供娱乐,严禁赌博>" copyData = string.format("%s%s\n%s\n%s",clubData,title,desc,tishi) logD(copyData) copyStringToClipboard(copyData) app.plugin:gotoWeiXin() end -- 恢复自己手牌 function PdkRoomView:recoverHandcards(_cards) self:cleanSelfCards() local cards = pokerSortPdkCards(_cards) local pos = 1 local allCount = #cards for i,card in ipairs(cards) do self:sendOneCardNoAct(card.cid, i, pos, i==allCount, allCount) end self:resetCardsPos() end function PdkRoomView:onPdkResponseGameRecover( data ) local roomInfo = app.room:getRoomInfo() if roomInfo.recoverItem then local recoverData = roomInfo.recoverItem self:recover(recoverData) self._passGameResult = nil end end function PdkRoomView:updateInviteClubButton() if app.club_php.clubID and app.club_php.clubID~=0 then local roomInfo = app.room:getRoomInfo() if roomInfo.nGameStartCount==0 and table.nums(roomInfo.memberList)0 then cardNum = cardNum + 1 end end self:resetRoundData() self:updateInviteClubButton() -- 托管状态 for k,v in pairs(data or {}) do local entrustType = v.isAi;--托管状态 1-托管中 0-未托管 local nUserID = v.userId; local viewId = app.room:getViewIdByUserId(nUserID) local isTuoGuan = entrustType == 1; if app.room:isMyself(nUserID) then if isTuoGuan then self:showTuoGuan(true) self.isTuoGuan = true else self:showTuoGuan(false) self.isTuoGuan = false end end local node = self:getPlayerNodeVpos(viewId) if node then node:setTuoGuan(isTuoGuan) end end if roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_INIT then for _,pdata in ipairs(data) do local player = app.room:getPlayer(pdata.userId) local node = self:getPlayerNode(pdata.userId) if app.room:isMyself(pdata.userId) then self:showTurnBtn(false)--能否出牌 self:showSitdownBtn(pdata.playFlag~=1 and pdata.playFlag~=2) end end --清理离线后的玩家 local players = app.room:getPlayers() for k,v in pairs(self._playerNodes) do local is = false for _,pd in pairs(players) do if pd.userId == tonumber(k) then is = true break end end if not is then self:delPlayerNode(tonumber(k)) end end if app.room.isReconnection == true then self:isShowFastStartView() end self:showFastStart(true) elseif roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_SEND_HAND_CARD or roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_OUT_CARD then -- 清除上一次的提示牌 self.ui.Items.Button_tip._tipCards = nil -- 离开房间不可点击 self.ui.Items.Button_Leave:setEnabled(false) local cp = app.room:getPlayer(curOpUserId) local preCid = app.room:getPreSeatId(cp.seatId) self._lastCards = {} self._lastOutPos = 0 self._lastOutType = 0 local lastOutPlayer = nil while cp.seatId ~= preCid do local d = app.room:getPlayerCid(preCid) if d then local tmp = tmpData[d.userId] if tmp and #tmp.outCards>0 then self._lastCards = tmp.outCards self._lastOutType = PokerUtil:checkType(tmp.outCards) self._lastOutPos = d.viewPos lastOutPlayer = d break end end preCid = app.room:getPreSeatId(preCid) end for _,pdata in ipairs(data) do local player = app.room:getPlayer(pdata.userId) self:clearPosShow(player.viewPos) local node = self:getPlayerNode(pdata.userId) if app.room:isMyself(pdata.userId) then if not connect then self:recoverHandcards(pdata.handCards) end if node then node:showLeft(#pdata.handCards) end else if node then node:showLeft(#pdata.handCards) node:setOffline(pdata.onlineStatus==0) node:setOfflineTime(pdata.onlineStatus==0,pdata.offtime or 0) end end if node then node:setTurn(pdata.isCanOp==1, 0) node:setScore(pdata.totalScore) node:setBanker(pdata.seatId==roomInfo.reBankerId) end local player = app.room:getPlayer(pdata.userId) if #pdata.outCards > 0 then--显示最后一手牌 if app.room:isMyself(pdata.userId) and pdata.isCanOp==1 then else node:setLastOp(PokerUtil:checkType(pdata.outCards), pdata.outCards) end else -- 判断是否一次牌都没出过 if app.room.roomInfo.nMaxPlayCount == outCount or (app.room:isMyself(pdata.userId) and pdata.isCanOp==1) or (pdata.isCanOp==1) then else if pdata.passShow then node:setLastOp(ETS.PASS, {}) end end end if pdata.isCanOp == 1 and cardNum==app.room.roomInfo.nMaxPlayCount then node:cleanLastCards() end end local isShowPass = false --发牌后,还未出牌,判断当前可操作玩家id是否为自己 if app.room:isMyself(roomInfo.curOpUid) then --当前操作玩家操作类型 0-pass 1-可以出牌也可以pass 2-只能出牌 if roomInfo.curOpType == 1 then isShowPass = true end end for _,pdata in ipairs(data) do if roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_SEND_HAND_CARD then--发牌庄家出牌 if app.room:isMyself(pdata.userId) then self:showTurnBtn(pdata.seatId==roomInfo.reBankerId, isShowPass) end local node = self:getPlayerNode(pdata.userId) if node and pdata.seatId==roomInfo.reBankerId then node:setTurn(true, 0) else node:setTurn(false) end else--游戏中途 if app.room:isMyself(pdata.userId) then self:showTurnBtn(pdata.isCanOp==1, isShowPass)--能否出牌 end end end self:showSitdownBtn(false) if self:getMode()==0 then self:showOtherCards(true) end --游戏中不显示2/3人快速开始按钮 self:showFastStart(false) elseif roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_ROUND_OVER then--需要判断是否已经有单局结算页面 self.ui.Items.Button_Leave:setEnabled(false) local response = {} response.gameStartCount = roomInfo.nGameStartCount response.totalGamenum = roomInfo.nTotalGameNum response.bankSeatId = roomInfo.reBankerId local players = {} for i,v in ipairs(data) do local p = {} p.userId = v.userId p.turnScore = v.turnScore p.totalScore = v.totalScore p.bombTimes = v.turnBombTimes--单局炸弹数 p.haveRedTen = v.haveRedTen p.bSpring = v.bSpring p.leftNum = #v.handCards table.insert(players, p) local player = app.room:getPlayer(p.userId) local playerNode = self:getPlayerNode(player.userId) if #v.outCards > 0 and player and playerNode then playerNode:showLastCards(v.outCards, PokerUtil:checkType(v.outCards)) end if #v.handCards>0 and player then self:showLeftCards(player.viewPos, v.handCards or {}) end end response.players = players response.leftCards = {} self:showGameResultRecover({response=response}) --游戏中不显示2/3人快速开始按钮 self:showFastStart(false) if self:getMode()==0 then self:showOtherCards(true) end elseif roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_GAME_OVER then local response = {} local players = {} for i,v in ipairs(data) do local p = {} p.userId = v.userId p.totalScore = v.totalScore --"extString" = "{"bombTimes":0,"loseTimes":0,"maxScore":3,"winTimes":2}" local extString = "" local d = {} d.bombTimes = v.totalBombTimes--总炸弹数 d.loseTimes = v.loseTimes d.maxScore = v.maxScore d.winTimes = v.winTimes p.extString = json.encode(d) table.insert(players, p) end response.players = players self:onResponseGameOver({response=response}) local quickStartInfo = app.room.roomInfo.quickStartInfo if quickStartInfo then if quickStartInfo.tablefaststate == true then local tmpInfo = {} for uid,status in pairs(quickStartInfo.list) do table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status}) end local response = {} response.pList = tmpInfo response.timeOut = app.room.roomInfo.quickStartInfo.time self:onBroadcastFaststart({response=response}) else self:showFastStart(true) end else self:showFastStart(true) end end if roomInfo.bUserDisbandGame == 1 then --房间是否是解散状态 app.room:dispatchEvent({name = "pdkNormalEvent_show_dissmiss_over"}) -- 其他玩家的解散状态 local dismissInfo = {} local list = {} for i,v in ipairs(data) do dismissInfo[v.userId] = v.disbandStatus local l = {} l.nUserId = v.userId l.dismissState = v.disbandStatus table.insert(list, l) end app.room.dismissInfo = dismissInfo local response = {} response.memberList = list response.timeLeft = roomInfo.leftTimeOut response.operateType = 1 self:onDismissResponse({response=response}) end if roomInfo.gameStatus > PdkRoomViewConfig.GameStatus.GAME_STATE_INIT and roomInfo.gameStatus <= PdkRoomViewConfig.GameStatus.GAME_STATE_GAME_OVER then self.ui.Items.Button_invite:setVisible(false) else self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum()~=app.room:getRoomInfo().nMaxPlayCount) end self:updateButtonPosition() ---------------------------------------------------------------------------------------- roomInfo.recoverItem = nil roomInfo.reBankerId = nil end -- 小局结算 function PdkRoomView:showGameResultRecover( data ) -- if self._gameResult then return false end--避免断线重连弹出多个小结算 local msg = data.response local maxCards = 0 for _,v in pairs(msg.players) do local node = self:getPlayerNode(v.userId) v.totalScore = tonumber(v.totalScore) if node then node:setScore(v.totalScore,false) end node:hideLeft() v.leftCards = v.leftCards or {} if #v.leftCards > maxCards then maxCards = #v.leftCards end local pdata = app.room:getPlayer(v.userId) v.unionid = pdata.unionid v.headimgurl = pdata.headimgurl v.gpsInfo = pdata.gpsInfo v.sex = pdata.sex v.openid = pdata.openid v.nickname = pdata.nickname v.areano = pdata.areano end --是不是最后一局 local roomInfo = app.room:getRoomInfo() msg.isLast = roomInfo.nGameStartCount==roomInfo.nTotalGameNum msg.isZhaniao = self.ruleZhaniao msg.ruleString = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo) self._resultMsg = {} self._resultMsg.players = msg.players self._resultMsg.isLast = msg.isLast self._resultMsg.isZhaniao = msg.isZhaniao self._resultMsg.ruleString = msg.ruleString self._resultMsg.gameStartCount = msg.gameStartCount self._resultMsg.totalGamenum = msg.totalGamenum -- -- 小结算 local showFunc = function () for _,v in pairs(self._playerNodes) do v:hideLeft() end self:showRstComfirm(true) end self._gameResult = true --中途恢复直接展示 -- showLeftFunc() showFunc() end function PdkRoomView:bindEvents() self:bindEvent(app.room , "onUserExitResponseRoom" , handler(self , self.onUserExitResponseRoom)) --onDismissResponse self:bindEvent(app.room , "onDismissResponse" , handler(self , self.onDismissResponse)) -- 其他玩家进入房间 self:bindEvent(app.room , "onResponseBroadcastLogin" , handler(self , self.onResponseBroadcastLogin)) -- 玩家离开房间 self:bindEvent(app.room , "onResponseBroadcastLogout" , handler(self , self.onResponseBroadcastLogout)) -- 玩家准备 self:bindEvent(app.room , "onResponseUserReady" , handler(self , self.onResponseUserReady)) -- 游戏开始 self:bindEvent(app.room , "onResponseGameStart" , handler(self , self.onResponseGameStart)) -- 给玩家发牌 self:bindEvent(app.room , "onResponseSendCards" , handler(self , self.onResponseSendCards)) -- 玩家出牌成功 self:bindEvent(app.room , "onResponseOutCards" , handler(self , self.onResponseOutCards)) -- 玩家出牌错误 self:bindEvent(app.room , "onResponseOutCardsErr" , handler(self , self.onResponseOutCardsErr)) -- 单局结算 self:bindEvent(app.room , "onResponseGameResult" , handler(self , self.onResponseGameResult)) -- 总结算 self:bindEvent(app.room , "onResponseGameOver" , handler(self , self.onResponseGameOver)) -- 玩家离线 self:bindEvent(app.room , "onOtherDroppedResponse" , handler(self , self.onOtherDroppedResponse)) -- 游戏设置里更换桌面 self:bindEvent(app.room , "pdkNormalEvent_changeDesktop" , handler(self , self.onNormalChangeDesktop)) -- 服务器通知更新当前玩家分数 self:bindEvent(app.room , "onResponseUpdateScore" , handler(self , self.onResponseUpdateScore)) -- 服务器通知当前玩家轮次 self:bindEvent(app.room , "onResponseUpdateTurns" , handler(self , self.onResponseUpdateTurns)) -- 显示大结算 self:bindEvent(app.room , "pdkNormalEvent_show_game_over" , handler(self , self.onNormalShowGameOver)) -- 断线重连 self:bindEvent(app.room , "onResponseGameRecover" , handler(self , self.onPdkResponseGameRecover)) -- 玩家请求快速开始广播 self:bindEvent(app.room , "onBroadcastFastRequest", handler(self, self.onBroadcastFaststart)) -- 快速开始成功 self:bindEvent(app.room , "onFastStartSucc", handler(self, self.onFastStartSucc)) --监听从后台进入游戏事件 self:bindEvent(app, "applicationWillEnterForeground", handler(self, self.onApplicationWillEnterForeground)) -- 玩家的GPS信息发生变化 self:bindEvent(app.room , "onGpsChangeResponse" , handler(self , self.onGpsChangeResponse)); --托管结果 self:bindEvent(app.room , "onTuoGuanResponse",handler(self , self.onTuoGuanResponse)); end function PdkRoomView:onNormalChangeDesktop( data ) if data.idx >5 and data.idx<1 then return end self.ui.Items.ImageView_bg:loadTexture(string.format("pk_paodekuai/res/ui/zy_game/zy_pdk_gamebg_%d.jpg", data.idx), 0) -- self.ui.Items.ImageView_2:setVisible(data.idx~=3) -- self.ui.Items.ImageView_3:setVisible(data.idx~=3) -- 水印 --[[local gameInfo = app.room:getRoomInfo().nGameInfo local rdata = json.decode(gameInfo) local logostr = "" local logoJingDian = { [1] = "pdk_img_logo_jdhuang.png", [2] = "pdk_img_logo_jdlv.png", [3] = "pdk_img_logo_jdlan.png", [4] = "pdk_img_logo_jdhong.png", } local logoShiWu = { [1] = "pdk_img_logo_15huang.png", [2] = "pdk_img_logo_15lv.png", [3] = "pdk_img_logo_15lan.png", [4] = "pdk_img_logo_15hong.png", } if tonumber(rdata.gamerule) == PdkDef.GameTypes.Normal then logostr = logoJingDian[data.idx]--(data.idx==1 or data.idx==2 ) and "pdk_img_logo_jingdian_3d.png" or "pdk_img_logo_jingdian.png" else logostr = logoShiWu[data.idx]--(data.idx==1 or data.idx==2 ) and "pdk_img_logo_swz_3d.png" or "pdk_img_logo_swz.png" end self.ui.Items.ImageView_logo:loadTexture(logostr, 1)--]] self:initLogo(data.idx) end -- 水印 function PdkRoomView:initLogo(idx) if not (type(getSubGameRoomLogo) == 'function') then--大厅不支持此方法,则隐藏logo self.ui.Items.ImageView_logo:setVisible(false); return end local gameInfo = app.room:getRoomInfo().nGameInfo local rdata = json.decode(gameInfo) local logofile = getSubGameRoomLogo(GAME_IDS.PaoDeKuai,tonumber(rdata.gamerule)) if logofile then self.ui.Items.ImageView_logo:loadTexture(logofile) self.ui.Items.ImageView_logo:setVisible(true); else self.ui.Items.ImageView_logo:setVisible(false); end end -- 服务器通知玩家分数 function PdkRoomView:onResponseUpdateScore( data ) local msg = data.response for _,pdata in ipairs(msg.players) do local node = self:getPlayerNode(pdata.userId) if node then node:setScore(pdata.totalScore) end end end -- 玩家掉线 function PdkRoomView:onOtherDroppedResponse( data ) local msg = data.response local node = self:getPlayerNode(msg.nUserId) local pdata = app.room:getPlayer(msg.nUserId) if node then if msg.nDroppedStatus == 1 then node:setOffline(true) node:setOfflineTime(true,0) pdata.onlineStatus = 0 elseif msg.nDroppedStatus == 0 then node:setOfflineTime(false) node:setOffline(false) pdata.onlineStatus = 1 end end end function PdkRoomView:onUserExitResponseRoom( data ) local function _exit( onEnd ) local response = data.response -- 0: 不退出(回到子游戏), 1: 退出(回到大厅) if not self._isGameOver then if response.logoutFlag == 1 then --app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.PaoDeKuai)) gotoMainView(GAME_IDS.PaoDeKuai) else --app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.PaoDeKuai)) gotoMainView(GAME_IDS.PaoDeKuai) end end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(_exit) end function PdkRoomView:onDismissResponse( data ) local __dis = function (onEnd) local response = data.response app.room:getRoomInfo().nDismissStateTime = response.timeLeft --剩余时间 app.room:getRoomInfo().nDismissToTalTime = app.room:getRoomInfo().nDisbandTimeout or 60 --总的时间 --显示解散(此标志会影响闹钟时间会冻住) app.room:getRoomInfo().nShowDismiss = true if response.operateType == 1 then if response.memberList ~= nil then for k,v in pairs(response.memberList) do if v.dismissState == 1 then --local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkDismissView"):new(v.nUserId) local view = require("luaScript.Views.Room.RoomDismissView"):new(v.nUserId,app.room.roomInfo.memberList,response.timeLeft) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) return end end else --local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkDismissView"):new(response.nUserId) local view = require("luaScript.Views.Room.RoomDismissView"):new(response.nUserId,app.room.roomInfo.memberList,response.timeLeft) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end else local memberStatus={} if response.memberList ~= nil then for k,v in pairs(response.memberList) do table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState}) end else table.insert(memberStatus,{userId = response.nUserId, status = response.operateType}) end app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus}); end end __dis() end -- 其他玩家进入 function PdkRoomView:onResponseBroadcastLogin( data ) self:addPlayerNode(data.pInfo) self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum()~=app.room:getRoomInfo().nMaxPlayCount) self:updateButtonPosition() if not isReviewVersion() and self.gpsComponent then --self.gpsComponent:updateUserInfos(app.room:getUserInfoList()) --self:checkGpsDistance(data.pInfo.userId,true) end local myself = app.room:getMyself() if myself.playFlag>=1 then self:showSitdownBtn(false) else self:showSitdownBtn(true) end self:showFastStart(true) end -- 玩家离开房间 function PdkRoomView:onResponseBroadcastLogout( data ) local function __logout( onEnd ) self:showFastStart(true) self:delPlayerNode(data.userId) local myself = app.room:getMyself() if myself.playFlag>=1 then self:showSitdownBtn(false) else self:showSitdownBtn(true) end --[[local roomInfo = app.room:getRoomInfo() if roomInfo and roomInfo.nGameStartCount == 0 then if not isReviewVersion() and self.gpsComponent then self.gpsComponent:updateUserInfos(app.room:getUserInfoList()) self:checkGpsDistance() end end--]] if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__logout) end -- 玩家准备 function PdkRoomView:onResponseUserReady( data ) local userId = data.userId local node = self:getPlayerNode(userId) if node then node:setReady(true) end if app.room:isMyself(userId) then self:resetRoundData() app.room:addPlayer({playFlag=1, userId=userId}) self:showSitdownBtn(false) end end -- 游戏开始 function PdkRoomView:onResponseGameStart( data ) local function __start( onEnd ) local roomInfo = app.room:getRoomInfo() if roomInfo.nGameStartCount and roomInfo.nGameStartCount == 0 then self:onUpdatePlayerPos(data) end self._gameResult = false self._passGameResult = nil -- 离开房间不可点击 self.ui.Items.Button_Leave:setEnabled(false) -- 取消玩家的准备标志 for _,node in pairs(self._playerNodes) do node:setReady(false) node:cleanScore() app.room:updateFlag( node:getInfo().userId, 2 ) end self:cleanSelfCards() self:cleanShowCards() self.ui.Items.Button_Ready:setVisible(false) self.ui.Items.Button_invite:setVisible(false) self:updateButtonPosition() self:updateInviteClubButton() -- self:showTurnBtn(false) self:updateRoomInfo(roomInfo.nGameStartCount, roomInfo.nTotalGameNum) if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__start) end --更新玩家位置 function PdkRoomView:onUpdatePlayerPos( data ) if not data then return end local response = data.response if not response then return end -- 更新椅子号 for _,v in pairs(response.players) do app.room:addPlayer({userId = v.nUserId, seatId = v.nSeatId}) end -- 更新视图ID for _,v in pairs(response.players) do app.room:addPlayer({userId = v.nUserId, viewPos = app.room:transPos(v.nSeatId)}) end --刷新房间玩家位置 if response then --删除所有玩家节点 for k,v in pairs(response.players) do self:delPlayerNode(v.nUserId) end self:initChatView() --重新添加玩家节点 local players = app.room:getPlayers() for _, info in pairs(players) do self:addPlayerNode( info ) end end end -- 给玩家发牌 function PdkRoomView:onResponseSendCards( data ) self:setRoomInfo(app.room:getRoomInfo()) local function __sendCards( onEnd ) self:resetRoundData() self._gameResult = false self._passGameResult = nil self:sendCards(data.response.cards) if onEnd and type(onEnd) == 'function' then onEnd() end end self:addFunction(__sendCards) local function __delay( onEnd ) self.ui:runDelay(1, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end self:addFunction(__delay) local function __setBanker( onEnd ) local bankerData = app.room:getPlayerCid(data.response.bankerSeat) if bankerData then for _,v in pairs( self._playerNodes ) do v:setBanker(v:getInfo().userId==bankerData.userId) v:setTurn(false) end end if onEnd and type(onEnd) == 'function' then onEnd() end end self:addFunction(__setBanker) local function __showTurn( onEnd ) local bankerData = app.room:getPlayerCid(data.response.bankerSeat) if app.room:isMyself(bankerData.userId) then --发完牌后庄家为自己,则不能操作不要按钮 local isShowPass = false self:showTurnBtn(true,isShowPass) local node = self:getPlayerNodeVpos(1) if node then node:setTurn(true) end else self:showTurnBtn(false) local node = self:getPlayerNode(bankerData.userId) if node then node:setTurn(true) end end if onEnd and type(onEnd) == 'function' then onEnd() end end self:addFunction(__showTurn) local function __showLeft( onEnd ) local left = 16 if self.ruleType==2 then left = 15 end for uid,v in pairs(self._playerNodes) do v:showLeft(left) end if onEnd and type(onEnd) == 'function' then onEnd() end end self:addFunction(__showLeft) end -- 显示轮次时钟 function PdkRoomView:showTurns( viewPos, cleanCards ) for _,node in pairs(self._playerNodes) do local is = node:getInfo().viewPos==viewPos node:setTurn(is) -- if cleanCards==nil then cleanCards = true end if cleanCards then self:clearPosShow(viewPos) end if is then node:cleanPass() end end end -- 广播当前桌子轮次@userId@seatId@outFlag function PdkRoomView:onResponseUpdateTurns( data ) local function __updateTurns( onEnd ) local msg = data.response self.lastOutFlag = msg.outFlag local viewPos = app.room:transPos(msg.seatId) if viewPos == 1 then self:showTurns(viewPos, viewPos==1) else--这个逻辑过了1天god知道是干什么的 local node = self:getPlayerNodeVpos(1) self:showTurns(viewPos, node:isShowPass()==false ) --如果要得起显示对方出的牌 -- if self._lastOutPos == viewPos then --新起一轮 -- self:showTurns(viewPos, false) -- else -- self:showTurns(viewPos, self._lastOutPos ~= viewPos) -- end end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__updateTurns) local function __showOp( onEnd ) local msg = data.response local viewPos = app.room:transPos(msg.seatId) local node = self:getPlayerNode(msg.userId) local delay = 0 if msg.outFlag == 0 then--pass delay = 0.5 local function _op() if viewPos == 1 then self:showPass() self:cleanLastCards(false) else end node:setLastOp(ETS.PASS, {}) self:showTurnBtn(false) end -- self.ui:runDelay(0, _op)--不需要延时,同时显示出来? _op() else--show op local isShowPass = false if viewPos == 1 then--自己能出牌 if msg.opType == 2 then--开启新的一轮 self:cleanLastCards() self.lastOutFlag = -1 end self:clearPosShow(1) --操作类型 0-只能pass 1-可以出牌也可以pass 2-必须出牌 if msg.opType == 1 then isShowPass = true end end self:showTurnBtn( viewPos == 1 , isShowPass) end self.ui:runDelay(delay, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end self:addFunction(__showOp) end -- 清理上一次的出牌 function PdkRoomView:cleanLastCards(isClean) if isClean==nil then isClean = true end -- if self._lastOutPos > 0 then if isClean == true then -- self:clearPosShow(self._lastOutPos) end self._lastCards = {} self._lastOutType = 0 self._lastOutPos = 0 -- end end -- 玩家出牌成功 function PdkRoomView:onResponseOutCards( data ) local function __outCards( onEnd ) local msg = data.response -- 清除上一次的提示牌 self.ui.Items.Button_tip._tipCards = nil local isContinue = #self._lastCards>0 and self._lastOutType>0 local viewPos = app.room:getPlayer(msg.userId).viewPos if self._lastOutPos == viewPos or self._lastOutPos == 0 then --连出两轮 for _,v in pairs(self._playerNodes) do v:cleanPass() end -- 清理上一次的出牌 self:cleanLastCards() isContinue = false end --操作类型,0:pass 1:接牌 if msg.opType == 1 then -- 缓存上次出的牌 self._lastOutPos = viewPos self._lastOutType = msg.cardType self._lastCards = msg.cards self._opType = msg.opType end self:showTurns(0) local playerNode = self:getPlayerNode(msg.userId) playerNode:setLastOp(msg.cardType, msg.cards, isContinue) -- playerNode:showLastCards(msg.cards, msg.cardType, isContinue) PdkSoundHelper:playOut() --玩家剩余牌 local node = self:getPlayerNode(msg.userId) if node then if not node:isAlarm() and msg.leftNum==1 then if self:getMode()==0 then if node:getInfo().viewPos==2 then PdkSoundHelper:single( node:getInfo().sex ) end elseif self:getMode()==1 then if node:getInfo().viewPos==3 then PdkSoundHelper:single( node:getInfo().sex ) end end end node:showLeft(msg.leftNum) end if viewPos == 1 then--判断是否自己出牌 self:showTurnBtn(false) for _,v in pairs(msg.cards) do self:removeCardNode(v) end if msg.leftNum==1 then PdkSoundHelper:single( node:getInfo().sex ) end --还原不可点 self:downCanotOuts(self:getHandCards(), false) self:resetCardsPos() end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__outCards) -- local function __delay( onEnd ) self.ui:runDelay(0.5, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end self:addFunction(__delay) end -- 检测手上牌能否一次打出 function PdkRoomView:checkOnceOut() --获取开房参数 local roomInfo = app.room:getRoomInfo() local gameInfo = roomInfo.nGameInfo local ruleInfo = json.decode(gameInfo) --是否选择了AAA可为炸弹 local isChoiceAAA = false --是否选择了3必带2 local isChoice3dai2 = false if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0080)>0 then isChoiceAAA = true end if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0200)>0 then isChoice3dai2 = true end local handCards = self:getHandCards() local bCan, tp = PokerUtil:checkOnceOut(handCards) if bCan then--检测是否少带接完 if tp==ETS.THREE_AND_ONE or tp==ETS.THREE then --if not self.ruleIsNotEnough then if isChoice3dai2 then return false, {} end elseif tp==ETS.AIRPLANE then local handCardCount = #handCards if isChoice3dai2 and handCardCount%5 ~= 0 then return false, {} end end -- 是否拥有炸弹 local allBombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) bCan = #allBombs<=0 end return bCan, handCards end -- 玩家自己显示要不起 function PdkRoomView:showPass() self.ui.Items.imgTip:setOpacity(0) self.ui.Items.imgTip:setVisible(true) local ac = cc.Sequence:create(cc.FadeIn:create(0.2), cc.DelayTime:create(1), cc.FadeOut:create(0.2)) self.ui.Items.imgTip:runAction(ac) --手牌变暗 local anFunc = function () self:resetSelect() for k,v in pairs(self._selfCards) do v:setNoTouch(true) end end local mingFunc = function () for k,v in pairs(self._selfCards) do v:setNoTouch(false) end end local ac = cc.Sequence:create(cc.CallFunc:create(anFunc), cc.DelayTime:create(0.5), cc.CallFunc:create(mingFunc)) self.cardRoot:runAction(ac) end -- 春天动画 function PdkRoomView:showSpring() local node = PdkEffectHelper:getSpring() local winSize = cc.Director:getInstance():getWinSize() node:setPosition(cc.p(winSize.width / 2, winSize.height / 2)) self:addChild(node) if node.onEnter and type(node.onEnter)=='function' then node:onEnter() PdkSoundHelper:spring() end end -- 反春天动画 function PdkRoomView:showFanSpring() local node = PdkEffectHelper:getFanSpring() if node then node:setPosition(cc.p(640, 360)) self:addChild(node) if node.onEnter and type(node.onEnter)=='function' then node:onEnter() PdkSoundHelper:spring() end end end -- 玩家出牌错误 function PdkRoomView:onResponseOutCardsErr( data ) local msg = data.response if msg.errFlag == 1 and app.room:isMyself(msg.userId) then self.errorOut = true self:showTurnBtn(true) end end -- 游戏单局结算 function PdkRoomView:onResponseGameResult( data ) -- 收到结算有动画,这个时候不让点击手牌 self:setCardsNoTouch() local msg = data.response local maxCards = 0 for _,v in pairs(msg.players) do local pdata = app.room:getPlayer(v.userId) v.unionid = pdata.unionid v.headimgurl = pdata.headimgurl v.gpsInfo = pdata.gpsInfo v.sex = pdata.sex v.openid = pdata.openid v.nickname = pdata.nickname v.areano = pdata.areano end local function __delay( onEnd ) self.ui:runDelay(0.6, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end self:addFunction(__delay) local function __pre( onEnd ) -- app.room:dispatchEvent({name = "pdkNormalEvent_show_dissmiss_over"}) self._gameResult = true for _,v in pairs(msg.players) do local node = self:getPlayerNode(v.userId) --找到本局炸弹得分 local bombScore = 0 if msg.playersBombScore then for i,j in pairs(msg.playersBombScore) do if j.userId and j.userId == v.userId then j.turnBombScore = tonumber(j.turnBombScore) bombScore = j.turnBombScore or 0 end end end if node then node:setScore(v.totalScore, false,v.turnScore-bombScore) node:setTurn(false) end node:hideLeft() v.leftCards = v.leftCards or {} if #v.leftCards > maxCards then maxCards = #v.leftCards end end local isSpring = false local isFanSpring = false for _,v in pairs(msg.players) do local node = self:getPlayerNode(v.userId) self:cleanSelfCards() self:showLeftCards(node:getInfo().viewPos, v.leftCards or {}) if v.bSpring==1 then isSpring = true end if v.bSpring==2 then isFanSpring = true end end local delay = maxCards *0.02+0.5 if isSpring then self.ui:runDelay(0.1, function() self:showSpring() end) elseif isFanSpring then self.ui:runDelay(0.1, function() self:showFanSpring() end) end local function __onEnd() if onEnd and type(onEnd)=='function' then onEnd() end end self.ui:runDelay(delay, __onEnd ) end self:addFunction(__pre) local function __showResult( onEnd ) local msg = data.response --是不是最后一局 local roomInfo = app.room:getRoomInfo() msg.isLast = roomInfo.nGameStartCount>=roomInfo.nTotalGameNum msg.isZhaniao = self.ruleZhaniao msg.ruleString = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo) if not msg.isLast then msg.isLast = msg.stopFlag==8 or msg.stopFlag==9 end self._resultMsg = {} self._resultMsg.players = msg.players self._resultMsg.isLast = msg.isLast self._resultMsg.isZhaniao = msg.isZhaniao self._resultMsg.ruleString = msg.ruleString self._resultMsg.gameStartCount = msg.gameStartCount self._resultMsg.totalGamenum = msg.totalGamenum self._resultMsg.stopFlag = msg.stopFlag for _,v in pairs(self._playerNodes) do v:hideLeft() end self:showRstComfirm(true) if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__showResult) end -- 总结算 function PdkRoomView:onResponseGameOver( data ) setShowCountAll(true) app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE}); local msg = data.response for _,player in ipairs(msg.players) do local pdata = app.room:getPlayer(player.userId) player.unionid = pdata.unionid player.headimgurl = pdata.headimgurl player.gpsInfo = pdata.gpsInfo player.sex = pdata.sex player.openid = pdata.openid player.nickname = pdata.nickname player.areano = pdata.areano app.room:updateFlag( player.userId, 0 ) end local function __over( onEnd ) -- 缓存结算信息 self._isGameOver = true self._gameOverData = msg local roomInfo = app.room:getRoomInfo() self._gameOverData.nShowTableId = roomInfo.nTableId app.room.roomInfo.nShowTableId = roomInfo.nTableId self._gameOverData.startCount = roomInfo.nGameStartCount self._gameOverData.totalCount = roomInfo.nTotalGameNum self._gameOverData.roomRule = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo) self:removeAllTuoGuan() if self._gameResult==false then--已经展示过小结算后解散房间 self:onNormalShowGameOver() end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__over) app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM}) end --[[先显示小局结算,再显示总结算--]] function PdkRoomView:onNormalShowGameOver( data ) self._gameResult = false local showFunc = function (msg) local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkGameOverView"):new(msg) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) stopBGMusic() end if self._isGameOver and self._gameOverData then showFunc(self._gameOverData) end end ---------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------- -- 单局结算显示剩余牌 function PdkRoomView:showLeftCards( pos, cards ) self:showTurnBtn(false) if #cards <=0 then return end self:clearPosShow(pos) if pos==2 then --self:getMode()==1 and local tmp = {} for _,v in ipairs(cards) do table.insert(tmp, 1, v) end cards = tmp end local root = cc.Node:create() local nodes = {} for i,card in ipairs(cards) do local node = self:genCard(card) local pt = cc.p(0, 25) if pos==1 then --self:getMode() == 0 or pt.x = pt.x + (i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2] node:setLocalZOrder(100+i) else if i>=9 then pt.y = pt.y - 80 if pos ~= 2 then pt.x = pt.x + (i-math.floor(i/9)*9)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2] else pt.x = pt.x - (i-math.floor(i/9)*9)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2] node:setLocalZOrder(36-i) end else if pos ~= 2 then pt.x = pt.x + (i-math.floor(i/9)*9-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2] else pt.x = pt.x - (i-math.floor(i/9)*9-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2] node:setLocalZOrder(16-i) end end end node:setScale(PdkRoomViewConfig.CARD_SCALE[2]) node:setPosition(pt) root:addChild(node) node:setVisible(false) table.insert(nodes, node) end local dltWidth = 0 local rpt = clone(PdkRoomViewConfig.SHOW_CARD_POS[self:getMode()][pos]) if pos == 1 then else dltWidth = #cards/2*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2] end root:setPosition(rpt) self.cardRoot:addChild(root) table.insert(self._showCards[pos], root) for i,v in ipairs(nodes) do v:runAction(cc.Sequence:create(cc.DelayTime:create((i-1)*0.02), cc.CallFunc:create(function () v:setVisible(true) end))) end end -- 清除某玩家的出牌 function PdkRoomView:clearPosShow(pos) local pNode = self:getPlayerNodeVpos(pos) if pNode then pNode:cleanLastCards() end end -- 添加玩家节点 function PdkRoomView:addPlayerNode( pInfo ) local node = self._playerNodes[pInfo.userId] if node then return end node = PdkPlayerNode:new() node:setPlayMode(self:getMode()) local gameInfo = app.room:getRoomInfo().nGameInfo local data = json.decode(gameInfo) local rule = tonumber(data.specialRule) node:setGameInfo(gameInfo) node:setMaxPlayerCount(app.room:getRoomInfo().nMaxPlayCount) node:setShowNum(getNumBand(rule, 0x0020)>0)--是否显示牌张数 node:setInfo(pInfo) node:setReady(pInfo.playFlag==1) node:setOffline((pInfo.onlineStatus and pInfo.onlineStatus==0)) node:setOfflineTime((pInfo.onlineStatus and pInfo.onlineStatus==0),pInfo.offtime or 0) node:setHost(pInfo.userId==app.room:getRoomInfo().nRoomOwnedUid) node:setPosition(PdkRoomViewConfig.PLAYER_POS[self:getMode()][pInfo.viewPos]) self._playerNodes[pInfo.userId] = node node:setLocalZOrder(10) self.ui.Items.toolPanel:addChild(node) -- self.panelMenu:getParent():addChild(node) -- 将玩家加入到chatView self.chatView:addPlayer(pInfo.userId) end -- 删除玩家节点 function PdkRoomView:delPlayerNode( uid ) if self._gameResult or self._isGameOver then return end local node = self._playerNodes[uid] if not node then return end node:removeFromParent() self._playerNodes[uid] = nil -- 将玩家从chatView移除 self.chatView:delPlayer(uid) end -- 获取玩家节点 function PdkRoomView:getPlayerNode( uid ) return self._playerNodes[uid] end -- 根据视图获取玩家节点 function PdkRoomView:getPlayerNodeVpos( viewPos ) for _,v in pairs(self._playerNodes) do if v:getInfo().viewPos==viewPos then return v end end return nil end ---------------------------------------------------------------------------- -- 检查拖牌节点 function PdkRoomView:checkTouches( pt ) local rect = nil local node = nil for i,v in ipairs(self._selfCards) do if cc.rectContainsPoint(v:getRect(), pt) then node = v break end end return node end ---------------------------------------------------------------------------- function PdkRoomView:touchBegan( pt ) if self._gameResult then return end self._selectCards = {} local node = self:checkTouches(pt) if node and node:getVal()>0 then self._selectCards[node:getVal()] = node end self:doSelectColor() end ---------------------------------------------------------------------------- function PdkRoomView:touchMoved( pt ) if self._gameResult then return end local node = self:checkTouches(pt) if node and self._selectCards[node:getVal()]==nil then self._selectCards[node:getVal()] = node end self:doSelectColor() end ---------------------------------------------------------------------------- function PdkRoomView:touchEnded( pt ) if self._gameResult then return end self:doSelect() if pt.y > PdkRoomViewConfig.NORMAL_HEIGHT + PdkRoomViewConfig.CARD_HEIGHT/2 and (not self:checkTouches(pt)) then for _,node in pairs(self._selfCards) do if node:isDown() then node:setNormal() end end end end ---------------------------------------------------------------------------- function PdkRoomView:doSelect() local i = 0 for _,node in pairs(self._selectCards) do i = i + 1 if (not tolua.isnull(node)) and node and node.getParent and node:getParent() then if node:isDown() then node:setNormal() else node:setDown() end if i==1 then PdkSoundHelper:selectSnd() end end end end ---------------------------------------------------------------------------- function PdkRoomView:doSelectColor() for _,node in pairs(self._selectCards) do if not tolua.isnull(node) and node and node.getParent and node:getParent() then node:setDownColor() end end end ---------------------------------------------------------------------------- function PdkRoomView:resetSelect() local i = 0 for _,v in pairs(self._selfCards) do i = i + 1 if v:isDown() then v:setNormal() v:setNormalColor() if i==1 then PdkSoundHelper:selectSnd() end end end self._selectCards = {} end function PdkRoomView:setCardsNoTouch() for _,v in pairs(self._selfCards) do v:setNoTouch(true) v:setNormal() v:setNormalColor() end self:resetSelect() end ---------------------------------------------------------------------------- -- 获取选择的牌的集合 function PdkRoomView:getSelected() local sel = {} for _,v in pairs(self._selfCards) do if v:isDown() then table.insert(sel, v:getVal()) end end return sel end -- 添加牌节点监听 function PdkRoomView:addTouchesListener() local function onTouchBegan(touch, event) local locationInNode = self:convertToWorldSpace(touch:getLocation())--触点 self:touchBegan(locationInNode) return true end local function onTouchMoved(touch, event) local locationInNode = touch:getLocation() self:touchMoved(locationInNode) end local function onTouchEnded(touch, event) local locationInNode = touch:getLocation() self:touchEnded(locationInNode) end local listener1 = cc.EventListenerTouchOneByOne:create() listener1:setSwallowTouches(false) listener1:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) listener1:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED ) listener1:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED ) local eventDispatcher = self.cardRoot:getEventDispatcher() eventDispatcher:addEventListenerWithSceneGraphPriority(listener1, self) end -- 发牌 function PdkRoomView:sendCards( cards_ ) local cards = pokerSortPdkCards(cards_) local pos = 1 local CardsCount = #cards for i,card in ipairs(cards) do local ac = cc.Sequence:create(cc.DelayTime:create(i*0.02), cc.CallFunc:create(function () self:sendOneCard(card.cid, i, pos, i==CardsCount, CardsCount) if self:getMode()==0 then if i==CardsCount then self:showOtherCards(true) end end end)) self.cardRoot:runAction(ac) end end -- 发一张牌 function PdkRoomView:sendOneCard( card, i, pos, islast, allCount ) -- local node = self:genCard(card) local node = self:genCard(-1)--back node.cid = card node:setScale(PdkRoomViewConfig.CARD_SCALE[pos])--PdkRoomViewConfig.CARD_SCALE_START node:setLast(islast) local endX = CENTER_X + (allCount-allCount/2+1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[1] local pt = cc.p(0, 0) if pos ~= 1 then pt = clone(PdkRoomViewConfig.PLAYER_POS[1][pos]) else pt.x = CENTER_X local midIdx = allCount/2 if i<=midIdx then--左边 pt.x = pt.x - (midIdx-i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[1] else--右边 pt.x = pt.x + (i-midIdx+1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[1] end pt.x = pt.x - PdkRoomViewConfig.CARD_WIDTH/2*PdkRoomViewConfig.CARD_SCALE[1] pt.y = PdkRoomViewConfig.CARD_POS[1][pos].y end node:setPosition(cc.p(endX, pt.y)) node:setLocalZOrder(i) node:setOpacity(0) self.cardRoot:addChild(node) local ac = nil if pos ~=1 then ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.05, pt), cc.ScaleTo:create(0.7, PdkRoomViewConfig.CARD_SCALE[pos])), cc.CallFunc:create(function () node:removeFromParent() end)) node:runAction(ac) else ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.05, pt), cc.FadeIn:create(0.1)), cc.CallFunc:create(function () table.insert(self._selfCards, node) PdkSoundHelper:playSend() end), cc.DelayTime:create((i)*0.01), cc.CallFunc:create(function() node:setCard(node.cid) end )) node:runAction(ac) end end -- 发一张牌没有动画 function PdkRoomView:sendOneCardNoAct( card, i, pos, islast, allCount ) local node = self:genCard(card) node:setScale(PdkRoomViewConfig.CARD_SCALE[pos]) node:setLast(islast) local pt = cc.p(0, 0) if pos ~= 1 then pt = clone(PdkRoomViewConfig.CARD_POS[self:getMode()][pos]) else local midIdx = math.floor(allCount/2) if i 0x00 and card <= 0x3d then for _,v in pairs(self._selfCards) do if v:getVal()==card then return v end end return nil else return nil end end -- 根据牌ID移除一张手牌,并重新调整手牌位置 function PdkRoomView:removeCardNode( card ) local node = self:getCardNode(card) if not node then return end for i=#self._selfCards,1,-1 do if self._selfCards[i]:getVal()==card then table.remove(self._selfCards, i) break end end node:removeFromParent() --reset pos self:resetCardsPos() end -- 获取当前手牌 function PdkRoomView:getHandCards() local handCards = {} for _,v in pairs(self._selfCards) do table.insert(handCards, v:getVal()) end return handCards end -- 重置手牌位置 function PdkRoomView:resetCardsPos( ) if #self._selfCards<=0 then return end local mode = self:getMode() local pos = 1 local scale = PdkRoomViewConfig.CARD_SCALE[pos] local dtpx = (16 - #self._selfCards)/2*PdkRoomViewConfig.CARD_DLT_WIDTH*scale local allCount = #self._selfCards local midIdx = allCount/2 for i,v in ipairs(self._selfCards) do if v and (not tolua.isnull(v)) then local pt = cc.p(CENTER_X, 0) if i0 then self._selectCards[node:getVal()] = node node:setDown() end end end -- 清除所有牌 function PdkRoomView:cleanSelfCards() for _,v in pairs(self._selfCards) do if v:getParent() then v:removeFromParent() end end self._selfCards = {} end function PdkRoomView:cleanShowCards() for _,v in pairs(self._showCards) do for _,vv in pairs(v) do if vv and vv:getParent() then vv:removeFromParent() end end end self._showCards = {{},{},{}} for _,v in pairs(self._playerNodes) do if v then v:cleanLastCards() end end end -- 二人玩显示另外一组牌 function PdkRoomView:showOtherCards(is) if is then self.imgOtherCards:setVisible(true) local num = 16 if self.ruleType==2 then num = 15 end self.txtOtherCards:setString(string.format("剩余%d张", num)) else self.imgOtherCards:setVisible(false) end end --发起申请 function PdkRoomView:onClickFastStart(sender) playBtnEffect() local request = PdkMessage.FastStartRequest:new() request.result = 1 self.ui:sendMsg(app.room, "requestFastStartGame", request) end --是否显示2/3人快速开始按钮 function PdkRoomView:showFastStart(is) local roomInfo = app.room:getRoomInfo() if roomInfo.gameStatus and roomInfo.gameStatus > PdkRoomViewConfig.GameStatus.GAME_STATE_INIT and roomInfo.gameStatus <= PdkRoomViewConfig.GameStatus.GAME_STATE_GAME_OVER then self.ui.Items.Button_fastStart:setVisible(false) else local playerCount = app.room:getPlayerNum() local gameInfo = json.decode(roomInfo.nGameInfo) if true == is and playerCount < roomInfo.nMaxPlayCount and roomInfo.nGameStartCount <= 0 and gameInfo.playerNum == 2 then self.ui.Items.Button_fastStart:setVisible(playerCount == 2 or playerCount == 3) else self.ui.Items.Button_fastStart:setVisible(false) end end end -- 服务器广播快速开始 function PdkRoomView:onBroadcastFaststart(data) local response = data.response local isRemove = false if response.nUserId and response.nStatus then if response.nStatus == 3 or response.nStatus > 4 then isRemove = true end end if not isRemove then for _,v in ipairs(response.pList) do if v.nStatus == 3 or v.nStatus > 4 then isRemove = true end end end if response.timeOut <=0 then isRemove = true end logD("PdkRoomView:onBroadcastFaststart isRemove:"..table.tostring(isRemove)..";self.fastStartRequestView = "..table.tostring(self.fastStartRequestView)) if self.fastStartRequestView == nil then if isRemove then return "" end local requesterId = 0 for _,v in ipairs(response.pList) do if v.nStatus == 1 then requesterId = v.nUserId end end if requesterId <= 0 then return "" end local view = import("pk_paodekuai.luaScript.Views.Room.PdkRequestStartView"):new(requesterId) view:setAnchorPoint(cc.p(0.5, 0.5)) view:showItems(response) app:showWaitDialog(view) self.fastStartRequestView = view else if isRemove then local userInfo = app.room.roomInfo.memberList[response.nUserId] self.fastStartRequestView:removeFromParent() self.fastStartRequestView = nil if userInfo then local u = json.decode(userInfo.userInfo) local txt = string.format("玩家【%s】拒绝立即开局", u.nickname) showTooltip(txt) end app.room.roomInfo.quickStartInfo = nil self:showFastStart(true) else self.fastStartRequestView:updateView(response) end end end function PdkRoomView:onFastStartSucc(data) if self.fastStartRequestView then self.fastStartRequestView:removeFromParent() self.fastStartRequestView = nil end self:showFastStart(false) --self.playerView:setPlayerVisible(false) --self:updateRoomBaseData() --刷新房间玩家位置 if data.response then --删除所有玩家节点 for k,v in pairs(data.response.pList) do self:delPlayerNode(v.nUserId) end self:initChatView() --重新添加玩家节点 local players = app.room:getPlayers() for _, info in pairs(players) do self:addPlayerNode( info ) end end end --是否显示快速开始页面 function PdkRoomView:isShowFastStartView() --快速开始数据 local roomInfo = app.room:getRoomInfo() if roomInfo then local fastData = {} fastData.response = {} fastData.response.nStatus = roomInfo.userFastStartStatus fastData.response.timeOut = roomInfo.fastStartTimeout fastData.response.pList = {} if roomInfo.fastStartPlayersStatus then for k,v in pairs(roomInfo.fastStartPlayersStatus) do local playerList = {} if v.fastStartStatus and v.fastStartStatus == 1 then --玩家发起申请 fastData.response.nUserId = v.userId end playerList.nStatus = v.fastStartStatus playerList.nUserId = v.userId table.insert(fastData.response.pList, playerList) end end logD("PdkRoomView:isShowFastStartView roomInfo = "..table.tostring(roomInfo)) logD("PdkRoomView:isShowFastStartView fastData = "..table.tostring(fastData)) self:onBroadcastFaststart(fastData) end end function PdkRoomView:onApplicationWillEnterForeground() --从后台返回游戏,但未重连,此时数据未改变 if app.room:getRoomInfo().nGameStartCount and app.room:getRoomInfo().nGameStartCount <= 0 then --从后台返回游戏时,如果已经开始游戏,则不处理快速开始view self:isShowFastStartView() end end -- 检测玩家与其他玩家之间的距离 -- 如果不传参数,则检测所有玩家相互之间的距离 --[[function PdkRoomView:checkGpsDistance(curUserId,isOpenGpsView) if self.gpsComponent then self.gpsComponent:updateUserInfos(app.room:getUserInfoList()) end if self.gpsComponent then local isDanger = self.gpsComponent:checkGpsDistance(curUserId) if isDanger and isOpenGpsView then self:onClickButtonGps() showTooltip("玩家距离过近或者未开启GPS!") end end end--]] -- 服务器广播玩家数据发生变化 function PdkRoomView:onGpsChangeResponse(data) logD("PdkRoomView:onGpsChangeResponse()") if not data or not data.nUserId then return end local roomInfo = app.room:getRoomInfo() local nUserId = data.nUserId logD("PdkRoomView:onGpsChangeResponse()", tostring(nUserId)) --self:checkGpsDistance(nUserId,roomInfo.nGameStartCount==0) end function PdkRoomView:initGpsComponent() if self.isRecordScene then return end--回放场景直接return local versionCode = getAppVersionCode() versionCode = tonumber(versionCode) or 0 logD("PdkRoomView:initGpsComponent() versionCode = ", versionCode) if isReviewVersion() then self.ui.Items.btnGps:setVisible(false) return end local function exitRoomCallback() local isGameStart = app.room:getRoomInfo().nGameStartCount > 0 if isGameStart then app.room:requestDismissRoom(1) else self.ui:sendMsg(app.room, "callLeaveRequest"); end end -- 创建 gps 组件 --self.gpsComponent = RoomGpsComponent:new(self.ui.Items.btnGps) self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(3,self.ui.Items.btnGps,exitRoomCallback,exitRoomCallback) self.gpsComponent:setLocalZOrder(100) self:addChild(self.gpsComponent) -- GPS 按钮 self.ui.Items.btnGps:registerClick(handler(self , self.showGpsView)) -- 我的GPS数据发生变化时检测是否需要通知服务器 --self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate)) --self.isInitCheckGps = false -- 进入时检测一遍我的GPS数据是否需要更新 --self:checkMyGpsNeedUpdate() end -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新 --[[function PdkRoomView:checkMyGpsNeedUpdate(event) logD("PdkRoomView:checkMyGpsNeedUpdate()") if self.isInitCheckGps and not event then return end self.isInitCheckGps = true local nMyUserId = app.user.loginInfo.uid local myMemberInfo = app.room:getUserInfo(nMyUserId) or nil if myMemberInfo then local userInfo = json.decode(myMemberInfo) if userInfo then local gpsInfo = userInfo.gpsInfo local isNewest = app.user:isGpsInfoNewest(gpsInfo) logD("PdkRoomView:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest)) if not isNewest then app.room:onGpsChangeRequest(); else logD("PdkRoomView:checkMyGpsNeedUpdate() gpsInfo is newest") end else logD("PdkRoomView:checkMyGpsNeedUpdate() userInfo is nil") end else logD("PdkRoomView:checkMyGpsNeedUpdate() myMemberInfo is nil") end end--]] -- 更新所有玩家的信息到GPS组件 function PdkRoomView:updateAllGpsInfo() if self.isRecordScene then return end--回放场景直接return local userInfoList = app.room:getUserInfoList() if self.gpsComponent then self.gpsComponent:updateUserInfos(userInfoList) end end --托管结果协议 function PdkRoomView:onTuoGuanResponse(data) --local function runTuoGuanResponse(onEnd) log("2000000000-PdkRoomView - (onTuoGuanResponse)") local response = data.response local entrustType = response.entrustType;--托管状态 1-托管中 0-未托管 local nUserID = response.nUserId; local viewId = app.room:getViewIdByUserId(nUserID) local isTuoGuan = entrustType == 1; if app.room:isMyself(nUserID) then if isTuoGuan then self:showTuoGuan(true) self.isTuoGuan = true else self:showTuoGuan(false) self.isTuoGuan = false end end local node = self:getPlayerNodeVpos(viewId) if node then node:setTuoGuan(isTuoGuan) end --self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan) --[[if onEnd then onEnd() end end log("2000000000-PdkRoomView - addCallBack(runTuoGuanResponse)") self:addFunction(runTuoGuanResponse)--]] end --显示隐藏托管(界面) function PdkRoomView:showTuoGuan(isShow) if isShow then if not self.tuoguanView then self.tuoguanView = import("pk_paodekuai.luaScript.Views.Room.PdkRoomTuoGuanView"):new() self:addChild(self.tuoguanView) end else if self.tuoguanView and not tolua.isnull(self.tuoguanView) then self.tuoguanView:removeFromParent() self.tuoguanView = nil end end end function PdkRoomView:removeAllTuoGuan() self:showTuoGuan(false) for i, node in pairs(self._playerNodes) do if node then node:setTuoGuan(false) end end end --- -- 检测是否可以解散房间 -- @param -- @return -- function PdkRoomView:checkCanDismiss( ) local onCanDismissCallback = function (info) local nUserId = app.room:getMyUserId() local roomInfo = app.room.roomInfo or {} local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin() if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then canDismiss = false end self:onCanDismissCallback(canDismiss) end if dd.IClub.getCanDismiss then local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback) if canDismiss then onCanDismissCallback({canDismiss = canDismiss}) end end end function PdkRoomView:onCanDismissCallback(canDismiss) if self.ui.Items.Button_Dismiss then self.ui.Items.Button_Dismiss:setEnabled(canDismiss) end end return PdkRoomView