diff --git a/lua/app/global/global_const.lua b/lua/app/global/global_const.lua index c788d397..b63ca318 100644 --- a/lua/app/global/global_const.lua +++ b/lua/app/global/global_const.lua @@ -177,6 +177,9 @@ GConst.TYPEOF_LUA_CLASS = { POP_HERO_CELL = "app/ui/shop/cell/pop_hero_cell", POP_REWARD_CELL = "app/ui/shop/cell/pop_reward_cell", GIFT_REWARD_CELL = "app/ui/shop/cell/gift_reward_cell", + + -- comp + HERO_FORMATION_COMP = "app/ui/common/component/hero_formation_comp", } GConst.ATLAS_PATH = { diff --git a/lua/app/ui/common/component/hero_formation_comp.lua b/lua/app/ui/common/component/hero_formation_comp.lua new file mode 100644 index 00000000..9bca851e --- /dev/null +++ b/lua/app/ui/common/component/hero_formation_comp.lua @@ -0,0 +1,47 @@ +-- 英雄编队 +local HeroFormationComp = class("HeroFormationComp", LuaComponent) + +function HeroFormationComp:init() + local uiMap = self.baseObject:genAllChildren() + + self.heroCells = { + uiMap["hero_formation_comp.hero_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + uiMap["hero_formation_comp.hero_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + uiMap["hero_formation_comp.hero_cell_3"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + uiMap["hero_formation_comp.hero_cell_4"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + uiMap["hero_formation_comp.hero_cell_5"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), + } +end + +function HeroFormationComp:refresh() + + -- todo 传参控制显示对手还是自己的编队 + + local formation = DataManager.FormationData:getStageFormation() + for i, heroCell in ipairs(self.heroCells) do + if formation[i] then + local heroEntity = DataManager.HeroData:getHeroById(formation[i]) + if heroEntity then + heroCell:setVisible(true, 1) + heroCell:refresh(heroEntity) + heroCell:addClickListener(function() + ModuleManager.HeroManager:showHeroDetailUI(heroEntity:getCfgId()) + end) + else + heroCell:setVisible(false) + end + else + heroCell:setVisible(false) + end + end +end + +function HeroFormationComp:setFormationVisible(visible) + self.baseObject:setVisible(visible) +end + +function HeroFormationComp:getFormationPosY() + return self.baseObject:fastGetAnchoredPositionY() +end + +return HeroFormationComp \ No newline at end of file diff --git a/lua/app/ui/common/component/hero_formation_comp.lua.meta b/lua/app/ui/common/component/hero_formation_comp.lua.meta new file mode 100644 index 00000000..939d70bd --- /dev/null +++ b/lua/app/ui/common/component/hero_formation_comp.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 313e4030686a03942908f4e6796b6ab6 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index c18f763a..7074280a 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -174,23 +174,16 @@ function MainComp:getCurRightModuleIdx() end function MainComp:initStageFormation() - self.heroCells = { - self.uiMap["main_comp.hero_bg.hero_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), - self.uiMap["main_comp.hero_bg.hero_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), - self.uiMap["main_comp.hero_bg.hero_cell_3"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), - self.uiMap["main_comp.hero_bg.hero_cell_4"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), - self.uiMap["main_comp.hero_bg.hero_cell_5"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL), - } + self.heroCells = self.uiMap["main_comp.hero_formation_comp"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_FORMATION_COMP) - self.heroFormation = self.uiMap["main_comp.hero_bg"] - local heroBgPosY = self.heroFormation:fastGetAnchoredPositionY() + local heroBgPosY = self.heroCells:getFormationPosY() local sWidth, sHeight = GFunc.getUIExpandScreenSize() local hSHeight = sHeight / 2 self.btnPosY = (heroBgPosY + (BOTTOM_HEIGHT / 2 - hSHeight)) / 2 end function MainComp:setFormationVisible(visible) - self.heroFormation:setVisible(visible) + self.heroCells:setFormationVisible(visible) end function MainComp:refresh() @@ -218,23 +211,7 @@ function MainComp:refreshDungeon() end function MainComp:refreshStageFormaion() - local formation = DataManager.FormationData:getStageFormation() - for i, heroCell in ipairs(self.heroCells) do - if formation[i] then - local heroEntity = DataManager.HeroData:getHeroById(formation[i]) - if heroEntity then - heroCell:setVisible(true, 1) - heroCell:refresh(heroEntity) - heroCell:addClickListener(function() - ModuleManager.HeroManager:showHeroDetailUI(heroEntity:getCfgId()) - end) - else - heroCell:setVisible(false) - end - else - heroCell:setVisible(false) - end - end + self.heroCells:refresh() end function MainComp:getDailyChallengeIconPos()