-- 茶馆桌子ItemLayout local ClubTableBaoJianItem = class("ClubTableBaoJianItem"); local ClubDefine = require("luaScript.Protocol.Club.ClubDefine") function ClubTableBaoJianItem:ctor(baoJianInfo,clubId) --单个茶馆数据 self.clubInfo = app.club_php:getClubInfo(clubId) self.baoJian = baoJianInfo self.baoJianId = self.baoJian.baoJianId self.playerNum = 0; self.lastPlayerNum = 0; self.layout = cc.Layout:create() self.layout:setSize(cc.size(310, 230)) -- 更新界面 self:updateView() --监听包间名修改 self.ui:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_RULE_PUSH , handler(self , self.updateView)) end function ClubTableBaoJianItem:removeSelf() if self.layout then self.layout:removeFromParent() end end function ClubTableBaoJianItem:updateData(baoJian) self.baoJian = baoJian; self:updateView(); end function ClubTableBaoJianItem:updateView() --显示桌子 self:showTable() --玩家数据 self:showTableInfo() --桌子下标 self.tableIndex = nil --再来一局逻辑 self.conbo = false local baojiandata = isContinueRoomGamedata() if baojiandata then if isContinueRoomGamebol() and baojiandata.baoJianId == self.baoJianId then self.conbo = true self.baoJian = isContinueRoomGamedata() setisContinueRoomGamedata(nil) self:createRoom() end end self.bPlayAgain = false local againBaoJianId = getAgainGameBaoJianId() local bPlayAgain,wanfa = getIsAgainGamebol() if againBaoJianId ~= -1 and bPlayAgain and self.baoJian.baoJianId == tonumber(againBaoJianId) then setMyGameCreateStatus(true) setIsAgainGamebol(false) self.bPlayAgain = true self:createRoom() end end function ClubTableBaoJianItem:updatePlayerNum() self.playerNum = app.club_php:getPlayerNum(self.baoJian) end function ClubTableBaoJianItem:showTable() --更新游戏所需玩家人数 self:updatePlayerNum() if self.lastPlayerNum ~= self.playerNum then self.lastPlayerNum = self.playerNum if self.playerNum == 2 then self.ui = loadUI("res/ui/ui_club/ui_club_table_item_2.ui"); elseif self.playerNum == 3 then self.ui = loadUI("res/ui/ui_club/ui_club_table_item.ui"); elseif self.playerNum == 4 then self.ui = loadUI("res/ui/ui_club/ui_club_table_item_4.ui"); elseif self.playerNum == 5 then self.ui = loadUI("res/ui/ui_club/ui_club_table_item_5.ui"); elseif self.playerNum == 6 then self.ui = loadUI("res/ui/ui_club/ui_club_table_item_6.ui"); elseif self.playerNum >= 7 then self.ui = loadUI("res/ui/ui_club/ui_club_table_item_8.ui"); end self.ui:bindEvent(app.club,GAME_EVENT.CLUB_CREATE_ERR , handler(self , self.onCreateRoomErr)) self.ui.Items.Layout_Touch:registerClick(handler(self , self.onTouchTable)) if self.layout then self.layout:removeAllChildren() self.layout:addChild(self.ui) end end end --创建桌子失败 function ClubTableBaoJianItem:onCreateRoomErr() if self.tableIndex then logD("ClubTableBaoJianItem:onCreateRoomErr = ",tostring(self.tableIndex)) self.tableIndex = self.tableIndex + 1 self:createRoom(self.tableIndex) end end function ClubTableBaoJianItem:hidNode() if self.baoJian then local gameId = self.baoJian.realGameId self.ui.Items.Text_Game_Rule:setText((self.baoJian.title and #self.baoJian.title > 0) and self.baoJian.title or "未设包间名"); local strGameRule = json.decode(self.baoJian.strGameRule) local gamerule = strGameRule.gamerule or strGameRule.gameRule -- gameRule 为了兼容个别特殊的游戏和线上情况,以后统一用gamerule local gameNum = self.baoJian.gameNum local config = getSubGameConfig(tonumber(gameId)) --包间名称 self.ui.Items.ImageView_Game_Rule:setVisible(self.baoJian.title and #self.baoJian.title > 0) --桌子玩法名称 local ruleName = getSubGameRuleName(self.baoJian.realGameId,gamerule) self.ui.Items.Text_game_name:setText(tostring(ruleName)..tostring(gameNum).."局") --桌子信息 local extraInfo = getClubTableRuleString(gameId, self.baoJian.strGameRule,self.playerNum) or "" self.ui.Items.Text_playernum:setText(extraInfo) --桌子颜色 local baoJian = self.baoJian local strExtJson = baoJian.ext or "" local extInfo = json.decode(strExtJson) or {} local tableStyle = extInfo.tableStyle or 1 --4人桌子有方有圆特殊处理 local desktopBgPath = string.format("res/ui/zy_club/club_room/club_table_pic/club_room_table_%d_%d.png", tableStyle,self.playerNum) self.ui.Items.ImageView:loadTexture(desktopBgPath) end for i = 1,self.playerNum do local nodeName = string.format("Layout_player_%d",i); if self.ui.Items and self.ui.Items[nodeName] then self.ui.Items[nodeName]:setVisible(false); end end end function ClubTableBaoJianItem:showTableInfo() self:hidNode() --包间桌子不显示下标 self.ui.Items.TextBMFont_table_num:setVisible(false) end --点击桌子加入房间 function ClubTableBaoJianItem:onTouchTable() self.ui.Items.Layout_Touch:setTouchEnabled(false) self.ui.Items.Layout_Touch:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function () self.ui.Items.Layout_Touch:setTouchEnabled(true) end))) self:createRoom() end --开设房间 function ClubTableBaoJianItem:createRoom(newTableIndex) setisContinueRoomGamebol(false) 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 local memberInfo = self.clubInfo.memberInfo if memberInfo and memberInfo.status == 0 then showTooltip("您已被暂停游戏,请联系管理员!") return end local rooms = app.club_php:getBaoJianRooms(self.clubInfo.clubId,self.baoJianId) local total = 0 for k,v in pairs(rooms) do --人没满 且未开局 if table.nums(v.players)= PLN.CLUB_LIMLIT_TABLE then showConfirmDialog("亲,已经有"..PLN.CLUB_LIMLIT_TABLE.."张未坐满的桌子,请点击任意一张桌子进入房间!") return end local tableIdx = nil; if newTableIndex then tableIdx = newTableIndex else --如果是1号包间 房间下标要去掉包间的数量 --local startIndex = self.baoJian.orderId == 1 and table.nums(self.clubInfo.baoJians)+1 or (self.baoJian.orderId - 1) * 100 + 1 local startIndex = (self.baoJian.orderId - 1) * ClubDefine.TableCountMax + 1 for i=startIndex,startIndex + (ClubDefine.TableCountMax - 1) do if not self.clubInfo.posList[i] then tableIdx = i break end end end if not tableIdx then showTooltip("当前房间数量已达到上限!") return end local myRoom = app.club_php:getMyInRoom(self.clubInfo.clubId) if myRoom then showTooltip("您已在其他桌落座,请先退出桌子后再进入!") return end if self.ui.Items.Button_enter_table then if self.ui.Items.Button_enter_table:isVisible() then showTooltip("您已在其他桌落座,请先退出桌子后再进入!") return end end if not app.subGameManager:isInstaller(self.baoJian.realGameId) or app.subGameManager:isNeedUpdate(self.baoJian.realGameId) then requestDownloadSubGame(self.baoJian.realGameId, function () showTooltip("下载完成") end, true) return end if not isEnableEnterRoom() then return end self.tableIndex = tableIdx local request = self:getCreateRoomData(tableIdx) logD("clubCreateRoomRequest() request = ",table.tostring(request)); --开房时记录茶馆id,用于退出房间时返回界面做判断 app.club_php.clubID = self.clubInfo.clubId app.club:requesetCreateRoomInClub(request) end function ClubTableBaoJianItem:getCreateRoomData(tableIdx) --记录茶馆桌子下标,用于房间切换回茶馆时做判断 app.club_php.tableIdx = tableIdx local gameId = self.baoJian.realGameId local request = ClubCreateRoomRequest:new() request.gameid = gameId--游戏id request.groupId =self.clubInfo.clubId--茶馆标识 request.groupIndex = tableIdx --茶馆桌子序号 request.groupUid = self.clubInfo.ownerId--茶馆管理员ID request.groupMemNum = self.clubInfo.playerNum--茶馆成员人数 --游戏局数 request.gameNum = self.baoJian.gameNum --游戏信息,同游戏创建参数 local gameinfo = self.baoJian.strGameRule local ttGameInfo = json.decode(gameinfo) or {} ttGameInfo.clubId = self.clubInfo.clubId ttGameInfo.tableIdx = tableIdx ttGameInfo.ruleid = self.baoJianId ttGameInfo.isArena = app.club_php.isArena --黄十八兼容性 if gameId == 2 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 --获取touch层 function ClubTableBaoJianItem:getTouchLayout() return self.ui.Items.Layout_Touch; end --获取下标 function ClubTableBaoJianItem:getTableIdx() return self.index end return ClubTableBaoJianItem