-- 桌子操作按钮Layout local ClubTableNewOperatMenu = class("ClubTableNewOperatMenu" , cc.UIView); --按钮对应编号 -- 1 : 邀请好友 -- 2 : 进入游戏 -- 3 : 解散房间 -- 4 : 踢出房间 -- tableIndex:点击桌子的下标 -- menuIdxs = {1,2,3,4} -- callback : 点击按钮之后的回调 function ClubTableNewOperatMenu:ctor(tableIndex,clubId,showIndex,isgamebol) ClubTableNewOperatMenu.super.ctor(self) self:loadUI() --单个茶馆数据 self.clubInfo = app.club_php.clubList[clubId] self.tableIndex = tableIndex self.showIndex = showIndex --是否直接进入 self.directbol = true if isgamebol == false then self.directbol = isgamebol end self:bindEvent(app, "applicationDidEnterBackground", handler(self, self.onApplicationDidEnterBackground)) if isContinueRoomGamebol() then setisContinueRoomGamebol(false) setIsRoomGamedata(nil) self:onGameEnter() end end function ClubTableNewOperatMenu:loadUI() local ui = loadUI("res/ui/ui_club/clubnew/ui_club_table_operat_menu_new.ui") self.ui = ui self:addChild(ui) end function ClubTableNewOperatMenu:getMenus() -- 1 : 邀请好友 -- 2 : 进入游戏 -- 3 : 解散房间 -- 4 : 踢出房间 local ttMenuIdx = {} if self.clubInfo ~= nil then if table.nums(self.clubInfo.rooms) <= 0 then --此桌子没有开房 if self.clubInfo.role == 2 or self.clubInfo.role == 3 then -- 邀请好友 table.insert(ttMenuIdx, 1) -- 进入游戏 table.insert(ttMenuIdx, 2) end else --当前桌子已有房间信息 if self.clubInfo.role == 2 or self.clubInfo.role == 3 then --2:管理员 3:创始人 -- 邀请好友 table.insert(ttMenuIdx, 1) -- 进入游戏 table.insert(ttMenuIdx, 2) if self.clubInfo.rooms[self.tableIndex] ~= nil then --只有管理员和创始人才有解散房间权限 table.insert(ttMenuIdx, 3) --当前房间是否已开局 local gameStatus = self.clubInfo.rooms[self.tableIndex].status if gameStatus == 1 and table.nums(self.clubInfo.rooms[self.tableIndex].players) > 0 then --未开局且有一个以上用户,没用户,不需要显示踢出按钮 -- 踢出房间 table.insert(ttMenuIdx, 4) end end end end else -- 邀请好友 table.insert(ttMenuIdx, 1) -- 进入游戏 table.insert(ttMenuIdx, 2) end return ttMenuIdx; end function ClubTableNewOperatMenu:onEnter() ClubTableNewOperatMenu.super.onEnter(self) -- 注册点击事件 for i =1,4 do local name = string.format("Button_%d",i) local node = self.ui.Items[name] if node then node:registerClick(function() self:onClickButton(i) end) end end -- 将需要显示的按钮索引标为 true local menus = self:getMenus() if #menus==0 then --如果没有菜单按钮显示直接进入 self.ui:setVisible(false) runInNextFrame(function() if self.directbol == true then self:onClickEnter() end self:removeFromParent() end) return end local tt = {} for k,idx in pairs(menus) do tt[idx] = true end -- 隐藏不相关的按钮 for i = 1,4 do local name = string.format("Layout_Btn_%d", i) local node = self.ui.Items[name] if node then -- 标记为true的显示 -- 否则不显示 if tt[i] then node:setVisible(true) else node:setVisible(false) end end end -- 重新布局 self.ui.Items.Layout_btn_menu:requestDoLayout() self.ui.Items.Layout_btn_menu:doLayout() end --设置管理员 function ClubTableNewOperatMenu:onClickButton(idx) if idx==1 then self:onClickInvite() elseif idx==2 then self:onClickEnter() elseif idx==3 then self:onClickJieSan() elseif idx==4 then self:onClickKick() end if idx~=4 then self:removeFromParent() end end function ClubTableNewOperatMenu:getMoreLayout() return self.ui.Items.Layout_more; end function ClubTableNewOperatMenu:onClickInvite() local gameId = ""; local rooID = "" local contStr = "" local tableIdx = self.tableIndex if self.clubInfo ~= nil then if self.clubInfo.mode == 1 then if table.nums(self.clubInfo.rooms) > 0 and self.clubInfo.rooms[tableIdx] then --获取游戏id(多玩法只能在包间信息里获取游戏id,roomlist里面没有) local baoJianId = self.clubInfo.rooms[tableIdx].baoJianId local baoJian = self.clubInfo.baoJians[baoJianId] if baoJian then gameId = baoJian.gameId end end else if self.clubInfo.settings ~= nil then gameId = self.clubInfo.settings.gameId end end if table.nums(self.clubInfo.rooms) > 0 and self.clubInfo.rooms[tableIdx] then rooID = self.clubInfo.rooms[tableIdx].roomId contStr = "\n复制信息打开游戏将自动入座" end end --游戏名+房间号 local gameName = getSubGameName(gameId) or "" if rooID ~= "" then gameName = string.format("%s[%d]", gameName, rooID) end --桌子号 local tableNum = string.format("%d号桌", tonumber(self.showIndex)) --房间设置的玩法 local setStr = "" local setInfo = self.clubInfo.settings if table.nums(setInfo) > 0 then -- local ruleID = json.encode(setInfo); local tt = getRuleFromString(setInfo.gameId, setInfo.gameNum, setInfo.strGameRule) for k,v in ipairs(tt) do -- 内容 local text = "" for kk, vv in pairs(v.value) do if "" == text then text = vv else text = text .. " " .. vv end end setStr = setStr .. v.name.. ":" .. text .." " end end local _name = (app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME) local copyData = string.format("%s %sID【%s】\n%s\n %s %s%s",self.clubInfo.clubName, _name, self.clubInfo.clubId, gameName, tableNum, setStr, contStr) --需要显示的按钮(1:微信 2:复制 3:茶馆 ) local menuIdxs = {1,4,5,6} local title = string.format("%s名称:%s",_name, self.clubInfo.clubName) local content = string.format("可视化牌桌,不用自己开房就可以玩牌。") local desc = string.format("%sID:%s\n%s",_name, self.clubInfo.clubId,content) local info = {} info.ClubID = self.clubInfo.clubId info.title = title info.description = desc print("用户开始分享") --需要显示的按钮(1:微信 2:复制 3:茶馆 ) if type(menuIdxs) ~= "table" then info.menuIdxs = {1,4,5,6} end if type(copyData) == "string" then info.copyData = copyData else info.copyData = "" end local view = import("luaScript.Views.Main.ShareView"):new(info) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function ClubTableNewOperatMenu:onGameEnter() local rooms = self.clubInfo.rooms local room = rooms[self.tableIndex] local baojian = room and app.club_php:getBaoJian(self.clubInfo.clubId,room.baoJianId) or nil local settings =self.clubInfo.mode==1 and baojian or self.clubInfo.settings local myRoom = app.club_php:getMyInRoom() if room then --如果点击的桌子存在 if myRoom then -- if myRoom == room then local view = app:getCurrentView() -- logD(view.__cname) if view and view.__cname ~= "MainView" then --没有主界面则在房间界面 app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM}) else self:joinClubRoom(self.tableIndex,room.roomId,settings) end return end if self.ui.Items.Button_enter_table then if self.ui.Items.Button_enter_table:isVisible() then local view = app:getCurrentView() if view and view.__cname ~= "MainView" then --没有主界面则在房间界面 app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM}) else self:joinClubRoom(self.tableIndex,room.roomId,settings) end return end end local gameConfig = getSubGameConfig(self.clubInfo.settings.gameId) or {} local num = app.club_php:getPlayerNum(settings) if gameConfig.isSupportWatch or table.nums(room.players) < num then self:joinClubRoom(self.tableIndex,room.roomId,settings) else showTooltip("当前桌子已经坐满!") end else showTooltip("当前桌子已经坐满!") end end function ClubTableNewOperatMenu:onClickEnter() local rooms = self.clubInfo.rooms local room = rooms[self.tableIndex] local baojian = room and app.club_php:getBaoJian(self.clubInfo.clubId,room.baoJianId) or nil local settings =self.clubInfo.mode==1 and baojian or self.clubInfo.settings local myRoom = app.club_php:getMyInRoom() if room then --如果点击的桌子存在 -- if myRoom or self.ui.Items.Button_enter_table:isVisible() then if myRoom then if myRoom == room then local view = app:getCurrentView() -- logD(view.__cname) if view and view.__cname ~= "MainView" then --没有主界面则在房间界面 app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM}) else self:joinClubRoom(self.tableIndex,room.roomId,settings) end else if room.status == 2 then local gameConfig = getSubGameConfig(self.clubInfo.settings.gameId) or {} local num = app.club_php:getPlayerNum(settings) if gameConfig.isSupportWatch or table.nums(room.players) < num then self:joinClubRoom(self.tableIndex,room.roomId,settings) else showTooltip("当前桌子已经坐满!") end else -- showTooltip("您已在其他桌落座,请先退出桌子后再进入!") if getMyGameStatus() == false then local content = "加入新牌桌需退出当前牌桌,是否继续?"; local function onOk() -- setisContinueRoomGamedata(baojian) local param = { clubInfo = self.clubInfo, tableIndex = self.tableIndex, showIndex = self.showIndex, } setIsRoomGamedata(param) self.ui:sendMsg(app.room, "callLeaveRequest") end local function onCancel() end showConfirmDialog(content, onOk,onCancel); else showTooltip("您已在其他桌落座,请先退出桌子后再进入!") end end end return else local view = app:getCurrentView() local isInMainView = view.__cname == "MainView" if not isInMainView then showTooltip("您已在其他桌落座,请先退出桌子后再进入!") return end end local gameConfig = getSubGameConfig(self.clubInfo.settings.gameId) or {} local num = app.club_php:getPlayerNum(settings) if gameConfig.isSupportWatch or table.nums(room.players) < num then self:joinClubRoom(self.tableIndex,room.roomId,settings) else showTooltip("当前桌子已经坐满!") end else -- if myRoom or self.ui.Items.Button_enter_table:isVisible() then if myRoom then -- showTooltip("您已在其他桌落座,请先退出桌子后再进入!") if getMyGameStatus() == false then local content = "加入新牌桌需退出当前牌桌,是否继续?"; local function onOk() -- setisContinueRoomGamedata(baojian) local param = { clubInfo = self.clubInfo, tableIndex = self.tableIndex, showIndex = self.showIndex, } setIsRoomGamedata(param) self.ui:sendMsg(app.room, "callLeaveRequest") end local function onCancel() end showConfirmDialog(content, onOk,onCancel); else showTooltip("您已在其他桌落座,请先退出桌子后再进入!") end return else local view = app:getCurrentView() local isInMainView = view.__cname == "MainView" if not isInMainView then showTooltip("您已在其他桌落座,请先退出桌子后再进入!") return end end self:createRoom(settings) end end function ClubTableNewOperatMenu:createRoom(ruleInfo) if self.clubInfo.status == 2 then showConfirmDialog(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_DONG_JIE_TIP or PLN.CLUB_DONG_JIE_TIP); return end if table.nums(ruleInfo) <= 0 then showConfirmDialog("未设置游戏玩法,请先设置游戏玩法后再来开房!") return end local memberInfo = self.clubInfo.memberInfo if memberInfo and memberInfo.status == 0 then showTooltip("您已被暂停游戏,请联系管理员!") return end if not app.subGameManager:isInstaller(tonumber(ruleInfo.gameId)) or app.subGameManager:isNeedUpdate(tonumber(ruleInfo.gameId)) then requestDownloadSubGame(tonumber(ruleInfo.gameId), function () showTooltip("下载完成") end, true) return end --[[if tonumber(ruleInfo.gameId) ~= GAME_IDS.LuZhouMJ then showTooltip("开发中...") return end--]] local request = self:getCreateRoomData(self.tableIndex, ruleInfo); print("clubCreateRoomRequest() request = ",table.tostring(request)); --开房时记录茶馆id,用于退出房间时返回界面做判断 app.club_php.clubID = self.clubInfo.clubId app.club:requesetCreateRoomInClub(request) end function ClubTableNewOperatMenu:getCreateRoomData(index, ruleInfo) --局数 local jushu = 0; if table.nums(ruleInfo) > 0 then jushu = ruleInfo.gameNum; end local tableIdx = index; --记录茶馆桌子下标,用于房间切换回茶馆时做判断 app.club_php.tableIdx = tableIdx local request = ClubCreateRoomRequest:new() request.gameid = tonumber(ruleInfo.gameId);--游戏id request.groupId = tonumber(self.clubInfo.clubId);--茶馆标识 request.groupIndex = tostring(tableIdx); --茶馆桌子序号 request.groupUid = tonumber(self.clubInfo.ownerId);--茶馆管理员ID request.groupMemNum = tonumber(self.clubInfo.playerNum);--茶馆成员人数 --游戏局数 request.gameNum = jushu; --游戏信息,同游戏创建参数 local gameinfo = ruleInfo.strGameRule local ttGameInfo = json.decode(gameinfo) or {} ttGameInfo.clubId = tonumber(self.clubInfo.clubId) ttGameInfo.tableIdx = tonumber(tableIdx) ttGameInfo.ruleid = tostring(ruleInfo.baoJianId) --柳州字牌增加23人玩法 if tonumber(ruleInfo.gameId) == 20 and not ttGameInfo.startMode then ttGameInfo.startMode = 1 end gameinfo = json.encode(ttGameInfo) request.gameInfo = gameinfo --发起创建的用户信息 local tt = json.decode(app.user.userInfo) tt.unionid = app.user.unionid tt.openid = app.user.openid tt.sex = tonumber(tt.sex) request.usrinfo =json.encode(tt) return request; end function ClubTableNewOperatMenu:joinClubRoom( index, roomid, ruleInfo) if self.clubInfo.status == 2 then showConfirmDialog("当前茶馆已被冻结,请联系馆主解冻茶馆!"); return; end local memberInfo = self.clubInfo.memberInfo if memberInfo and memberInfo.status == 0 then showTooltip("您已被暂停游戏,请联系管理员!") return end if not app.subGameManager:isInstaller(tonumber(ruleInfo.gameId)) or app.subGameManager:isNeedUpdate(tonumber(ruleInfo.gameId)) then requestDownloadSubGame(tonumber(ruleInfo.gameId), function () showTooltip("下载完成") end, true) return end local request = ClubJoinRoomRequest:new() request.gameid = tonumber(ruleInfo.gameId); --游戏id request.tableid = tonumber(roomid); --房间号 request.grouId = tonumber(self.clubInfo.clubId); --茶馆标识 request.groupIndex = tonumber(index); --茶馆桌子序号 --发起创建的用户信息 local tt = json.decode(app.user.userInfo) tt.unionid = app.user.unionid tt.openid = app.user.openid tt.sex = tonumber(sex) request.usrinfo =json.encode(tt) --游戏信息,同游戏创建参数 local gameinfo = json.decode(ruleInfo.strGameRule) if gameinfo then request.gamerule = gameinfo.gamerule end print("clubJoinRoomRequest() request = ",table.tostring(request)); --开房时记录茶馆id,用于退出房间时返回界面做判断 app.club_php.clubID = self.clubInfo.clubId; local createRoomRequest = self:getCreateRoomData(index, ruleInfo); app.club:requestJoinRoomInClub(request, createRoomRequest) end --点击解散 function ClubTableNewOperatMenu:onClickJieSan() --解散房间 local content = "是否要强制解散当前正在游戏的"..tostring(self.showIndex).."号桌子?"; local gameId = ""; local roomid = ""; local tableIdx = self.tableIndex if self.clubInfo ~= nil then if self.clubInfo.mode == 1 then -- tableIdx = tonumber(self.tableIndex) if table.nums(self.clubInfo.rooms) > 0 and self.clubInfo.rooms[tableIdx] then --房间号 roomid = self.clubInfo.rooms[tableIdx].roomId --获取游戏id(多玩法只能在包间信息里获取游戏id,roomlist里面没有) local baoJianId = self.clubInfo.rooms[tableIdx].baoJianId local baoJian = self.clubInfo.baoJians[baoJianId]--app.club_php.clubRuleList; if baoJian then gameId = baoJian.gameId end end else gameId = self.clubInfo.settings.gameId if table.nums(self.clubInfo.rooms) > 0 and self.clubInfo.rooms[tableIdx] then roomid = self.clubInfo.rooms[tableIdx].roomId end end end --确认回调 local function okCallback() local dismissInfo = ClubDismissRequest:new() --游戏id dismissInfo.gameid = gameId --房间号 dismissInfo.tableid = roomid --茶馆id dismissInfo.groupid = self.clubInfo.clubId app.club:requestDismissInClub(dismissInfo) end local function onCancel() end showConfirmDialog(content, okCallback, onCancel, nil); end function ClubTableNewOperatMenu:onClickKick() local function onClose() self:removeFromParent() end local director = cc.Director:getInstance() local resolutionSize = director:getOpenGLView():getDesignResolutionSize() --踢出房间 local view = import("luaScript.Views.Club.ClubTableKickMenu"):new(self.clubInfo.clubId, self.tableIndex ,onClose) view:setAnchorPoint(cc.p(0.5, 0.5)) --计算坐标 local viewNode = self:getMoreLayout(); local worldPos = viewNode:getWorldPosition(); local viewContentSize = cc.size(545, 80); local x = worldPos.x + viewNode:getContentSize().width; if worldPos.x>resolutionSize.width/2 then x = worldPos.x - viewContentSize.width; view.ui.Items.ImageView_1:setVisible(false) else view.ui.Items.ImageView_2:setVisible(false) end local y = worldPos.y; local newPos = cc.p(x, y); view:setPosition(newPos); app:showWaitDialog(view, 0, true); self._kickTableMenu = view end function ClubTableNewOperatMenu:onApplicationDidEnterBackground() if not tolua.isnull(self._kickTableMenu) then self._kickTableMenu:removeFromParent() end self._kickTableMenu = nil end return ClubTableNewOperatMenu