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 local LV_CELL = "app/ui/hero/cell/lv_cell" function HeroInfoComp:init() local uiMap = self:getUIMap() 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.txElement = uiMap["hero_info.element_bg.element_desc"] self.spineObj = uiMap["hero_info.ui_spine_obj"] self.upgrade = uiMap["hero_info.up"] self.bgElement = uiMap["hero_info.element_bg"] self.gotoBtn = uiMap["hero_info.up.goto_btn"] self.vfx04 = uiMap["hero_info.bg_7.scrollrect.viewport.content.vfx_c1_ui_up_b04"] self.vfx04:setActive(false) self.costCell = uiMap["hero_info.up.reward_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.REWARD_CELL) 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:bind(DataManager.BagData.ItemData, "dirty", function() self:refresh() end) self.scrollrect = uiMap["hero_info.bg_7.scrollrect"] self.scrollRectComp = uiMap["hero_info.bg_7.scrollrect"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) self.scrollRectComp:addInitCallback(function() return LV_CELL end) self.scrollRectComp:addRefreshCallback(function(index, cell) cell:refresh(self.heroEntity, index, self.lvUp) end) self.scrollRectComp:clearCells() local bg7 = uiMap["hero_info.bg_7"] local rect = self.baseObject:getRectSize() bg7:setSizeDeltaY(rect.height - 620) 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(lvUp) self.lvUp = lvUp self:refreshLvInfo() self:refreshUpInfo() end function HeroInfoComp:refreshLvInfo() local list = self.heroEntity:getLvAttrPointList() self.scrollRectComp:refillCells(#list) if self.lvUp then local lv = self.heroEntity:getLv() for i, v in ipairs(list) do if lv == v then self.scrollRectComp:moveToIndex(i - 1) self.vfx04:setAnchoredPositionY(-33 - (i - 1) * 58) self.vfx04:setActive(true) break end end else self.vfx04:setActive(false) end end function HeroInfoComp:refreshUpInfo() local canLvUp = self.heroEntity:canLvUp() if not self.heroEntity:isActived() then self.btnUp:setActive(false) self.btnUp5:setActive(false) self.gotoBtn:setActive(false) self.costCell:setActive(false) self.upgrade:setVisible(false) else self.upgrade:setVisible(not self.onlyLook) if self.heroEntity:isMaxLv() then self.btnUp:setActive(false) self.btnUp5:setActive(false) self.gotoBtn:setActive(false) self.costCell:setActive(false) else self.btnUp:setActive(true) self.btnUp5:setActive(true) self.gotoBtn:setActive(false) local cost = {id = self.heroEntity:getLvUpCostId(), num = self.heroEntity:getLvUpMaterialNum() 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("" .. hadNum .. "" .. "/" .. cost.num) end if canLvUp then self.btnUp:setTouchEnable(true) self.btnUp5:setTouchEnable(true) self.btnUp:addRedPoint(70, 30, 1) self.btnUp5:addRedPoint(70, 30, 1) self.btnUp:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[1]) self.btnUp5:setSprite(GConst.ATLAS_PATH.COMMON, BTN_ICON[2]) else self.btnUp:setTouchEnable(false) self.btnUp5:setTouchEnable(false) 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 end end return HeroInfoComp