-- local MatchDefined = require("luaScript.Views.Match.Constant.MatchDefined") local MatchInfo = class("MatchInfo", cc.UIView) local RuleText = { [1] = { "赛事名称:%s", "报名时间:%s", "比赛时间:%s", "报名条件:%s", "赛事玩法:%s", }, [2] = { "使用'定局积分'赛制,同一轮比赛中对手相同,打完规定局数后,同桌最高分晋级。" }, [3] = { "第一名: %s", "第二名: %s", "第三名: %s" }, } function MatchInfo:ctor(matchInfo) MatchInfo.super.ctor(self) local ui = loadUI("res/ui/ui_match/ui_match_rule.ui") self.ui = ui self:addChild(ui) self.matchInfo = matchInfo end function MatchInfo:onEnter() MatchInfo.super.onEnter(self) self:init(); end function MatchInfo:init() self.ui.Items.Button:registerClick(function () self:onClickClose() end) self.ui.Items.Button_Sign:registerClick(function () playBtnEffect() local cost = json.decode(self.matchInfo.signupInfo) local costStr="" for n,signInfos in pairs(cost.signInfo) do for _,info in pairs(signInfos) do if info.type==MatchDefined.CURRENCY_TYPE.Card then costStr=costStr.."房卡x"..info.value elseif info.type==MatchDefined.CURRENCY_TYPE.Coin then costStr=costStr.."金币x"..info.value -- elseif info.type==MatchDefined.CURRENCY_TYPE.Money then -- costStr=costStr.."红包"..info.value.."元" end end if n~=#cost.signInfo then costStr=costStr.." 或 " end end local function btnCallbackOk() app.match:signUp(self.matchInfo); end local function btnCallbackCancel() end if not app.subGameManager:isInstaller(tonumber(self.matchInfo.gameId)) or app.subGameManager:isNeedUpdate(tonumber(self.matchInfo.gameId)) then --未下载时提示下载 requestDownloadSubGame(tonumber(self.matchInfo.gameId), function () showTooltip("下载完成") end, true) return; end showConfirmDialog("确定花费["..costStr.."]报名?",btnCallbackOk,btnCallbackCancel) end) if not self.matchInfo then self.ui.Items.Button_Sign:setVisible(false) end self.ruleButtonList = {} self.ui.Items.Layout_Content:setVisible(false) self.ui.Items.Layout_Item_Award:setVisible(false) self:initLayout() for i = 1, 3 do local btnName = string.format("Button_%d",i) local layoutName = string.format("Layout_%d",i) --init if i == 1 then self.ui.Items[btnName]:setBright(true) self.ui.Items[layoutName]:setVisible(true) else self.ui.Items[btnName]:setBright(false) self.ui.Items[layoutName]:setVisible(false) end --data self.ruleButtonList[i] = self.ui.Items[btnName]; self.ui.Items[btnName]:setTag(i) self.ui.Items[btnName]:registerClick(function () self:onClickType(i) end) end end function MatchInfo:onClickType(tag) playBtnEffect() for k,v in pairs(self.ruleButtonList) do local layoutName = string.format("Layout_%d",k) if v:getTag() == tag then v:setBright(true) self.ui.Items[layoutName]:setVisible(true) else v:setBright(false) self.ui.Items[layoutName]:setVisible(false) end end end function MatchInfo:initLayout() local matchInfo = app.match.matchInfo for i = 1, 3 do local name = string.format("ScrollView_"..i) local uiScrollView = self.ui.Items[name]; uiScrollView:getInnerContainer():setAutoSize(true) if i==1 then self.ui.Items.ImageView_Macth_Info:loadTexture("res/ui/zy_match/match_"..matchInfo.matchIndex..".png") -- local cost = json.decode(self.matchInfo.signupInfo) -- local costStr="" -- for n,signInfos in pairs(cost.signInfo) do -- for _,info in pairs(signInfos) do -- if info.type==13 then -- costStr=costStr.."房卡x"..info.value -- elseif info.type==1 then -- costStr=costStr.."金币x"..info.value -- end -- end -- if n~=#cost.signInfo then -- costStr=costStr.." 或 " -- end -- end -- local tab={ -- self.matchInfo.matchName, -- "全天", -- "人满开赛", -- costStr, -- "", -- } -- for k,v in pairs(RuleText[i]) do -- local uiContent = self:createContent(string.format(v,tab[k])) -- uiScrollView:addChild(uiContent) -- end elseif i==2 then self.ui.Items.ImageView_Macth_Rule:loadTexture("res/ui/zy_match/match_"..matchInfo.matchIndex.."_rule.png") -- for k,v in pairs(RuleText[i]) do -- local uiContent = self:createContent(v) -- uiScrollView:addChild(uiContent) -- end else -- local str="" local rewards = matchInfo.rewards for j=1,3 do if rewards[j] then local awardStr = "" local tp = MatchDefined.CURRENCY_TYPE.Card for k,v in pairs(rewards[j]) do tp=v.type if v.type==MatchDefined.CURRENCY_TYPE.Card then --房卡 awardStr=awardStr.."房卡x"..v.value.." " elseif v.type==MatchDefined.CURRENCY_TYPE.Coin then --金币 awardStr=awardStr.."金币x"..v.value.." " elseif v.type==MatchDefined.CURRENCY_TYPE.Money then awardStr=awardStr.."红包"..v.value.."元" end end local uiContent = self:createContentTwo(j,awardStr,tp) uiScrollView:addChild(uiContent) else end end end uiScrollView:hideAllBar() uiScrollView:jumpToTopOnSizeChanged() end end function MatchInfo:createContent(text) local ui = self.ui.Items.Layout_Content:getCopied() ui.Items = getUIItems(ui); ui.Items.Text_Content:setText(text) ui:requestDoLayout() ui:doLayout() return ui end function MatchInfo:createContentTwo(rank,award,tp) local ui = self.ui.Items.Layout_Item_Award:getCopied() ui.Items = getUIItems(ui); if rank<=3 then ui.Items.Text_Rank_Award:setVisible(false) ui.Items.ImageView_Rank_Award:loadTexture("match_common_rank"..rank..".png",cc.TextureResType.plistType) else ui.Items.ImageView_Rank_Award:setVisible(false) ui.Items.Text_Rank_Award:setString(rank) end if tp==MatchDefined.CURRENCY_TYPE.Money then ui.Items.ImageView_Item_Icon:loadTexture("match_common_icon_hongbao.png",cc.TextureResType.plistType) ui.Items.ImageView_Item_Icon:setScale(0.5) end ui.Items.Text_Num:setString(award) ui:requestDoLayout() ui:doLayout() return ui end function MatchInfo:onClickClose() playBtnCloseEffect() self:removeFromParent() end return MatchInfo