--茶馆包间Layout local ClubBaojian = class("ClubBaojian",cc.UIView) local ClubDefine = require("luaScript.Protocol.Club.ClubDefine") function ClubBaojian:ctor(clubId) --单个茶馆数据 self.clubInfo = app.club_php.clubList[clubId] self:initUI() self:initBindEvent() self.lastSendAdd = 0 --请求茶馆游戏玩法总配置 app.club_php:requestGameRule(self.clubInfo.clubId) end function ClubBaojian:initUI() self.ui = loadUI("res/ui/ui_club/ui_club_baojian.ui") self:addChild(self.ui) self.ui.Items.Layout_baojian_item:setVisible(false); self.ui.Items.Layout_baojian_create:setVisible(false); self.ui.Items.Layout_show_rule:setVisible(false) if app.club_php:getCestIsOpen(self.clubInfo.clubId) then self.ui.Items.ImageView_title:loadTexture("res/ui/zy_club/club_room/club_baojian/club_cest_bisai_title.png") end end function ClubBaojian:initBindEvent() --如果添加新的游戏玩法成功了,游戏被激活,需要重新计算未激活游戏的数量 self:bindEvent(app.club_php , GAME_EVENT.CLUB_CALUATE_ACTIVE_GAME , handler(self , self.onUpdateActiveGame)) --请求茶馆玩法回调 self.ui:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_RULE_PUSH , handler(self , self.updateBaoJian)) --切换包间时候会重新请求桌子需要刷新一下 self.ui:bindEvent(app.club_php , GAME_EVENT.CLUB_TABLE , handler(self , self.updateBaoJian)) --获取游戏数据 self:bindEvent(app.club_php , GAME_EVENT.CLUB_GAME_RULE , handler(self , self.onClubGameRule)); --激活包间成功后关闭 self:bindEvent(app.club_php , GAME_EVENT.CLUB_ACTIVE_RULE , handler(self , self.onActiveRuleResponse)) end function ClubBaojian:onActiveRuleResponse(data) local status = data.status local groupView = self.ui.Items.ScrollView_BaoJian local pos = groupView:getInnerContainer():getPosition() if status == 0 then groupView:getInnerContainer():requestDoLayout() groupView:getInnerContainer():doLayout() groupView:requestDoLayout() groupView:doLayout() groupView:getInnerContainer():setPosition(cc.p(0,0)) end end function ClubBaojian:updateBaoJian() local baoJians = self.clubInfo.baoJians --包间个数 local baojianNum = table.nums(baoJians) local groupView = self.ui.Items.ScrollView_BaoJian groupView:getInnerContainer():setAutoSize(true) groupView:hideAllBar() groupView:removeAllChildren() local uiTemplate = self.ui.Items.Layout_baojian_item local index = 1 --包间排序 local newBaoJians = app.club_php:getSortClubBaoJians(self.clubInfo.clubId) for _,baojian in ipairs(newBaoJians) do if tonumber(baojian.is_use) == 1 then local uiItem = uiTemplate:getCopied() uiItem.Items = getUIItems(uiItem) local gameId = baojian.realGameId --包间下标 uiItem.Items.Text_index:setText(index) --包间名 local baojianName = baojian.title if not baojianName or baojianName == "" then if self.clubInfo.role == ClubDefine.Job.Manager or self.clubInfo.role == ClubDefine.Job.Creator then baojianName = "设置包间名" if app.club_php:getCestIsOpen(self.clubInfo.clubId) then baojianName = "设置赛事名" end else baojianName = "管理员未设置名字" end end uiItem.Items.Text_baojian_name:setText(baojianName) -- 局数 uiItem.Items.Text_jushu:setText(baojian.gameNum.."局") -- 玩法名 local rules = json.decode(baojian.strGameRule); local gamerule = rules.gamerule or rules.gameRule if gamerule then local ruleName = getSubGameRuleName(gameId, gamerule) uiItem.Items.Text_rule:setText(ruleName) end if self.clubInfo.mode ~= ClubDefine.BaoJianType.Normal then uiItem.Items.ImageView_selected:setVisible(false) else --普通模式添加切换包间 uiItem.Items.Layout_touch_item:registerClick(function () --选择当前包间 playBtnEffect() app.club_php:requestRuleSet(self.clubInfo.clubId, baojian.baoJianId, 1, 1) end) logD("self.clubInfo.settings.baoJianId:",self.clubInfo.settings.baoJianId) if self.clubInfo.settings.baoJianId == baojian.baoJianId then uiItem.Items.ImageView_selected:setVisible(true) else uiItem.Items.ImageView_selected:setVisible(false) end end --(1:成员 2:管理员 3:创始人) if (self.clubInfo.role == ClubDefine.Job.Manager or self.clubInfo.role == ClubDefine.Job.Creator) and not app.club_php:getIsSlaveUnion(self.clubInfo.clubId) then uiItem.Items.Button_change_name:setVisible(true) uiItem.Items.Button_set_rule:setVisible(true) uiItem.Items.Button_look:setVisible(false) --包间名修改 uiItem.Items.Button_change_name:registerClick(function () playBtnEffect() local view = import("luaScript.Views.Club.ClubBaojianChangeName"):new(self.clubInfo.clubId, baojian.baoJianId, baojian.title) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end) --修改玩法规则 uiItem.Items.Button_set_rule:registerClick(function () playBtnEffect() local view = import("luaScript.Views.Club.ClubChangeRule"):new(self.clubInfo.clubId, baojian.gameId, gamerule, baojian.baoJianId) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end) else uiItem.Items.Button_change_name:setVisible(false) uiItem.Items.Button_set_rule:setVisible(false) uiItem.Items.Button_look:setVisible(true) --查看玩法详情 uiItem.Items.Button_look:registerClick(function () playBtnEffect() self:showBaojianRuleInfo(uiItem, baojian,uiItem.Items.Button_look) end) end groupView:addChild(uiItem) index = index + 1 end end --包间小于后台下发的个数 显示添加按钮 if self.noActiveGames and type(self.noActiveGames) == "table" and table.nums(self.noActiveGames) > 0 and (self.clubInfo.role == ClubDefine.Job.Manager or self.clubInfo.role == ClubDefine.Job.Creator) and not app.club_php:getIsSlaveUnion(self.clubInfo.clubId) then local uiAddItem = self.ui.Items.Layout_baojian_create:getCopied() uiAddItem.Items = getUIItems(uiAddItem) --新增包间 uiAddItem.Items.Button_add_baojian:registerClick(function () playBtnEffect() local timeNow = os.time(); if timeNow - self.lastSendAdd <= 1 then showTooltip("正在更新包间,请稍后") return end self.lastSendAdd = timeNow; local view = import("luaScript.Views.Club.ClubChangeRule"):new(self.clubInfo.clubId,self.noActiveGames) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end) groupView:addChild(uiAddItem); end --groupView:jumpToTopOnSizeChanged() end --- -- 显示包间玩法信息(新版,玩法显示调用比赛场的框) -- @param baojian -- @return -- function ClubBaojian:showClubBaoJianInfo(baojian) local clubId = self.clubInfo.clubId local gameId = baojian.realGameId local gameNum = baojian.gameNum local strGameRule = baojian.strGameRule local arena = baojian.arena local title = baojian.title local ClubBaoJianInfoClass = import("luaScript.Views.Club.ClubBaoJianInfo") local view = ClubBaoJianInfoClass:new(clubId, gameId, gameNum, strGameRule, arena, title) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function ClubBaojian:showBaojianRuleInfo(parentNode, baoJian,btn) if true then self:showClubBaoJianInfo(baoJian) return end self.ui:removeChildByTag(100) local uiTemplate = self.ui.Items.Layout_show_rule; local uiRuleItem = uiTemplate:getCopied() uiRuleItem.Items = getUIItems(uiRuleItem) uiRuleItem.Items.Layout_Rule_item:setVisible(false) local scrollUI = uiRuleItem.Items.ScrollView_show_rule scrollUI:getInnerContainer():setAutoSize(true); scrollUI:hideAllBar(); scrollUI:removeAllChildren(); --增加数据 if table.nums(baoJian) > 0 then local tt = getRuleFromString(baoJian.realGameId, baoJian.gameNum, baoJian.strGameRule) local ttMatch = getClubMatchRule(baoJian.arena,"比赛规则") for k,v in ipairs(ttMatch) do table.insert(tt,v) end local uiTemp = uiRuleItem.Items.Layout_Rule_item for k,v in ipairs(tt) do local uiItem = uiTemp:getCopied() uiItem.Items = getUIItems(uiItem) -- 标题 uiItem.Items.Text_RuleName:setText(v.name) -- 内容 local text = "" for kk, vv in pairs(v.value) do if "" == text then text = vv else text = text .. "," .. vv end end uiItem.Items.Text_RuleText:setText(text); scrollUI:addChild(uiItem); end uiRuleItem:setTag(100) end scrollUI:jumpToTopOnSizeChanged() local idx = parentNode.Items.Text_index:getText() self.ui:addChild(uiRuleItem) -- local worldPos = btn:getWorldPosition() --计算坐标 local x = self.ui.Items.Layout_rule:getPositionX() local y = worldPos.y - uiRuleItem:getSize().height*2/3 - 9 local newPos = cc.p(x, y); uiRuleItem:setPosition(newPos) end function ClubBaojian:onClubGameRule(event) self.gameRules = event.result or {} if table.nums(self.gameRules) == 0 then return end --计算未激活的游戏 self:onUpdateActiveGame() end function ClubBaojian:onUpdateActiveGame() if not self.gameRules then return end local tt = {} for strGameId,v in pairs(self.gameRules) do if v.status == 1 then local gameConfig = getSubGameConfig(tonumber(strGameId)) if gameConfig and gameConfig.bSingleGame then for k,v in pairsByKeys(gameConfig.GameType) do table.insert(tt,tostring(k + tonumber(strGameId) * 10000)) end else table.insert(tt,tostring(strGameId)) end end end local activeGames = self.clubInfo.activeGames for i,j in ipairs(activeGames) do for k,strGameId in ipairs(tt) do local baoJians = app.club_php:getBaoJianByGameId(self.clubInfo.clubId,tonumber(j)) local isUseNum = 0 if baoJians then for k,v in pairs(baoJians) do if tonumber(v.is_use) == 1 then isUseNum = isUseNum + 1 end end end if tonumber(strGameId) == tonumber(j) and isUseNum > 0 then table.remove(tt,k) break end end end table.sort(tt,function (a,b) return toNumber(a) < toNumber(b) end) logD("self.noActiveGames:",table.tostring(self.noActiveGames)) self.noActiveGames = tt --更新包间 self:updateBaoJian() end return ClubBaojian