mirror of
https://github.com/ppy/osu
synced 2024-12-28 09:52:56 +00:00
Allow skinnable drawables to be of non-restricted size
This commit is contained in:
parent
fbe8641ec4
commit
bd952ce370
@ -32,12 +32,7 @@ namespace osu.Game.Skinning
|
||||
var texture = textures.Get(componentName);
|
||||
if (texture == null) return null;
|
||||
|
||||
return new Sprite
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
FillMode = FillMode.Fit,
|
||||
Texture = texture,
|
||||
};
|
||||
return new Sprite { Texture = texture };
|
||||
}
|
||||
|
||||
public override SampleChannel GetSample(string sampleName) => samples.Get(sampleName);
|
||||
@ -48,7 +43,8 @@ namespace osu.Game.Skinning
|
||||
private readonly IResourceStore<byte[]> underlyingStore;
|
||||
|
||||
private string getPathForFile(string filename) =>
|
||||
skin.Files.FirstOrDefault(f => string.Equals(Path.GetFileNameWithoutExtension(f.Filename), filename.Split('/').Last(), StringComparison.InvariantCultureIgnoreCase))?.FileInfo.StoragePath;
|
||||
skin.Files.FirstOrDefault(f => string.Equals(Path.GetFileNameWithoutExtension(f.Filename), filename.Split('/').Last(), StringComparison.InvariantCultureIgnoreCase))?.FileInfo
|
||||
.StoragePath;
|
||||
|
||||
public LegacySkinResourceStore(SkinInfo skin, IResourceStore<byte[]> underlyingStore)
|
||||
{
|
||||
|
@ -3,13 +3,14 @@
|
||||
|
||||
using System;
|
||||
using osu.Framework.Graphics;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
||||
{
|
||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true)
|
||||
: base(name, defaultImplementation, fallback)
|
||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true, bool restrictSize = true)
|
||||
: base(name, defaultImplementation, fallback, restrictSize)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -21,10 +22,16 @@ namespace osu.Game.Skinning
|
||||
|
||||
private readonly string componentName;
|
||||
|
||||
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true) : base(fallback)
|
||||
/// <summary>
|
||||
/// Whether a user-skin drawable should be limited to the size of our parent.
|
||||
/// </summary>
|
||||
public readonly bool RestrictSize;
|
||||
|
||||
public SkinnableDrawable(string name, Func<string, T> defaultImplementation, bool fallback = true, bool restrictSize = true) : base(fallback)
|
||||
{
|
||||
componentName = name;
|
||||
createDefault = defaultImplementation;
|
||||
RestrictSize = restrictSize;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
@ -32,11 +39,25 @@ namespace osu.Game.Skinning
|
||||
protected override void SkinChanged(Skin skin, bool allowFallback)
|
||||
{
|
||||
var drawable = skin.GetDrawableComponent(componentName);
|
||||
if (drawable == null && allowFallback)
|
||||
if (drawable != null)
|
||||
{
|
||||
if (RestrictSize)
|
||||
{
|
||||
drawable.RelativeSizeAxes = Axes.Both;
|
||||
drawable.Size = Vector2.One;
|
||||
drawable.FillMode = FillMode.Fit;
|
||||
}
|
||||
}
|
||||
else if (allowFallback)
|
||||
drawable = createDefault(componentName);
|
||||
|
||||
if (drawable != null)
|
||||
{
|
||||
drawable.Origin = Anchor.Centre;
|
||||
drawable.Anchor = Anchor.Centre;
|
||||
|
||||
InternalChild = drawable;
|
||||
}
|
||||
else
|
||||
ClearInternal();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user