From 9be9feefbdb4e4f350620afb81fedaa51d7e59cc Mon Sep 17 00:00:00 2001 From: xiekaidong Date: Wed, 19 Apr 2023 22:20:22 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=B1=E9=9B=84=E8=A7=A3=E9=94=81=E5=92=8C?= =?UTF-8?q?=E5=BC=BA=E5=88=B6=E4=B8=8A=E9=98=B5=E7=9A=84=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../localization_global_const.lua | 3 + lua/app/config/strings/cn/global.lua | 3 + lua/app/module/chapter/chapter_manager.lua | 4 ++ .../module/formation/formation_manager.lua | 21 ++++++ lua/app/ui/common/cell/hero_cell.lua | 15 +++++ lua/app/ui/hero/hero_comp.lua | 67 ++++++++++++++----- lua/app/userdata/chapter/chapter_data.lua | 6 +- lua/app/userdata/hero/hero_data.lua | 35 ++++++++++ lua/app/userdata/hero/hero_entity.lua | 8 +++ 9 files changed, 145 insertions(+), 17 deletions(-) diff --git a/lua/app/config/localization/localization_global_const.lua b/lua/app/config/localization/localization_global_const.lua index a01bdb82..014be4c7 100644 --- a/lua/app/config/localization/localization_global_const.lua +++ b/lua/app/config/localization/localization_global_const.lua @@ -38,6 +38,9 @@ local LocalizationGlobalConst = REWARD_PREVIEW_DESC = "REWARD_PREVIEW_DESC", HERO_DESC_8 = "HERO_DESC_8", HERO_DESC_9 = "HERO_DESC_9", + + BATTLE_DESC_8 = "BATTLE_DESC_8", + HERO_DESC_10 = "HERO_DESC_10", } return LocalizationGlobalConst \ No newline at end of file diff --git a/lua/app/config/strings/cn/global.lua b/lua/app/config/strings/cn/global.lua index cf47b7bf..a7956554 100644 --- a/lua/app/config/strings/cn/global.lua +++ b/lua/app/config/strings/cn/global.lua @@ -38,6 +38,9 @@ local localization_global = ["REWARD_PREVIEW_DESC"] = "奖励预览", ["HERO_DESC_8"] = "使用", ["HERO_DESC_9"] = "信息", + + ["HERO_DESC_10"] = "通关章节{0}解锁", + ["BATTLE_DESC_8"] = "还有可上阵英雄", } return localization_global \ No newline at end of file diff --git a/lua/app/module/chapter/chapter_manager.lua b/lua/app/module/chapter/chapter_manager.lua index 823d9ce6..cbc0decd 100644 --- a/lua/app/module/chapter/chapter_manager.lua +++ b/lua/app/module/chapter/chapter_manager.lua @@ -20,6 +20,10 @@ function ChapterManager:openBox(chapterId, index) end function ChapterManager:startFight() + if not ModuleManager.FormationManager:formationIsFull() then + GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.BATTLE_DESC_8)) + return + end ---- 通信 ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE) end diff --git a/lua/app/module/formation/formation_manager.lua b/lua/app/module/formation/formation_manager.lua index 8905c2c2..591fe097 100644 --- a/lua/app/module/formation/formation_manager.lua +++ b/lua/app/module/formation/formation_manager.lua @@ -17,4 +17,25 @@ function FormationManager:upHeroToStageFormation(heroId, matchType) end) end +function FormationManager:formationIsFull() + local actvieMap = DataManager.HeroData:getMatchActiveHeroMap() + local formation = DataManager.FormationData:getStageFormation() + local count = 0 + for matchtype = 1, GConst.BattleConst.ELEMENT_TYPE_COUNT do + if not formation[matchtype] or formation[matchtype] <= 0 then + if actvieMap[matchtype] and table.nums(actvieMap[matchtype]) > 0 then + return false + end + else + count = count + 1 + end + end + + if count <= 0 then + return false + end + + return true +end + return FormationManager \ No newline at end of file diff --git a/lua/app/ui/common/cell/hero_cell.lua b/lua/app/ui/common/cell/hero_cell.lua index ec692f52..712a5fb3 100644 --- a/lua/app/ui/common/cell/hero_cell.lua +++ b/lua/app/ui/common/cell/hero_cell.lua @@ -6,9 +6,11 @@ function HeroCell:init() self.heroBg = uiMap["hero_cell.hero_bg"] self.check = uiMap["hero_cell.hero_bg.mask"] self.matchImg = uiMap["hero_cell.hero_bg.match_img"] + self.progressBg = uiMap["hero_cell.hero_bg.progress_bg"] self.progress = uiMap["hero_cell.hero_bg.progress"] self.progressTx = uiMap["hero_cell.hero_bg.progress_tx"] self.lvTx = uiMap["hero_cell.hero_bg.lv_tx"] + self.unlockTx = uiMap["hero_cell.hero_bg.unlock_tx"] self.isGray = false self.baseObject:addClickListener(function() if self.clickCallback then @@ -27,6 +29,16 @@ function HeroCell:refresh(heroEntity, isGray) self.progressTx:setText(fragmentCount .. "/" .. needFragmentCount) self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, heroEntity:getLv())) + if heroEntity:isUnlock() then + self.lvTx:setVisible(true) + self.progressBg:setVisible(not heroEntity:isMaxLv()) + self.unlockTx:setVisible(false) + else + self.lvTx:setVisible(false) + self.progressBg:setVisible(false) + self.unlockTx:setVisible(true) + self.unlockTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_10, heroEntity:getUnlcokChapter())) + end end function HeroCell:refreshWithCfgId(id, isGray) @@ -41,6 +53,9 @@ function HeroCell:refreshWithCfgId(id, isGray) self.progressTx:setText(fragmentCount .. "/" .. needFragmentCount) self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, lv)) + self.lvTx:setVisible(true) + self.progressBg:setVisible(true) + self.unlockTx:setVisible(false) end function HeroCell:_refresh(heroInfo, isGray) diff --git a/lua/app/ui/hero/hero_comp.lua b/lua/app/ui/hero/hero_comp.lua index 375e4a84..80c8d271 100644 --- a/lua/app/ui/hero/hero_comp.lua +++ b/lua/app/ui/hero/hero_comp.lua @@ -10,7 +10,7 @@ function HeroComp:init() return HERO_LIST_CELL end) self.scrollRect:addRefreshCallback(function(index, cell) - cell:refresh(index, self.heroList, self.stageFormation, self.allHeroCount, self.activeCount, function(cell, heroId) + cell:refresh(index, self.heroList, self.stageFormation, self.allHeroCount, self.unlockCount, function(cell, heroId) self:onClickHero(cell, heroId) end) end) @@ -55,6 +55,8 @@ function HeroComp:init() end function HeroComp:refresh() + self:clearAdapt() + self:adapt() self.stageFormation = DataManager.FormationData:getStageFormation() self:refreshStageFormation() self:refreshScrollRect() @@ -95,11 +97,11 @@ end function HeroComp:refreshScrollRect() self:sortHeroList() self.allHeroCount = #self.heroList - self.activeCount = DataManager.HeroData:getActiveHeroCount() - local lockCount = self.allHeroCount - self.activeCount + self.unlockCount = DataManager.HeroData:getUnlockHeroCount() + local lockCount = self.allHeroCount - self.unlockCount local cellCount = 0 - if self.activeCount > 0 then - cellCount = cellCount + math.ceil(self.activeCount / 4) + if self.unlockCount > 0 then + cellCount = cellCount + math.ceil(self.unlockCount / 4) end if lockCount > 0 then cellCount = cellCount + math.ceil(lockCount / 4) @@ -121,22 +123,26 @@ function HeroComp:sortHeroList() table.sort(self.heroList, function(a, b) heroA = HeroData:getHeroById(a) heroB = HeroData:getHeroById(b) - if heroA:isActived() and heroB:isActived() then - if heroA:getLv() == heroB:getLv() then - if heroA:getQlt() == heroB:getQlt() then - return a > b + if heroA:isUnlock() == heroB:isUnlock() then + if heroA:isActived() and heroB:isActived() then + if heroA:getLv() == heroB:getLv() then + if heroA:getQlt() == heroB:getQlt() then + return a > b + else + return heroA:getQlt() > heroB:getQlt() + end else - return heroA:getQlt() > heroB:getQlt() + return heroA:getLv() > heroB:getLv() end + elseif heroA:isActived() and not heroB:isActived() then + return true + elseif heroB:isActived() and not heroA:isActived() then + return false else - return heroA:getLv() > heroB:getLv() + return a > b end - elseif heroA:isActived() and not heroB:isActived() then - return true - elseif heroB:isActived() and not heroA:isActived() then - return false else - return a > b + return heroA:isUnlock() end end) end @@ -166,4 +172,33 @@ function HeroComp:onClickHero(cell, heroId) end end +function HeroComp:adapt() + local addH = GFunc.calculateFitSizeY() + local uiMap = self:getBaseObject():genAllChildren() + local scrollRect = uiMap["hero_ui.scrollrect"] + local viewport = uiMap["hero_ui.scrollrect.viewport"] + if not self.rectDefaultSize then + self.rectDefaultSize = scrollRect:getSizeDelta() + end + if not self.viewDefaultSize then + self.viewDefaultSize = viewport:getSizeDelta() + end + scrollRect:setSizeDelta(self.rectDefaultSize.x, self.rectDefaultSize.y + addH) + viewport:setSizeDelta(self.viewDefaultSize.x, self.viewDefaultSize.y + addH) +end + +function HeroComp:clearAdapt() + local uiMap = self:getBaseObject():genAllChildren() + local scrollRect = uiMap["hero_ui.scrollrect"] + local viewport = uiMap["hero_ui.scrollrect.viewport"] + if not self.rectDefaultSize then + self.rectDefaultSize = scrollRect:getSizeDelta() + end + if not self.viewDefaultSize then + self.viewDefaultSize = viewport:getSizeDelta() + end + scrollRect:setSizeDelta(self.rectDefaultSize.x, self.rectDefaultSize.y) + viewport:setSizeDelta(self.viewDefaultSize.x, self.viewDefaultSize.y) +end + return HeroComp \ No newline at end of file diff --git a/lua/app/userdata/chapter/chapter_data.lua b/lua/app/userdata/chapter/chapter_data.lua index ed4934be..3b76e461 100644 --- a/lua/app/userdata/chapter/chapter_data.lua +++ b/lua/app/userdata/chapter/chapter_data.lua @@ -21,7 +21,7 @@ function ChapterData:init(data, notChangeChapterId) if not notChangeChapterId then self.data.chapterId = data and data.chapterId or MIN_CHAPTER_ID end - self.data.maxChapterId = data and data.maxChapterId or self.data.chapterId - 1 + self.data.maxChapterId = 2--data and data.maxChapterId or self.data.chapterId - 1 self.data.chapterBoxInfo = data and data.chapterBoxInfo or {} self.data.chapterFightInfo = data and data.chapterFightInfo or {} end @@ -136,4 +136,8 @@ function ChapterData:getFightCost(chapterId) return 0 end +function ChapterData:getMaxChapterId() + return self.data.maxChapterId +end + return ChapterData \ No newline at end of file diff --git a/lua/app/userdata/hero/hero_data.lua b/lua/app/userdata/hero/hero_data.lua index 4ac5f175..a25d2ad9 100644 --- a/lua/app/userdata/hero/hero_data.lua +++ b/lua/app/userdata/hero/hero_data.lua @@ -1,10 +1,13 @@ local HeroEntity = require "app/userdata/hero/hero_entity" local HeroData = class("HeroData", BaseData) +local HERO_CFG = ConfigManager:getConfig("hero") + function HeroData:ctor() self.heroes = {} self.data.activeCount = 0 self.data.isDirty = false + self.matchActiveHeroMap = {} end function HeroData:clear() @@ -18,6 +21,17 @@ function HeroData:init(data) self:addHero(heroInfo.cfg_id, heroInfo.lv) end end + + for heroId, info in pairs(HERO_CFG) do + local entity = self:getHeroById(heroId) + if entity:isActived() then + local matchType = entity:getMatchType() + if not self.matchActiveHeroMap[matchType] then + self.matchActiveHeroMap[matchType] = {} + end + self.matchActiveHeroMap[matchType][entity:getCfgId()] = true + end + end end function HeroData:addHero(cfgId, lv) @@ -50,12 +64,33 @@ function HeroData:getActiveHeroCount() return self.data.activeCount end +function HeroData:getUnlockHeroCount() + local count = 0 + for id, entity in pairs(self.heroes) do + if entity:isUnlock() then + count = count + 1 + end + end + return count +end + function HeroData:setHeroLv(id, lv) local entity = self:getHeroById(id) if not entity:isActived() then self.data.activeCount = self.data.activeCount + 1 end entity:setLv(lv) + if entity:isActived() then + local matchType = entity:getMatchType() + if not self.matchActiveHeroMap[matchType] then + self.matchActiveHeroMap[matchType] = {} + end + self.matchActiveHeroMap[matchType][entity:getCfgId()] = true + end +end + +function HeroData:getMatchActiveHeroMap() + return self.matchActiveHeroMap end function HeroData:setDirty() diff --git a/lua/app/userdata/hero/hero_entity.lua b/lua/app/userdata/hero/hero_entity.lua index c14696e6..4bfb7e0d 100644 --- a/lua/app/userdata/hero/hero_entity.lua +++ b/lua/app/userdata/hero/hero_entity.lua @@ -105,6 +105,10 @@ function HeroEntity:getCfgAtk(lv) return 0 end +function HeroEntity:getUnlcokChapter() + return self.config.unlock_chapter or 0 +end + function HeroEntity:updateAllAttr() for k, v in pairs(self.baseAttrOriginal) do self.allAttr[k] = v @@ -156,6 +160,10 @@ function HeroEntity:canLvUp() return true end +function HeroEntity:isUnlock() + return self:getUnlcokChapter() <= DataManager.ChapterData:getMaxChapterId() +end + function HeroEntity:isActived() return self.data.lv >= self:getBeginLv() end