c1_lua/lua/app/ui/hero/star_info_comp.lua
2025-10-10 15:11:18 +08:00

118 lines
4.0 KiB
Lua

local StarInfoComp = class("StarInfoComp", LuaComponent)
local STAR_CELL = "app/ui/hero/cell/star_info_cell"
function StarInfoComp:init()
local uiMap = self:getUIMap()
self.upBtn = uiMap["star_info.upgrade.up_btn"]
self.upBtnTx = uiMap["star_info.upgrade.up_btn.text"]
self.descTx = uiMap["star_info.upgrade.desc_tx"]
self.upgrade = uiMap["star_info.upgrade"]
self.bg = uiMap["star_info.bg"]
self.vfx04 = uiMap["star_info.bg.scrollrect.viewport.content.vfx_c1_ui_up_b04"]
self.vfx04:setActive(false)
self.attrBg = uiMap["star_info.attr_bg"]
self.attrNode = uiMap["star_info.attr_bg.attr_node"]
local descTx = uiMap["star_info.attr_bg.attr_node.desc_tx_1"]
self.attrTx = uiMap["star_info.attr_bg.attr_node.desc_tx_2"]
uiMap["star_info.attr_bg.desc_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_24))
descTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_25))
local meshProComp = descTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO)
local contentWidth = meshProComp.preferredWidth
descTx:setSizeDeltaX(contentWidth)
self.costCell = uiMap["star_info.upgrade.reward_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
self.upBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_16))
self.upBtn:addClickListener(function()
ModuleManager.HeroManager:upgradeHeroStar(self.heroEntity:getCfgId())
end)
self.attrBg:addClickListener(function()
ModuleManager.HeroManager:showAttrAllUI()
end)
self.scrollrect = uiMap["star_info.bg.scrollrect"]
self.scrollRectComp = uiMap["star_info.bg.scrollrect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE)
self.scrollRectComp:addInitCallback(function()
return STAR_CELL
end)
self.scrollRectComp:addRefreshCallback(function(index, cell)
cell:refresh(self.heroEntity, index, self.starUp)
end)
self.scrollRectComp:clearCells()
local rect = self.baseObject:getRectSize()
self.bg:setSizeDeltaY(rect.height - 620)
end
function StarInfoComp:setParentUI(parentUI)
self.parentUI = parentUI
end
function StarInfoComp:setHeroData(heroEntity, onlyLook)
self.heroEntity = heroEntity
self.onlyLook = onlyLook
self:bind(self.heroEntity, "isDirty", function()
self:refresh(true)
end)
end
function StarInfoComp:refresh(starUp)
self.starUp = starUp
self:refreshStarBtn()
self:refreshStarInfo()
self:refreshAttrInfo()
end
function StarInfoComp:refreshStarBtn()
if not self.heroEntity:isActived() or self.heroEntity:getIsStarMax() then
self.upgrade:setActive(false)
local rect = self.baseObject:getRectSize()
self.bg:setAnchoredPositionY(150)
self.bg:setSizeDeltaY(rect.height - 488)
else
self.upgrade:setActive(true)
self.upBtn:setActive(true)
self.descTx:setActive(false)
local rect = self.baseObject:getRectSize()
self.bg:setAnchoredPositionY(283)
self.bg:setSizeDeltaY(rect.height - 620)
local cost = {id = self.heroEntity:getStarUpCostId(), num = self.heroEntity:getStarUpMaterialNum() or 0, type = 1}
local hadNum = DataManager.BagData.ItemData:getItemNumById(cost.id)
self.costCell:setActive(true)
self.costCell:refreshByConfig(cost)
if hadNum >= cost.num then
self.costCell:setNumTx(hadNum .. "/" .. cost.num)
else
self.costCell:setNumTx("<color=#D82F2D>" .. hadNum .. "</color>" .. "/" .. cost.num)
end
end
end
function StarInfoComp:refreshStarInfo()
local maxStarLv = self.heroEntity:getMaxStar()
self.scrollRectComp:refillCells(maxStarLv)
if self.starUp then
local star = self.heroEntity:getStar()
self.scrollRectComp:moveToIndex(star - 1)
self.vfx04:setAnchoredPositionY(-33 - (star - 1) * 56)
self.vfx04:setActive(true)
else
self.vfx04:setActive(false)
end
end
function StarInfoComp:refreshAttrInfo()
-- self.attrTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_26))
self.attrTx:setText("10%")
local meshProComp = self.attrTx:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_TEXT_MESH_PRO)
local contentWidth = meshProComp.preferredWidth
self.attrTx:setSizeDeltaX(contentWidth)
self.attrNode:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_HORIZONTAL_OR_VERTICAL_LAYOUT):RefreshLayout()
end
return StarInfoComp