diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs
index 8ee065aaea..9981585f9e 100644
--- a/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs
+++ b/osu.Game.Rulesets.Osu/Objects/Drawables/Pieces/ApproachCircle.cs
@@ -4,7 +4,6 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
-using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Skinning;
@@ -25,7 +24,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
[BackgroundDependencyLoader]
private void load(TextureStore textures)
{
- Child = new SkinnableDrawable("Play/osu/approachcircle", name => new Sprite { Texture = textures.Get(name) });
+ Child = new SkinnableSprite("Play/osu/approachcircle");
}
}
}
diff --git a/osu.Game/Skinning/SkinnableDrawable.cs b/osu.Game/Skinning/SkinnableDrawable.cs
index 3ca58dc625..995cb15136 100644
--- a/osu.Game/Skinning/SkinnableDrawable.cs
+++ b/osu.Game/Skinning/SkinnableDrawable.cs
@@ -15,6 +15,10 @@ namespace osu.Game.Skinning
}
}
+ ///
+ /// A drawable which can be skinned via an .
+ ///
+ /// The type of drawable.
public class SkinnableDrawable : SkinReloadableDrawable
where T : Drawable
{
@@ -23,48 +27,63 @@ namespace osu.Game.Skinning
///
protected Drawable Drawable { get; private set; }
- private readonly Func createDefault;
-
private readonly string componentName;
private readonly bool restrictSize;
///
- ///
+ /// Create a new skinnable drawable.
///
/// The namespace-complete resource name for this skinnable element.
/// A function to create the default skin implementation of this element.
/// A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present.
/// Whether a user-skin drawable should be limited to the size of our parent.
public SkinnableDrawable(string name, Func defaultImplementation, Func allowFallback = null, bool restrictSize = true)
+ : this(name, allowFallback, restrictSize)
+ {
+ createDefault = defaultImplementation;
+ }
+
+ protected SkinnableDrawable(string name, Func allowFallback = null, bool restrictSize = true)
: base(allowFallback)
{
componentName = name;
- createDefault = defaultImplementation;
this.restrictSize = restrictSize;
RelativeSizeAxes = Axes.Both;
}
+ private readonly Func createDefault;
+
+ protected virtual T CreateDefault(string name) => createDefault(name);
+
+ ///
+ /// Whether to apply size restrictions (specified via ) to the default implementation.
+ ///
+ protected virtual bool ApplySizeRestrictionsToDefault => false;
+
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
{
Drawable = skin.GetDrawableComponent(componentName);
+ bool isDefault = false;
+
+ if (Drawable == null && allowFallback)
+ {
+ Drawable = CreateDefault(componentName);
+ isDefault = true;
+ }
+
if (Drawable != null)
{
- if (restrictSize)
+ if (restrictSize && (!isDefault || ApplySizeRestrictionsToDefault))
{
Drawable.RelativeSizeAxes = Axes.Both;
Drawable.Size = Vector2.One;
Drawable.Scale = Vector2.One;
Drawable.FillMode = FillMode.Fit;
}
- }
- else if (allowFallback)
- Drawable = createDefault(componentName);
- if (Drawable != null)
- {
Drawable.Origin = Anchor.Centre;
Drawable.Anchor = Anchor.Centre;
diff --git a/osu.Game/Skinning/SkinnableSprite.cs b/osu.Game/Skinning/SkinnableSprite.cs
new file mode 100644
index 0000000000..ceb1ed0f70
--- /dev/null
+++ b/osu.Game/Skinning/SkinnableSprite.cs
@@ -0,0 +1,28 @@
+// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence.
+// See the LICENCE file in the repository root for full licence text.
+
+using System;
+using osu.Framework.Allocation;
+using osu.Framework.Graphics.Sprites;
+using osu.Framework.Graphics.Textures;
+
+namespace osu.Game.Skinning
+{
+ ///
+ /// A skinnable element which uses a stable sprite and can therefore share implementation logic.
+ ///
+ public class SkinnableSprite : SkinnableDrawable
+ {
+ protected override bool ApplySizeRestrictionsToDefault => true;
+
+ [Resolved]
+ private TextureStore textures { get; set; }
+
+ public SkinnableSprite(string name, Func allowFallback = null, bool restrictSize = true)
+ : base(name, allowFallback, restrictSize)
+ {
+ }
+
+ protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) };
+ }
+}