1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 14:42:54 +08:00

Use SkinnableSprite to reduce complexity of implementation

This commit is contained in:
Dean Herbert 2019-06-24 14:39:46 +09:00
parent 06b087db70
commit d9f7011769
3 changed files with 9 additions and 23 deletions

View File

@ -1,11 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK; using osuTK;
@ -22,22 +20,13 @@ namespace osu.Game.Rulesets.Catch.UI
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(TextureStore textures) private void load()
{ {
InternalChild = new Container InternalChild = new SkinnableSprite(@"Play/Catch/fruit-catcher-idle")
{
RelativeSizeAxes = Axes.Both,
Child = new SkinnableDrawable("fruit-catcher-idle", _ => new Sprite
{
Texture = textures.Get(@"Play/Catch/fruit-catcher-idle"),
RelativeSizeAxes = Axes.Both,
Size = Vector2.One,
}, restrictSize: true)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Anchor = Anchor.TopCentre, Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre, Origin = Anchor.TopCentre,
}
}; };
} }
} }

View File

@ -23,7 +23,7 @@ namespace osu.Game.Skinning
/// </summary> /// </summary>
protected Drawable Drawable { get; private set; } protected Drawable Drawable { get; private set; }
protected virtual T CreateDefault() => createDefault(componentName); protected virtual T CreateDefault(string name) => createDefault(name);
private readonly Func<string, T> createDefault; private readonly Func<string, T> createDefault;
@ -63,7 +63,7 @@ namespace osu.Game.Skinning
if (Drawable == null && allowFallback) if (Drawable == null && allowFallback)
{ {
Drawable = CreateDefault(); Drawable = CreateDefault(componentName);
isDefault = true; isDefault = true;
} }

View File

@ -12,17 +12,14 @@ namespace osu.Game.Skinning
{ {
protected override bool ApplySizeToDefault => true; protected override bool ApplySizeToDefault => true;
private readonly string defaultName; protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) };
protected override Sprite CreateDefault() => new Sprite { Texture = textures.Get(defaultName) };
[Resolved] [Resolved]
private TextureStore textures { get; set; } private TextureStore textures { get; set; }
public SkinnableSprite(string name, string defaultName, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true) public SkinnableSprite(string name, Func<ISkinSource, bool> allowFallback = null, bool restrictSize = true)
: base(name, allowFallback, restrictSize) : base(name, allowFallback, restrictSize)
{ {
this.defaultName = defaultName;
} }
} }
} }