require("Base/BasePanel") HandBookRoleSkinPanel = Inherit(BasePanel) local this = HandBookRoleSkinPanel local porpertyConfigs = ConfigManager.GetConfig(ConfigName.PropertyConfig) local artResConfig = ConfigManager.GetConfig(ConfigName.ArtResourcesConfig) local skinPres = {} local porpertys = {} local curHeroData = {} local curSkinId = 0 local parent = nil local skins = {} function HandBookRoleSkinPanel:New(gameObject) local b = {} b.gameObject = gameObject b.transform = gameObject.transform setmetatable(b, { __index = HandBookRoleSkinPanel }) return b end function HandBookRoleSkinPanel:InitComponent() this.spLoader = SpriteLoader.New() this.skinPre = Util.GetGameObject(self.gameObject,"skinPre") this.Select = Util.GetGameObject(self.gameObject,"selectLight") this.skinGrid = Util.GetGameObject(self.gameObject,"scroll/skinGrid") for i = 1, this.skinGrid.transform.childCount do skinPres[i] = {} skinPres[i].obj = this.skinGrid.transform:GetChild(i - 1) skinPres[i].data = nil end end function HandBookRoleSkinPanel:BindEvent() end --添加事件监听(用于子类重写) function HandBookRoleSkinPanel:AddListener() end --移除事件监听(用于子类重写) function HandBookRoleSkinPanel:RemoveListener() end this.UpdateShow = this:OnShow() --界面打开时调用 function HandBookRoleSkinPanel:OnShow(_sortinglayer,_parent,_curHerodata) self.gameObject:SetActive(true) end function HandBookRoleSkinPanel:SetData(_sortinglayer,_parent,_curHerodata) curHeroData = _curHerodata parent = _parent curSkinId = 0 local configs = ConfigManager.GetAllConfigsDataByKey(ConfigName.HeroSkin,"HeroId",curHeroData.Id) local tempskins = {} for i = 1 ,#configs do --LogGreen("configs[i].Type:"..configs[i].Type) if not tempskins[configs[i].Type] and configs[i].Show == 1 then tempskins[configs[i].Type] = configs[i] end end skins = {} for i,v in pairs(tempskins) do table.insert(skins,v) end table.sort(skins,function(a,b) if a.Type == b.Type then return a.Id < b.Id else return a.Type < b.Type end end) this:UpdateView() end function HandBookRoleSkinPanel:UpdateView() for k,v in pairs(skinPres) do v.obj.gameObject:SetActive(false) v.data = nil end local index = 1 for i,v in ipairs(skins) do if not skinPres[index] then skinPres[index] = {} end if not skinPres[index].obj then skinPres[index].obj = newObjToParent(this.skinPre,this.skinGrid) end skinPres[index].data = v skinPres[index].obj.gameObject:SetActive(true) self:SetSingleData(skinPres[index].obj,v) index = index + 1 end end function HandBookRoleSkinPanel:SetSingleData(go,data) local icon = Util.GetGameObject(go,"skinIcon"):GetComponent("Image") local lock = Util.GetGameObject(go,"skinState").gameObject:SetActive(false) local infoPre = Util.GetGameObject(go,"skinInfo/infoPre") local infoGrid = Util.GetGameObject(go,"skinInfo/grid") local skinName = Util.GetGameObject(go,"skinName/name"):GetComponent("Text") skinName.text = GetLanguageStrById(data.ReadingName) if data.IsDefault == 1 then skinName.text = Language[11828] end --icon.sprite = this.spLoader:LoadSprite(artResConfig[data.Painting].Name) if not porpertys then porpertys = {} end if not porpertys[go] then porpertys[go] = {} end for i = 1, infoGrid.transform.childCount do porpertys[go][i] = infoGrid.transform:GetChild(i - 1) porpertys[go][i].gameObject:SetActive(false) end if data.MonomerProperty and #data.MonomerProperty > 0 then for i = 1, #data.MonomerProperty do if not porpertys[go][i] then porpertys[go][i] = newObjToParent(infoPre,infoGrid) end porpertys[go][i].gameObject:SetActive(true) local tempProData = porpertyConfigs[data.MonomerProperty[i][1]] Util.GetGameObject(porpertys[go][i],"info"):GetComponent("Text").text = GetLanguageStrById(tempProData.Info) .. "+" ..GetPropertyFormatStr(tempProData.Style,data.MonomerProperty[i][2]) porpertys[go][i]:GetComponent("Button").enabled = false end end Util.AddOnceClick(go.gameObject,function() local skinId = data.IsDefault == 1 and 0 or data.Type this:BtnAction(skinId,data) end) end function HandBookRoleSkinPanel:BtnAction(skinId,data) if skinId == curSkinId then return end curSkinId = skinId if skinId == 0 then parent:ChangeCurentHeroSkinLive() else parent:ChangeCurentHeroSkinLive(data) end end function HandBookRoleSkinPanel:OnHide() self.gameObject:SetActive(false) if parent then parent:ChangeCurentHeroSkinLive() end end function HandBookRoleSkinPanel:OnClose() skinPres = {} porpertys = {} curHeroData = {} end function HandBookRoleSkinPanel:OnDestroy() this.spLoader:Destroy() skinPres = {} porpertys = {} curHeroData = {} end return HandBookRoleSkinPanel