169 lines
7.2 KiB
Lua
169 lines
7.2 KiB
Lua
local HeroDetailUI = class("HeroDetailUI", BaseUI)
|
|
|
|
local DEFAULT_FACTOR = GConst.BattleConst.DEFAULT_FACTOR
|
|
|
|
local BTN_ICON = {"common_btn_green_2", "common_btn_grey_2"}
|
|
|
|
function HeroDetailUI:isFullScreen()
|
|
return false
|
|
end
|
|
|
|
function HeroDetailUI:getPrefabPath()
|
|
return "assets/prefabs/ui/hero/hero_detail_ui.prefab"
|
|
end
|
|
|
|
function HeroDetailUI:ctor(parmas)
|
|
local heroId = parmas.heroId
|
|
self.heroEntity = DataManager.HeroData:getHeroById(heroId)
|
|
end
|
|
|
|
function HeroDetailUI:onLoadRootComplete()
|
|
self:_initSpineObjs()
|
|
self:_display()
|
|
self:_addListeners()
|
|
self:_bind()
|
|
end
|
|
|
|
function HeroDetailUI:_display(lvChange)
|
|
local uiMap = self.root:genAllChildren()
|
|
uiMap["hero_detail_ui.bg.title_desc"]:setText(self.heroEntity:getName())
|
|
uiMap["hero_detail_ui.bg.lv_desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, self.heroEntity:getLv()))
|
|
uiMap["hero_detail_ui.bg.element_desc"]:setText(ModuleManager.HeroManager:getMatchTypeName(self.heroEntity:getMatchType()))
|
|
uiMap["hero_detail_ui.bg.skill_desc"]:setText(ModuleManager.HeroManager:getSkillDesc(self.heroEntity:getBaseSkill()))
|
|
uiMap["hero_detail_ui.bg.hp_name"]:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_2))
|
|
uiMap["hero_detail_ui.bg.atk_name"]:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_3))
|
|
|
|
uiMap["hero_detail_ui.bg.skill_icon"]:setSprite(GConst.ATLAS_PATH.ICON_SKILL_ROGUE, ModuleManager.HeroManager:getSkillRogueIcon(self.heroEntity:getUnlockRogueId()))
|
|
uiMap["hero_detail_ui.bg.hero_element"]:setSprite(GConst.ATLAS_PATH.ICON_HERO, ModuleManager.HeroManager:getMatchTypeIcon(self.heroEntity:getMatchType()))
|
|
|
|
local materials = self.heroEntity:getLvUpMaterials() or {}
|
|
local fragmentCount = DataManager.BagData.ItemData:getItemNumById(self.heroEntity:getFragmentId())
|
|
local needFragmentCount = materials[1] or 1
|
|
uiMap["hero_detail_ui.bg.fragment_num"]:setText(fragmentCount .. "/" .. needFragmentCount)
|
|
|
|
local slider = uiMap["hero_detail_ui.bg.slider"]
|
|
if fragmentCount >= needFragmentCount then
|
|
slider:setSprite(GConst.ATLAS_PATH.COMMON, "common_progress_1", nil, slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER))
|
|
else
|
|
slider:setSprite(GConst.ATLAS_PATH.COMMON, "common_progress_2", nil, slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER))
|
|
end
|
|
slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount
|
|
|
|
local activeCount = self.heroEntity:getActiveRogueCount()
|
|
local skillList = self.heroEntity:getRogueSkillList()
|
|
local skillLvs = ModuleManager.HeroManager:getActiveRogueLvs()
|
|
for i = 1, 3 do
|
|
local skillId = skillList[i]
|
|
if skillId then
|
|
local skillIcon = uiMap["hero_detail_ui.bg.skill_up_" .. i .. ".icon"]
|
|
local skillBg = uiMap["hero_detail_ui.bg.skill_up_" .. i]
|
|
local skillLv = uiMap["hero_detail_ui.bg.skill_up_" .. i .. ".desc"]
|
|
skillBg:addClickListener(function()
|
|
ModuleManager.TipsManager:showDescTips(ModuleManager.HeroManager:getSkillRogueDesc(skillId), skillIcon)
|
|
end)
|
|
skillIcon:setSprite(GConst.ATLAS_PATH.ICON_SKILL_ROGUE, ModuleManager.HeroManager:getSkillRogueIcon(skillId))
|
|
skillBg:setTouchEnable(true)
|
|
if i > activeCount then
|
|
skillLv:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, skillLvs[i] or 0))
|
|
skillBg:setSprite(GConst.ATLAS_PATH.ICON_SKILL_ROGUE, "frame_0")
|
|
else
|
|
skillLv:setText(GConst.EMPTY_STRING)
|
|
skillBg:setSprite(GConst.ATLAS_PATH.ICON_SKILL_ROGUE, ModuleManager.HeroManager:getSkillRogueBg(skillId, true))
|
|
if i == activeCount and lvChange and self.heroEntity:getLv() == skillLvs[i] then
|
|
local x, y = skillBg:fastGetAnchoredPosition()
|
|
self.spineObjSkill:setLocalPositionX(x)
|
|
self.spineObjSkill:setVisible(true)
|
|
self.spineObjSkill:playAnim("idle", false, true)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
uiMap["hero_detail_ui.bg.fragment_bg"]:setVisible(not self.heroEntity:isMaxLv())
|
|
|
|
local canLvUp = self.heroEntity:canLvUp()
|
|
uiMap["hero_detail_ui.bg.fragment_icon"]:setVisible(not canLvUp)
|
|
|
|
local lv = self.heroEntity:getLv()
|
|
local str
|
|
local hpStr
|
|
local atkStr
|
|
if self.heroEntity:isActived() then
|
|
str = I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_4)
|
|
local curHp = self.heroEntity:getCfgHp() // DEFAULT_FACTOR
|
|
local curAtk = self.heroEntity:getCfgAtk() // DEFAULT_FACTOR
|
|
local addHp = self.heroEntity:getCfgHp(lv + 1) // DEFAULT_FACTOR - curHp
|
|
local addAtk = self.heroEntity:getCfgAtk(lv + 1) // DEFAULT_FACTOR - curAtk
|
|
if addHp <= 0 then
|
|
hpStr = curHp
|
|
else
|
|
hpStr = curHp .. "<color=#82FF82>+" .. addHp .. "</color>"
|
|
end
|
|
|
|
if addAtk <= 0 then
|
|
atkStr = curAtk
|
|
else
|
|
atkStr = curAtk .. "<color=#82FF82>+" .. addAtk .. "</color>"
|
|
end
|
|
else
|
|
str = I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_5)
|
|
hpStr = self.heroEntity:getCfgHp(self.heroEntity:getBeginLv()) // DEFAULT_FACTOR
|
|
atkStr = self.heroEntity:getCfgAtk(self.heroEntity:getBeginLv()) // DEFAULT_FACTOR
|
|
end
|
|
uiMap["hero_detail_ui.bg.up_btn.desc"]:setText(str)
|
|
uiMap["hero_detail_ui.bg.up_btn.num"]:setText(materials[2])
|
|
uiMap["hero_detail_ui.bg.up_btn.rp"]:setVisible(self.heroEntity:canLvUp())
|
|
uiMap["hero_detail_ui.bg.hp"]:setText(hpStr)
|
|
uiMap["hero_detail_ui.bg.atk"]:setText(atkStr)
|
|
|
|
local btn = uiMap["hero_detail_ui.bg.up_btn"]
|
|
self.spineObjLv:setVisible(canLvUp)
|
|
if canLvUp then
|
|
btn:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[1])
|
|
self.spineObjLv:playAnim("animation", true, false)
|
|
else
|
|
btn:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[2])
|
|
end
|
|
btn:setTouchEnable(true)
|
|
btn:setActive(not self.heroEntity:isMaxLv())
|
|
|
|
if lvChange then
|
|
self.spineObj:setVisible(true)
|
|
self.spineObj:playAnim("idle", false, true)
|
|
end
|
|
end
|
|
|
|
function HeroDetailUI:_addListeners()
|
|
local uiMap = self.root:genAllChildren()
|
|
uiMap["hero_detail_ui.bg.back_btn"]:addClickListener(function()
|
|
self:closeUI()
|
|
end)
|
|
|
|
uiMap["hero_detail_ui.bg.up_btn"]:addClickListener(function()
|
|
ModuleManager.HeroManager:upgradeHero(self.heroEntity:getCfgId(), self.heroEntity)
|
|
end)
|
|
end
|
|
|
|
function HeroDetailUI:_bind()
|
|
self:bind(self.heroEntity, "lv", function()
|
|
self:_display(true)
|
|
end)
|
|
end
|
|
|
|
function HeroDetailUI:_initSpineObjs()
|
|
local uiMap = self.root:genAllChildren()
|
|
self.spineObjSkill = uiMap["hero_detail_ui.bg.spine_node.ui_spine_obj_skill"]
|
|
self.spineObjLv = uiMap["hero_detail_ui.bg.spine_node.ui_spine_obj_lv"]
|
|
self.spineObj = uiMap["hero_detail_ui.bg.spine_node.ui_spine_obj"]
|
|
self.spineObjAvatar = uiMap["hero_detail_ui.bg.spine_node.ui_spine_obj_avatar"]
|
|
|
|
self.spineObjAvatar:loadAssetAsync(self.heroEntity:getModelId(), function()
|
|
self.spineObjAvatar:playAnim("idle", true, true, true)
|
|
end, true)
|
|
|
|
self.spineObjSkill:setVisible(false)
|
|
self.spineObjLv:setVisible(false)
|
|
self.spineObj:setVisible(false)
|
|
end
|
|
|
|
return HeroDetailUI |