local CollectionHeroCell = class("CollectionHeroCell", BaseCell) function CollectionHeroCell:init() local uiMap = self:getUIMap() self.imgQlt = uiMap["collection_hero_cell.img_qlt"] self.imgType = uiMap["collection_hero_cell.img_qlt.img_type"] self.txLevel = uiMap["collection_hero_cell.tx_level"] self.txName = uiMap["collection_hero_cell.tx_name"] self.txMax = uiMap["collection_hero_cell.tx_max"] self.btnCollect = uiMap["collection_hero_cell.btn_collect"] self.imgIcon = uiMap["collection_hero_cell.btn_collect.img_icon"] self.txValue = uiMap["collection_hero_cell.btn_collect.tx_value"] self.spineRoot = uiMap["collection_hero_cell.spine_root.spine_hero"] self.btnCollect:addClickListener(function() if DataManager.CollectionData:getCanCollectPoint(GConst.CollectionConst.TYPE.HERO, self.heroData.id) > 0 then AudioManager:playEffect(AudioManager.EFFECT_ID.STAR_GET) ModuleManager.CollectionManager:reqHeroPoint(self.heroData.id) EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.COLLECTION_CLICK_GET_POINT, self.imgIcon:getPosition()) else GFunc.showToast(I18N:getGlobalText(I18N.GlobalConst.COLLECTION_DESC_12)) end end) self:bind(DataManager.CollectionData, "dirtyHero", function() self:refreshCollectPoint() end) end function CollectionHeroCell:refresh(data) self.heroData = data local entity = DataManager.HeroData:getHeroById(self.heroData.id) SpineManager:loadHeroAsync(entity:getModelId(), self.spineRoot, function(spineObject) if self.spineHero then self.spineHero:destroy() self.spineHero = nil end spineObject:setDefaultMix(0) self.spineHero = spineObject end) self.baseObject:setSprite(GConst.ATLAS_PATH.HERO, GConst.HERO_FRAME_QLT[self.heroData.qlt]) self.imgQlt:setSprite(GConst.ATLAS_PATH.HERO, GConst.HERO_FRAME_BG_QLT[self.heroData.qlt]) self.imgType:setSprite(GConst.ATLAS_PATH.ICON_HERO, GConst.HeroConst.MATCH_ICON_NAME[self.heroData.position]) self.txName:setText(ModuleManager.HeroManager:getHeroName(self.heroData.id)) local heroEntity = DataManager.HeroData:getHeroById(self.heroData.id) if heroEntity then self.txLevel:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, heroEntity:getLv())) else self.txLevel:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, 0)) end self.txMax:setText(I18N:getGlobalText(I18N.GlobalConst.COLLECTION_DESC_2)) self:refreshCollectPoint() end -- 刷新收集点数状态 function CollectionHeroCell:refreshCollectPoint() local canGetValue = DataManager.CollectionData:getCanCollectPoint(GConst.CollectionConst.TYPE.HERO, self.heroData.id) local heroEntity = DataManager.HeroData:getHeroById(self.heroData.id) -- Logger.logHighlight("id:"..self.heroData.id..",level:"..heroEntity:getLv()..",canGetValue:"..canGetValue) if canGetValue > 0 then self.txValue:setText("+" .. canGetValue) self.txLevel:setText(""..I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, heroEntity:getLv()).."") GFunc.getShakeSeq(self.txLevel, false, 1, true) self.btnCollect:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_green_3") self.btnCollect:setActive(true) self.txMax:setActive(false) else self.txValue:setText("+" .. heroEntity:getCollectionPoint()) self.txLevel:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_DESC_1, heroEntity:getLv())) GFunc.getShakeSeq(self.txLevel, true) self.btnCollect:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_3") self.btnCollect:setActive(not heroEntity:isMaxLv()) self.txMax:setActive(heroEntity:isMaxLv()) end GFunc.centerTxAndImg(self.txValue, self.imgIcon, 2) end return CollectionHeroCell