mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 19:23:22 +08:00
Use SkinnableSprite to reduce complexity of implementation
This commit is contained in:
parent
06b087db70
commit
d9f7011769
@ -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.
|
||||
|
||||
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;
|
||||
using osuTK;
|
||||
|
||||
@ -22,22 +20,13 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
}
|
||||
|
||||
[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,
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
}
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.TopCentre,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Skinning
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
@ -63,7 +63,7 @@ namespace osu.Game.Skinning
|
||||
|
||||
if (Drawable == null && allowFallback)
|
||||
{
|
||||
Drawable = CreateDefault();
|
||||
Drawable = CreateDefault(componentName);
|
||||
isDefault = true;
|
||||
}
|
||||
|
||||
|
@ -12,17 +12,14 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
protected override bool ApplySizeToDefault => true;
|
||||
|
||||
private readonly string defaultName;
|
||||
|
||||
protected override Sprite CreateDefault() => new Sprite { Texture = textures.Get(defaultName) };
|
||||
protected override Sprite CreateDefault(string name) => new Sprite { Texture = textures.Get(name) };
|
||||
|
||||
[Resolved]
|
||||
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)
|
||||
{
|
||||
this.defaultName = defaultName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user