160 lines
5.7 KiB
Lua
160 lines
5.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.heroDec = uiMap["hero_cell.hero_bg.dec"]
|
|
self.check = uiMap["hero_cell.hero_bg.mask"]
|
|
self.matchImg = uiMap["hero_cell.hero_bg.match_img"]
|
|
self.lvTx = uiMap["hero_cell.hero_bg.lv_tx"]
|
|
self.sImg = uiMap["hero_cell.hero_bg.s"]
|
|
-- 个人节点
|
|
self.selfNode = uiMap["hero_cell.hero_bg.self_node"]
|
|
self.progressBg = uiMap["hero_cell.hero_bg.self_node.progress_bg"]
|
|
self.progress = uiMap["hero_cell.hero_bg.self_node.progress_bg.progress"]
|
|
self.progressTx = uiMap["hero_cell.hero_bg.self_node.progress_bg.progress_tx"]
|
|
self.unlockTx = uiMap["hero_cell.hero_bg.self_node.unlock_tx"]
|
|
self.fragmenImg = uiMap["hero_cell.hero_bg.self_node.progress_bg.fragment_img"]
|
|
self.lvUpArrow = uiMap["hero_cell.hero_bg.self_node.effect_node.ui_spine_obj"]
|
|
-- 他人节点
|
|
self.otherNode = uiMap["hero_cell.hero_bg.other_node"]
|
|
self.otherTxName = uiMap["hero_cell.hero_bg.other_node.tx_name"]
|
|
|
|
self.isGray = false
|
|
self.baseObject:addClickListener(function()
|
|
if self.clickCallback then
|
|
self.clickCallback()
|
|
end
|
|
end)
|
|
end
|
|
|
|
-- 显示自己英雄
|
|
function HeroCell:refresh(heroEntity, isGray)
|
|
self.selfNode:setVisible(true)
|
|
self.otherNode:setVisible(false)
|
|
|
|
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
|
|
if heroEntity:isUnlock() then
|
|
if heroEntity:isActived() then
|
|
self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, heroEntity:getLv()))
|
|
self.lvTx:setVisible(true)
|
|
else
|
|
self.lvTx:setVisible(false)
|
|
end
|
|
self.progressBg:setVisible(not heroEntity:isMaxLv())
|
|
self.unlockTx:setVisible(false)
|
|
else
|
|
self.lvTx:setVisible(false)
|
|
if canLvUp then
|
|
self.unlockTx:setVisible(false)
|
|
self.progressBg:setVisible(true)
|
|
else
|
|
self.unlockTx:setVisible(true)
|
|
self.progressBg:setVisible(false)
|
|
local unlcokChapter = heroEntity:getUnlcokChapter()
|
|
if unlcokChapter then
|
|
self.unlockTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_10, unlcokChapter))
|
|
else
|
|
self.unlockTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_11))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
--显示其他人英雄
|
|
function HeroCell:refreshBriefInfo(id, level)
|
|
self.selfNode:setVisible(false)
|
|
self.otherNode:setVisible(true)
|
|
|
|
self:_refresh(ConfigManager:getConfig("hero")[id])
|
|
|
|
self.otherTxName:setText(ModuleManager.HeroManager:getHeroName(id))
|
|
self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, level))
|
|
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.heroDec:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HERO_DEC_QLT[heroInfo.qlt])
|
|
self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO_2, 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:setSpineVisible(visible, scale)
|
|
self.lvUpArrow: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
|