c1_lua/lua/app/ui/common/cell/hero_cell.lua
2023-04-19 15:36:44 +08:00

80 lines
2.7 KiB
Lua

local HeroCell = class("HeroCell", BaseCell)
function HeroCell: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.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.isGray = false
self.baseObject:addClickListener(function()
if self.clickCallback then
self.clickCallback()
end
end)
end
function HeroCell:refresh(heroEntity, isGray)
local heroInfo = heroEntity:getConfig()
self:_refresh(heroInfo, isGray)
local materials = heroEntity:getLvUpMaterials() or {}
local fragmentCount = DataManager.BagData.ItemData:getItemNumById(heroEntity:getFramentId())
local needFragmentCount = materials[1] or 1
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()))
end
function HeroCell:refreshWithCfgId(id, isGray)
local heroInfo = ConfigManager:getConfig("hero")[id]
self:_refresh(heroInfo, isGray)
local lv = heroInfo.begin_lv
local lvInfo = ConfigManager:getConfig("hero_level")[lv]
local materials = lvInfo["cost_" .. heroInfo.qlt]
local fragmentCount = DataManager.BagData.ItemData:getItemNumById(heroInfo.item_id)
local needFragmentCount = materials[1] or 1
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))
end
function HeroCell:_refresh(heroInfo, isGray)
self.clickCallback = nil
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.HERO_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 HeroCell:showCheck(visible)
self.check:setVisible(visible)
end
function HeroCell:addClickListener(callback)
self.clickCallback = callback
end
function HeroCell:setVisible(visible, scale)
self.baseObject:setVisible(visible, scale)
end
function HeroCell:setGray(isGray)
if self.isGray == isGray then
return
end
self.icon:setImageGray(isGray)
self.matchImg:setImageGray(isGray)
end
return HeroCell