c1_lua/lua/app/ui/common/cell/hero_cell.lua
2023-05-26 18:16:57 +08:00

121 lines
4.5 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.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.lvUpArrow = uiMap["hero_cell.hero_bg.effect_node.ui_spine_obj"]
self.fragmenImg = uiMap["hero_cell.hero_bg.progress_bg.fragment_img"]
self.sImg = uiMap["hero_cell.hero_bg.s"]
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 canLvUp = heroEntity:canLvUp()
self.lvUpArrow:setVisible(canLvUp)
if canLvUp then
self.lvUpArrow:playAnim("animation", true, false)
end
self.fragmenImg:setVisible(not canLvUp)
local materials = heroEntity:getLvUpMaterials() or {}
local fragmentCount = DataManager.BagData.ItemData:getItemNumById(heroEntity:getFragmentId())
local needFragmentCount = materials[1] or 1
self.progressTx:setText(fragmentCount .. "/" .. needFragmentCount)
if fragmentCount >= needFragmentCount then
self.progress:setSprite(GConst.ATLAS_PATH.COMMON, "common_progress_1", nil, self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER))
else
self.progress:setSprite(GConst.ATLAS_PATH.COMMON, "common_progress_2", nil, self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER))
end
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)
if not heroEntity:isActived() then
self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_11))
end
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)
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)
if fragmentCount >= needFragmentCount then
self.progress:setSprite(GConst.ATLAS_PATH.COMMON, "common_progress_1", nil, self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER))
else
self.progress:setSprite(GConst.ATLAS_PATH.COMMON, "common_progress_2", nil, self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER))
end
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)
self.lvUpArrow:setVisible(false)
self.fragmenImg:setVisible(true)
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.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.sImg:setVisible(heroInfo.qlt >= 4)
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.isGray = isGray
self.icon:setImageGray(isGray)
self.matchImg:setImageGray(isGray)
end
return HeroCell