c1_lua/lua/app/ui/common/cell/large_hero_cell.lua
2023-04-21 23:31:49 +08:00

88 lines
2.8 KiB
Lua

local LargeHeroCell = class("LargeHeroCell", BaseCell)
local OUT_SCREEN_X = 10000
function LargeHeroCell:init()
local uiMap = self.baseObject:genAllChildren()
self.icon = uiMap["hero_cell.hero_bg.icon"]
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.infoBtnDesc = uiMap["large_hero_cell.hero_bg.info_btn.desc"]
self.useBtnDesc = uiMap["large_hero_cell.hero_bg.use_btn.desc"]
self.isGray = false
self.useBtnDesc:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_8))
uiMap["large_hero_cell.hero_bg.info_btn"]:addClickListener(function()
if not self.heroId or not self.matchType then
return
end
self.baseObject:setAnchoredPositionX(OUT_SCREEN_X)
ModuleManager.HeroManager:showHeroDetailUI(self.heroId)
end)
uiMap["large_hero_cell.hero_bg.use_btn"]:addClickListener(function()
if not self.heroId or not self.matchType then
return
end
self.baseObject:setAnchoredPositionX(OUT_SCREEN_X)
ModuleManager.FormationManager:upHeroToStageFormation(self.heroId, self.matchType)
end)
end
function LargeHeroCell:refresh(heroEntity, isGray)
self.heroId = heroEntity:getCfgId()
self.matchType = heroEntity:getMatchType()
local heroInfo = heroEntity:getConfig()
self:_refresh(heroInfo, isGray)
local str
if heroEntity:canLvUp() then
str = I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_4)
else
str = I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_9)
end
self.infoBtnDesc:setText(str)
end
function LargeHeroCell:refreshWithCfgId(id, isGray)
local heroInfo = ConfigManager:getConfig("hero")[id]
self.heroId = id
self.matchType = heroInfo.position
self:_refresh(heroInfo, isGray)
self.infoBtnDesc:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_9))
end
function LargeHeroCell:_refresh(heroInfo, isGray)
if isGray then
self.heroBg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HERO_FRAME_GRAY_QLT[heroInfo.qlt])
else
self.heroBg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.FRAME_QLT[heroInfo.qlt])
end
self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO, tostring(heroInfo.icon))
self.matchImg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HeroConst.MATCH_ICON_NAME[heroInfo.position])
self.check:setVisible(false)
self:setGray(isGray)
end
function LargeHeroCell:showCheck(visible)
self.check:setVisible(visible)
end
function LargeHeroCell:addClickListener(func)
self.baseObject:addClickListener(func)
end
function LargeHeroCell:setVisible(visible)
self.baseObject:setVisible(visible)
end
function LargeHeroCell:setGray(isGray)
if self.isGray == isGray then
return
end
self.icon:setImageGray(isGray)
self.matchImg:setImageGray(isGray)
end
return LargeHeroCell