|
- -- 桌子操作按钮Layout
- local ClubTableOperatMenu = class("ClubTableOperatMenu" , cc.UIView);
- local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
-
- --按钮对应编号
- -- 1 : 邀请好友
- -- 2 : 进入游戏
- -- 3 : 解散房间
- -- 4 : 踢出房间
-
- -- menuIdxs = {1,2,3,4}
- -- callback : 点击按钮之后的回调
- function ClubTableOperatMenu:ctor(clubId, realIndex, showIndex, isgamebol)
- ClubTableOperatMenu.super.ctor(self)
-
- self:loadUI()
-
- self.clubId = clubId;
- self.realIndex = realIndex
- self.showIndex = showIndex
-
-
- --单个茶馆数据
- self.clubInfo = app.club_php:getClubInfo(self.clubId)
- self.roomInfo = nil
- local rooms = app.club_php:getShowRooms(nil, nil)
- for k, v in pairs(rooms or {}) do
- if v.pos == self.realIndex then
- self.roomInfo = v
- break
- end
- end
-
- --是否直接进入
- self.directbol = true
- if isgamebol == false then
- self.directbol = isgamebol
- end
-
- if isContinueRoomGamebol() then
- setisContinueRoomGamebol(false)
- setIsRoomGamedata(nil)
- self:onGameEnter()
- end
-
- self:initBindEvent()
- end
-
-
- function ClubTableOperatMenu:initBindEvent()
- --如果管理员点了桌子没操作,创始人执行了包间切换,菜单要消失。绑定回调
- self:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_PUSH , handler(self , self.updateSetting));
- end
-
- function ClubTableOperatMenu:updateSetting(event)
- self:removeFromParent()
- end
-
- function ClubTableOperatMenu:loadUI()
- local ui = loadUI("res/ui/ui_club/ui_club_table_operat_menu.ui")
- self.ui = ui
- self:addChild(ui)
- end
-
- function ClubTableOperatMenu:getMenus()
- -- 1 : 邀请好友
- -- 2 : 进入游戏
- -- 3 : 解散房间
- -- 4 : 踢出房间
- local ttMenuIdx = {}
-
- if app.club_php:getCestIsOpen(self.clubId) then
- self.ui.Items.Button_4:loadTextureNormal("res/ui/zy_club/club_room/club_cest_table_operatemenu/btn_cest_kick.png")
- end
-
- if not self.roomInfo then
- --此桌子没有开房
- if self.clubInfo.role == 2 or self.clubInfo.role == 3 then
- -- 邀请好友
- if not isReviewVersion() then
- table.insert(ttMenuIdx, 1)
- end
- -- 进入游戏
- table.insert(ttMenuIdx, 2)
- end
- else
- --当前桌子已有房间信息
- if (self.clubInfo.role == 2 or self.clubInfo.role == 3) and not app.club_php:getIsSlaveUnion(self.clubInfo.clubId) then
- --当前房间是否已开局
- local gameStatus = self.roomInfo.status
- --2:管理员 3:创始人
- -- 邀请好友
- if gameStatus == 1 and not isReviewVersion() then
- table.insert(ttMenuIdx, 1)
- end
- if gameStatus == 1 then
- -- 进入游戏
- table.insert(ttMenuIdx, 2)
- end
-
- if self.roomInfo then
- --只有管理员和创始人才有解散房间权限
- table.insert(ttMenuIdx, 3)
- if gameStatus == 1 and table.nums(self.roomInfo.players) > 0 then
- --未开局且有一个以上用户,没用户,不需要显示踢出按钮
- -- 踢出房间
- table.insert(ttMenuIdx, 4)
- end
- end
- end
- end
-
- return ttMenuIdx;
- end
-
- function ClubTableOperatMenu:onEnter()
- ClubTableOperatMenu.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 ClubTableOperatMenu: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 ClubTableOperatMenu:getMoreLayout()
- return self.ui.Items.Layout_more;
- end
-
- function ClubTableOperatMenu:onClickInvite()
- local gameId = "";
- local rooID = ""
- local contStr = ""
-
- if self.clubInfo ~= nil then
- if self.roomInfo then
- --获取游戏id(多玩法只能在包间信息里获取游戏id,roomlist里面没有)
- local baoJianId = self.roomInfo.baoJianId
- local baoJian = self.clubInfo.baoJians[baoJianId]
- if baoJian then
- gameId = baoJian.realGameId
- end
- rooID = self.roomInfo.roomId
- contStr = "\n复制信息打开游戏将自动入座"
- else
- gameId = self.clubInfo.settings.realGameId
- 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 = ""
- if self.roomInfo then
- local baoJianId = self.roomInfo.baoJianId
- local baoJian = self.clubInfo.baoJians[baoJianId]
- if not baoJian then
- showTooltip("包间查找失败")
- return
- end
- local tt = getRuleFromString(baoJian.realGameId, baoJian.gameNum, baoJian.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
- logD("用户开始分享")
- --需要显示的按钮(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 ClubTableOperatMenu:onGameEnter()
- local room = self.roomInfo
- local baojian = room and app.club_php:getBaoJian(self.clubInfo.clubId,room.baoJianId) or nil
- local settings = self.clubInfo.mode == ClubDefine.BaoJianType.Normal and self.clubInfo.settings or baojian
- local myRoom = app.club_php:getMyInRoom(self.clubInfo.clubId)
- 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.realIndex,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()
- -- logD(view.__cname)
- if view and view.__cname ~= "MainView" then --没有主界面则在房间界面
- app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
- else
- self:joinClubRoom(self.realIndex,room.roomId,settings)
- end
- return
- end
- end
-
- local gameConfig = getSubGameConfig(settings.realGameId) or {}
- local num = app.club_php:getPlayerNum(settings)
- if gameConfig.isSupportWatch or table.nums(room.players) < num then
- self:joinClubRoom(self.realIndex,room.roomId,settings)
- else
- showTooltip("当前桌子已经坐满!")
- end
- else
- self:createRoom(settings)
- end
- end
-
- function ClubTableOperatMenu:onClickEnter()
- local room = self.roomInfo
- local baojian = room and app.club_php:getBaoJian(self.clubInfo.clubId,room.baoJianId) or nil
- baojian = self.clubInfo.mode == ClubDefine.BaoJianType.Normal and self.clubInfo.settings or baojian
- local myRoom = app.club_php:getMyInRoom(self.clubInfo.clubId)
- if room then --如果点击的桌子存在
- --1.没落座直接进入2.已落坐进入其他桌子3.没落座进入已经开始或者满人的桌子,4已落座进入自己桌子
- if myRoom then
- --2和4进来
- local isEnterSelfTable = false
- for nUserId,v in pairs(room.players) do
- if tonumber(nUserId) == tonumber(app.user.loginInfo.uid) then
- isEnterSelfTable = true
- end
- end
- if not isEnterSelfTable then
- if room.status == 2 then
- showTooltip("当前桌子已经坐满!")
- else
- showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
- end
- else
- app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
- end
- else
- --1.3进来
- local gameConfig = getSubGameConfig(baojian.realGameId) or {}
- local num = app.club_php:getPlayerNum(baojian)
- if gameConfig.isSupportWatch or table.nums(room.players) < num then
- self:joinClubRoom(self.realIndex,room.roomId,baojian)
- else
- showTooltip("当前桌子已经坐满!")
- end
- end
- else
- if myRoom then
- showTooltip("您已在其他桌落座,请先退出桌子后再进入!")
- return
- end
- if baojian then
- self:createRoom(baojian)
- end
- end
- end
-
- function ClubTableOperatMenu: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 (not ruleInfo) or 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.realGameId)) or app.subGameManager:isNeedUpdate(tonumber(ruleInfo.realGameId)) then
- requestDownloadSubGame(tonumber(ruleInfo.realGameId), function ()
- showTooltip("下载完成")
- end, true)
- return
- end
-
- if not isEnableEnterRoom() then
- return
- end
-
- local request = self:getCreateRoomData(self.realIndex, ruleInfo);
-
- logD("clubCreateRoomRequest() request = ",table.tostring(request));
-
- --开房时记录茶馆id,用于退出房间时返回界面做判断
- app.club_php.clubID = self.clubInfo.clubId
-
- app.club:requesetCreateRoomInClub(request)
- end
-
- function ClubTableOperatMenu:getCreateRoomData(index, ruleInfo)
- --局数
- local jushu = 0;
- if table.nums(ruleInfo) > 0 then
- jushu = ruleInfo.gameNum;
- end
-
- --记录茶馆桌子下标,用于房间切换回茶馆时做判断
- app.club_php.tableIdx = self.realIndex
-
- local gameId = tonumber(ruleInfo.realGameId)
-
- local request = ClubCreateRoomRequest:new()
- request.gameid = gameId;--游戏id
- request.groupId = tonumber(self.clubInfo.clubId);--茶馆标识
- request.groupIndex = tostring(self.realIndex); --茶馆桌子序号
- 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(self.realIndex)
- ttGameInfo.ruleid = tostring(ruleInfo.baoJianId)
- ttGameInfo.isArena = app.club_php.isArena
- --柳州字牌增加23人玩法
- if 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
- request.usrinfo =json.encode(tt)
-
- return request;
- end
-
-
-
- function ClubTableOperatMenu: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
-
- local gameId = tonumber(ruleInfo.realGameId)
-
- if not app.subGameManager:isInstaller(gameId) or app.subGameManager:isNeedUpdate(gameId) then
- requestDownloadSubGame(gameId, function ()
- showTooltip("下载完成")
- end, true)
- return
- end
-
- if not isEnableEnterRoom() then
- return
- end
-
- local request = ClubJoinRoomRequest:new()
- request.gameid = 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
-
- logD("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 ClubTableOperatMenu:onClickJieSan()
- --解散房间
- local content = string.format("是否要强制解散当前正在游戏的%d号桌子?", tonumber(self.showIndex));
-
- local gameId = "";
- local roomid = "";
-
- if self.clubInfo ~= nil then
- if self.roomInfo then
- --房间号
- roomid = self.roomInfo.roomId
-
- --获取游戏id(多玩法只能在包间信息里获取游戏id,roomlist里面没有)
- local baoJianId = self.roomInfo.baoJianId
- local baoJian = self.clubInfo.baoJians[baoJianId]--app.club_php.clubRuleList;
- if baoJian then
- gameId = baoJian.realGameId
- 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 ClubTableOperatMenu:onClickKick()
- self.roomInfo = self.clubInfo.rooms[self.realIndex]
- if not self.roomInfo then
- showTooltip("房间不存在!")
- self:removeFromParent()
- return
- end
-
- 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.realIndex, 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);
- end
-
- return ClubTableOperatMenu
|