-- 竞技场:匹配 local ArenaMatchUI = class("ArenaMatchUI", BaseUI) function ArenaMatchUI:isFullScreen() return true end function ArenaMatchUI:showCommonBG() return false end function ArenaMatchUI:getPrefabPath() return "assets/prefabs/ui/arena/arena_match_ui.prefab" end function ArenaMatchUI:onPressBackspace() self:closeUI() end function ArenaMatchUI:ctor(isBack) self.isBack = isBack-- 是否是返回到匹配结果界面 end function ArenaMatchUI:onCover() end function ArenaMatchUI:onReshow() end function ArenaMatchUI:onClose() if self.waitSid then ModuleManager.BattleManager:unscheduleGlobal(self.waitSid) end if self.countdownSid then ModuleManager.BattleManager:unscheduleGlobal(self.countdownSid) end end function ArenaMatchUI:onLoadRootComplete() local uiMap = self.root:genAllChildren() -- 匹配等待页 self.matchLoading = uiMap["arena_match_ui.match_loading"] self.txSeason = uiMap["arena_match_ui.match_loading.tx_season"] self.txLoading = uiMap["arena_match_ui.match_loading.tx_loading"] self.btnCancel = uiMap["arena_match_ui.match_loading.btn_cancel"] self.txCancel = uiMap["arena_match_ui.match_loading.btn_cancel.tx_cancel"] -- 匹配结果页 self.matchResult = uiMap["arena_match_ui.match_result"] self.btnClose = uiMap["arena_match_ui.match_result.btn_close"] -- 对手信息 self.matchAvatar = CellManager:addCellComp(uiMap["arena_match_ui.match_result.match.info.player_head_cell"], GConst.TYPEOF_LUA_CLASS.PLAYER_HEAD_CELL) self.matchTxName = uiMap["arena_match_ui.match_result.match.info.tx_name"] self.matchTxLevel = uiMap["arena_match_ui.match_result.match.info.tx_level"] self.matchGrading = uiMap["arena_match_ui.match_result.match.arena_grading_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.ARENA_GRADING_CELL) self.matchHeroFormationComp = uiMap["arena_match_ui.match_result.match.formation.hero_formation_comp"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_FORMATION_COMP) -- 自己信息 self.selfAvatar = CellManager:addCellComp(uiMap["arena_match_ui.match_result.self.info.player_head_cell"], GConst.TYPEOF_LUA_CLASS.PLAYER_HEAD_CELL) self.selfTxName = uiMap["arena_match_ui.match_result.self.info.tx_name"] self.selfTxLevel = uiMap["arena_match_ui.match_result.self.info.tx_level"] self.selfGrading = uiMap["arena_match_ui.match_result.self.arena_grading_cell"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.ARENA_GRADING_CELL) self.selfHeroFormationComp = uiMap["arena_match_ui.match_result.self.formation.hero_formation_comp"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_FORMATION_COMP) -- 功能按钮 self.btnStart = uiMap["arena_match_ui.match_result.btn_start"] self.imgCost = uiMap["arena_match_ui.match_result.btn_start.cost.img_cost"] self.txStart = uiMap["arena_match_ui.match_result.btn_start.tx_start"] self.txConst = uiMap["arena_match_ui.match_result.btn_start.cost.tx_cost"] self.btnRematch = uiMap["arena_match_ui.match_result.btn_rematch"] self.txRematch = uiMap["arena_match_ui.match_result.btn_rematch.tx_rematch"] self.txFreeCountdown = uiMap["arena_match_ui.match_result.btn_rematch.tx_free_countdown"] self.imgAd = uiMap["arena_match_ui.match_result.btn_rematch.img_ad"] self.btnFormation = uiMap["arena_match_ui.match_result.btn_formation"] self.txFormation = uiMap["arena_match_ui.match_result.btn_formation.tx_formation"] self.btnCancel:addClickListener(function() self:closeUI() end) self.btnClose:addClickListener(function() self:closeUI() end) self.btnStart:addClickListener(function() ModuleManager.ArenaManager:reqChallenge() self:closeUI() end) self.btnRematch:addClickListener(function() self:onClickRematch() end) self.btnFormation:addClickListener(function() UIManager:showUI("app/ui/arena/arena_formation_ui", GConst.BattleConst.FORMATION_TYPE.ARENA_ATTACK) self:closeUI() end) self:bind(DataManager.ArenaData, "isDirty", function() self:showMatchResult() end) end function ArenaMatchUI:onRefresh() if DataManager.ArenaData:getMatchInfo() == nil then ModuleManager.ArenaManager:reqMatch() end if self.isBack and DataManager.ArenaData:getMatchInfo() ~= nil then self:showMatchResult() else self:showMatchLoading() end end -- 展示匹配等待页 function ArenaMatchUI:showMatchLoading() self.matchLoading:setActive(true) self.matchResult:setActive(false) self.txSeason:setText(I18N:getGlobalText(I18N.GlobalConst.ARENA_DESC_21, DataManager.ArenaData:getSeason())) self.txLoading:setText(I18N:getGlobalText(I18N.GlobalConst.ARENA_DESC_22)) self.txCancel:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_TEXT_CANCEL)) -- 等待 if self.waitSid then ModuleManager.BattleManager:unscheduleGlobal(self.waitSid) end self.waitSid = self.matchLoading:performWithDelayGlobal(function() self:showMatchResult() end, 1.5) end -- 展示匹配结果页 function ArenaMatchUI:showMatchResult() local matchInfo = DataManager.ArenaData:getMatchInfo() if not matchInfo then -- 基本不会走到这 Logger.logError("没有匹配对象却进入了匹配结果页,检查是否是网络慢了等情况") return end self.matchLoading:setActive(false) self.matchResult:setActive(true) self.freeRematchCD = DataManager.ArenaData:getFreeRematchCd() Logger.printTable(matchInfo) Logger.printTable(self.freeRematchCD) self.txStart:setText(I18N:getGlobalText(I18N.GlobalConst.TASK_CHALLENGE)) self.txConst:setText(DataManager.ArenaData:getFightCostNum()) self.txRematch:setText(I18N:getGlobalText(I18N.GlobalConst.ARENA_DESC_23)) self.txFormation:setText(I18N:getGlobalText(I18N.GlobalConst.ARENA_DESC_10)) self.imgAd:setActive(self.freeRematchCD > 0 and DataManager.ArenaData:canAdRematch()) self.matchAvatar:refresh(matchInfo.avatar, matchInfo.avatar_frame) self.matchTxName:setText(matchInfo.name) self.matchTxLevel:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, matchInfo.level)) self.matchGrading:refresh(DataManager.ArenaData:getGradingIdFromScore(matchInfo.score)) self.matchHeroFormationComp:refreshBriefInfo(matchInfo.array_heroes) self.selfAvatar:refresh(nil, nil, false) self.selfTxName:setText(DataManager.PlayerData:getNickname()) self.selfTxLevel:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, DataManager.PlayerData:getLv())) self.selfGrading:refresh(DataManager.ArenaData:getGradingId()) GFunc.centerImgAndTx(self.imgCost, self.txConst, 5) local formation = {} for idx, id in pairs(DataManager.FormationData:getArenaAttackFormation()) do local hero = DataManager.HeroData:getHeroById(id) if hero then formation[idx] = {id = id, level = hero:getLv()} else formation[idx] = nil end end self.selfHeroFormationComp:refreshBriefInfo(formation) if self.countdownSid then ModuleManager.BattleManager:unscheduleGlobal(self.countdownSid) end self.countdownSid = self.txFreeCountdown:scheduleGlobal(function() self:refreshCountdown() end, 1) self:refreshCountdown() end function ArenaMatchUI:refreshCountdown() self.freeRematchCD = self.freeRematchCD - 1 if self.freeRematchCD <= 0 then -- 冷却已好 self.txFreeCountdown:setActive(false) ModuleManager.BattleManager:unscheduleGlobal(self.countdownSid) else -- 冷却未好 self.txFreeCountdown:setActive(true) self.txFreeCountdown:setText(GFunc.getTimeStrWithHMS(self.freeRematchCD)) end end -- 点击重新匹配 function ArenaMatchUI:onClickRematch() if self.freeRematchCD > 0 then -- 在cd时间内 if DataManager.ArenaData:canAdRematch() then -- 看视频 SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.ARENA_REMATCH, function () ModuleManager.ArenaManager:reqOverCD(true) end) else -- 钻石 local params ={ content = I18N:getGlobalText(I18N.GlobalConst.BOUNTY_BUY_LEVEL_COUNTENT), boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL, costId = ItemConst.ITEM_ID_GEM, costNum = DataManager.ArenaData:getRematchConstGem(), okFunc = function() ModuleManager.ArenaManager:reqOverCD(false) end, } GFunc.showMessageBox(params) end else -- 冷却已好 ModuleManager.ArenaManager:reqMatch() self:showMatchLoading() end end return ArenaMatchUI