1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 08:32:57 +08:00

Merge pull request #26598 from frenzibyte/fix-storyboard-sprites-2

Remove handling for non-legacy texture lookup paths in `LegacySkin`
This commit is contained in:
Dean Herbert 2024-01-22 17:50:55 +09:00 committed by GitHub
commit 993e733fce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 59 additions and 103 deletions

View File

@ -3,47 +3,39 @@
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Skinning.Default
{
public partial class DefaultApproachCircle : SkinnableSprite
public partial class DefaultApproachCircle : Sprite
{
private readonly IBindable<Color4> accentColour = new Bindable<Color4>();
[Resolved]
private DrawableHitObject drawableObject { get; set; } = null!;
public DefaultApproachCircle()
: base("Gameplay/osu/approachcircle")
{
}
private IBindable<Color4> accentColour = null!;
[BackgroundDependencyLoader]
private void load()
private void load(TextureStore textures)
{
accentColour.BindTo(drawableObject.AccentColour);
Texture = textures.Get(@"Gameplay/osu/approachcircle").WithMaximumSize(OsuHitObject.OBJECT_DIMENSIONS * 2);
// account for the sprite being used for the default approach circle being taken from stable,
// when hitcircles have 5px padding on each size. this should be removed if we update the sprite.
Scale = new Vector2(128 / 118f);
}
protected override void LoadComplete()
{
base.LoadComplete();
accentColour.BindValueChanged(colour => Colour = colour.NewValue, true);
}
protected override Drawable CreateDefault(ISkinComponentLookup lookup)
{
var drawable = base.CreateDefault(lookup);
// Although this is a non-legacy component, osu-resources currently stores approach circle as a legacy-like texture.
// See LegacyApproachCircle for documentation as to why this is required.
drawable.Scale = new Vector2(128 / 118f);
return drawable;
accentColour = drawableObject.AccentColour.GetBoundCopy();
accentColour.BindValueChanged(colour => Colour = LegacyColourCompatibility.DisallowZeroAlpha(colour.NewValue), true);
}
}
}

View File

@ -1,9 +1,10 @@
// 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 System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Skinning;
@ -12,40 +13,31 @@ using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
// todo: this should probably not be a SkinnableSprite, as this is always created for legacy skins and is recreated on skin change.
public partial class LegacyApproachCircle : SkinnableSprite
public partial class LegacyApproachCircle : Sprite
{
private readonly IBindable<Color4> accentColour = new Bindable<Color4>();
[Resolved]
private DrawableHitObject drawableObject { get; set; } = null!;
public LegacyApproachCircle()
: base("Gameplay/osu/approachcircle", OsuHitObject.OBJECT_DIMENSIONS * 2)
{
}
private IBindable<Color4> accentColour = null!;
[BackgroundDependencyLoader]
private void load()
private void load(ISkinSource skin)
{
accentColour.BindTo(drawableObject.AccentColour);
var texture = skin.GetTexture(@"approachcircle");
Debug.Assert(texture != null);
Texture = texture.WithMaximumSize(OsuHitObject.OBJECT_DIMENSIONS * 2);
// account for the sprite being used for the default approach circle being taken from stable,
// when hitcircles have 5px padding on each size. this should be removed if we update the sprite.
Scale = new Vector2(128 / 118f);
}
protected override void LoadComplete()
{
base.LoadComplete();
accentColour = drawableObject.AccentColour.GetBoundCopy();
accentColour.BindValueChanged(colour => Colour = LegacyColourCompatibility.DisallowZeroAlpha(colour.NewValue), true);
}
protected override Drawable CreateDefault(ISkinComponentLookup lookup)
{
var drawable = base.CreateDefault(lookup);
// account for the sprite being used for the default approach circle being taken from stable,
// when hitcircles have 5px padding on each size. this should be removed if we update the sprite.
drawable.Scale = new Vector2(128 / 118f);
return drawable;
}
}
}

View File

@ -34,19 +34,19 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
[BackgroundDependencyLoader]
private void load(DrawableHitObject drawableObject, ISkinSource skinSource)
{
const string lookup_name = @"reversearrow";
drawableRepeat = (DrawableSliderRepeat)drawableObject;
AutoSizeAxes = Axes.Both;
string lookupName = new OsuSkinComponentLookup(OsuSkinComponents.ReverseArrow).LookupName;
var skin = skinSource.FindProvider(s => s.GetTexture(lookupName) != null);
var skin = skinSource.FindProvider(s => s.GetTexture(lookup_name) != null);
InternalChild = arrow = new Sprite
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin?.GetTexture(lookupName)?.WithMaximumSize(maxSize: OsuHitObject.OBJECT_DIMENSIONS * 2),
Texture = skin?.GetTexture(lookup_name)?.WithMaximumSize(maxSize: OsuHitObject.OBJECT_DIMENSIONS * 2),
};
textureIsDefaultSkin = skin is ISkinTransformer transformer && transformer.Skin is DefaultLegacySkin;

