mirror of
https://github.com/ppy/osu.git
synced 2024-09-21 18:47:27 +08:00
Allow disabling high resolution texture lookups in LegacySkin
This commit is contained in:
parent
da29faffd0
commit
5ad2918a75
@ -127,8 +127,29 @@ namespace osu.Game.Tests.NonVisual.Skinning
|
|||||||
Assert.IsNull(texture);
|
Assert.IsNull(texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestDisallowHighResolutionSprites()
|
||||||
|
{
|
||||||
|
var textureStore = new TestTextureStore("hitcircle", "hitcircle@2x");
|
||||||
|
var legacySkin = new TestLegacySkin(textureStore) { HighResolutionSprites = false };
|
||||||
|
|
||||||
|
var texture = legacySkin.GetTexture("hitcircle");
|
||||||
|
|
||||||
|
Assert.IsNotNull(texture);
|
||||||
|
Assert.That(texture.ScaleAdjust, Is.EqualTo(1));
|
||||||
|
|
||||||
|
texture = legacySkin.GetTexture("hitcircle@2x");
|
||||||
|
|
||||||
|
Assert.IsNotNull(texture);
|
||||||
|
Assert.That(texture.ScaleAdjust, Is.EqualTo(1));
|
||||||
|
}
|
||||||
|
|
||||||
private class TestLegacySkin : LegacySkin
|
private class TestLegacySkin : LegacySkin
|
||||||
{
|
{
|
||||||
|
public bool HighResolutionSprites { get; set; } = true;
|
||||||
|
|
||||||
|
protected override bool AllowHighResolutionSprites => HighResolutionSprites;
|
||||||
|
|
||||||
public TestLegacySkin(IResourceStore<TextureUpload> textureStore)
|
public TestLegacySkin(IResourceStore<TextureUpload> textureStore)
|
||||||
: base(new SkinInfo(), new TestResourceProvider(textureStore), null, string.Empty)
|
: base(new SkinInfo(), new TestResourceProvider(textureStore), null, string.Empty)
|
||||||
{
|
{
|
||||||
|
@ -477,6 +477,11 @@ namespace osu.Game.Skinning
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether high-resolution textures ("@2x"-suffixed) are allowed to be used by <see cref="GetTexture"/> when available.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual bool AllowHighResolutionSprites => true;
|
||||||
|
|
||||||
public override Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
|
public override Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
|
||||||
{
|
{
|
||||||
switch (componentName)
|
switch (componentName)
|
||||||
@ -488,15 +493,22 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
foreach (string name in getFallbackNames(componentName))
|
foreach (string name in getFallbackNames(componentName))
|
||||||
{
|
{
|
||||||
// some component names (especially user-controlled ones, like `HitX` in mania)
|
string lookupName = name;
|
||||||
// may contain `@2x` scale specifications.
|
Texture? texture = null;
|
||||||
// stable happens to check for that and strip them, so do the same to match stable behaviour.
|
float ratio = 1;
|
||||||
string lookupName = name.Replace(@"@2x", string.Empty);
|
|
||||||
|
|
||||||
float ratio = 2;
|
if (AllowHighResolutionSprites)
|
||||||
string twoTimesFilename = $"{Path.ChangeExtension(lookupName, null)}@2x{Path.GetExtension(lookupName)}";
|
{
|
||||||
|
// some component names (especially user-controlled ones, like `HitX` in mania)
|
||||||
|
// may contain `@2x` scale specifications.
|
||||||
|
// stable happens to check for that and strip them, so do the same to match stable behaviour.
|
||||||
|
lookupName = name.Replace(@"@2x", string.Empty);
|
||||||
|
|
||||||
var texture = Textures?.Get(twoTimesFilename, wrapModeS, wrapModeT);
|
string twoTimesFilename = $"{Path.ChangeExtension(lookupName, null)}@2x{Path.GetExtension(lookupName)}";
|
||||||
|
|
||||||
|
texture = Textures?.Get(twoTimesFilename, wrapModeS, wrapModeT);
|
||||||
|
ratio = 2;
|
||||||
|
}
|
||||||
|
|
||||||
if (texture == null)
|
if (texture == null)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user