local HeroCell = class("HeroCell", BaseCell) function HeroCell:init() local uiMap = self.baseObject:genAllChildren() self.icon = uiMap["hero_cell.hero_bg.icon"] self.heroBg = uiMap["hero_cell.hero_bg"] self.check = uiMap["hero_cell.hero_bg.mask"] self.matchImg = uiMap["hero_cell.hero_bg.match_img"] self.progressBg = uiMap["hero_cell.hero_bg.progress_bg"] self.progress = uiMap["hero_cell.hero_bg.progress"] self.progressTx = uiMap["hero_cell.hero_bg.progress_tx"] self.lvTx = uiMap["hero_cell.hero_bg.lv_tx"] self.unlockTx = uiMap["hero_cell.hero_bg.unlock_tx"] self.lvUpArrow = uiMap["hero_cell.hero_bg.progress_bg.arrow"] self.fragmenImg = uiMap["hero_cell.hero_bg.progress_bg.fragment_img"] self.isGray = false self.baseObject:addClickListener(function() if self.clickCallback then self.clickCallback() end end) end function HeroCell:refresh(heroEntity, isGray) local heroInfo = heroEntity:getConfig() self:_refresh(heroInfo, isGray) local canLvUp = heroEntity:canLvUp() self.lvUpArrow:setVisible(canLvUp) self.fragmenImg:setVisible(not canLvUp) local materials = heroEntity:getLvUpMaterials() or {} local fragmentCount = DataManager.BagData.ItemData:getItemNumById(heroEntity:getFragmentId()) local needFragmentCount = materials[1] or 1 self.progressTx:setText(fragmentCount .. "/" .. needFragmentCount) self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, heroEntity:getLv())) if heroEntity:isUnlock() then self.lvTx:setVisible(true) self.progressBg:setVisible(not heroEntity:isMaxLv()) self.unlockTx:setVisible(false) if not heroEntity:isActived() then self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_11)) end else self.lvTx:setVisible(false) self.progressBg:setVisible(false) self.unlockTx:setVisible(true) self.unlockTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_10, heroEntity:getUnlcokChapter())) end end function HeroCell:refreshWithCfgId(id, isGray) local heroInfo = ConfigManager:getConfig("hero")[id] self:_refresh(heroInfo, isGray) local lv = heroInfo.begin_lv local lvInfo = ConfigManager:getConfig("hero_level")[lv] local materials = lvInfo["cost_" .. heroInfo.qlt] local fragmentCount = DataManager.BagData.ItemData:getItemNumById(heroInfo.item_id) local needFragmentCount = materials[1] or 1 self.progressTx:setText(fragmentCount .. "/" .. needFragmentCount) self.progress:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = fragmentCount / needFragmentCount self.lvTx:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, lv)) self.lvTx:setVisible(true) self.progressBg:setVisible(true) self.unlockTx:setVisible(false) self.lvUpArrow:setVisible(false) self.fragmenImg:setVisible(true) end function HeroCell:_refresh(heroInfo, isGray) self.clickCallback = nil if isGray then self.heroBg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HERO_FRAME_GRAY_QLT[heroInfo.qlt]) else self.heroBg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.FRAME_QLT[heroInfo.qlt]) end self.icon:setSprite(GConst.ATLAS_PATH.ICON_HERO, tostring(heroInfo.icon)) self.matchImg:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HeroConst.MATCH_ICON_NAME[heroInfo.position]) self.check:setVisible(false) self:setGray(isGray) end function HeroCell:showCheck(visible) self.check:setVisible(visible) end function HeroCell:addClickListener(callback) self.clickCallback = callback end function HeroCell:setVisible(visible, scale) self.baseObject:setVisible(visible, scale) end function HeroCell:setGray(isGray) if self.isGray == isGray then return end self.isGray = isGray self.icon:setImageGray(isGray) self.matchImg:setImageGray(isGray) end return HeroCell