|
- local CRConfig = require("luaScript.Views.CreateRoom.Com.CRConfig")
-
- -- 茶馆修改游戏玩法Layout
- local ClubChangeRule = class("ClubChangeRule" , cc.UIView);
- local ClubDefine = require("luaScript.Protocol.Club.ClubDefine")
-
- -- @param clubId 俱乐部ID
- -- @param gameId 游戏ID,黄十八,碰胡的ID大于1万
- -- @param ruleId 玩法ID
- -- @param baoJianId 包间ID
- -- @param index 包间的序号
- function ClubChangeRule:ctor(clubId, gameId, ruleId, baoJianId,index)
- ClubChangeRule.super.ctor(self)
- if gameId == 0 then
- logD("ClubChangeRule:ctor()", debug.traceback())
- end
- logD("ClubChangeRule:ctor gameId :",gameId)
- logD("clubId :",clubId)
- logD("ruleId :",ruleId)
- logD("baoJianId :",baoJianId)
- logD("index :",index)
- self:loadUI()
-
- --单个茶馆数据
- self.clubInfo = app.club_php.clubList[clubId]
- self.normalColor = cc.c3b(130,201,200)
- self.selectColor = cc.c3b(255,255,255)
-
- self.baoJianNoSelColor = cc.c4b(206,236,253,255)
-
- if type(gameId) == "table" then
- --单玩法,混合玩法添加包间
- self.strGameId = gameId[1] and tostring(gameId[1]) or nil
- --未激活游戏列表
- self.noActiveGames = gameId
- else
- --子游戏多包间
- self.strGameId = gameId and tostring(gameId) or nil
- end
- self.realGameId = tonumber(self.strGameId)
- if toNumber(self.strGameId) > 10000 then
- self.realGameId = math.floor(toNumber(self.strGameId)/10000)
- self.ruleId = math.floor(toNumber(self.strGameId)%10000)
- else
- self.ruleId = ruleId
- end
-
- self.baoJianId = baoJianId
-
- self._baoJianName = ""
-
- self.index = index
-
- local baoJian = app.club_php:getBaoJian(clubId,baoJianId)
- if baoJian then
- self.arena = baoJian.arena
- else
- self.arena = ""
- end
- if self.strGameId and baoJianId and baoJianId > 0 then
- self.defaultValues = json.decode(self.clubInfo.baoJians[tonumber(baoJianId)].strGameRule or "") or {}
- else
- self.defaultValues = {}
- end
- end
-
- function ClubChangeRule:loadUI()
- local ui = loadUI("res/ui/ui_chuangjian/ui_chuangjian.ui")
- self.ui = ui
- self:addChild(ui)
- end
-
- function ClubChangeRule:onEnter()
- ClubChangeRule.super.onEnter(self)
-
- self:initView()
-
- self:initButton()
-
- self:intBindEvent()
-
- --请求茶馆游戏玩法总配置
- app.club_php:requestGameRule(self.clubInfo.clubId)
- end
-
- function ClubChangeRule:initView()
- self.ui.Items.Text_Tip:setText("注:第一局未发牌扣除的"..PLN.CURRENCY.."将在1小时内返回。")
-
- self.ui.Items.ImageView_title:loadTexture("res/ui/zy_dating/chuanjian/createRoom_title_modify_wanfa.png")
-
- self.ui.Items.Button_Create:loadTextureNormal("res/ui/zy_dating/chuanjian/createRoom_btn_save.png")
-
- self.ui.Items.Button_Match:setVisible(false)
- self.ui.Items.Layout_BaoJian_Name:setVisible(true)
- self.ui.Items.ImageView_Input_Normal:setVisible(true)
- self.ui.Items.ImageView_Input_Error:setVisible(false)
- self.ui.Items.Layout_leixing:setVisible(false)
- self.ui.Items.ScrollView_rule:setVisible(false)
- self.ui.Items.ScrollView_rule_club:setVisible(true)
- self.ui.Items.ScrollView:hideAllBar()
- self.ui.Items.ScrollView:getInnerContainer():setAutoSize(true)
- self.ui.Items.ScrollView:requestDoLayout()
- self.ui.Items.ScrollView:doLayout()
- self.ui.Items.CheckBox_baojian:setVisible(false)
-
- --比赛场模块
- if app.config.ModuleConfig.IsSupportDaLianMeng and self.clubInfo.isArena ~= ClubDefine.MATCH_SWITCH.SERVER_CLOSE then
- if (self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.CLIENT_OPEN or
- self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_MATCH_OPEN) and self.clubInfo.role == ClubDefine.Job.Creator then
- self.ui.Items.Button_Match:setVisible(true)
- end
- if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_MATCH_OPEN then
- self.ui.Items.Button_Match:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_match.png")
- end
-
- -- todo lwqcest cest海选赛
- if (self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.CLIENT_OPEN or
- self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN) and self.clubInfo.role == ClubDefine.Job.Creator then
- self.ui.Items.Button_Match:setVisible(true)
- self.ui.Items.Text:setText("赛事名:")
- end
- if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
- self.ui.Items.Button_Match:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_match_n.png")
- end
- end
-
- --初始化包间名字
- local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId) or {}
- self.ui.Items.TextField_BaoJian_Name:setText(baoJian.title or "")
-
- --箭头动画
- local action = cc.Sequence:create(cc.MoveBy:create(0.5,cc.p(0,10)),cc.MoveBy:create(0.5,cc.p(0,-10)))
- self.ui.Items.ImageView_Arrow:runAction(cc.RepeatForever:create(action))
-
- local action = cc.Sequence:create(cc.ScaleTo:create(0.4,0.95),cc.ScaleTo:create(0.4,1.2))
- self.ui.Items.ImageView_hand:runAction(cc.RepeatForever:create(action))
- self.ui.Items.ImageView_hand:setVisible(false)
-
- self:initBaoJianView()
-
- --包间开启or关闭
- local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId) or {}
- self.ui.Items.CheckBox:setSelectedState(toNumber(baoJian.is_use) == 1)
- if not self.baoJianId then
- self.ui.Items.CheckBox:setVisible(false)
- end
-
- -- CEST
- if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
- self.ui.Items.CheckBox:loadTextureBackGroundSelected("res/ui/zy_club/club_room/club_cest_baojian/club_baojian_close.png")
- self.ui.Items.CheckBox:loadTextureFrontCross("res/ui/zy_club/club_room/club_cest_baojian/club_baojian_open.png")
- self.ui.Items.CheckBox:loadTextureBackGround("res/ui/zy_club/club_room/club_cest_baojian/club_baojian_close.png")
- end
- end
-
- function ClubChangeRule:initBaoJianView()
- self.ui.Items.Layout_BaoJian:removeAllChildren()
-
- --五个包间节点
- self.baoJianList = {}
- self.baoJianListUI = {}
- self.radioManager = import("luaScript.Tools.RadioManager"):new()
- self.radioManager:setNormalColor(self.baoJianNoSelColor)
- self.radioManager:setSelectColor(cc.c4b(200,62,7,255))
-
-
- local baojians = app.club_php:getBaoJianByGameId(self.clubInfo.clubId,self.strGameId)
- for k,v in pairsByKeys(baojians) do
- table.insert(self.baoJianList,toNumber(v.baoJianId))
- end
- table.sort(self.baoJianList,function (a,b)
- if a ~= nil and b ~= nil then
- return a < b
- else
- return a < b
- end
- end)
-
- if #self.baoJianList == 0 then
- self:createBaoJianItem(1,1)
- else
- for i = 1, #self.baoJianList do
- self:createBaoJianItem(#self.baoJianList,i)
- if self.baoJianList[i] and self.baoJianList[i] == self.baoJianId then
- self.index = i
- end
- end
- end
-
- if not self.index then
- self.index = 1
- end
-
- self.ui.Items.Layout_addBaoJian:setVisible(#self.baoJianListUI ~= ClubDefine.BaoJianCount)
-
- self.radioManager:setCallback(handler(self , self.onClickBaoJianTag))
- self.radioManager:setDefault(self.index)
-
- self.ui.Items.Layout_BaoJian:requestDoLayout()
- self.ui.Items.Layout_BaoJian:doLayout()
-
- self.ui.Items.ScrollView:requestDoLayout()
- self.ui.Items.ScrollView:doLayout()
-
- self.ui.Items.ScrollView:setInnerContainerSize(self.ui.Items.ScrollView:getSize())
- runDelayWithTime(function ()
- self.ui.Items.ScrollView:jumpToLeft()
- end,0.05)
- end
-
-
- function ClubChangeRule:createBaoJianItem(totalNum,index)
- local node = self.ui.Items.CheckBox_baojian:getCopied()
- node.Items = getUIItems(node)
- if totalNum == 1 then
- local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn_single.png"
- node:loadTextureBackGroundSelected(file)
- node:loadTextureFrontCross(file)
- elseif totalNum >= 2 then
- if index == 1 then --首
- local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn_left.png"
- node:loadTextureBackGroundSelected(file)
- node:loadTextureFrontCross(file)
- elseif index == totalNum then --末端
- local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn_right.png"
- node:loadTextureBackGroundSelected(file)
- node:loadTextureFrontCross(file)
- --反向修改前一个
- if totalNum >= 2 then
- --倒数第二个
- local frontNode = self.baoJianListUI[totalNum - 1]
- local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn.png"
- frontNode:loadTextureBackGroundSelected(file)
- frontNode:loadTextureFrontCross(file)
- --第一个
- local frontNode = self.baoJianListUI[1]
- local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn_left.png"
- frontNode:loadTextureBackGroundSelected(file)
- frontNode:loadTextureFrontCross(file)
- end
- elseif index > 1 and index < totalNum then
- local file = "res/ui/zy_club/club_room/club_baojian/club_baojian_top_btn.png"
- node:loadTextureBackGroundSelected(file)
- node:loadTextureFrontCross(file)
- end
- end
-
- -- todo lwqcest
- if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
- node.Items.Text_Name:setText("赛事"..index)
- else
- node.Items.Text_Name:setText("包间"..index)
- end
-
- node.Items.Text_Name:setTextColor(self.baoJianNoSelColor)
- self.radioManager:addItem(node,index)
- self.ui.Items.Layout_BaoJian:addChild(node)
- self.baoJianListUI[index] = node
- end
-
- function ClubChangeRule:onClickAddBaoJian()
- playBtnEffect()
-
- self:createBaoJianItem(#self.baoJianListUI + 1,#self.baoJianListUI + 1)
- if #self.baoJianListUI == ClubDefine.BaoJianCount then
- self.ui.Items.Layout_addBaoJian:setVisible(false)
- end
- self.ui.Items.Layout_BaoJian:requestDoLayout()
- self.ui.Items.Layout_BaoJian:doLayout()
-
- self.ui.Items.ScrollView:requestDoLayout()
- self.ui.Items.ScrollView:doLayout()
-
- self.ui.Items.ScrollView:setInnerContainerSize(self.ui.Items.ScrollView:getSize())
-
- runDelayWithTime(function ()
- self.ui.Items.ScrollView:jumpToRight()
- self.index = #self.baoJianListUI
- self.radioManager:setDefault(self.index)
- end,0.05)
- end
-
- function ClubChangeRule:initButton()
- --关闭
- self.ui.Items.Button_close:registerClick(handler(self , self.onClose))
-
- --保存
- self.ui.Items.Button_Create:registerClick(handler(self , self.onSave))
-
- self.ui.Items.Button_jia:registerClick(handler(self, self.onClickJuShuAdd))
-
- self.ui.Items.Button_jian:registerClick(handler(self, self.onClickJuShuJian))
-
- self.ui.Items.Button_Match:registerClick(handler(self, self.onClickMatchSet))
-
- self.ui.Items.ButtonAdd:registerClick(handler(self, self.onClickAddBaoJian))
-
- self.ui.Items.CheckBox:registerClick(function ()
- self.isOpen = self.ui.Items.CheckBox:getSelectedState() and 0 or 1
- self.ui.Items.CheckBox:setSelectedState(not self.ui.Items.CheckBox:getSelectedState())
- logD("self.baoJianId",self.baoJianId)
- local txt = self.isOpen == 1 and "是否开启包间" or "是否关闭包间"
- if app.club_php:getCestIsOpen(self.clubInfo.clubId) then
- txt = self.isOpen == 1 and "是否开启赛事" or "是否关闭赛事"
- end
- if self.baoJianId then
- showConfirmDialog(txt,function ()
- app.club_php:requestActiveRule(self.clubInfo.clubId,self.isOpen,self.baoJianId)
- end,function ()end)
- end
- end)
-
- self.ui.Items.ScrollView_rule_club:addEventListener(function (obj, type)
- local inner = self.ui.Items.ScrollView_rule_club:getInnerContainer()
- local innerSize = inner:getContentSize()
- local pos = inner:getPosition()
- local h = innerSize.height - self.ui.Items.ScrollView_rule_club:getContentSize().height
- if h>0 then
- if pos.y>=-h + 10 then
- self.ui.Items.ImageView_Arrow:setVisible(false)
- else
- self.ui.Items.ImageView_Arrow:setVisible(true)
- end
- end
- end)
- end
-
- function ClubChangeRule:intBindEvent()
- --绑定修改玩法成功回调
- self:bindEvent(app.club_php , GAME_EVENT.CLUB_CHANGE_RULE , handler(self , self.onChangeRuleCallback));
-
- --请求茶馆玩法回调
- self:bindEvent(app.club_php , GAME_EVENT.CLUB_GAME_RULE , handler(self , self.onUpdateGameRule))
-
- --创建界面修改支付模式通知这里更新显示
- self:bindEvent(app, "onChangePayMode", handler(self, self.updateJushuData));
-
- --绑定比赛开关
- self:bindEvent(app.club_php , GAME_EVENT.CLUB_SET , handler(self , self.onSetSuccess));
-
- --激活包间成功后关闭
- self:bindEvent(app.club_php , GAME_EVENT.CLUB_ACTIVE_RULE , handler(self , self.onActiveRuleResponse))
- --
- self:bindEvent(app , GAME_EVENT.UPDATE_SCOREVIEW_SIZE , handler(self , self.updateScollowViewSize))
- -- 支付方式发生改变时更新房卡消耗
- if CRConfig then
- self.ui:bindEvent(app, CRConfig.CREATE_ROOM_DEDUCTRULE_CHANGE, handler(self, self.updateDiamondCost))
- end
- end
-
- function ClubChangeRule:onClose()
- playBtnCloseEffect()
- self:removeFromParent()
- end
-
-
- function ClubChangeRule:onActiveRuleResponse()
- self.ui.Items.CheckBox:setSelectedState(not self.ui.Items.CheckBox:getSelectedState())
- end
-
-
-
- --修改玩法回调
- function ClubChangeRule:onChangeRuleCallback(data)
- if not data or (self.clubInfo.clubId~=data.clubId) then
- return
- end
- local clubId = data.clubId
- local baoJianId = data.baoJianId
- local baoJian = app.club_php:getBaoJian(clubId,baoJianId)
-
- --修改内存数据
- self.baoJianList[self.index] = baoJianId
- self.baoJianId = baoJianId
- self._baoJianName = baoJian.title
-
- --刷新当前标签
- self:onClickBaoJianTag(self.index)
- end
-
- -- 当比赛一关,其他和比赛有关的界面需要关闭
- function ClubChangeRule:onSetSuccess(data)
- if not data or not data.setType then
- return
- end
- if data.setType == GAME_CLUB_SET_STATE.Math_Switch then
- self.ui.Items.Button_Match:setVisible(false)
- if app.config.ModuleConfig.IsSupportDaLianMeng and self.clubInfo.isArena ~= 0 then
- if self.clubInfo.isArena == 2 and self.clubInfo.role == ClubDefine.Job.Creator then
- self.ui.Items.Button_Match:setVisible(true)
- end
- end
- end
- end
-
- --更新游戏类型
- function ClubChangeRule:onUpdateGameRule(event)
- self.gameRules = event.result or {}
-
- if table.nums(self.gameRules) == 0 then
- return
- end
-
- --游戏类型
- local gameTypes = {}
- for strGameId,v in pairs(self.gameRules) do
- local gameConfig = getSubGameConfig(tonumber(strGameId))
- if gameConfig then
- gameTypes[gameConfig.belongType] = gameConfig.belongType
- end
- end
-
- local selectGameType
- local gameConfig = getSubGameConfig(tonumber(self.realGameId or 0))
- if gameConfig then
- selectGameType = gameConfig.belongType
- end
-
- --先清空当前类型Item
- self.gameTypeItem = {}
- for k, gameType in pairsByKeys(gameTypes) do
- self.ui.Items["Button_leixing_"..gameType]:registerClick(function ()
- playBtnTagEffect()
- if selectGameType~= gameType then
- selectGameType = gameType
- self.strGameId = nil --切换标签重置gameid
- self.ruleId = nil
- self:setGameTypeBtnStatus(gameType)
- self:updateGameRuleItem(gameType)
- self:updateRuleUI()
- --self:onGameItemClicked(tostring(strGameId), nil, gameType)
- end
- end)
- self.gameTypeItem[gameType] = self.ui.Items["Button_leixing_"..gameType]
-
- --没有类型设置默认为第一个
- if not selectGameType then
- selectGameType = gameType
- end
- end
-
- --设置左边游戏类型按钮状态
- self:setGameTypeBtnStatus(selectGameType)
- self:updateGameRuleItem(selectGameType)
- self:updateRuleUI()
- end
-
- --更新条目选项
- function ClubChangeRule:updateGameRuleItem(gameType,bNotJump)
- local gameIDs = {}
- local gameList = app.serverConfigs.subGameList
- if self.noActiveGames then
- gameIDs = self.noActiveGames
- else
- --logD("ClubChangeRule:updateGameRuleItem:",table.tostring(self.gameRules))
- --[[for strGameId,v in pairs(self.gameRules) do
- local gameConfig = getSubGameConfig(tonumber(strGameId))
- if gameConfig and gameConfig.belongType==gameType and v.status ~= 3 then
- table.insert(gameIDs,strGameId)
- end
- end
- table.sort(gameIDs, function (aGameId,bGameId)
- local gameA = gameList[tonumber(aGameId)]
- local gameB = gameList[tonumber(bGameId)]
- return gameA.sortIndex<gameB.sortIndex
- end)--]]
- table.insert(gameIDs,self.strGameId)
- end
-
- local mScorllView = self.ui.Items.ScrollView_game;
- mScorllView:hideAllBar()
-
- local mListView = self.ui.Items.Layout_scrollview_game
- mListView:removeAllChildren()
-
- local uiTemplate = self.ui.Items.Layout_game_item
-
- for k,strGameId in pairsByKeys(gameIDs) do
- if not self.strGameId then --没有Id设置默认的
- self.strGameId = strGameId
- end
- local ruleID = 0
- if toNumber(strGameId) > 10000 then
- ruleID = math.floor(toNumber(strGameId)%10000)
- strGameId = math.floor(toNumber(strGameId)/10000)
- end
- local gameConfig = getSubGameConfig(toNumber(strGameId))
- if gameConfig then
- if gameConfig.bSingleGame then
- local uiItem = uiTemplate:getCopied()
- uiItem.Items = getUIItems(uiItem)
- mListView:addChild(uiItem)
- --隐藏更新标签
- uiItem.Items.ImageView_update_icon:setVisible(false)
- -- 游戏名字按钮
- uiItem.Items.Button_game:registerClick(function ()
- self.defaultValues = {}
- playBtnTagEffect()
- if toNumber(self.strGameId) ~= tonumber(strGameId) or self.ruleId ~= ruleID then
- self:onGameItemClicked(tostring(strGameId), ruleID, gameType)
- end
- end)
-
- if tonumber(self.realGameId) == tonumber(strGameId) and self.ruleId == ruleID then
- uiItem.Items.Button_game:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_btn_sel.png")
- uiItem.Items.Text_GameName:setVisible(false)
- uiItem.Items.Text_GameName_sel:setVisible(true)
- else
- uiItem.Items.Button_game:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_btn_nor.png")
- uiItem.Items.Text_GameName:setVisible(true)
- uiItem.Items.Text_GameName_sel:setVisible(false)
- end
-
- uiItem.Items.Text_GameName:setString(gameConfig.GameType[ruleID] or "")
- uiItem.Items.Text_GameName_sel:setString(gameConfig.GameType[ruleID] or "")
-
- --刷新layout布局
- uiItem:requestDoLayout()
- uiItem:doLayout()
- else
- local uiItem = uiTemplate:getCopied()
- uiItem.Items = getUIItems(uiItem)
- if toNumber(self.strGameId) == toNumber(strGameId) then
- uiItem.Items.Button_game:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_btn_sel.png")
- uiItem.Items.Text_GameName:setVisible(false)
- uiItem.Items.Text_GameName_sel:setVisible(true)
- else
- uiItem.Items.Button_game:loadTextureNormal("res/ui/zy_dating/chuanjian/chuangjian_btn_nor.png")
- uiItem.Items.Text_GameName:setVisible(true)
- uiItem.Items.Text_GameName_sel:setVisible(false)
- end
- --隐藏更新标签
- uiItem.Items.ImageView_update_icon:setVisible(false)
- -- 游戏名字按钮
- uiItem.Items.Button_game:registerClick(function ()
- self.defaultValues = {}
- playBtnTagEffect()
- if self.strGameId ~= strGameId then
- self:onGameItemClicked(tostring(strGameId), nil, gameType)
- end
- end)
-
- --添加规则
- local uiRuleTemplate = self.ui.Items.Layout_rule_item
- local rules = self.gameRules[tostring(self.realGameId)].gamerule
- if not self.ruleId then --默认规则 2个玩法以上时服务器的key变成了字符
- self.ruleId = rules[1] and rules[1].rulekey or rules["1"].rulekey--rules["1"].rulekey or rules[1].rulekey
- end
-
- if table.nums(rules) > 1 and tonumber(self.realGameId) == tonumber(strGameId) then
- for _,v in pairsByKeys(rules) do
- local uiRuleItem = uiRuleTemplate:getCopied()
- uiRuleItem.Items = getUIItems(uiRuleItem)
- if self.ruleId ~= v.rulekey then
- uiRuleItem.Items.ImageView_bg_select:setVisible(false)
- uiRuleItem.Items.Text_rule_name:setColor(self.normalColor)
- local config = uiRuleItem.Items.Text_rule_name:getFontConfig()
- config.fontSize = 32
- uiRuleItem.Items.Text_rule_name:setFontConfig(config)
- else
- uiRuleItem.Items.Text_rule_name:setColor(self.selectColor)
- end
-
- --玩法名
- uiRuleItem.Items.Text_rule_name:setText(v.rulename)
- --点击事件
- uiRuleItem.Items.Layout_touch:registerClick(function ()
- playBtnTagEffect()
- if self.ruleId~= v.rulekey then
- self.ruleId = v.rulekey
- self:updateGameRuleItem(gameType, true) --ljx添加 二级游戏菜单不跳转到最顶部
- self:updateRuleUI()
- end
- end)
- uiItem:addChild(uiRuleItem)
- end
- --刷新layout布局
- uiItem:requestDoLayout()
- uiItem:doLayout()
- end
-
- local cfg = getSubGameConfig(strGameId)
- uiItem.Items.Text_GameName:setString(cfg.gameName or "")
- uiItem.Items.Text_GameName_sel:setString(cfg.gameName or "")
-
- mListView:addChild(uiItem)
- end
- end
- end
-
- mListView:requestDoLayout()
- mListView:doLayout()
- local layoutSize = mListView:getContentSize()
- mScorllView:setInnerContainerSize(layoutSize)
-
- if bNotJump then
- return
- end
- mScorllView:jumpToTop()
- end
-
- function ClubChangeRule:onGameItemClicked(gameId, ruleId, gameType)
- self.strGameId = gameId
- local config = getSubGameConfig(tonumber(gameId))
- if config and config.bSingleGame then
- self.strGameId = tostring(tonumber(gameId) * 10000 + tonumber(ruleId))
- end
- self.ruleId = ruleId
- self.realGameId = toNumber(self.strGameId)
- if toNumber(self.strGameId) > 10000 then
- self.realGameId = math.floor(toNumber(self.strGameId)/10000)
- end
- self.baoJianList = {}
- local baojians = app.club_php:getBaoJianByGameId(self.clubInfo.clubId,self.strGameId)
- for k,v in pairsByKeys(baojians) do
- table.insert(self.baoJianList,toNumber(v.baoJianId))
- end
- table.sort(self.baoJianList,function (a,b)
- if a ~= nil and b ~= nil then
- return a < b
- else
- return a < b
- end
- end)
- self.radioManager:setDefault(1)
- self:initBaoJianView()
- end
-
- --更新选项UI
- function ClubChangeRule:updateRuleUI()
- local mScorllView = self.ui.Items.ScrollView_rule_club
- mScorllView:hideAllBar()
- mScorllView:removeAllChildren()
-
- if self.ruleView then
- self.ruleView = nil
- end
- ruleId = tonumber(self.ruleId)
- gameId = tonumber(self.realGameId)
-
- local ruleConfig = getSubGameCreateRuleConfig(gameId)
-
- if ruleConfig then
- self.ruleView = import("core.luaScript.Views.CreateRoom.CreateRoomItemNew"):new(ruleConfig, self.defaultValues, gameId, ruleId, true)
- mScorllView:addChild(self.ruleView)
- self:updateScollowViewSize()
- else
- local ruleClass = getSubGameCreateRoomUi(gameId, ruleId)
- if ruleClass then
- self.ruleView = import(ruleClass):new(self.defaultValues, ruleId)
- mScorllView:addChild(self.ruleView)
- self:updateScollowViewSize()
-
- -- todo lwqcest
- if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
- if type(self.ruleView.onShowCestView) == "function" then
- self.ruleView:onShowCestView()
- end
- end
- end
- end
-
- self:initJuShu()
-
- mScorllView:jumpToTop()
- end
-
- function ClubChangeRule:updateScollowViewSize()
- local mScorllView = self.ui.Items.ScrollView_rule_club
- local layoutSize = self.ruleView:getLayoutContentSize()
- if layoutSize then
- mScorllView:setInnerContainerSize(layoutSize)
- end
- local innerSize = mScorllView:getInnerContainer():getContentSize()
- if innerSize.height > mScorllView:getContentSize().height then
- self.ui.Items.ImageView_Arrow:setVisible(true)
- else
- self.ui.Items.ImageView_Arrow:setVisible(false)
- end
- end
-
-
- --初始化局数
- function ClubChangeRule:initJuShu()
- if self.realGameId then
- local gameConfig = getSubGameConfig(tonumber(self.realGameId))
- if gameConfig then
- self.curGameCount = app.serverConfigs:getSubGameCostInfo(self.realGameId)
- if self.curGameCount and #self.curGameCount > 0 then
- -- 局数最大索引
- self.maxSelJushuIndex = #self.curGameCount
-
- -- 从后台数据中读取默认值
- local defaultValue
- if self.defaultValues and table.nums(self.defaultValues) > 0 then
- defaultValue = self.defaultValues.jushu or self.curGameCount[1].round or 0
- else
- defaultValue = gameConfig.defaultRound or self.curGameCount[1].round or 0
- end
-
- --找到当前选中的局数在配置中的下标
- for i,v in pairs(self.curGameCount) do
- if v.round == tonumber(defaultValue) then
- self.curSelJushuIndex = i
- end
- end
- if not self.curSelJushuIndex then
- self.curSelJushuIndex = 1
- end
- self:updateJushuData(self.curSelJushuIndex)
- else
- if gameConfig.gameCount then
- self.curGameCount = gameConfig.gameCount
- local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId)
- local jushu = nil
- if baoJian then
- jushu = baoJian.gameNum
- end
- local gameConfig = getSubGameConfig(tonumber(self.realGameId))
- local defaultValue = gameConfig.gameCount[1]
- if gameConfig.bSingleGame then
- defaultValue = jushu or gameConfig.gameCount[gameConfig.defaultJushuIndex[self.ruleId] or 1]
- else
- defaultValue = jushu or gameConfig.gameCount[gameConfig.defaultJushuIndex] or gameConfig.gameCount[1]
- end
- --找到当前选中的局数在配置中的下标
- for i,v in pairs(gameConfig.gameCount) do
- if v == tonumber(defaultValue) then
- self.curSelJushuIndex = i
- end
- end
- if not self.curSelJushuIndex then
- self.curSelJushuIndex = 1
- defaultValue = gameConfig.gameCount[1]
- end
- self:updateJushuData(defaultValue)
- end
- end
- end
- end
- end
-
- -- 更新房卡消耗
- function ClubChangeRule:updateDiamondCost()
- if self.ruleView then
- local costCard = self.ruleView:getCreateRoomCost(self.curRound)
- self.ui.Items.Text_Diamond:setText("x "..costCard)
- end
- end
-
- --刷新局数数据显示
- function ClubChangeRule:updateJushuData(jushu)
- local severConfig = app.serverConfigs:getSubGameCostInfo(self.realGameId)
- if severConfig then
- if not self.curSelJushuIndex
- or not self.maxSelJushuIndex
- or tonumber(self.curSelJushuIndex) <= 0
- or tonumber(self.curSelJushuIndex) > tonumber(self.maxSelJushuIndex) then
- return
- end
- jushu = self.curGameCount[self.curSelJushuIndex].round or 0
- else
- if not tonumber(jushu) then
- if self.curGameCount and self.curSelJushuIndex then
- jushu = self.curGameCount[self.curSelJushuIndex]
- end
- end
- end
- self.curRound = jushu
- self.ui.Items.Text_jushu:setText(jushu.."局")
-
- self:updateDiamondCost()
- end
-
- --局数按钮加
- function ClubChangeRule:onClickJuShuAdd()
- if not self.curSelJushuIndex then
- return
- end
-
- local severConfig = app.serverConfigs:getSubGameCostInfo(self.realGameId)
- if severConfig then
- if self.curSelJushuIndex >= self.maxSelJushuIndex then
- return
- end
- playBtnEffect()
- self.curSelJushuIndex = self.curSelJushuIndex + 1
- self:updateJushuData(self.curSelJushuIndex)
- else
- playBtnEffect()
- self.curSelJushuIndex = self.curSelJushuIndex + 1
- if tonumber(self.strGameId) == 2 and (self.ruleId == 1 or self.ruleId == 3) then
- if self.curSelJushuIndex > 2 then
- self.curSelJushuIndex = 2
- return
- end
- end
- if self.curGameCount and self.curGameCount[self.curSelJushuIndex] then
- self:updateJushuData(self.curGameCount[self.curSelJushuIndex])
- else
- self.curSelJushuIndex = self.curSelJushuIndex - 1
- end
- end
- end
- --局数按钮减
- function ClubChangeRule:onClickJuShuJian()
- if not self.curSelJushuIndex then
- return
- end
-
- local severConfig = app.serverConfigs:getSubGameCostInfo(self.realGameId)
- if severConfig then
- playBtnEffect()
- if self.curSelJushuIndex <= 1 then
- return
- end
- self.curSelJushuIndex = self.curSelJushuIndex - 1
- self:updateJushuData(self.curSelJushuIndex)
- else
- playBtnEffect()
- self.curSelJushuIndex = self.curSelJushuIndex - 1
- --兼容下原有的局数和新的局数配置不等时候导致修改不了的问题
- if self.curSelJushuIndex <= 0 then
- self.curSelJushuIndex = 1
- end
- if self.curGameCount and self.curGameCount[self.curSelJushuIndex] then
- self:updateJushuData(self.curGameCount[self.curSelJushuIndex])
- else
- self.curSelJushuIndex = self.curSelJushuIndex + 1
- end
- end
- end
-
- --比赛设置
- function ClubChangeRule:onClickMatchSet()
- playBtnEffect()
- self.ui.Items.ImageView_hand:setVisible(false)
- local function callBack(data)
- self.arena = data
- end
- if self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_MATCH_OPEN then
- local view = import("luaScript.Views.Club.Match.ClubCreateRoomChongBangSet"):new(self.clubInfo.clubId,self.baoJianId,self.realGameId,self.arena,callBack)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- elseif self.clubInfo.isArena == ClubDefine.MATCH_SWITCH.PEOPLE_CEST_OPEN then
- local view = import("luaScript.Views.Club.Cest.ClubCestCreateRoomChongBangSet"):new(self.clubInfo.clubId,self.baoJianId,self.realGameId,self.arena,callBack)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- else
- local view = import("luaScript.Views.Club.Match.ClubCreateRoomMatchSet"):new(self.clubInfo.clubId,self.baoJianId,self.arena,callBack)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
-
- -- todo lwqcest
- -- 先写死,进入到cest
-
- end
-
- --点击选择游戏类型
- function ClubChangeRule:setGameTypeBtnStatus(curGameType)
- for gameType,item in pairsByKeys(self.gameTypeItem) do
- local gameImgName = ""
- if tonumber(gameType) == tonumber(curGameType) then
- item:setBright(false)
- else
- item:setBright(true)
- end
- end
- end
-
- function ClubChangeRule:onSave()
- playBtnEffect()
-
- --未选择任何玩法时,不做处理
- if not self.ruleView then
- showTooltip("请先选择玩法!");
- return
- end
-
- local baoJianName = self.ui.Items.TextField_BaoJian_Name:getText()
-
- self._baoJianName = baoJianName
- local function onClickOk()
- if not self.ruleView then
- showTooltip("请先选择玩法!");
- return
- end
- local severConfig = app.serverConfigs:getSubGameCostInfo(self.realGameId)
- local jushu
- local strRuleInfo
- if severConfig then
- jushu = self.curGameCount[self.curSelJushuIndex].round
- _, strRuleInfo = self.ruleView:getRuleResult()
- else
- jushu, strRuleInfo = self.ruleView:getRuleResult()
- jushu = self.curGameCount[self.curSelJushuIndex]
- end
-
- if not strRuleInfo or type(strRuleInfo) ~= "string" then
- showTooltip("玩法选择失败,请重新选择!");
- return
- end
-
- local stRuleInfo = json.decode(strRuleInfo)
- if stRuleInfo then
- stRuleInfo.jushu = jushu
- strRuleInfo = json.encode(stRuleInfo)
- end
-
- local isDelete = 0;
- local gameId = self.strGameId
- --排名赛模式下,校验排名赛规则是否设置
- if self.arena == "" and app.club_php:getMatchIsOpen(self.clubInfo.clubId) then
- showTooltip("请设置排名赛规则!")
- self.ui.Items.ImageView_hand:setVisible(true)
- return
- end
-
- --海选模式下,校验海选赛规则是否设置
- if self.arena == "" and app.club_php:getCestIsOpen(self.clubInfo.clubId) then
- showTooltip("请设置赛事规则!")
- self.ui.Items.ImageView_hand:setVisible(true)
- return
- end
- app.club_php:requestChangeRule(self.clubInfo.clubId,self.baoJianId and self.baoJianId or 0,gameId,jushu,strRuleInfo,isDelete,self.arena,self._baoJianName);
- end
-
- local function onClickCancel()
-
- end
-
- --防止暴力点击
- self.ui.Items.Button_Create:setTouchEnabled(false)
- self.ui.Items.Button_Create:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
- self.ui.Items.Button_Create:setTouchEnabled(true)
- end)))
-
- --包间开启or关闭
- local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId) or {}
- --没有包间ID 证明是新增,新增或者存在的包间但关闭了,不走二次确认
- if not self.baoJianId or self.baoJianId and toNumber(baoJian.is_use) == 0 then
- onClickOk()
- else
- local view = import("luaScript.Views.Club.ClubBaoJianChangeTip"):new(onClickOk,onClickCancel)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
- end
-
- function ClubChangeRule:onClickBaoJianTag(value,node)
- self.ui.Items.ImageView_hand:setVisible(false)
- self.baoJianId = self.baoJianList[value]
-
- self._baoJianName = ""
-
- local baoJian = app.club_php:getBaoJian(self.clubInfo.clubId,self.baoJianId)
- if baoJian then
- self.ui.Items.TextField_BaoJian_Name:setText(baoJian.title or "")
- self.ui.Items.CheckBox:setSelectedState(toNumber(baoJian.is_use) == 1)
- else
- self.ui.Items.TextField_BaoJian_Name:setText("")
- self.ui.Items.CheckBox:setSelectedState(false)
- end
- if not self.baoJianId then
- self.ui.Items.CheckBox:setVisible(false)
- else
- self.ui.Items.CheckBox:setVisible(true)
- end
-
- if baoJian and baoJian.strGameRule then
- local strGameRule = json.decode(baoJian.strGameRule)
- self.ruleId = tonumber(strGameRule.gamerule)
- end
-
- self.index = value
-
- if baoJian then
- self.arena = baoJian.arena
- else
- self.arena = ""
- end
- if self.strGameId and self.baoJianId and self.baoJianId > 0 then
- self.defaultValues = json.decode(self.clubInfo.baoJians[tonumber(self.baoJianId)].strGameRule or "") or {}
- else
- self.defaultValues = {}
- end
- local selectGameType
- if self.gameRules then
- local gameConfig = getSubGameConfig(tonumber(self.realGameId or 0))
- if gameConfig then
- selectGameType = gameConfig.belongType
- end
- self:updateGameRuleItem(selectGameType,true)
- end
-
- self:updateRuleUI()
- end
-
- return ClubChangeRule
|