Allow skinnable drawables to be of non-restricted size

This commit is contained in:
Dean Herbert 2018-03-07 18:20:20 +09:00
parent fbe8641ec4
commit bd952ce370
2 changed files with 28 additions and 11 deletions

View File

@ -32,12 +32,7 @@ public override Drawable GetDrawableComponent(string componentName)
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 @@ private class LegacySkinResourceStore : IResourceStore<byte[]>
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)
{

View File

@ -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 @@ public class SkinnableDrawable<T> : SkinReloadableDrawable
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 @@ public SkinnableDrawable(string name, Func<string, T> defaultImplementation, boo
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();
}