mirror of https://github.com/ppy/osu
Allow skinnable drawables to be of non-restricted size
This commit is contained in:
parent
fbe8641ec4
commit
bd952ce370
|
@ -32,12 +32,7 @@ public override Drawable GetDrawableComponent(string componentName)
|
||||||
var texture = textures.Get(componentName);
|
var texture = textures.Get(componentName);
|
||||||
if (texture == null) return null;
|
if (texture == null) return null;
|
||||||
|
|
||||||
return new Sprite
|
return new Sprite { Texture = texture };
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
FillMode = FillMode.Fit,
|
|
||||||
Texture = texture,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override SampleChannel GetSample(string sampleName) => samples.Get(sampleName);
|
public override SampleChannel GetSample(string sampleName) => samples.Get(sampleName);
|
||||||
|
@ -48,7 +43,8 @@ private class LegacySkinResourceStore : IResourceStore<byte[]>
|
||||||
private readonly IResourceStore<byte[]> underlyingStore;
|
private readonly IResourceStore<byte[]> underlyingStore;
|
||||||
|
|
||||||
private string getPathForFile(string filename) =>
|
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)
|
public LegacySkinResourceStore(SkinInfo skin, IResourceStore<byte[]> underlyingStore)
|
||||||
{
|
{
|
||||||
|
|
|
@ -3,13 +3,14 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
|
using OpenTK;
|
||||||
|
|
||||||
namespace osu.Game.Skinning
|
namespace osu.Game.Skinning
|
||||||
{
|
{
|
||||||
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
public class SkinnableDrawable : SkinnableDrawable<Drawable>
|
||||||
{
|
{
|
||||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true)
|
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, bool fallback = true, bool restrictSize = true)
|
||||||
: base(name, defaultImplementation, fallback)
|
: base(name, defaultImplementation, fallback, restrictSize)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,10 +22,16 @@ public class SkinnableDrawable<T> : SkinReloadableDrawable
|
||||||
|
|
||||||
private readonly string componentName;
|
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;
|
componentName = name;
|
||||||
createDefault = defaultImplementation;
|
createDefault = defaultImplementation;
|
||||||
|
RestrictSize = restrictSize;
|
||||||
|
|
||||||
RelativeSizeAxes = Axes.Both;
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
@ -32,11 +39,25 @@ public SkinnableDrawable(string name, Func<string, T> defaultImplementation, boo
|
||||||
protected override void SkinChanged(Skin skin, bool allowFallback)
|
protected override void SkinChanged(Skin skin, bool allowFallback)
|
||||||
{
|
{
|
||||||
var drawable = skin.GetDrawableComponent(componentName);
|
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);
|
drawable = createDefault(componentName);
|
||||||
|
|
||||||
if (drawable != null)
|
if (drawable != null)
|
||||||
|
{
|
||||||
|
drawable.Origin = Anchor.Centre;
|
||||||
|
drawable.Anchor = Anchor.Centre;
|
||||||
|
|
||||||
InternalChild = drawable;
|
InternalChild = drawable;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
ClearInternal();
|
ClearInternal();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue