-- 房间设置界面 local PKDef = PKFramework.PKImport("pk_base.luaScript.PKDef") local PKWanFa = PKFramework.ImportWanFa("luaScript.SubGameDefine.PuKe.PKWanFa") local PKRuleView = PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomRuleView") local PKRoomToolView = class("PKRoomToolView", cc.UIView) function PKRoomToolView:ctor(parent) PKRoomToolView.super.ctor(self); self.parent = parent end function PKRoomToolView:onEnter() PKRoomToolView.super.onEnter(self) local ui = loadUI("pk_base/res/ui/ui_fangjian/pk_ui_toolView.ui"); self.ui = ui; self:addChild(ui); if app.club_php.clubID and app.club_php.clubID ~= 0 then if app.room.roomInfo then local clubGameInfo = json.decode(app.room.roomInfo.Datas.strGameInfo) if clubGameInfo.ruleid then setAgainGameBaoJianId(clubGameInfo.ruleid) end end end self:initToolLayer() self:checkCanDismiss() end function PKRoomToolView:initToolLayer() --快速开始 local fastImgMapping = { [4] = "pk_base/res/ui/zy_fangjian/pk_btn/pk_fangjian_fast_23.png", [3] = "pk_base/res/ui/zy_fangjian/pk_btn/pk_fangjian_23_start_btn.png", } self.ui.Items.Button_SpeedStart:loadTextureNormal(fastImgMapping[app.room.roomInfo.nMaxPlayCount] or fastImgMapping[3]) self.ui.Items.Button_SpeedStart:registerClick(handler(self , self.onClickStart)) -- 设置按钮 self.ui.Items.Button_Menu:registerClick(handler(self , self.onClickMenu)) -- 离开按钮 self.ui.Items.Button_Leave:registerClick(function() if app.room.roomInfo.tableOverFlag and app.room.roomInfo.tableOverFlag > TABLE_OVER_FLAG.TABLE_OVER_NORMAL then showTooltip(TABLE_OVER_FLAG_TEXT[app.room.roomInfo.tableOverFlag]); gotoMainView() else playBtnEffect() self:leaveRoomRequet(); end end) -- 解散按钮 self.ui.Items.Button_Dismiss:registerClick(function () playBtnEffect() app.room:requestDismissRoom(1) end) -- 设置按钮 self.ui.Items.Button_Set:registerClick(function () playBtnEffect() local view = import("pk_base.luaScript.Views.Room.PKRoomSettingView"):new(); view:setAnchorPoint(cc.p(0.5, 0.5)); app:showWaitDialog(view); end) -- 截屏按钮 --[[self.ui.Items.Button_jieping:registerClick(function () playBtnEffect() showScreenShot() end)--]] -- 邀请微信好友 self.ui.Items.Button_Invite:registerClick(handler(self , self.onClickFriends)) if app.club_php.clubID and app.club_php.clubID ~= 0 then self.ui.Items.Button_club:setVisible(true) --切换回亲友圈 self.ui.Items.Button_club:registerClick(function () 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.roomInfo; if roomInfo then --创建房间时传入的桌子下标 local strGameInfo = roomInfo.strGameInfo local ttGameInfo = json.decode(strGameInfo) local tableIdx = tonumber(ttGameInfo.tableIdx) log("PKRoomToolView:initToolLayer() clubList = ", clubList); if not clubList[tonumber(app.club_php.clubID)] or table.nums(clubList[tonumber(app.club_php.clubID)]) <= 0 then app.club_php:getClubList(); return end local view = import("luaScript.Views.Club.ClubTable"):new(clubList[tonumber(app.club_php.clubID)], tableIdx) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end else --未找到亲友圈列表数据时,请求亲友圈列表(可能是断线重连) app.club_php:getClubList(); end end end) else self.ui.Items.Button_club:setVisible(false) end -- 准备按钮 self.ui.Items.Button_Ready:registerClick(handler(self , self.onClickReady)) -- 亲友圈邀请 self.ui.Items.Button_ClubInvite:registerClick(handler(self , self.onClickClubInvite)) -- 详情按钮 self.ui.Items.Button_Rule:registerClick(handler(self , self.onClickRule)) --Button_WetChat --[[self.ui.Items.Button_gotoWeiXin:registerClick(function () playBtnEffect() app.plugin:gotoWeiXin() end)--]] self:setMenuVisible(false) if not self.parent.isRecordview then self:initChatView() end end function PKRoomToolView:onClickReady() playBtnEffect() self.ui:sendMsg(app.room, PKDef.PKEvent.CallReadyRequest); end function PKRoomToolView:onClickStart() playBtnEffect() app.room:sendSpeedStartCmd(PKDef.SPEED_START_GAME.START_OPT_TYPE_REQ) end function PKRoomToolView:onClickMenu() playBtnEffect() self.ui.Items.Button_Menu:setBright(not self.ui.Items.Button_Menu:isBright()) self:setMenuVisible(not self.ui.Items.Button_Menu:isBright()) end --设置按钮菜单 function PKRoomToolView:setMenuVisible(bVisible) self.ui.Items.ImageView_menu_bg:setVisible(bVisible) end -- 邀请好友 function PKRoomToolView:onClickFriends() --2-4人的字牌,通用 local ttFour = { [0]= "零缺四", [1]= "一缺三", [2]= "二缺二", [3]= "三缺一", [4]= "满座", } local ttThree = { [0]= "零缺三", [1]= "一缺二", [2]= "二缺一", [3]= "满座", } local ttTwo = { [0]= "零缺二", [1]= "一缺一", [2]= "满座", } local nowPlayer = app.room:getCurMaxPlayer() local maxPlayer = app.room.roomInfo.nMaxPlayCount local strNum = nil if maxPlayer == 2 then strNum = ttTwo[nowPlayer] elseif maxPlayer == 3 then strNum = ttThree[nowPlayer] elseif maxPlayer == 4 then strNum = ttFour[nowPlayer] end --根据游戏类型分享 local title = string.format("板子炮 房号[%s] %s", app.room.roomInfo.nShowTableId, strNum) 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 local strGameNum = string.format("%s局", app.room.roomInfo.nTotalGameNum) local strGameMode = PKWanFa.getRuleInfo() local strNames = "" local index = 0 for k,v in pairs(app.room.roomInfo.memberList) do index = index + 1 local userInfo = json.decode(v.userInfo) local name = getSubStringNickname(userInfo.nickname) strNames = strNames..name if index < maxPlayer then strNames = strNames.."," end end local desc = string.format("%s,%s \n玩家:%s", strGameNum, strGameMode, strNames) local info = {} if not app.room.roomInfo.nShowTableId then showTooltip("房间号不存在") return end info.title = title info.description = desc info.gameMode = strGameMode info.copyData={type=2} if app.club_php.clubID and app.club_php.clubID ~= 0 then info.menuIdxs = {1,2,4,5,6} else info.menuIdxs = {1,2,4,5,6} end print("用户开始分享") local view = import("luaScript.Views.Main.ShareView"):new(info) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function PKRoomToolView:onClickClubInvite() playBtnEffect() if app.club_php.clubID and app.club_php.clubID ~= 0 then local ruleStr = PKWanFa.getInviteInfo() local view = import("luaScript.Views.Club.ClubInvite"):new(app.room.roomInfo.nShowTableId, ruleStr) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end --显示详情 function PKRoomToolView:onClickRule() playBtnEffect() local view = PKRuleView:new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function PKRoomToolView:initChatView() local children = self.ui.Items.Layout_FaceView:getChildByTag(99) if children then children:removeFromParent() end local messageList = PKDef.GameChatTxt local headInfos = {} headInfos[1] = {headPos = cc.pAdd(self.parent.PlayerView.allNodes[1].head:getWorldPosition() , cc.p(0,0)), voiceDir = 1} headInfos[2] = {headPos = cc.pAdd(self.parent.PlayerView.allNodes[2].head:getWorldPosition() , cc.p(0,0)), voiceDir = 2} headInfos[3] = {headPos = cc.pAdd(self.parent.PlayerView.allNodes[3].head:getWorldPosition() , cc.p(0,0)), voiceDir = 2} headInfos[4] = {headPos = cc.pAdd(self.parent.PlayerView.allNodes[4].head:getWorldPosition() , cc.p(0,0)), voiceDir = 2} self.chatView = require("luaScript.Views.Room.ChatView"):new({chatList=messageList},headInfos,true) if self.chatView then self.chatView:setLanguage(false) -- 如果没有语音插件,则不显示语音按钮 if not app.plugin.pluginVoice then logE("ZPRoomView:没有语音插件") --self.messageView.ui.Items.Button_Voice:setVisible(false) end end self.chatView:setTag(99) self.chatView:setBtnFace(cc.p(0.9601563,0.1930273)) self.chatView:setBtnVoice(cc.p(0.9601563,0.0630273)) self.ui.Items.Layout_FaceView:addChild(self.chatView) end function PKRoomToolView:leaveRoomRequet() app.room.roomInfo.bQuitRoom = true; self.ui:sendMsg(app.room, PKDef.PKEvent.CallLeaveRequest); end function PKRoomToolView:showFastStart(is) local roomInfo = app.room.roomInfo local curCount = roomInfo.nGameStartCount or 0 if curCount > 0 then self.ui.Items.Button_SpeedStart:setVisible(false) else local gameInfo=json.decode(roomInfo.strGameInfo) local playnum = gameInfo.playerNum or 0 local isHaveEarlyStart = false if playnum == 5 then isHaveEarlyStart = true playnum = app.room.roomInfo.nMaxPlayCount end local isPeopleEnough = app.room:getCurMaxPlayer() < playnum and app.room:getCurMaxPlayer() > 1 if isHaveEarlyStart and isPeopleEnough then self.ui.Items.Button_SpeedStart:setVisible(true) else self.ui.Items.Button_SpeedStart:setVisible(false) end end end --- -- 检测是否可以解散房间 -- @param -- @return -- function PKRoomToolView: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 PKRoomToolView:onCanDismissCallback(canDismiss) if self.ui.Items.Button_Dismiss then self.ui.Items.Button_Dismiss:setEnabled(canDismiss) end end return PKRoomToolView;