2018-02-22 08:33:47 +00:00
|
|
|
|
// 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.Graphics;
|
2018-03-07 09:20:20 +00:00
|
|
|
|
using OpenTK;
|
2018-02-22 08:33:47 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
|
|
|
|
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
|
|
|
|
{
|
2018-03-07 09:20:20 +00:00
|
|
|
|
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true, bool restrictSize = true)
|
|
|
|
|
: base(name, defaultImplementation, fallback, restrictSize)
|
2018-02-22 08:33:47 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 11:34:08 +00:00
|
|
|
|
public class SkinnableDrawable<T> : SkinReloadableDrawable
|
2018-02-22 08:33:47 +00:00
|
|
|
|
where T : Drawable
|
|
|
|
|
{
|
2018-02-23 11:34:08 +00:00
|
|
|
|
private readonly Func<string, T> createDefault;
|
2018-02-22 08:33:47 +00:00
|
|
|
|
|
2018-02-23 11:34:08 +00:00
|
|
|
|
private readonly string componentName;
|
2018-02-22 08:33:47 +00:00
|
|
|
|
|
2018-03-12 02:02:02 +00:00
|
|
|
|
private readonly bool restrictSize;
|
|
|
|
|
|
2018-03-07 09:20:20 +00:00
|
|
|
|
/// <summary>
|
2018-03-12 02:02:02 +00:00
|
|
|
|
///
|
2018-03-07 09:20:20 +00:00
|
|
|
|
/// </summary>
|
2018-03-12 02:02:02 +00:00
|
|
|
|
/// <param name="name">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="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>
|
2018-03-07 09:20:20 +00:00
|
|
|
|
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true, bool restrictSize = true) : base(fallback)
|
2018-02-22 08:33:47 +00:00
|
|
|
|
{
|
2018-02-23 11:34:08 +00:00
|
|
|
|
componentName = name;
|
|
|
|
|
createDefault = defaultImplementation;
|
2018-03-12 02:02:02 +00:00
|
|
|
|
this.restrictSize = restrictSize;
|
2018-02-22 08:33:47 +00:00
|
|
|
|
|
2018-02-23 11:34:08 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-02-22 08:33:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 11:34:08 +00:00
|
|
|
|
protected override void SkinChanged(Skin skin, bool allowFallback)
|
2018-02-22 08:33:47 +00:00
|
|
|
|
{
|
2018-02-23 11:34:08 +00:00
|
|
|
|
var drawable = skin.GetDrawableComponent(componentName);
|
2018-03-07 09:20:20 +00:00
|
|
|
|
if (drawable != null)
|
|
|
|
|
{
|
2018-03-12 02:02:02 +00:00
|
|
|
|
if (restrictSize)
|
2018-03-07 09:20:20 +00:00
|
|
|
|
{
|
|
|
|
|
drawable.RelativeSizeAxes = Axes.Both;
|
|
|
|
|
drawable.Size = Vector2.One;
|
|
|
|
|
drawable.FillMode = FillMode.Fit;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (allowFallback)
|
2018-02-23 11:34:08 +00:00
|
|
|
|
drawable = createDefault(componentName);
|
2018-02-22 08:33:47 +00:00
|
|
|
|
|
|
|
|
|
if (drawable != null)
|
2018-03-07 09:20:20 +00:00
|
|
|
|
{
|
|
|
|
|
drawable.Origin = Anchor.Centre;
|
|
|
|
|
drawable.Anchor = Anchor.Centre;
|
|
|
|
|
|
2018-02-22 08:33:47 +00:00
|
|
|
|
InternalChild = drawable;
|
2018-03-07 09:20:20 +00:00
|
|
|
|
}
|
2018-02-22 08:33:47 +00:00
|
|
|
|
else
|
|
|
|
|
ClearInternal();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|