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

Use List to guarantee lookup order

This commit is contained in:
Dean Herbert 2021-07-06 22:51:56 +09:00
parent 255f7b7b53
commit 523546d8b6

View File

@ -44,7 +44,7 @@ namespace osu.Game.Skinning
/// <summary> /// <summary>
/// A dictionary mapping each <see cref="ISkin"/> source to a wrapper which handles lookup allowances. /// A dictionary mapping each <see cref="ISkin"/> source to a wrapper which handles lookup allowances.
/// </summary> /// </summary>
private readonly Dictionary<ISkin, DisableableSkinSource> skinSources = new Dictionary<ISkin, DisableableSkinSource>(); private readonly List<(ISkin skin, DisableableSkinSource wrapped)> skinSources = new List<(ISkin, DisableableSkinSource)>();
/// <summary> /// <summary>
/// Constructs a new <see cref="SkinProvidingContainer"/> initialised with a single skin source. /// Constructs a new <see cref="SkinProvidingContainer"/> initialised with a single skin source.
@ -70,7 +70,7 @@ namespace osu.Game.Skinning
/// <param name="skin">The skin to add.</param> /// <param name="skin">The skin to add.</param>
protected void AddSource(ISkin skin) protected void AddSource(ISkin skin)
{ {
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 += TriggerSourceChanged; source.SourceChanged += TriggerSourceChanged;
@ -82,7 +82,7 @@ namespace osu.Game.Skinning
/// <param name="skin">The skin to remove.</param> /// <param name="skin">The skin to remove.</param>
protected void RemoveSource(ISkin skin) protected void RemoveSource(ISkin skin)
{ {
if (!skinSources.Remove(skin)) if (skinSources.RemoveAll(s => s.skin == skin) == 0)
return; return;
if (skin is ISkinSource source) if (skin is ISkinSource source)
@ -116,8 +116,8 @@ namespace osu.Game.Skinning
{ {
get get
{ {
foreach (var skin in skinSources.Keys) foreach (var i in skinSources)
yield return skin; yield return i.skin;
if (AllowFallingBackToParent && ParentSource != null) if (AllowFallingBackToParent && ParentSource != null)
{ {
@ -226,8 +226,11 @@ namespace osu.Game.Skinning
if (ParentSource != null) if (ParentSource != null)
ParentSource.SourceChanged -= TriggerSourceChanged; ParentSource.SourceChanged -= TriggerSourceChanged;
foreach (var source in skinSources.Keys.OfType<ISkinSource>()) foreach (var i in skinSources)
source.SourceChanged -= TriggerSourceChanged; {
if (i.skin is ISkinSource source)
source.SourceChanged -= TriggerSourceChanged;
}
} }
private class DisableableSkinSource : ISkin private class DisableableSkinSource : ISkin