Introduce the concept of SkinComponents

Removes reliance on string lookups and better defines elements for introduction into database
This commit is contained in:
Dean Herbert
2019-08-30 14:39:02 +09:00
parent ae05faa6d2
commit a15828ab25
43 changed files with 264 additions and 104 deletions

View File

@ -18,39 +18,39 @@ namespace osu.Game.Skinning
/// </summary>
public Drawable Drawable { get; private set; }
private readonly string componentName;
private readonly ISkinComponent component;
private readonly ConfineMode confineMode;
/// <summary>
/// Create a new skinnable drawable.
/// </summary>
/// <param name="name">The namespace-complete resource name for this skinnable element.</param>
/// <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(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
: this(name, allowFallback, confineMode)
public SkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
: this(component, allowFallback, confineMode)
{
createDefault = defaultImplementation;
}
protected SkinnableDrawable(string name, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
protected SkinnableDrawable(ISkinComponent component, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
: base(allowFallback)
{
componentName = name;
this.component = component;
this.confineMode = confineMode;
RelativeSizeAxes = Axes.Both;
}
private readonly Func<string, Drawable> createDefault;
private readonly Func<ISkinComponent, Drawable> createDefault;
private readonly Cached scaling = new Cached();
private bool isDefault;
protected virtual Drawable CreateDefault(string name) => createDefault(name);
protected virtual Drawable CreateDefault(ISkinComponent component) => createDefault(component);
/// <summary>
/// Whether to apply size restrictions (specified via <see cref="confineMode"/>) to the default implementation.
@ -59,13 +59,13 @@ namespace osu.Game.Skinning
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
{
Drawable = skin.GetDrawableComponent(componentName);
Drawable = skin.GetDrawableComponent(component);
isDefault = false;
if (Drawable == null && allowFallback)
{
Drawable = CreateDefault(componentName);
Drawable = CreateDefault(component);
isDefault = true;
}