mirror of
https://github.com/ppy/osu.git
synced 2025-01-06 09:42:55 +08:00
Remove double fetch/binding of parent source
This commit is contained in:
parent
93ef783339
commit
935fbe7cc6
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -47,22 +48,19 @@ namespace osu.Game.Skinning
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISkinSource parentSource;
|
|
||||||
|
|
||||||
private ResourceStoreBackedSkin rulesetResourcesSkin;
|
private ResourceStoreBackedSkin rulesetResourcesSkin;
|
||||||
|
|
||||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
{
|
{
|
||||||
parentSource = parent.Get<ISkinSource>();
|
|
||||||
parentSource.SourceChanged += OnSourceChanged;
|
|
||||||
|
|
||||||
if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources)
|
if (Ruleset.CreateResourceStore() is IResourceStore<byte[]> resources)
|
||||||
rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get<GameHost>(), parent.Get<AudioManager>());
|
rulesetResourcesSkin = new ResourceStoreBackedSkin(resources, parent.Get<GameHost>(), parent.Get<AudioManager>());
|
||||||
|
|
||||||
|
var dependencies = base.CreateChildDependencies(parent);
|
||||||
|
|
||||||
// ensure sources are populated and ready for use before childrens' asynchronous load flow.
|
// ensure sources are populated and ready for use before childrens' asynchronous load flow.
|
||||||
UpdateSkinSources();
|
UpdateSkinSources();
|
||||||
|
|
||||||
return base.CreateChildDependencies(parent);
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnSourceChanged()
|
protected override void OnSourceChanged()
|
||||||
@ -77,7 +75,9 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
var skinSources = new List<ISkin>();
|
var skinSources = new List<ISkin>();
|
||||||
|
|
||||||
foreach (var skin in parentSource.AllSources)
|
Debug.Assert(ParentSource != null);
|
||||||
|
|
||||||
|
foreach (var skin in ParentSource.AllSources)
|
||||||
{
|
{
|
||||||
switch (skin)
|
switch (skin)
|
||||||
{
|
{
|
||||||
@ -121,9 +121,6 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (parentSource != null)
|
|
||||||
parentSource.SourceChanged -= OnSourceChanged;
|
|
||||||
|
|
||||||
rulesetResourcesSkin?.Dispose();
|
rulesetResourcesSkin?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ namespace osu.Game.Skinning
|
|||||||
private readonly Dictionary<ISkin, DisableableSkinSource> skinSources = new Dictionary<ISkin, DisableableSkinSource>();
|
private readonly Dictionary<ISkin, DisableableSkinSource> skinSources = new Dictionary<ISkin, DisableableSkinSource>();
|
||||||
|
|
||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
private ISkinSource fallbackSource;
|
protected ISkinSource ParentSource { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether falling back to parent <see cref="ISkinSource"/>s is allowed in this container.
|
/// Whether falling back to parent <see cref="ISkinSource"/>s is allowed in this container.
|
||||||
@ -101,7 +101,10 @@ namespace osu.Game.Skinning
|
|||||||
return skin;
|
return skin;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fallbackSource?.FindProvider(lookupFunction);
|
if (!AllowFallingBackToParent)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return ParentSource?.FindProvider(lookupFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<ISkin> AllSources
|
public IEnumerable<ISkin> AllSources
|
||||||
@ -111,9 +114,9 @@ namespace osu.Game.Skinning
|
|||||||
foreach (var skin in SkinSources)
|
foreach (var skin in SkinSources)
|
||||||
yield return skin;
|
yield return skin;
|
||||||
|
|
||||||
if (fallbackSource != null)
|
if (AllowFallingBackToParent && ParentSource != null)
|
||||||
{
|
{
|
||||||
foreach (var skin in fallbackSource.AllSources)
|
foreach (var skin in ParentSource.AllSources)
|
||||||
yield return skin;
|
yield return skin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +131,10 @@ namespace osu.Game.Skinning
|
|||||||
return sourceDrawable;
|
return sourceDrawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fallbackSource?.GetDrawableComponent(component);
|
if (!AllowFallingBackToParent)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return ParentSource?.GetDrawableComponent(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
|
public Texture GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
|
||||||
@ -140,7 +146,10 @@ namespace osu.Game.Skinning
|
|||||||
return sourceTexture;
|
return sourceTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fallbackSource?.GetTexture(componentName, wrapModeS, wrapModeT);
|
if (!AllowFallingBackToParent)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return ParentSource?.GetTexture(componentName, wrapModeS, wrapModeT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISample GetSample(ISampleInfo sampleInfo)
|
public ISample GetSample(ISampleInfo sampleInfo)
|
||||||
@ -152,7 +161,10 @@ namespace osu.Game.Skinning
|
|||||||
return sourceSample;
|
return sourceSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fallbackSource?.GetSample(sampleInfo);
|
if (!AllowFallingBackToParent)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return ParentSource?.GetSample(sampleInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
||||||
@ -164,7 +176,10 @@ namespace osu.Game.Skinning
|
|||||||
return bindable;
|
return bindable;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fallbackSource?.GetConfig<TLookup, TValue>(lookup);
|
if (!AllowFallingBackToParent)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return ParentSource?.GetConfig<TLookup, TValue>(lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnSourceChanged() => SourceChanged?.Invoke();
|
protected virtual void OnSourceChanged() => SourceChanged?.Invoke();
|
||||||
@ -173,12 +188,9 @@ namespace osu.Game.Skinning
|
|||||||
{
|
{
|
||||||
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||||
|
|
||||||
if (AllowFallingBackToParent)
|
ParentSource = dependencies.Get<ISkinSource>();
|
||||||
{
|
if (ParentSource != null)
|
||||||
fallbackSource = dependencies.Get<ISkinSource>();
|
ParentSource.SourceChanged += OnSourceChanged;
|
||||||
if (fallbackSource != null)
|
|
||||||
fallbackSource.SourceChanged += OnSourceChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
dependencies.CacheAs<ISkinSource>(this);
|
dependencies.CacheAs<ISkinSource>(this);
|
||||||
|
|
||||||
@ -192,8 +204,8 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (fallbackSource != null)
|
if (ParentSource != null)
|
||||||
fallbackSource.SourceChanged -= OnSourceChanged;
|
ParentSource.SourceChanged -= OnSourceChanged;
|
||||||
|
|
||||||
foreach (var source in SkinSources.OfType<ISkinSource>())
|
foreach (var source in SkinSources.OfType<ISkinSource>())
|
||||||
source.SourceChanged -= OnSourceChanged;
|
source.SourceChanged -= OnSourceChanged;
|
||||||
|
Loading…
Reference in New Issue
Block a user