mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 17:53:15 +08:00
Remove BindableList usage
This commit is contained in:
parent
fe70b52086
commit
93ef783339
@ -1,6 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||||
// 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.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -72,31 +73,36 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
protected virtual void UpdateSkinSources()
|
protected virtual void UpdateSkinSources()
|
||||||
{
|
{
|
||||||
SkinSources.Clear();
|
ResetSources();
|
||||||
|
|
||||||
|
var skinSources = new List<ISkin>();
|
||||||
|
|
||||||
foreach (var skin in parentSource.AllSources)
|
foreach (var skin in parentSource.AllSources)
|
||||||
{
|
{
|
||||||
switch (skin)
|
switch (skin)
|
||||||
{
|
{
|
||||||
case LegacySkin legacySkin:
|
case LegacySkin legacySkin:
|
||||||
SkinSources.Add(GetLegacyRulesetTransformedSkin(legacySkin));
|
skinSources.Add(GetLegacyRulesetTransformedSkin(legacySkin));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
SkinSources.Add(skin);
|
skinSources.Add(skin);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int lastDefaultSkinIndex = SkinSources.IndexOf(SkinSources.OfType<DefaultSkin>().LastOrDefault());
|
int lastDefaultSkinIndex = skinSources.IndexOf(skinSources.OfType<DefaultSkin>().LastOrDefault());
|
||||||
|
|
||||||
// Ruleset resources should be given the ability to override game-wide defaults
|
// Ruleset resources should be given the ability to override game-wide defaults
|
||||||
// This is achieved by placing them before the last instance of DefaultSkin.
|
// This is achieved by placing them before the last instance of DefaultSkin.
|
||||||
// Note that DefaultSkin may not be present in some test scenes.
|
// Note that DefaultSkin may not be present in some test scenes.
|
||||||
if (lastDefaultSkinIndex >= 0)
|
if (lastDefaultSkinIndex >= 0)
|
||||||
SkinSources.Insert(lastDefaultSkinIndex, rulesetResourcesSkin);
|
skinSources.Insert(lastDefaultSkinIndex, rulesetResourcesSkin);
|
||||||
else
|
else
|
||||||
SkinSources.Add(rulesetResourcesSkin);
|
skinSources.Add(rulesetResourcesSkin);
|
||||||
|
|
||||||
|
foreach (var skin in skinSources)
|
||||||
|
AddSource(skin);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin)
|
protected ISkin GetLegacyRulesetTransformedSkin(ISkin legacySkin)
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -27,13 +26,13 @@ namespace osu.Game.Skinning
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Skins which should be exposed by this container, in order of lookup precedence.
|
/// Skins which should be exposed by this container, in order of lookup precedence.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly BindableList<ISkin> SkinSources = new BindableList<ISkin>();
|
protected IEnumerable<ISkin> SkinSources => skinSources.Keys;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A dictionary mapping each <see cref="ISkin"/> from the <see cref="SkinSources"/>
|
/// A dictionary mapping each <see cref="ISkin"/> from the <see cref="SkinSources"/>
|
||||||
/// to one that performs the "allow lookup" checks before proceeding with a lookup.
|
/// to one that performs the "allow lookup" checks before proceeding with a lookup.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly Dictionary<ISkin, DisableableSkinSource> disableableSkinSources = new Dictionary<ISkin, DisableableSkinSource>();
|
private readonly Dictionary<ISkin, DisableableSkinSource> skinSources = new Dictionary<ISkin, DisableableSkinSource>();
|
||||||
|
|
||||||
[CanBeNull]
|
[CanBeNull]
|
||||||
private ISkinSource fallbackSource;
|
private ISkinSource fallbackSource;
|
||||||
@ -60,7 +59,7 @@ namespace osu.Game.Skinning
|
|||||||
: this()
|
: this()
|
||||||
{
|
{
|
||||||
if (skin != null)
|
if (skin != null)
|
||||||
SkinSources.Add(skin);
|
AddSource(skin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -70,61 +69,35 @@ namespace osu.Game.Skinning
|
|||||||
protected SkinProvidingContainer()
|
protected SkinProvidingContainer()
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
}
|
||||||
|
|
||||||
SkinSources.BindCollectionChanged(((_, args) =>
|
public void AddSource(ISkin skin)
|
||||||
{
|
{
|
||||||
switch (args.Action)
|
skinSources.Add(skin, new DisableableSkinSource(skin, this));
|
||||||
{
|
|
||||||
case NotifyCollectionChangedAction.Add:
|
|
||||||
foreach (var skin in args.NewItems.Cast<ISkin>())
|
|
||||||
{
|
|
||||||
disableableSkinSources.Add(skin, new DisableableSkinSource(skin, this));
|
|
||||||
|
|
||||||
if (skin is ISkinSource source)
|
if (skin is ISkinSource source)
|
||||||
source.SourceChanged += OnSourceChanged;
|
source.SourceChanged += OnSourceChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
public void RemoveSource(ISkin skin)
|
||||||
|
{
|
||||||
|
skinSources.Remove(skin);
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Reset:
|
if (skin is ISkinSource source)
|
||||||
case NotifyCollectionChangedAction.Remove:
|
source.SourceChanged += OnSourceChanged;
|
||||||
foreach (var skin in args.OldItems.Cast<ISkin>())
|
}
|
||||||
{
|
|
||||||
disableableSkinSources.Remove(skin);
|
|
||||||
|
|
||||||
if (skin is ISkinSource source)
|
public void ResetSources()
|
||||||
source.SourceChanged -= OnSourceChanged;
|
{
|
||||||
}
|
foreach (var skin in AllSources.ToArray())
|
||||||
|
RemoveSource(skin);
|
||||||
break;
|
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Replace:
|
|
||||||
foreach (var skin in args.OldItems.Cast<ISkin>())
|
|
||||||
{
|
|
||||||
disableableSkinSources.Remove(skin);
|
|
||||||
|
|
||||||
if (skin is ISkinSource source)
|
|
||||||
source.SourceChanged -= OnSourceChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var skin in args.NewItems.Cast<ISkin>())
|
|
||||||
{
|
|
||||||
disableableSkinSources.Add(skin, new DisableableSkinSource(skin, this));
|
|
||||||
|
|
||||||
if (skin is ISkinSource source)
|
|
||||||
source.SourceChanged += OnSourceChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ISkin FindProvider(Func<ISkin, bool> lookupFunction)
|
public ISkin FindProvider(Func<ISkin, bool> lookupFunction)
|
||||||
{
|
{
|
||||||
foreach (var skin in SkinSources)
|
foreach (var skin in SkinSources)
|
||||||
{
|
{
|
||||||
if (lookupFunction(disableableSkinSources[skin]))
|
if (lookupFunction(skinSources[skin]))
|
||||||
return skin;
|
return skin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,7 +124,7 @@ namespace osu.Game.Skinning
|
|||||||
foreach (var skin in SkinSources)
|
foreach (var skin in SkinSources)
|
||||||
{
|
{
|
||||||
Drawable sourceDrawable;
|
Drawable sourceDrawable;
|
||||||
if ((sourceDrawable = disableableSkinSources[skin]?.GetDrawableComponent(component)) != null)
|
if ((sourceDrawable = skinSources[skin]?.GetDrawableComponent(component)) != null)
|
||||||
return sourceDrawable;
|
return sourceDrawable;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,7 +136,7 @@ namespace osu.Game.Skinning
|
|||||||
foreach (var skin in SkinSources)
|
foreach (var skin in SkinSources)
|
||||||
{
|
{
|
||||||
Texture sourceTexture;
|
Texture sourceTexture;
|
||||||
if ((sourceTexture = disableableSkinSources[skin]?.GetTexture(componentName, wrapModeS, wrapModeT)) != null)
|
if ((sourceTexture = skinSources[skin]?.GetTexture(componentName, wrapModeS, wrapModeT)) != null)
|
||||||
return sourceTexture;
|
return sourceTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +148,7 @@ namespace osu.Game.Skinning
|
|||||||
foreach (var skin in SkinSources)
|
foreach (var skin in SkinSources)
|
||||||
{
|
{
|
||||||
ISample sourceSample;
|
ISample sourceSample;
|
||||||
if ((sourceSample = disableableSkinSources[skin]?.GetSample(sampleInfo)) != null)
|
if ((sourceSample = skinSources[skin]?.GetSample(sampleInfo)) != null)
|
||||||
return sourceSample;
|
return sourceSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +160,7 @@ namespace osu.Game.Skinning
|
|||||||
foreach (var skin in SkinSources)
|
foreach (var skin in SkinSources)
|
||||||
{
|
{
|
||||||
IBindable<TValue> bindable;
|
IBindable<TValue> bindable;
|
||||||
if ((bindable = disableableSkinSources[skin]?.GetConfig<TLookup, TValue>(lookup)) != null)
|
if ((bindable = skinSources[skin]?.GetConfig<TLookup, TValue>(lookup)) != null)
|
||||||
return bindable;
|
return bindable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user