1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 15:47:26 +08:00

Merge pull request #24706 from frenzibyte/limit-gameplay-sprite-dimensions

Add maximum dimensions limit to skinnable gameplay elements
This commit is contained in:
Dean Herbert 2023-09-26 17:15:55 +09:00 committed by GitHub
commit 3b85a636b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 196 additions and 62 deletions

View File

@ -2,17 +2,21 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Textures;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Catch.Skinning.Legacy
{
public partial class LegacyBananaPiece : LegacyCatchHitObjectPiece
{
private static readonly Vector2 banana_max_size = new Vector2(128);
protected override void LoadComplete()
{
base.LoadComplete();
Texture? texture = Skin.GetTexture("fruit-bananas");
Texture? overlayTexture = Skin.GetTexture("fruit-bananas-overlay");
Texture? texture = Skin.GetTexture("fruit-bananas")?.WithMaximumSize(banana_max_size);
Texture? overlayTexture = Skin.GetTexture("fruit-bananas-overlay")?.WithMaximumSize(banana_max_size);
SetTexture(texture, overlayTexture);
}

View File

@ -2,12 +2,15 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Graphics.Textures;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Catch.Skinning.Legacy
{
public partial class LegacyDropletPiece : LegacyCatchHitObjectPiece
{
private static readonly Vector2 droplet_max_size = new Vector2(82, 103);
public LegacyDropletPiece()
{
Scale = new Vector2(0.8f);
@ -17,8 +20,8 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
{
base.LoadComplete();
Texture? texture = Skin.GetTexture("fruit-drop");
Texture? overlayTexture = Skin.GetTexture("fruit-drop-overlay");
Texture? texture = Skin.GetTexture("fruit-drop")?.WithMaximumSize(droplet_max_size);
Texture? overlayTexture = Skin.GetTexture("fruit-drop-overlay")?.WithMaximumSize(droplet_max_size);
SetTexture(texture, overlayTexture);
}

View File

@ -2,11 +2,15 @@
// See the LICENCE file in the repository root for full licence text.
using osu.Game.Rulesets.Catch.Objects;
using osu.Game.Skinning;
using osuTK;
namespace osu.Game.Rulesets.Catch.Skinning.Legacy
{
internal partial class LegacyFruitPiece : LegacyCatchHitObjectPiece
{
private static readonly Vector2 fruit_max_size = new Vector2(128);
protected override void LoadComplete()
{
base.LoadComplete();
@ -22,21 +26,26 @@ namespace osu.Game.Rulesets.Catch.Skinning.Legacy
switch (visualRepresentation)
{
case FruitVisualRepresentation.Pear:
SetTexture(Skin.GetTexture("fruit-pear"), Skin.GetTexture("fruit-pear-overlay"));
setTextures("pear");
break;
case FruitVisualRepresentation.Grape:
SetTexture(Skin.GetTexture("fruit-grapes"), Skin.GetTexture("fruit-grapes-overlay"));
setTextures("grapes");
break;
case FruitVisualRepresentation.Pineapple:
SetTexture(Skin.GetTexture("fruit-apple"), Skin.GetTexture("fruit-apple-overlay"));
setTextures("apple");
break;
case FruitVisualRepresentation.Raspberry:
SetTexture(Skin.GetTexture("fruit-orange"), Skin.GetTexture("fruit-orange-overlay"));
setTextures("orange");
break;
}
void setTextures(string fruitName) => SetTexture(
Skin.GetTexture($"fruit-{fruitName}")?.WithMaximumSize(fruit_max_size),
Skin.GetTexture($"fruit-{fruitName}-overlay")?.WithMaximumSize(fruit_max_size)
);
}
}
}

View File

@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components
{
Origin = Anchor.Centre;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
InternalChild = content = new Container
{

View File

@ -16,7 +16,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles.Components
{
Origin = Anchor.Centre;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
CornerRadius = Size.X / 2;
CornerExponent = 2;

View File

@ -244,7 +244,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public HitReceptor()
{
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;

View File

@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
Origin = Anchor.Centre;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Children = new[]
{

View File

@ -50,7 +50,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private void load()
{
Origin = Anchor.Centre;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
AddInternal(scaleContainer = new Container
{

View File

@ -55,7 +55,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
private void load()
{
Origin = Anchor.Centre;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
AddRangeInternal(new Drawable[]
{

View File

@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
[BackgroundDependencyLoader]
private void load()
{
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Origin = Anchor.Centre;
AddInternal(scaleContainer = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.SliderScorePoint), _ => new CircularContainer

View File

@ -21,6 +21,11 @@ namespace osu.Game.Rulesets.Osu.Objects
/// </summary>
public const float OBJECT_RADIUS = 64;
/// <summary>
/// The width and height any element participating in display of a hitcircle (or similarly sized object) should be.
/// </summary>
public static readonly Vector2 OBJECT_DIMENSIONS = new Vector2(OBJECT_RADIUS * 2);
/// <summary>
/// Scoring distance with a speed-adjusted beat length of 1 second (ie. the speed slider balls move through their track).
/// </summary>

View File

@ -48,7 +48,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Argon
private Bindable<bool> configHitLighting = null!;
private static readonly Vector2 circle_size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
private static readonly Vector2 circle_size = OsuHitObject.OBJECT_DIMENSIONS;
[Resolved]
private DrawableHitObject drawableObject { get; set; } = null!;

View File

@ -27,7 +27,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Argon
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
InternalChildren = new Drawable[]
{

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osuTK;
namespace osu.Game.Rulesets.Osu.Skinning.Default
{
@ -22,7 +21,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
public CirclePiece()
{
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Masking = true;
CornerRadius = Size.X / 2;

View File

@ -7,7 +7,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osuTK;
namespace osu.Game.Rulesets.Osu.Skinning.Default
{
@ -20,7 +19,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
public ExplodePiece()
{
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;

View File

@ -5,7 +5,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Osu.Objects;
using osuTK;
namespace osu.Game.Rulesets.Osu.Skinning.Default
{
@ -13,7 +12,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
{
public FlashPiece()
{
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Skinning.Default
@ -25,7 +24,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
public MainCirclePiece()
{
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;

View File

@ -27,7 +27,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Child = new SkinnableDrawable(new OsuSkinComponentLookup(OsuSkinComponents.ReverseArrow), _ => new SpriteIcon
{

View File

@ -5,7 +5,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Rulesets.Osu.Objects;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Skinning.Default
@ -14,7 +13,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Default
{
public RingPiece(float thickness = 9)
{
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;

View File

@ -5,12 +5,14 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
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.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
{
private readonly IBindable<Color4> accentColour = new Bindable<Color4>();
@ -19,7 +21,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
private DrawableHitObject drawableObject { get; set; } = null!;
public LegacyApproachCircle()
: base("Gameplay/osu/approachcircle")
: base("Gameplay/osu/approachcircle", OsuHitObject.OBJECT_DIMENSIONS)
{
}

View File

@ -14,7 +14,6 @@ using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
@ -51,7 +50,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
this.priorityLookupPrefix = priorityLookupPrefix;
this.hasNumber = hasNumber;
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = OsuHitObject.OBJECT_DIMENSIONS;
}
[BackgroundDependencyLoader]
@ -68,7 +67,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
// expected behaviour in this scenario is not showing the overlay, rather than using hitcircleoverlay.png.
InternalChildren = new[]
{
CircleSprite = new LegacyKiaiFlashingDrawable(() => new Sprite { Texture = skin.GetTexture(circleName) })
CircleSprite = new LegacyKiaiFlashingDrawable(() => new Sprite { Texture = skin.GetTexture(circleName)?.WithMaximumSize(OsuHitObject.OBJECT_DIMENSIONS) })
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
@ -77,7 +76,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Child = OverlaySprite = new LegacyKiaiFlashingDrawable(() => skin.GetAnimation(@$"{circleName}overlay", true, true, frameLength: 1000 / 2d))
Child = OverlaySprite = new LegacyKiaiFlashingDrawable(() => skin.GetAnimation(@$"{circleName}overlay", true, true, frameLength: 1000 / 2d, maxSize: OsuHitObject.OBJECT_DIMENSIONS))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,

View File

@ -7,6 +7,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Skinning;
using osuTK.Graphics;
@ -35,7 +36,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
var skin = skinSource.FindProvider(s => s.GetTexture(lookupName) != null);
InternalChild = arrow = (skin?.GetAnimation(lookupName, true, true) ?? Empty());
InternalChild = arrow = (skin?.GetAnimation(lookupName, true, true, maxSize: OsuHitObject.OBJECT_DIMENSIONS) ?? Empty());
textureIsDefaultSkin = skin is ISkinTransformer transformer && transformer.Skin is DefaultLegacySkin;
}

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Skinning;
using osuTK.Graphics;
@ -46,7 +47,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin.GetTexture("sliderb-nd"),
Texture = skin.GetTexture("sliderb-nd")?.WithMaximumSize(OsuHitObject.OBJECT_DIMENSIONS),
Colour = new Color4(5, 5, 5, 255),
},
LegacyColourCompatibility.ApplyWithDoubledAlpha(animationContent.With(d =>
@ -58,7 +59,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin.GetTexture("sliderb-spec"),
Texture = skin.GetTexture("sliderb-spec")?.WithMaximumSize(OsuHitObject.OBJECT_DIMENSIONS),
Blending = BlendingParameters.Additive,
},
};

View File

@ -4,6 +4,7 @@
using System;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Skinning;
using osuTK;
@ -20,7 +21,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
/// Their hittable area is 128px, but the actual circle portion is 118px.
/// We must account for some gameplay elements such as slider bodies, where this padding is not present.
/// </summary>
public const float LEGACY_CIRCLE_RADIUS = 64 - 5;
public const float LEGACY_CIRCLE_RADIUS = OsuHitObject.OBJECT_RADIUS - 5;
public OsuLegacySkinTransformer(ISkin skin)
: base(skin)
@ -41,14 +42,14 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
return this.GetAnimation("sliderscorepoint", false, false);
case OsuSkinComponents.SliderFollowCircle:
var followCircleContent = this.GetAnimation("sliderfollowcircle", true, true, true);
var followCircleContent = this.GetAnimation("sliderfollowcircle", true, true, true, maxSize: new Vector2(308f));
if (followCircleContent != null)
return new LegacyFollowCircle(followCircleContent);
return null;
case OsuSkinComponents.SliderBall:
var sliderBallContent = this.GetAnimation("sliderb", true, true, animationSeparator: "");
var sliderBallContent = this.GetAnimation("sliderb", true, true, animationSeparator: "", maxSize: OsuHitObject.OBJECT_DIMENSIONS);
// todo: slider ball has a custom frame delay based on velocity
// Math.Max((150 / Velocity) * GameBase.SIXTY_FRAME_TIME, GameBase.SIXTY_FRAME_TIME);
@ -138,7 +139,7 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
if (!this.HasFont(LegacyFont.HitCircle))
return null;
return new LegacySpriteText(LegacyFont.HitCircle)
return new LegacySpriteText(LegacyFont.HitCircle, OsuHitObject.OBJECT_DIMENSIONS)
{
// stable applies a blanket 0.8x scale to hitcircle fonts
Scale = new Vector2(0.8f),

View File

@ -95,7 +95,7 @@ namespace osu.Game.Rulesets.Osu.UI.Cursor
{
new RingPiece(3)
{
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2),
Size = OsuHitObject.OBJECT_DIMENSIONS,
Alpha = 0.1f,
}
};

View File

@ -22,6 +22,8 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
{
public partial class LegacyCirclePiece : CompositeDrawable, IHasAccentColour
{
private static readonly Vector2 circle_piece_size = new Vector2(128);
private Drawable backgroundLayer = null!;
private Drawable? foregroundLayer;
@ -52,9 +54,9 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
string prefix = ((drawableHitObject.HitObject as TaikoStrongableHitObject)?.IsStrong ?? false) ? big_hit : normal_hit;
return skin.GetAnimation($"{prefix}{lookup}", true, false) ??
return skin.GetAnimation($"{prefix}{lookup}", true, false, maxSize: circle_piece_size) ??
// fallback to regular size if "big" version doesn't exist.
skin.GetAnimation($"{normal_hit}{lookup}", true, false);
skin.GetAnimation($"{normal_hit}{lookup}", true, false, maxSize: circle_piece_size);
}
// backgroundLayer is guaranteed to exist due to the pre-check in TaikoLegacySkinTransformer.
@ -96,7 +98,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
// Not all skins (including the default osu-stable) have similar sizes for "hitcircle" and "hitcircleoverlay".
// This ensures they are scaled relative to each other but also match the expected DrawableHit size.
foreach (var c in InternalChildren)
c.Scale = new Vector2(DrawHeight / 128);
c.Scale = new Vector2(DrawHeight / circle_piece_size.Y);
if (foregroundLayer is IFramedAnimation animatableForegroundLayer)
animateForegroundLayer(animatableForegroundLayer);

View File

@ -0,0 +1,80 @@
// 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;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Textures;
using osu.Framework.Testing;
using osu.Game.IO;
using osu.Game.Rulesets;
using osu.Game.Screens.Play;
using osu.Game.Skinning;
namespace osu.Game.Tests.Visual.Gameplay
{
/// <summary>
/// Upscales all gameplay sprites by a huge amount, to aid in manually checking skin texture size limits
/// on individual elements.
/// </summary>
/// <remarks>
/// The HUD is hidden as it does't really affect game balance if HUD elements are larger than they should be.
/// </remarks>
public partial class TestScenePlayerMaxDimensions : TestSceneAllRulesetPlayers
{
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
// for now this only applies to legacy skins, as modern skins don't have texture-based gameplay elements yet.
dependencies.CacheAs<ISkinSource>(new UpscaledLegacySkin(dependencies.Get<SkinManager>()));
return dependencies;
}
protected override void AddCheckSteps()
{
}
protected override Player CreatePlayer(Ruleset ruleset)
{
var player = base.CreatePlayer(ruleset);
player.OnLoadComplete += _ =>
{
// this test scene focuses on gameplay elements, so let's hide the hud.
var hudOverlay = player.ChildrenOfType<HUDOverlay>().Single();
hudOverlay.ShowHud.Value = false;
hudOverlay.ShowHud.Disabled = true;
};
return player;
}
private class UpscaledLegacySkin : DefaultLegacySkin, ISkinSource
{
public UpscaledLegacySkin(IStorageResourceProvider resources)
: base(resources)
{
}
public event Action? SourceChanged
{
add { }
remove { }
}
public override Texture? GetTexture(string componentName, WrapMode wrapModeS, WrapMode wrapModeT)
{
var texture = base.GetTexture(componentName, wrapModeS, wrapModeT);
if (texture != null)
texture.ScaleAdjust /= 40f;
return texture;
}
public ISkin FindProvider(Func<ISkin, bool> lookupFunction) => this;
public IEnumerable<ISkin> AllSources => new[] { this };
}
}
}

View File

@ -5,6 +5,7 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Textures;
using osu.Framework.Timing;
using osuTK;
namespace osu.Game.Skinning
{
@ -13,7 +14,7 @@ namespace osu.Game.Skinning
/// </summary>
/// <remarks>
/// This should not be used to start an animation immediately at the current time.
/// To do so, use <see cref="LegacySkinExtensions.GetAnimation(ISkin, string, WrapMode, WrapMode, bool, bool, bool, string, bool, double?)"/> with <code>startAtCurrentTime = true</code> instead.
/// To do so, use <see cref="LegacySkinExtensions.GetAnimation(ISkin, string, WrapMode, WrapMode, bool, bool, bool, string, bool, double?, Vector2?)"/> with <code>startAtCurrentTime = true</code> instead.
/// </remarks>
[Cached]
public interface IAnimationTimeReference

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osuTK;
using static osu.Game.Skinning.SkinConfiguration;
namespace osu.Game.Skinning
@ -18,16 +19,16 @@ namespace osu.Game.Skinning
public static partial class LegacySkinExtensions
{
public static Drawable? GetAnimation(this ISkin? source, string componentName, bool animatable, bool looping, bool applyConfigFrameRate = false, string animationSeparator = "-",
bool startAtCurrentTime = true, double? frameLength = null)
=> source.GetAnimation(componentName, default, default, animatable, looping, applyConfigFrameRate, animationSeparator, startAtCurrentTime, frameLength);
bool startAtCurrentTime = true, double? frameLength = null, Vector2? maxSize = null)
=> source.GetAnimation(componentName, default, default, animatable, looping, applyConfigFrameRate, animationSeparator, startAtCurrentTime, frameLength, maxSize);
public static Drawable? GetAnimation(this ISkin? source, string componentName, WrapMode wrapModeS, WrapMode wrapModeT, bool animatable, bool looping, bool applyConfigFrameRate = false,
string animationSeparator = "-", bool startAtCurrentTime = true, double? frameLength = null)
string animationSeparator = "-", bool startAtCurrentTime = true, double? frameLength = null, Vector2? maxSize = null)
{
if (source == null)
return null;
var textures = GetTextures(source, componentName, wrapModeS, wrapModeT, animatable, animationSeparator, out var retrievalSource);
var textures = GetTextures(source, componentName, wrapModeS, wrapModeT, animatable, animationSeparator, maxSize, out var retrievalSource);
switch (textures.Length)
{
@ -53,7 +54,7 @@ namespace osu.Game.Skinning
}
}
public static Texture[] GetTextures(this ISkin? source, string componentName, WrapMode wrapModeS, WrapMode wrapModeT, bool animatable, string animationSeparator, out ISkin? retrievalSource)
public static Texture[] GetTextures(this ISkin? source, string componentName, WrapMode wrapModeS, WrapMode wrapModeT, bool animatable, string animationSeparator, Vector2? maxSize, out ISkin? retrievalSource)
{
retrievalSource = null;
@ -80,6 +81,9 @@ namespace osu.Game.Skinning
// if an animation was not allowed or not found, fall back to a sprite retrieval.
var singleTexture = retrievalSource.GetTexture(componentName, wrapModeS, wrapModeT);
if (singleTexture != null && maxSize != null)
singleTexture = singleTexture.WithMaximumSize(maxSize.Value);
return singleTexture != null
? new[] { singleTexture }
: Array.Empty<Texture>();
@ -88,11 +92,14 @@ namespace osu.Game.Skinning
{
for (int i = 0; true; i++)
{
Texture? texture;
var texture = skin.GetTexture(getFrameName(i), wrapModeS, wrapModeT);
if ((texture = skin.GetTexture(getFrameName(i), wrapModeS, wrapModeT)) == null)
if (texture == null)
break;
if (maxSize != null)
texture = texture.WithMaximumSize(maxSize.Value);
yield return texture;
}
}
@ -100,6 +107,16 @@ namespace osu.Game.Skinning
string getFrameName(int frameIndex) => $"{componentName}{animationSeparator}{frameIndex}";
}
public static Texture WithMaximumSize(this Texture texture, Vector2 maxSize)
{
if (texture.DisplayWidth <= maxSize.X && texture.DisplayHeight <= maxSize.Y)
return texture;
// use scale adjust property for downscaling the texture in order to meet the specified maximum dimensions.
texture.ScaleAdjust *= Math.Max(texture.DisplayWidth / maxSize.X, texture.DisplayHeight / maxSize.Y);
return texture;
}
public static bool HasFont(this ISkin source, LegacyFont font)
{
return source.GetTexture($"{source.GetFontPrefix(font)}-0") != null;

View File

@ -13,6 +13,7 @@ namespace osu.Game.Skinning
public sealed partial class LegacySpriteText : OsuSpriteText
{
private readonly LegacyFont font;
private readonly Vector2? maxSizePerGlyph;
private LegacyGlyphStore glyphStore = null!;
@ -20,9 +21,11 @@ namespace osu.Game.Skinning
protected override char[] FixedWidthExcludeCharacters => new[] { ',', '.', '%', 'x' };
public LegacySpriteText(LegacyFont font)
public LegacySpriteText(LegacyFont font, Vector2? maxSizePerGlyph = null)
{
this.font = font;
this.maxSizePerGlyph = maxSizePerGlyph;
Shadow = false;
UseFullGlyphHeight = false;
}
@ -33,7 +36,7 @@ namespace osu.Game.Skinning
Font = new FontUsage(skin.GetFontPrefix(font), 1, fixedWidth: true);
Spacing = new Vector2(-skin.GetFontOverlap(font), 0);
glyphStore = new LegacyGlyphStore(skin);
glyphStore = new LegacyGlyphStore(skin, maxSizePerGlyph);
}
protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
@ -41,10 +44,12 @@ namespace osu.Game.Skinning
private class LegacyGlyphStore : ITexturedGlyphLookupStore
{
private readonly ISkin skin;
private readonly Vector2? maxSize;
public LegacyGlyphStore(ISkin skin)
public LegacyGlyphStore(ISkin skin, Vector2? maxSize)
{
this.skin = skin;
this.maxSize = maxSize;
}
public ITexturedCharacterGlyph? Get(string fontName, char character)
@ -56,6 +61,9 @@ namespace osu.Game.Skinning
if (texture == null)
return null;
if (maxSize != null)
texture = texture.WithMaximumSize(maxSize.Value);
return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture.Width, texture.Height, null), texture, 1f / texture.ScaleAdjust);
}

View File

@ -197,7 +197,7 @@ namespace osu.Game.Skinning
{
// This fallback is important for user skins which use SkinnableSprites.
case SkinnableSprite.SpriteComponentLookup sprite:
return this.GetAnimation(sprite.LookupName, false, false);
return this.GetAnimation(sprite.LookupName, false, false, maxSize: sprite.MaxSize);
case SkinComponentsContainerLookup containerLookup:

View File

@ -34,8 +34,8 @@ namespace osu.Game.Skinning
[Resolved]
private ISkinSource source { get; set; } = null!;
public SkinnableSprite(string textureName, ConfineMode confineMode = ConfineMode.NoScaling)
: base(new SpriteComponentLookup(textureName), confineMode)
public SkinnableSprite(string textureName, Vector2? maxSize = null, ConfineMode confineMode = ConfineMode.NoScaling)
: base(new SpriteComponentLookup(textureName, maxSize), confineMode)
{
SpriteName.Value = textureName;
}
@ -56,10 +56,14 @@ namespace osu.Game.Skinning
protected override Drawable CreateDefault(ISkinComponentLookup lookup)
{
var texture = textures.Get(((SpriteComponentLookup)lookup).LookupName);
var spriteLookup = (SpriteComponentLookup)lookup;
var texture = textures.Get(spriteLookup.LookupName);
if (texture == null)
return new SpriteNotFound(((SpriteComponentLookup)lookup).LookupName);
return new SpriteNotFound(spriteLookup.LookupName);
if (spriteLookup.MaxSize != null)
texture = texture.WithMaximumSize(spriteLookup.MaxSize.Value);
return new Sprite { Texture = texture };
}
@ -69,10 +73,12 @@ namespace osu.Game.Skinning
internal class SpriteComponentLookup : ISkinComponentLookup
{
public string LookupName { get; set; }
public Vector2? MaxSize { get; set; }
public SpriteComponentLookup(string textureName)
public SpriteComponentLookup(string textureName, Vector2? maxSize = null)
{
LookupName = textureName;
MaxSize = maxSize;
}
}

View File

@ -135,7 +135,7 @@ namespace osu.Game.Storyboards.Drawables
// When reading from a skin, we match stables weird behaviour where `FrameCount` is ignored
// and resources are retrieved until the end of the animation.
foreach (var texture in skin.GetTextures(Path.GetFileNameWithoutExtension(Animation.Path)!, default, default, true, string.Empty, out _))
foreach (var texture in skin.GetTextures(Path.GetFileNameWithoutExtension(Animation.Path)!, default, default, true, string.Empty, null, out _))
AddFrame(texture, Animation.FrameDelay);
}