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
1 changed files with 10 additions and 7 deletions

View File

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