Make fallback bool into a function

Allows correct handling now that beatmap skins are also a thing.
This commit is contained in:
Dean Herbert 2018-03-16 10:36:26 +09:00
parent f03abb3145
commit fb3d319d0e
6 changed files with 12 additions and 10 deletions

View File

@ -25,7 +25,7 @@ public ExplodePiece()
Blending = BlendingMode.Additive,
RelativeSizeAxes = Axes.Both,
Alpha = 0.2f,
}, false);
}, s => s.GetTexture("Play/osu/hitcircle") == null);
}
}
}

View File

@ -29,7 +29,7 @@ public FlashPiece()
{
RelativeSizeAxes = Axes.Both
}
}, false);
}, s => s.GetTexture("Play/osu/hitcircle") == null);
}
}
}

View File

@ -29,7 +29,7 @@ private void load(TextureStore textures)
Texture = textures.Get(name),
Blending = BlendingMode.Additive,
Alpha = 0.5f
}, false);
}, s => s.GetTexture("Play/osu/hitcircle") == null);
}
}
}

View File

@ -40,7 +40,7 @@ public NumberPiece()
Colour = Color4.White.Opacity(0.5f),
},
Child = new Box()
}, false),
}, s => s.GetTexture("Play/osu/hitcircle") == null),
number = new OsuSpriteText
{
Text = @"1",

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
@ -11,20 +12,21 @@ namespace osu.Game.Skinning
/// </summary>
public abstract class SkinReloadableDrawable : CompositeDrawable
{
private readonly Func<ISkinSource, bool> allowFallback;
private ISkinSource skin;
/// <summary>
/// Whether fallback to default skin should be allowed if the custom skin is missing this resource.
/// </summary>
private readonly bool allowDefaultFallback;
private bool allowDefaultFallback => allowFallback == null || allowFallback.Invoke(skin);
/// <summary>
/// Create a new <see cref="SkinReloadableDrawable"/>
/// </summary>
/// <param name="fallback">Whether fallback to default skin should be allowed if the custom skin is missing this resource.</param>
protected SkinReloadableDrawable(bool fallback = true)
protected SkinReloadableDrawable(Func<ISkinSource, bool> allowFallback = null)
{
allowDefaultFallback = fallback;
this.allowFallback = allowFallback;
}
[BackgroundDependencyLoader]

View File

@ -9,8 +9,8 @@ namespace osu.Game.Skinning
{
public class SkinnableDrawable : SkinnableDrawable<Drawable>
{
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true, bool restrictSize = true)
: base(name, defaultImplementation, fallback, restrictSize)
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
: base(name, defaultImplementation, allowFallback, restrictSize)
{
}
}
@ -31,7 +31,7 @@ public class SkinnableDrawable<T> : SkinReloadableDrawable
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
/// <param name="fallback">Whther to fallback to the default implementation when a custom skin is specified but not implementation is present.</param>
/// <param name="restrictSize">Whether a user-skin drawable should be limited to the size of our parent.</param>
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true, bool restrictSize = true) : base(fallback)
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true) : base(allowFallback)
{
componentName = name;
createDefault = defaultImplementation;