c1_lua/lua/app/ui/hero/hero_info_comp.lua
2025-08-19 20:31:19 +08:00

278 lines
11 KiB
Lua

local HeroInfoComp = class("HeroInfoComp", LuaComponent)
local DEFAULT_FACTOR = GConst.BattleConst.DEFAULT_FACTOR
local BTN_ICON = {"common_btn_blue_1", "common_btn_yellow_1", "common_btn_grey_1"}
local SIZE_DELTA_Y_HERO = 942
local SIZE_DELTA_Y_LOOK = 802
function HeroInfoComp:init()
local uiMap = self:getUIMap()
-- self.slider = uiMap["hero_info.fragment_bg.slider"]
self.imgSkill = uiMap["hero_info.skill_node.skill_icon"]
-- self.imgFragment = uiMap["hero_info.fragment_bg.fragment_icon"]
self.btnUp = uiMap["hero_info.up.up_btn"]
self.txUpdesc = uiMap["hero_info.up.up_btn.text"]
self.btnUp5 = uiMap["hero_info.up.up_5_btn"]
self.txUpdesc5 = uiMap["hero_info.up.up_5_btn.text"]
self.txLv = uiMap["hero_info.lv_desc"]
self.txElement = uiMap["hero_info.element_bg.element_desc"]
self.txSkill = uiMap["hero_info.skill_desc"]
self.btnskillDescTxs = uiMap["hero_info.skill_desc.btn_skill_desc"]
-- self.txFragmentNum = uiMap["hero_info.fragment_bg.fragment_num"]
self.txHpName = uiMap["hero_info.bg_6.hp_name_tx"]
self.txAtkName = uiMap["hero_info.bg_5.atk_name_tx"]
self.txHp = uiMap["hero_info.bg_6.hp_tx"]
self.txAtk = uiMap["hero_info.bg_5.atk_tx"]
-- self.bgFragment = uiMap["hero_info.fragment_bg"]
self.spineObjSkill = uiMap["hero_info.ui_spine_obj_skill"]
-- self.spineObjLv = uiMap["hero_info.ui_spine_obj_lv"]
self.spineObj = uiMap["hero_info.ui_spine_obj"]
self.upgrade = uiMap["hero_info.up"]
self.bgElement = uiMap["hero_info.element_bg"]
self.btnAttr = uiMap["hero_info.bg_6.attr_btn"]
self.gotoBtn = uiMap["hero_info.up.goto_btn"]
self.needStarNode = uiMap["hero_info.up.need_star_node"]
self.needStarNodeDescTx1 = uiMap["hero_info.up.need_star_node.desc_tx_1"]
self.needStarNodeStarImg = uiMap["hero_info.up.need_star_node.star_img"]
self.needStarNodeDescTx2 = uiMap["hero_info.up.need_star_node.desc_tx_2"]
uiMap["hero_info.up.goto_btn.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_18))
self.needStarNodeDescTx2:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_20))
local meshProComp = self.needStarNodeDescTx2:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO)
local contentWidth = meshProComp.preferredWidth
self.needStarNodeDescTx2:setSizeDeltaX(contentWidth)
self.skill = {}
self.skillIcon = {}
self.skillDescTxs = {}
for i = 1, 4 do
self.skill[i] = uiMap["hero_info.skill_up_" .. i]
self.skillIcon[i] = uiMap["hero_info.skill_up_" .. i .. ".icon"]
self.skillDescTxs[i] = uiMap["hero_info.skill_up_" .. i .. ".desc_tx"]
end
self.costCells = {}
for i = 1, 2 do
self.costCells[i] = uiMap["hero_info.up.reward_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
end
self.spineObjSkill:setVisible(false)
-- self.spineObjLv:setVisible(false)
self.spineObj:setVisible(false)
self.txUpdesc:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_15, 1))
self.txUpdesc5:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_15, 5))
self.btnUp:addClickListener(function()
ModuleManager.HeroManager:upgradeHero(self.heroEntity:getCfgId(), self.heroEntity)
end)
self.btnUp5:addClickListener(function()
local canLvUpLv, canLvUp = self.heroEntity:getLvUpLv()
if not canLvUp then
return
end
ModuleManager.HeroManager:upgradeHero(self.heroEntity:getCfgId(), self.heroEntity, canLvUpLv)
end)
self.gotoBtn:addClickListener(function()
self.parentUI:changePage(GConst.HeroConst.PANEL_TYPE.STAR)
end)
self.btnskillDescTxs:addClickListener(function()
local cfg = ConfigManager:getConfig("skill")[self.heroEntity:getBaseSkill()]
if cfg.buff_id and #cfg.buff_id > 0 then
ModuleManager.TipsManager:showSkillTips(self.btnskillDescTxs, 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:setParentUI(parentUI)
self.parentUI = parentUI
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.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()))
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 skillList = self.heroEntity:getRogueSkillList()
local lv = self.heroEntity:getLv()
for i = 1, 4 do
local skillInfo = skillList[i]
if skillInfo then
local skillUnlcokLv = skillInfo[1]
local skillId = skillInfo[2]
local skillBg = self.skill[i]
local skillIcon = self.skillIcon[i]
local skillLv = self.skillDescTxs[i]
local nextLvUp = self.heroEntity:getNextRougeLvUp(i)
skillBg:addClickListener(function()
local cfg = ConfigManager:getConfig("skill_rogue")[skillId]
-- ModuleManager.TipsManager:showSkillTips(skillIcon, cfg.buff_id, skillId)
ModuleManager.HeroManager:showHeroSkillInfoUI(self.heroEntity, i, cfg.buff_id)
end)
skillIcon:setSprite(GConst.ATLAS_PATH.ICON_SKILL_ROGUE, ModuleManager.HeroManager:getSkillRogueIcon(skillId))
skillBg:setTouchEnable(true)
if skillUnlcokLv > lv then
-- skillLv:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, skillLvs[i] or 0))
skillLv:setText(I18N:getGlobalText(I18N.GlobalConst.LV_UNLOCK, skillUnlcokLv))
skillBg:setSprite(GConst.ATLAS_PATH.ICON_ITEM, "frame_1")
else
if nextLvUp then
skillLv:setText(nextLvUp .. I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_17))
else
skillLv:setText(GConst.EMPTY_STRING)
end
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()
local nextLv = self.heroEntity:getNextLv()
-- 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
-- local costId = self.heroEntity:getLvUpCostId()
-- self.imgUpIcon:setSprite(GFunc.getIconRes(costId))
-- self.txUpdesc:setText(str)
-- self.txUpNum:setText(materials[2])
self.txHp:setText(hpStr)
self.txAtk:setText(atkStr)
if self.heroEntity:isMaxLv() then
self.btnUp:setActive(false)
self.btnUp5:setActive(false)
self.gotoBtn:setActive(false)
self.needStarNode:setActive(false)
elseif lv >= nextLv then
self.btnUp:setActive(false)
self.btnUp5:setActive(false)
self.gotoBtn:setActive(true)
self.needStarNode:setActive(true)
local star = self.heroEntity:getStar()
local currStar = star%5 + 1
self.needStarNodeDescTx1:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_19, currStar))
local meshProComp = self.needStarNodeDescTx1:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO)
local contentWidth = meshProComp.preferredWidth
self.needStarNodeDescTx1:setSizeDeltaX(contentWidth)
self.needStarNode:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT):RefreshLayout()
local starType = math.ceil(currStar / 5)
self.needStarNodeStarImg:setSprite(GFunc.getStarImg(starType))
for i,v in ipairs(self.costCells) do
v:setActive(false)
end
else
self.btnUp:setActive(true)
self.btnUp5:setActive(true)
self.gotoBtn:setActive(false)
self.needStarNode:setActive(false)
local costs = {}
costs[1] = {id = self.heroEntity:getFragmentId(), num = materials[1], type = 1}
costs[2] = {id = self.heroEntity:getLvUpCostId(), num = materials[2], type = 1}
for i,v in ipairs(self.costCells) do
v:setActive(true)
v:refreshByConfig(costs[i])
end
if canLvUp then
self.btnUp:addRedPoint(70, 30, 0.6)
self.btnUp5:addRedPoint(70, 30, 0.6)
self.btnUp:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[1])
self.btnUp5:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[2])
else
self.btnUp:removeRedPoint()
self.btnUp5:removeRedPoint()
self.btnUp:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[3])
self.btnUp5:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[3])
end
end
-- self.needStarNode = uiMap["hero_info.up.need_star_node"]
-- self.needStarNodeDescTx1 = uiMap["hero_info.up.need_star_node.desc_tx_1"]
-- self.needStarNodeStarImg = uiMap["hero_info.up.need_star_node.star_img"]
-- self.needStarNodeDescTx2 = uiMap["hero_info.up.need_star_node.desc_tx_2"]
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.bgFragment: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.bgFragment:setVisible(true)
end
end
return HeroInfoComp