Implement skinnable sprite text

This commit is contained in:
smoogipoo
2018-09-27 16:27:11 +09:00
parent b84994e643
commit 0d8276c5f8
4 changed files with 104 additions and 21 deletions

View File

@ -18,6 +18,8 @@ namespace osu.Game.Skinning
public class SkinnableDrawable<T> : SkinReloadableDrawable
where T : Drawable
{
protected Drawable Drawable { get; private set; }
private readonly Func<string, T> createDefault;
private readonly string componentName;
@ -31,7 +33,8 @@ namespace osu.Game.Skinning
/// <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="restrictSize">Whether a user-skin drawable should be limited to the size of our parent.</param>
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true) : base(allowFallback)
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
: base(allowFallback)
{
componentName = name;
createDefault = defaultImplementation;
@ -42,26 +45,28 @@ namespace osu.Game.Skinning
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
{
var drawable = skin.GetDrawableComponent(componentName);
if (drawable != null)
Drawable = null;
Drawable = skin.GetDrawableComponent(componentName);
if (Drawable != null)
{
if (restrictSize)
{
drawable.RelativeSizeAxes = Axes.Both;
drawable.Size = Vector2.One;
drawable.Scale = Vector2.One;
drawable.FillMode = FillMode.Fit;
Drawable.RelativeSizeAxes = Axes.Both;
Drawable.Size = Vector2.One;
Drawable.Scale = Vector2.One;
Drawable.FillMode = FillMode.Fit;
}
}
else if (allowFallback)
drawable = createDefault(componentName);
Drawable = createDefault(componentName);
if (drawable != null)
if (Drawable != null)
{
drawable.Origin = Anchor.Centre;
drawable.Anchor = Anchor.Centre;
Drawable.Origin = Anchor.Centre;
Drawable.Anchor = Anchor.Centre;
InternalChild = drawable;
InternalChild = Drawable;
}
else
ClearInternal();