1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 01:02:56 +08:00

Localise source changed flow for better clarity

This commit is contained in:
Dean Herbert 2021-07-06 16:57:19 +09:00
parent 935fbe7cc6
commit ec1224218c

View File

@ -76,7 +76,7 @@ namespace osu.Game.Skinning
skinSources.Add(skin, new DisableableSkinSource(skin, this)); skinSources.Add(skin, new DisableableSkinSource(skin, this));
if (skin is ISkinSource source) if (skin is ISkinSource source)
source.SourceChanged += OnSourceChanged; source.SourceChanged += anySourceChanged;
} }
public void RemoveSource(ISkin skin) public void RemoveSource(ISkin skin)
@ -84,7 +84,7 @@ namespace osu.Game.Skinning
skinSources.Remove(skin); skinSources.Remove(skin);
if (skin is ISkinSource source) if (skin is ISkinSource source)
source.SourceChanged += OnSourceChanged; source.SourceChanged += anySourceChanged;
} }
public void ResetSources() public void ResetSources()
@ -182,7 +182,10 @@ namespace osu.Game.Skinning
return ParentSource?.GetConfig<TLookup, TValue>(lookup); return ParentSource?.GetConfig<TLookup, TValue>(lookup);
} }
protected virtual void OnSourceChanged() => SourceChanged?.Invoke(); /// <summary>
/// Invoked when any source has changed (either <see cref="ParentSource"/> or <see cref="AllSources"/>
/// </summary>
protected virtual void OnSourceChanged() { }
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{ {
@ -190,13 +193,21 @@ namespace osu.Game.Skinning
ParentSource = dependencies.Get<ISkinSource>(); ParentSource = dependencies.Get<ISkinSource>();
if (ParentSource != null) if (ParentSource != null)
ParentSource.SourceChanged += OnSourceChanged; ParentSource.SourceChanged += anySourceChanged;
dependencies.CacheAs<ISkinSource>(this); dependencies.CacheAs<ISkinSource>(this);
return dependencies; return dependencies;
} }
private void anySourceChanged()
{
// Expose to implementations, giving them a chance to react before notifying external consumers.
OnSourceChanged();
SourceChanged?.Invoke();
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
// Must be done before base.Dispose() // Must be done before base.Dispose()
@ -205,10 +216,10 @@ namespace osu.Game.Skinning
base.Dispose(isDisposing); base.Dispose(isDisposing);
if (ParentSource != null) if (ParentSource != null)
ParentSource.SourceChanged -= OnSourceChanged; ParentSource.SourceChanged -= anySourceChanged;
foreach (var source in SkinSources.OfType<ISkinSource>()) foreach (var source in SkinSources.OfType<ISkinSource>())
source.SourceChanged -= OnSourceChanged; source.SourceChanged -= anySourceChanged;
} }
private class DisableableSkinSource : ISkin private class DisableableSkinSource : ISkin