2019-06-24 05:39:20 +00:00
|
|
|
// 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;
|
2019-07-19 09:38:24 +00:00
|
|
|
using osu.Framework.Graphics;
|
2019-06-24 05:39:20 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
|
|
|
|
namespace osu.Game.Skinning
|
|
|
|
{
|
2019-06-24 06:25:01 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A skinnable element which uses a stable sprite and can therefore share implementation logic.
|
|
|
|
/// </summary>
|
2019-07-19 09:38:24 +00:00
|
|
|
public class SkinnableSprite : SkinnableDrawable
|
2019-06-24 05:39:20 +00:00
|
|
|
{
|
2019-06-24 06:25:01 +00:00
|
|
|
protected override bool ApplySizeRestrictionsToDefault => true;
|
2019-06-24 05:39:20 +00:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private TextureStore textures { get; set; }
|
|
|
|
|
2021-05-27 05:50:42 +00:00
|
|
|
public SkinnableSprite(string textureName, ConfineMode confineMode = ConfineMode.NoScaling)
|
|
|
|
: base(new SpriteComponent(textureName), confineMode)
|
2019-06-24 05:39:20 +00:00
|
|
|
{
|
|
|
|
}
|
2019-06-24 06:27:46 +00:00
|
|
|
|
2020-11-18 07:18:27 +00:00
|
|
|
protected override Drawable CreateDefault(ISkinComponent component)
|
|
|
|
{
|
|
|
|
var texture = textures.Get(component.LookupName);
|
|
|
|
|
|
|
|
if (texture == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return new Sprite { Texture = texture };
|
|
|
|
}
|
2019-09-03 05:21:54 +00:00
|
|
|
|
|
|
|
private class SpriteComponent : ISkinComponent
|
|
|
|
{
|
|
|
|
public SpriteComponent(string textureName)
|
|
|
|
{
|
2019-11-12 09:45:42 +00:00
|
|
|
LookupName = textureName;
|
2019-09-03 05:21:54 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 09:45:42 +00:00
|
|
|
public string LookupName { get; }
|
2019-09-03 05:21:54 +00:00
|
|
|
}
|
2019-06-24 05:39:20 +00:00
|
|
|
}
|
|
|
|
}
|