From b87a5956dd62de3fb77532073022ee6ac0a08e21 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sun, 6 Jun 2021 12:17:55 +0900 Subject: [PATCH] Add fallback logic to `SkinManager` --- osu.Game/Skinning/SkinManager.cs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/osu.Game/Skinning/SkinManager.cs b/osu.Game/Skinning/SkinManager.cs index d373618232..9aa2d90064 100644 --- a/osu.Game/Skinning/SkinManager.cs +++ b/osu.Game/Skinning/SkinManager.cs @@ -204,16 +204,34 @@ namespace osu.Game.Skinning public event Action SourceChanged; - public Drawable GetDrawableComponent(ISkinComponent component) => CurrentSkin.Value.GetDrawableComponent(component); + public Drawable GetDrawableComponent(ISkinComponent component) => lookupWithFallback(s => s.GetDrawableComponent(component)); - public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => CurrentSkin.Value.GetTexture(componentName, wrapModeS, wrapModeT); + public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT) => lookupWithFallback(s => s.GetTexture(componentName, wrapModeS, wrapModeT)); - public ISample GetSample(ISampleInfo sampleInfo) => CurrentSkin.Value.GetSample(sampleInfo); + public ISample GetSample(ISampleInfo sampleInfo) => lookupWithFallback(s => s.GetSample(sampleInfo)); - public IBindable GetConfig(TLookup lookup) => CurrentSkin.Value.GetConfig(lookup); + public IBindable GetConfig(TLookup lookup) => lookupWithFallback(s => s.GetConfig(lookup)); public ISkin FindProvider(Func lookupFunction) => lookupFunction(CurrentSkin.Value) ? CurrentSkin.Value : null; + private Skin defaultLegacySkin; + + private T lookupWithFallback(Func func) + where T : class + { + var selectedSkin = func(CurrentSkin.Value); + + if (selectedSkin != null) + return selectedSkin; + + defaultLegacySkin ??= new DefaultLegacySkin(this); + + if (CurrentSkin.Value is LegacySkin) + return func(defaultLegacySkin); + + return null; + } + #region IResourceStorageProvider AudioManager IStorageResourceProvider.AudioManager => audio;