View File

@ -163,7 +163,10 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
return null;
case OsuSkinComponents.ApproachCircle:
return new LegacyApproachCircle();
if (GetTexture(@"approachcircle") != null)
return new LegacyApproachCircle();
return null;
default:
throw new UnsupportedSkinComponentException(lookup);

View File

@ -56,24 +56,6 @@ namespace osu.Game.Tests.NonVisual.Skinning
"Gameplay/osu/followpoint", 1
},
new object[]
{
new[] { "followpoint@2x", "followpoint" },
"Gameplay/osu/followpoint",
"followpoint@2x", 2
},
new object[]
{
new[] { "followpoint@2x" },
"Gameplay/osu/followpoint",
"followpoint@2x", 2
},
new object[]
{
new[] { "followpoint" },
"Gameplay/osu/followpoint",
"followpoint", 1
},
new object[]
{
// Looking up a filename with extension specified should work.
new[] { "followpoint.png" },

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
@ -28,8 +27,5 @@ namespace osu.Game.Skinning
protected virtual string RulesetPrefix => string.Empty;
protected virtual string ComponentName => Component.ToString();
public string LookupName =>
string.Join('/', new[] { "Gameplay", RulesetPrefix, ComponentName }.Where(s => !string.IsNullOrEmpty(s)));
}
}

View File

@ -491,39 +491,30 @@ namespace osu.Game.Skinning
break;
}
foreach (string name in getFallbackNames(componentName))
Texture? texture = null;
float ratio = 1;
if (AllowHighResolutionSprites)
{
string lookupName = name;
Texture? texture = null;
float ratio = 1;
// 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.
componentName = componentName.Replace(@"@2x", string.Empty);
if (AllowHighResolutionSprites)
{
// 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);
string twoTimesFilename = $"{Path.ChangeExtension(componentName, null)}@2x{Path.GetExtension(componentName)}";
string twoTimesFilename = $"{Path.ChangeExtension(lookupName, null)}@2x{Path.GetExtension(lookupName)}";
texture = Textures?.Get(twoTimesFilename, wrapModeS, wrapModeT);
texture = Textures?.Get(twoTimesFilename, wrapModeS, wrapModeT);
if (texture != null)
ratio = 2;
}
if (texture == null)
{
ratio = 1;
texture = Textures?.Get(lookupName, wrapModeS, wrapModeT);
}
if (texture == null)
continue;
texture.ScaleAdjust = ratio;
return texture;
}
return null;
texture ??= Textures?.Get(componentName, wrapModeS, wrapModeT);
if (texture != null)
texture.ScaleAdjust = ratio;
return texture;
}
public override ISample? GetSample(ISampleInfo sampleInfo)
@ -534,7 +525,7 @@ namespace osu.Game.Skinning
lookupNames = getLegacyLookupNames(hitSample);
else
{
lookupNames = sampleInfo.LookupNames.SelectMany(getFallbackNames);
lookupNames = sampleInfo.LookupNames.SelectMany(getFallbackSampleNames);
}
foreach (string lookup in lookupNames)
@ -552,7 +543,7 @@ namespace osu.Game.Skinning
private IEnumerable<string> getLegacyLookupNames(HitSampleInfo hitSample)
{
var lookupNames = hitSample.LookupNames.SelectMany(getFallbackNames);
var lookupNames = hitSample.LookupNames.SelectMany(getFallbackSampleNames);
if (!UseCustomSampleBanks && !string.IsNullOrEmpty(hitSample.Suffix))
{
@ -571,13 +562,13 @@ namespace osu.Game.Skinning
yield return hitSample.Name;
}
private IEnumerable<string> getFallbackNames(string componentName)
private IEnumerable<string> getFallbackSampleNames(string name)
{
// May be something like "Gameplay/osu/approachcircle" from lazer, or "Arrows/note1" from a user skin.
yield return componentName;
// May be something like "Gameplay/normal-hitnormal" from lazer.
yield return name;
// Fall back to using the last piece for components coming from lazer (e.g. "Gameplay/osu/approachcircle" -> "approachcircle").
yield return componentName.Split('/').Last();
// Fall back to using the last piece for components coming from lazer (e.g. "Gameplay/normal-hitnormal" -> "normal-hitnormal").
yield return name.Split('/').Last();
}
}
}