c1_lua/lua/app/ui/hero/star_info_comp.lua
2025-10-09 19:56:15 +08:00

129 lines
4.5 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.lvBtn = uiMap["star_info.upgrade.lv_btn"]
self.lvBtnTx = uiMap["star_info.upgrade.lv_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.costCell = uiMap["star_info.upgrade.reward_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
-- self.costCells = {}
-- for i = 1, 2 do
-- self.costCells[i] = uiMap["star_info.upgrade.reward_cell_" .. i]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL)
-- end
-- self.currStarBg = uiMap["star_info.info_node.curr_star_bg"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.STAR_CELL)
-- self.nextStarBg = uiMap["star_info.info_node.next_star_bg"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.STAR_CELL)
-- self.currLvTx = uiMap["star_info.info_node.curr_lv_tx"]
-- self.nextLvTx = uiMap["star_info.info_node.next_lv_tx"]
self.upBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_16))
self.lvBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_18))
self.upBtn:addClickListener(function()
ModuleManager.HeroManager:upgradeHeroStar(self.heroEntity:getCfgId())
end)
self.lvBtn:addClickListener(function()
self.parentUI:changePage(GConst.HeroConst.PANEL_TYPE.HERO)
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()
end
function StarInfoComp:refreshStarBtn()
if not self.heroEntity:isActived() or self.heroEntity:getIsStarMax() then
self.upgrade:setActive(false)
-- self.scrollrect:setSizeDeltaY(378)
-- self.bg:setSizeDeltaY(378)
-- elseif not self.heroEntity:getIsCurLvMax() then
-- self.upgrade:setActive(true)
-- self.upBtn:setActive(false)
-- self.lvBtn:setActive(true)
-- self.descTx:setActive(true)
-- for i,v in ipairs(self.costCells) do
-- v:setActive(false)
-- end
-- local nextLv = self.heroEntity:getNextLv()
-- self.descTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_21, nextLv))
-- self.scrollrect:setSizeDeltaY(268)
-- self.bg:setSizeDeltaY(268)
else
self.upgrade:setActive(true)
self.upBtn:setActive(true)
self.lvBtn:setActive(false)
self.descTx:setActive(false)
-- local materials = self.heroEntity:getStarUpMaterialNum()
-- local costs = {}
-- costs[1] = {id = self.heroEntity:getFragmentId(), num = materials[1], type = 1}
-- costs[2] = {id = self.heroEntity:getStarUpCostId(), num = materials[2], type = 1}
-- for i,v in ipairs(self.costCells) do
-- v:setActive(true)
-- v:refreshByConfig(costs[i])
-- end
-- self.scrollrect:setSizeDeltaY(268)
-- self.bg:setSizeDeltaY(268)
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
return StarInfoComp