c1_lua/lua/app/ui/hero/hero_info_comp.lua
2023-09-12 10:35:46 +08:00

223 lines
9.8 KiB
Lua

local HeroInfoComp = class("HeroInfoComp", LuaComponent)
local DEFAULT_FACTOR = GConst.BattleConst.DEFAULT_FACTOR
local BTN_ICON = {"common_btn_green_2", "common_btn_grey_2"}
local SIZE_DELTA_Y_HERO = 942
local SIZE_DELTA_Y_LOOK = 802
function HeroInfoComp:init()
local uiMap = self:getUIMap()
self.slider = uiMap["hero_detail_ui.bg.fragment_bg.slider"]
self.imgElement = uiMap["hero_detail_ui.bg.hero_element"]
self.imgSkill = uiMap["hero_detail_ui.bg.skill_node.skill_icon"]
self.imgFragment = uiMap["hero_detail_ui.bg.fragment_bg.fragment_icon"]
self.btnUp = uiMap["hero_detail_ui.bg.up_btn"]
self.imgUpIcon = uiMap["hero_detail_ui.bg.up_btn.icon"]
self.txUpdesc = uiMap["hero_detail_ui.bg.up_btn.desc"]
self.txUpNum = uiMap["hero_detail_ui.bg.up_btn.num"]
self.txLv = uiMap["hero_detail_ui.bg.lv_desc"]
self.txElement = uiMap["hero_detail_ui.bg.element_desc"]
self.txSkill = uiMap["hero_detail_ui.bg.skill_desc"]
self.btnSkillDesc = uiMap["hero_info.skill_desc.btn_skill_desc"]
self.txFragmentNum = uiMap["hero_detail_ui.bg.fragment_bg.fragment_num"]
self.txHpName = uiMap["hero_detail_ui.bg.hp_name"]
self.txAtkName = uiMap["hero_detail_ui.bg.atk_name"]
self.txHp = uiMap["hero_detail_ui.bg.hp"]
self.txAtk = uiMap["hero_detail_ui.bg.atk"]
self.bgFragment = uiMap["hero_detail_ui.bg.fragment_bg"]
self.spineObjSkill = uiMap["hero_detail_ui.bg.ui_spine_obj_skill"]
self.spineObjLv = uiMap["hero_detail_ui.bg.ui_spine_obj_lv"]
self.spineObj = uiMap["hero_detail_ui.bg.ui_spine_obj"]
self.spineObjAvatar = uiMap["hero_detail_ui.bg.ui_spine_obj_avatar"]
self.upgrade = uiMap["hero_info.up"]
self.bgElement = uiMap["hero_detail_ui.bg.element_bg"]
self.btnAttr = uiMap["hero_info.bg_6.btn_attr"]
self.fragmentNode = uiMap["hero_detail_ui.bg.fragment_bg"]
self.btnSkin = uiMap["hero_info.up.btn_skin"]
self.txSkin = uiMap["hero_info.up.btn_skin.tx_skin"]
self.skill = {}
self.skillIcon = {}
self.skillDesc = {}
for i = 1, 7 do
self.skill[i] = uiMap["hero_detail_ui.bg.skill_up_" .. i]
self.skillIcon[i] = uiMap["hero_detail_ui.bg.skill_up_" .. i .. ".icon"]
self.skillDesc[i] = uiMap["hero_detail_ui.bg.skill_up_" .. i .. ".desc"]
end
self.spineObjSkill:setVisible(false)
self.spineObjLv:setVisible(false)
self.spineObj:setVisible(false)
self.txSkin:setText(I18N:getGlobalText(I18N.GlobalConst.SKIN))
self.btnSkin:setActive(DataManager.SkinData:isOpen())
self.btnSkin:addClickListener(function()
ModuleManager.HeroManager:showHeroSkinUI(self.heroEntity:getCfgId())
end)
self.btnUp:addClickListener(function()
ModuleManager.HeroManager:upgradeHero(self.heroEntity:getCfgId(), self.heroEntity)
end)
self.btnSkillDesc:addClickListener(function()
local cfg = ConfigManager:getConfig("skill")[self.heroEntity:getBaseSkill()]
if cfg.buff_id and #cfg.buff_id > 0 then
ModuleManager.TipsManager:showSkillTips(self.btnSkillDesc, cfg.buff_id)
end
end)
self.btnAttr:addClickListener(function()
UIManager:showUI("app/ui/hero/hero_attr_ui", {heroEntity = self.heroEntity})
end)
self:bind(DataManager.BagData.ItemData, "dirty", function()
self:refresh()
end)
end
function HeroInfoComp:setHeroData(heroEntity, onlyLook)
self.curLevel = heroEntity:getLv()
self.heroEntity = heroEntity
self.onlyLook = onlyLook
self:bind(self.heroEntity, "isDirty", function()
self:refresh(true)
end)
end
function HeroInfoComp:refresh(checkLevel)
local isLvChange = checkLevel and self.curLevel ~= self.heroEntity:getLv()
self.txLv:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, self.heroEntity:getLv()))
local lvTxW = self.txLv:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).preferredWidth
self.txLv:setSizeDeltaX(lvTxW)
self.spineObjAvatar:getSkeletonGraphic().enabled = false
self.spineObjAvatar:loadAssetAsync(self.heroEntity:getModelId(), function()
self.spineObjAvatar:getSkeletonGraphic().enabled = true
self.spineObjAvatar:playAnim("idle", true, true, true)
end, true)
self.txElement:setText(ModuleManager.HeroManager:getMatchTypeName(self.heroEntity:getMatchType()))
local elementTxRectWidth = self.txElement:getRectWidth()
local elementTxWidth = self.txElement:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO).preferredWidth
if elementTxWidth > elementTxRectWidth then
self.bgElement:setSizeDeltaX(52 + elementTxWidth)
else
self.bgElement:setSizeDeltaX(52 + elementTxRectWidth)
end
self.txSkill:setText(ModuleManager.HeroManager:getSkillDesc(self.heroEntity:getBaseSkill()))
self.txHpName:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_2))
self.txAtkName:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_3))
self.imgSkill:setSprite(GConst.ATLAS_PATH.ICON_SKILL_BIG, ModuleManager.HeroManager:getSkillIcon(self.heroEntity:getBaseSkill()))
self.imgElement:setSprite(GConst.ATLAS_PATH.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
self.txFragmentNum:setText(fragmentCount .. "/" .. needFragmentCount)
if fragmentCount >= needFragmentCount then
self.slider:setSprite(GConst.ATLAS_PATH.COMMON, "common_progress_1", nil, self.slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER))
else
self.slider:setSprite(GConst.ATLAS_PATH.COMMON, "common_progress_2", nil, self.slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER))
end
self.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, 7 do
local skillId = skillList[i]
if skillId then
local skillBg = self.skill[i]
local skillIcon = self.skillIcon[i]
local skillLv = self.skillDesc[i]
skillBg:addClickListener(function()
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
ModuleManager.TipsManager:showSkillTips(skillIcon, cfg.buff_id, skillId)
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 isLvChange and self.heroEntity:getLv() == skillLvs[i] then
local x, y = skillBg:fastGetAnchoredPosition()
self.spineObjSkill:setAnchoredPosition(x, y)
self.spineObjSkill:setVisible(true)
self.spineObjSkill:playAnim("idle", false, true)
end
end
end
end
self.bgFragment:setVisible(not self.heroEntity:isMaxLv())
local canLvUp = self.heroEntity:canLvUp()
self.imgFragment: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:getHp() // DEFAULT_FACTOR
local curAtk = self.heroEntity:getAtk() // DEFAULT_FACTOR
local addHp = (self.heroEntity:getCfgHp(lv + 1) - self.heroEntity:getCfgHp()) // DEFAULT_FACTOR
local addAtk = (self.heroEntity:getCfgAtk(lv + 1) - self.heroEntity:getCfgAtk()) // DEFAULT_FACTOR
if addHp <= 0 then
hpStr = curHp
else
hpStr = curHp .. "<color=#A2FF29>+" .. addHp .. "</color>"
end
if addAtk <= 0 then
atkStr = curAtk
else
atkStr = curAtk .. "<color=#A2FF29>+" .. 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
self.txUpdesc:setText(str)
self.txUpNum:setText(materials[2])
self.txHp:setText(hpStr)
self.txAtk:setText(atkStr)
if canLvUp then
self.btnUp:addRedPoint(120, 50, 0.6)
else
self.btnUp:removeRedPoint()
end
self.spineObjLv:setVisible(canLvUp)
if canLvUp then
self.btnUp:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[1])
self.spineObjLv:playAnim("animation", true, false)
else
self.btnUp:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[2])
end
self.btnUp:setTouchEnable(true)
self.btnUp:setActive(not self.heroEntity:isMaxLv())
if isLvChange then
self.spineObj:setVisible(true)
self.spineObj:playAnim("idle", false, true)
end
if self.onlyLook then -- 仅查看的不显示升级和激活按钮
self.upgrade:setVisible(false)
self.baseObject:setSizeDeltaY(SIZE_DELTA_Y_LOOK)
self.fragmentNode:setVisible(false)
self.spineObjLv:setVisible(false)
self.txLv:setAnchoredPositionX(lvTxW / 2)
else
self.upgrade:setVisible(true)
self.baseObject:setSizeDeltaY(SIZE_DELTA_Y_HERO)
self.txLv:setAnchoredPositionX(-44)
self.fragmentNode:setVisible(true)
end
end
return HeroInfoComp