-- 茶馆桌子ItemLayout local ClubTableItem = class("ClubTableItem"); local ClubDefine = require("luaScript.Protocol.Club.ClubDefine") -- clubId :(必需)俱乐部ID -- realIndex : (必需)桌子的真实下标 -- showIndex :(非必需)桌子用来显示的下标 function ClubTableItem:ctor(clubId, realIndex, showIndex) self.clubId = clubId; self.realIndex = realIndex self.showIndex = showIndex; --当前桌子是否有人坐下 self.issitdown = false self.playerNum = 0; self.lastPlayerNum = 0; self.layout = cc.Layout:create() self.layout:setSize(cc.size(310, 230)) self:updateView(); end function ClubTableItem:removeSelf() if not tolua.isnull(self.layout) then self.layout:removeFromParent() end end function ClubTableItem:updateData(clubId, realIndex, showIndex) logD("ClubTableItem:updateData()", tostring(clubId), tostring(realIndex), tostring(showIndex)) self.clubId = clubId; self.realIndex = realIndex self.showIndex = showIndex; self:updateView(); end ---- function ClubTableItem:updateView() logD("ClubTableItem:updateView()", tostring(self.clubId), tostring(self.realIndex)) if not self.clubId or not self.realIndex then return end self.clubInfo = app.club_php:getClubInfo(self.clubId) if not self.clubInfo then logD("ClubTableItem:updateView() self.clubInfo is nil!") return end -- 多玩法模式时能拿到房间信息 -- 包间模式可能拿不到房间信息 --[[self.roomInfo = nil local showRooms, hideRooms = app.club_php:getShowRooms(self.clubId, nil) for k, v in pairs(showRooms or {}) do if v.pos == self.realIndex then self.roomInfo = v break end end--]] if self.clubInfo.rooms or self.clubInfo.rooms[self.realIndex] then self.roomInfo = self.clubInfo.rooms[self.realIndex]; end --显示桌子 self:showTable() --隐藏 self:hidNode() --玩家数据 self:showTableInfo() local againid = getAgainGameBaoJianId() local againbol,wanfa = getIsAgainGamebol() if againid ~= -1 and againbol and self.clubInfo.settings.baoJianId == tonumber(againid) and self.issitdown == true then setMyGameCreateStatus(true) setAgainGameBaoJianId(-1) setIsAgainGamebol(false) setisContinueRoomGamebol(true) self:onTouchTable() end end function ClubTableItem:updatePlayerNum() logD("self.clubInfo.mode:",self.clubInfo.mode) if self.clubInfo.mode ~= ClubDefine.BaoJianType.Normal then if self.roomInfo then local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.roomInfo.baoJianId) self.playerNum = app.club_php:getPlayerNum(baoJian) logD("ClubTableItem:updatePlayerNum() 1",self.playerNum) end else self.playerNum = app.club_php:getPlayerNum(self.clubInfo.settings) logD("ClubTableItem:updatePlayerNum() 2") end end function ClubTableItem:showTable() --更新游戏所需玩家人数 self:updatePlayerNum() logD("self.playerNum",self.playerNum); 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.Items.Layout_Touch:registerClick(handler(self , self.onTouchTable)) self.ui:bindEvent(app.club_php , GAME_EVENT.CLUB_UPDATE_TABLE , handler(self , self.updateTable)) if self.layout then self.layout:removeAllChildren() self.layout:addChild(self.ui) end end end function ClubTableItem:updateTable(event) if not self.roomInfo or not event or event.pos ~= self.roomInfo.pos then return end self:updateData(self.clubId, self.realIndex,self.showIndex) end function ClubTableItem:hidNode() local baoJian if self.clubInfo.mode ~= ClubDefine.BaoJianType.Normal then baoJian = self.roomInfo and app.club_php:getBaoJian(self.clubInfo.clubId, self.roomInfo.baoJianId) if baoJian then local gameId = baoJian.realGameId local strGameRule = json.decode(baoJian.strGameRule) local gamerule = strGameRule.gamerule or strGameRule.gameRule -- gameRule 为了兼容个别特殊的游戏和线上情况,以后统一用gamerule local gameNum = baoJian.gameNum local config = getSubGameConfig(tonumber(gameId)) self.ui.Items.Text_Game_Rule:setText(baoJian.title or ""); self.ui.Items.ImageView_Game_Rule:setVisible(baoJian.title and string.len(baoJian.title) > 0) --桌子玩法名称 local ruleName = getSubGameRuleName(baoJian.realGameId,gamerule) self.ui.Items.Text_game_name:setText(tostring(ruleName)..tostring(gameNum).."局") --桌子信息 local extraInfo = getClubTableRuleString(gameId, baoJian.strGameRule,self.playerNum) or "" self.ui.Items.Text_playernum:setText(extraInfo) end else baoJian = self.clubInfo.settings self.ui.Items.Layout_allMode_info:setVisible(false) self.ui.Items.ImageView_Game_Rule:setVisible(false) end if baoJian then local gameId = baoJian.realGameId local config = getSubGameConfig(tonumber(gameId)) --桌子颜色 local strExtJson = baoJian.ext or "" local extInfo = json.decode(strExtJson) or {} local tableStyle = extInfo.tableStyle or 1 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 ClubTableItem:showTableInfo() if tolua.isnull(self.ui) then return end local tableInfo = self.roomInfo if tableInfo == nil then self.issitdown = true end if tableInfo ~= nil then local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId, tableInfo.baoJianId) if baoJian then if self.clubInfo.mode ~= ClubDefine.BaoJianType.Normal then self.ui.Items.ImageView_Game_Rule:setVisible(baoJian.title and #baoJian.title > 0 and tableInfo.status ~= 2) end --桌子玩法名称 if tableInfo.status == 2 then local strGameRule = json.decode(baoJian.strGameRule) local gamerule = strGameRule.gamerule local ruleName = getSubGameRuleName(baoJian.realGameId,gamerule) self.ui.Items.Text_game_name:setText(tostring(ruleName)) end end --人数 local playerIdx = 1; for k,v in pairsByKeys(tableInfo.players) do local nodeName = string.format("Layout_player_%d",playerIdx); if self.ui.Items and self.ui.Items[nodeName] then self.ui.Items[nodeName]:setVisible(true); end --头像 local nodeHeadImg = string.format("ImageView_head_%d",playerIdx); local nodeHead = self.ui.Items[nodeHeadImg]; if self.ui.Items and nodeHead then local headSize = nodeHead:getContentSize(); setPlayerHeadImage(v.uid, v.headimgurl, nodeHead); end --名字 local nameNode = string.format("Text_player_name_%d",playerIdx); if self.ui.Items and self.ui.Items[nameNode] then v.nickname = getSubStringNickname(v.nickname,self.ui.Items[nameNode]) self.ui.Items[nameNode]:setText(v.nickname); end --准备状态 local readyNode = string.format("ImageView_ready_%d", playerIdx) if self.ui.Items and self.ui.Items[readyNode] then -- -1未收到服务器处理消息0未连接,可判断离线1已登陆,正常为坐下 --2准备3在玩4在玩过程中离线5准备但离线6坐下但离线 if v.state == 2 or v.state == 5 then self.ui.Items[readyNode]:setVisible(true) else self.ui.Items[readyNode]:setVisible(false) end if k == tonumber(app.user.loginInfo.uid) then if v.state == 3 then--自己在游戏中 setMyGameStatus(true) else setMyGameStatus(false) end end end --离线状态 local offlineNode = string.format("ImageView_offline_%d", playerIdx) if self.ui.Items and self.ui.Items[offlineNode] then if v.state==4 or v.state==5 or v.state==6 then self.ui.Items[offlineNode]:setVisible(true) else self.ui.Items[offlineNode]:setVisible(false) end end --分数 local scoreText = string.format("Text_score_%d", playerIdx) local scoreNode = string.format("ImageView_score_%d", playerIdx) if self.ui.Items and self.ui.Items[scoreText] then if self.roomInfo.status==1 or not v.score then self.ui.Items[scoreNode]:setVisible(false) else self.ui.Items[scoreNode]:setVisible(true) if v.score>0 then self.ui.Items[scoreText]:setTextColor(cc.c4b(255,227,113,255)) self.ui.Items[scoreText]:setText("+"..v.score) else self.ui.Items[scoreText]:setTextColor(cc.c4b(140,232,255,255)) self.ui.Items[scoreText]:setText(v.score) end end end playerIdx = playerIdx + 1; end -- self:updatePlayerNum() for i = playerIdx,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 else self:hidNode(); end self.ui.Items.TextBMFont_table_num:setText(self.showIndex) self.ui.Items.TextBMFont_table_num:setVisible(false) self:updatePlayerReadyStatus() self:updateJushu() end --单独更新玩家准备状态 function ClubTableItem:updatePlayerReadyStatus() if self.roomInfo ~= nil and table.nums(self.roomInfo) > 0 and table.nums(self.roomInfo.players) > 0 then local playerIdx = 1; for k,v in pairsByKeys(self.roomInfo.players) do --准备状态 local readyNode = string.format("ImageView_ready_%d", playerIdx) if self.ui.Items and self.ui.Items[readyNode] then -- -1未收到服务器处理消息0未连接,可判断离线1已登陆,正常为坐下2准备3在玩4在玩过程中离线5准备但离线6坐下但离线 if v.state == 2 or v.state == 5 then self.ui.Items[readyNode]:setVisible(true) else self.ui.Items[readyNode]:setVisible(false) end end playerIdx = playerIdx + 1; end end end --单独更新局数 function ClubTableItem:updateJushu() if self.roomInfo ~= nil and table.nums(self.roomInfo) > 0 and table.nums(self.roomInfo.players) > 0 then --当前状态1未开局 2开局 if self.roomInfo.status == 1 then --self.ui.Items.Text_jushu:setText("准备中"); else self.ui.Items.Layout_allMode_info:setVisible(true) self.ui.Items.ImageView_rule_bg:setVisible(true) self.ui.Items.Text_game_name:setVisible(true) local jushuStr = string.format("第%d/%d局",self.roomInfo.currentNum,self.roomInfo.totalNum) self.ui.Items.Text_playernum:setText(jushuStr); end end end --点击桌子加入房间 function ClubTableItem:onTouchTable() if not tolua.isnull(self._tableMenuView) then self._tableMenuView:removeFromParent() end self._tableMenuView = nil local bRuleChange = getRuleChangeStatus() if bRuleChange then local againbol,wanfa = getIsAgainGamebol() if wanfa ~= "" then showTooltip("房间创建失败,该包间玩法已被删除或修改!") end setIsAgainGamebol(false,"") setRuleChangeStatus(false) setisContinueRoomGamebol(false) return end local tableMenuView = import("luaScript.Views.Club.ClubTableOperatMenu"):new(self.clubId, self.realIndex, self.showIndex) tableMenuView.ui.Items.Button_enter_table = self.ui.Items.Button_enter_table tableMenuView:setAnchorPoint(cc.p(0.5, 0.5)) local worldPos = self.ui.Items.ImageView:getWorldPosition(); local x = worldPos.x + 20; local y = worldPos.y local newPos = cc.p(x, y); tableMenuView:setPosition(newPos); app:showWaitDialog(tableMenuView, 0, true) end --获取touch层 function ClubTableItem:getTouchLayout() return self.ui.Items.Layout_Touch; end --获取下标 function ClubTableItem:getTableIdx() return self.realIndex end return ClubTableItem