Remove `allowFallback` parameters completely

This commit is contained in:
Dean Herbert 2021-05-27 14:50:42 +09:00
parent 4fd89faaa4
commit 70a844ac10
14 changed files with 45 additions and 76 deletions

View File

@ -25,9 +25,9 @@ public CatchComboDisplay()
{
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
ComboCounter?.UpdateCombo(currentCombo);
}

View File

@ -399,9 +399,9 @@ private void runHyperDashStateTransition(bool hyperDashing)
private void updateTrailVisibility() => trails.DisplayTrail = Dashing || HyperDashing;
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
hyperDashColour =
skin.GetConfig<CatchSkinColour, Color4>(CatchSkinColour.HyperDash)?.Value ??

View File

@ -33,9 +33,9 @@ private void load(IScrollingInfo scrollingInfo)
Direction.BindValueChanged(onDirectionChanged, true);
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
UpdateHitPosition();
}

View File

@ -18,9 +18,9 @@ public SkinnableLighting()
{
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
updateColour();
}

View File

@ -31,7 +31,7 @@ public OsuCursor()
Size = new Vector2(size);
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
cursorExpand = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.CursorExpand)?.Value ?? true;
}

View File

@ -42,9 +42,9 @@ public void TestConfineScaleDown()
Spacing = new Vector2(10),
Children = new[]
{
new ExposedSkinnableDrawable("default", _ => new DefaultBox(), _ => true),
new ExposedSkinnableDrawable("available", _ => new DefaultBox(), _ => true),
new ExposedSkinnableDrawable("available", _ => new DefaultBox(), _ => true, ConfineMode.NoScaling)
new ExposedSkinnableDrawable("default", _ => new DefaultBox()),
new ExposedSkinnableDrawable("available", _ => new DefaultBox()),
new ExposedSkinnableDrawable("available", _ => new DefaultBox(), ConfineMode.NoScaling)
}
},
};
@ -73,9 +73,9 @@ public void TestConfineScaleUp()
Spacing = new Vector2(10),
Children = new[]
{
new ExposedSkinnableDrawable("default", _ => new DefaultBox(), _ => true),
new ExposedSkinnableDrawable("available", _ => new DefaultBox(), _ => true, ConfineMode.ScaleToFit),
new ExposedSkinnableDrawable("available", _ => new DefaultBox(), _ => true, ConfineMode.NoScaling)
new ExposedSkinnableDrawable("default", _ => new DefaultBox()),
new ExposedSkinnableDrawable("available", _ => new DefaultBox(), ConfineMode.ScaleToFit),
new ExposedSkinnableDrawable("available", _ => new DefaultBox(), ConfineMode.NoScaling)
}
},
};
@ -100,7 +100,7 @@ public void TestInitialLoad()
Child = new SkinProvidingContainer(secondarySource)
{
RelativeSizeAxes = Axes.Both,
Child = consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"), source => true)
Child = consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"))
}
};
});
@ -129,7 +129,7 @@ public void TestOverride()
};
});
AddStep("add permissive", () => target.Add(consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"), source => true)));
AddStep("add permissive", () => target.Add(consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"))));
AddAssert("consumer using override source", () => consumer.Drawable is SecondarySourceBox);
AddAssert("skinchanged only called once", () => consumer.SkinChangedCount == 1);
}
@ -152,7 +152,7 @@ public void TestSwitchOff()
};
});
AddStep("add permissive", () => target.Add(consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"), source => true)));
AddStep("add permissive", () => target.Add(consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"))));
AddAssert("consumer using override source", () => consumer.Drawable is SecondarySourceBox);
AddStep("disable", () => target.Disable());
AddAssert("consumer using base source", () => consumer.Drawable is BaseSourceBox);
@ -180,9 +180,8 @@ private class ExposedSkinnableDrawable : SkinnableDrawable
{
public new Drawable Drawable => base.Drawable;
public ExposedSkinnableDrawable(string name, Func<ISkinComponent, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null,
ConfineMode confineMode = ConfineMode.ScaleToFit)
: base(new TestSkinComponent(name), defaultImplementation, allowFallback, confineMode)
public ExposedSkinnableDrawable(string name, Func<ISkinComponent, Drawable> defaultImplementation, ConfineMode confineMode = ConfineMode.ScaleToFit)
: base(new TestSkinComponent(name), defaultImplementation, confineMode)
{
}
}
@ -250,14 +249,14 @@ private class SkinConsumer : SkinnableDrawable
public new Drawable Drawable => base.Drawable;
public int SkinChangedCount { get; private set; }
public SkinConsumer(string name, Func<ISkinComponent, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null)
: base(new TestSkinComponent(name), defaultImplementation, allowFallback)
public SkinConsumer(string name, Func<ISkinComponent, Drawable> defaultImplementation)
: base(new TestSkinComponent(name), defaultImplementation)
{
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
SkinChangedCount++;
}
}

View File

@ -70,9 +70,9 @@ public void Apply(ISampleInfo sampleInfo)
updateSample();
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
updateSample();
}
@ -88,15 +88,6 @@ private void updateSample()
var sample = CurrentSkin.GetSample(sampleInfo);
if (sample == null && AllowDefaultFallback)
{
foreach (var lookup in sampleInfo.LookupNames)
{
if ((sample = sampleStore.Get(lookup)) != null)
break;
}
}
if (sample == null)
return;

View File

@ -56,9 +56,9 @@ public SkinManager(Storage storage, DatabaseContextFactory contextFactory, GameH
this.legacyDefaultResources = legacyDefaultResources;
CurrentSkin.Value = new DefaultSkin(this);
CurrentSkinInfo.ValueChanged += skin => CurrentSkin.Value = GetSkin(skin.NewValue);
CurrentSkin.Value = new DefaultSkin(this);
CurrentSkin.ValueChanged += skin =>
{
if (skin.NewValue.SkinInfo != CurrentSkinInfo.Value)

View File

@ -22,22 +22,6 @@ public abstract class SkinReloadableDrawable : PoolableDrawable
/// </summary>
protected ISkinSource CurrentSkin { get; private set; }
private readonly Func<ISkinSource, bool> allowFallback;
/// <summary>
/// Whether fallback to default skin should be allowed if the custom skin is missing this resource.
/// </summary>
protected bool AllowDefaultFallback => allowFallback == null || allowFallback.Invoke(CurrentSkin);
/// <summary>
/// Create a new <see cref="SkinReloadableDrawable"/>
/// </summary>
/// <param name="allowFallback">A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present.</param>
protected SkinReloadableDrawable(Func<ISkinSource, bool> allowFallback = null)
{
this.allowFallback = allowFallback;
}
[BackgroundDependencyLoader]
private void load(ISkinSource source)
{
@ -58,7 +42,7 @@ protected override void LoadAsyncComplete()
private void skinChanged()
{
SkinChanged(CurrentSkin, AllowDefaultFallback);
SkinChanged(CurrentSkin);
OnSkinChanged?.Invoke();
}
@ -66,8 +50,7 @@ private void skinChanged()
/// Called when a change is made to the skin.
/// </summary>
/// <param name="skin">The new skin.</param>
/// <param name="allowFallback">Whether fallback to default skin should be allowed if the custom skin is missing this resource.</param>
protected virtual void SkinChanged(ISkinSource skin, bool allowFallback)
protected virtual void SkinChanged(ISkinSource skin)
{
}

View File

@ -40,17 +40,14 @@ public class SkinnableDrawable : SkinReloadableDrawable
/// </summary>
/// <param name="component">The namespace-complete resource name for this skinnable element.</param>
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
/// <param name="allowFallback">A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present.</param>
/// <param name="confineMode">How (if at all) the <see cref="Drawable"/> should be resize to fit within our own bounds.</param>
public SkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable> defaultImplementation = null, Func<ISkinSource, bool> allowFallback = null,
ConfineMode confineMode = ConfineMode.NoScaling)
: this(component, allowFallback, confineMode)
public SkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable> defaultImplementation = null, ConfineMode confineMode = ConfineMode.NoScaling)
: this(component, confineMode)
{
createDefault = defaultImplementation;
}
protected SkinnableDrawable(ISkinComponent component, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.NoScaling)
: base(allowFallback)
protected SkinnableDrawable(ISkinComponent component, ConfineMode confineMode = ConfineMode.NoScaling)
{
this.component = component;
this.confineMode = confineMode;
@ -76,13 +73,13 @@ protected SkinnableDrawable(ISkinComponent component, Func<ISkinSource, bool> al
/// </summary>
protected virtual bool ApplySizeRestrictionsToDefault => false;
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
Drawable = skin.GetDrawableComponent(component);
isDefault = false;
if (Drawable == null && allowFallback)
if (Drawable == null)
{
Drawable = CreateDefault(component);
isDefault = true;

View File

@ -1,7 +1,6 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
@ -19,8 +18,8 @@ public class SkinnableSprite : SkinnableDrawable
[Resolved]
private TextureStore textures { get; set; }
public SkinnableSprite(string textureName, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.NoScaling)
: base(new SpriteComponent(textureName), allowFallback, confineMode)
public SkinnableSprite(string textureName, ConfineMode confineMode = ConfineMode.NoScaling)
: base(new SpriteComponent(textureName), confineMode)
{
}

View File

@ -9,14 +9,14 @@ namespace osu.Game.Skinning
{
public class SkinnableSpriteText : SkinnableDrawable, IHasText
{
public SkinnableSpriteText(ISkinComponent component, Func<ISkinComponent, SpriteText> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.NoScaling)
: base(component, defaultImplementation, allowFallback, confineMode)
public SkinnableSpriteText(ISkinComponent component, Func<ISkinComponent, SpriteText> defaultImplementation, ConfineMode confineMode = ConfineMode.NoScaling)
: base(component, defaultImplementation, confineMode)
{
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
if (Drawable is IHasText textDrawable)
textDrawable.Text = Text;

View File

@ -73,9 +73,9 @@ public void Remove(ISkinnableDrawable component)
components.Remove(component);
}
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
Reload();
}

View File

@ -31,9 +31,9 @@ public DrawableStoryboardSample(StoryboardSampleInfo sampleInfo)
[Resolved]
private IBindable<IReadOnlyList<Mod>> mods { get; set; }
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
protected override void SkinChanged(ISkinSource skin)
{
base.SkinChanged(skin, allowFallback);
base.SkinChanged(skin);
foreach (var mod in mods.Value.OfType<IApplicableToSample>())
{