2018-02-22 16:33:47 +08: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;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
|
{
|
|
|
|
|
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
|
|
|
|
{
|
|
|
|
|
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true)
|
|
|
|
|
: base(name, defaultImplementation, fallback)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 19:34:08 +08:00
|
|
|
|
public class SkinnableDrawable<T> : SkinReloadableDrawable
|
2018-02-22 16:33:47 +08:00
|
|
|
|
where T : Drawable
|
|
|
|
|
{
|
2018-02-23 19:34:08 +08:00
|
|
|
|
private readonly Func<string, T> createDefault;
|
2018-02-22 16:33:47 +08:00
|
|
|
|
|
2018-02-23 19:34:08 +08:00
|
|
|
|
private readonly string componentName;
|
2018-02-22 16:33:47 +08:00
|
|
|
|
|
2018-02-23 19:34:08 +08:00
|
|
|
|
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true) : base(fallback)
|
2018-02-22 16:33:47 +08:00
|
|
|
|
{
|
2018-02-23 19:34:08 +08:00
|
|
|
|
componentName = name;
|
|
|
|
|
createDefault = defaultImplementation;
|
2018-02-22 16:33:47 +08:00
|
|
|
|
|
2018-02-23 19:34:08 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2018-02-22 16:33:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-23 19:34:08 +08:00
|
|
|
|
protected override void SkinChanged(Skin skin, bool allowFallback)
|
2018-02-22 16:33:47 +08:00
|
|
|
|
{
|
2018-02-23 19:34:08 +08:00
|
|
|
|
var drawable = skin.GetDrawableComponent(componentName);
|
|
|
|
|
if (drawable == null && allowFallback)
|
|
|
|
|
drawable = createDefault(componentName);
|
2018-02-22 16:33:47 +08:00
|
|
|
|
|
|
|
|
|
if (drawable != null)
|
|
|
|
|
InternalChild = drawable;
|
|
|
|
|
else
|
|
|
|
|
ClearInternal();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|