Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add maximum dimensions limit to skinnable gameplay elements #24706

Merged
merged 23 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2c81fe5
Make gameplay skin elements in `special-skin` awfully large
frenzibyte Sep 1, 2023
6674c70
Add support for limiting skin texture/animation dimensions
frenzibyte Sep 2, 2023
351081e
Add limit to osu! hit circle elements
frenzibyte Sep 2, 2023
d286816
Add limit to taiko hit elements
frenzibyte Sep 2, 2023
f182f57
Add limit to catch palpable object elements
frenzibyte Sep 2, 2023
96f12cf
Update `GetTexture` signature rather than creating new overload
peppy Sep 5, 2023
9d17539
Add size limitations for taiko drum rolls
peppy Sep 5, 2023
57dc76b
Revert "Update `GetTexture` signature rather than creating new overload"
frenzibyte Sep 19, 2023
291a91b
Change extension from retrieval to post-processing instead
frenzibyte Sep 19, 2023
a373d71
Add basic test scene upscaling all skin elements
frenzibyte Sep 19, 2023
fc1a39e
Add size limitations for slider balls
frenzibyte Sep 19, 2023
f963a92
Add size limitation for slider follow circle
frenzibyte Sep 19, 2023
b823507
Add size limitation for approach circles
frenzibyte Sep 19, 2023
ab52268
Add size limitation for slider reverse arrow piece
frenzibyte Sep 19, 2023
922f6f3
Add size limitation for hit object numbers
frenzibyte Sep 19, 2023
8f5d1b5
Revert "Make gameplay skin elements in `special-skin` awfully large"
frenzibyte Sep 19, 2023
8e16b1d
Simplify some maximum size specs
peppy Sep 20, 2023
bd66285
Rename parameter on `LegacySpriteText` to better imply the maximum si…
peppy Sep 20, 2023
1316403
Fix inspection in new test scene
peppy Sep 20, 2023
c4fc419
Use correct maximum size for droplets
frenzibyte Sep 21, 2023
ad86bf2
Revert redundant size limitations
frenzibyte Sep 21, 2023
b1561b6
Rename test scene, add xmldoc and increase scale factor to something …
peppy Sep 26, 2023
990c545
Merge branch 'master' into limit-gameplay-sprite-dimensions
peppy Sep 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyBananaPiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.GetTextureWithMaxSize("fruit-bananas", banana_max_size);
Texture? overlayTexture = Skin.GetTextureWithMaxSize("fruit-bananas-overlay", banana_max_size);

SetTexture(texture, overlayTexture);
}
Expand Down
7 changes: 5 additions & 2 deletions osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyDropletPiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(100);
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does 100 come from? The template skin is 82 x 103 (@1x).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to say it's correct, but I think I picked 100 as it's closest to 103...I'll change to 82x103


public LegacyDropletPiece()
{
Scale = new Vector2(0.8f);
Expand All @@ -17,8 +20,8 @@ protected override void LoadComplete()
{
base.LoadComplete();

Texture? texture = Skin.GetTexture("fruit-drop");
Texture? overlayTexture = Skin.GetTexture("fruit-drop-overlay");
Texture? texture = Skin.GetTextureWithMaxSize("fruit-drop", droplet_max_size);
Texture? overlayTexture = Skin.GetTextureWithMaxSize("fruit-drop-overlay", droplet_max_size);

SetTexture(texture, overlayTexture);
}
Expand Down
12 changes: 8 additions & 4 deletions osu.Game.Rulesets.Catch/Skinning/Legacy/LegacyFruitPiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -22,19 +26,19 @@ private void setTexture(FruitVisualRepresentation visualRepresentation)
switch (visualRepresentation)
{
case FruitVisualRepresentation.Pear:
SetTexture(Skin.GetTexture("fruit-pear"), Skin.GetTexture("fruit-pear-overlay"));
SetTexture(Skin.GetTextureWithMaxSize("fruit-pear", fruit_max_size), Skin.GetTextureWithMaxSize("fruit-pear-overlay", fruit_max_size));
break;

case FruitVisualRepresentation.Grape:
SetTexture(Skin.GetTexture("fruit-grapes"), Skin.GetTexture("fruit-grapes-overlay"));
SetTexture(Skin.GetTextureWithMaxSize("fruit-grapes", fruit_max_size), Skin.GetTextureWithMaxSize("fruit-grapes-overlay", fruit_max_size));
break;

case FruitVisualRepresentation.Pineapple:
SetTexture(Skin.GetTexture("fruit-apple"), Skin.GetTexture("fruit-apple-overlay"));
SetTexture(Skin.GetTextureWithMaxSize("fruit-apple", fruit_max_size), Skin.GetTextureWithMaxSize("fruit-apple-overlay", fruit_max_size));
break;

case FruitVisualRepresentation.Raspberry:
SetTexture(Skin.GetTexture("fruit-orange"), Skin.GetTexture("fruit-orange-overlay"));
SetTexture(Skin.GetTextureWithMaxSize("fruit-orange", fruit_max_size), Skin.GetTextureWithMaxSize("fruit-orange-overlay", fruit_max_size));
break;
}
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ namespace osu.Game.Rulesets.Osu.Skinning.Legacy
{
public partial class LegacyMainCirclePiece : CompositeDrawable
{
private static readonly Vector2 circle_piece_size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);

public override bool RemoveCompletedTransforms => false;

/// <summary>
Expand Down Expand Up @@ -51,7 +53,7 @@ public LegacyMainCirclePiece(string? priorityLookupPrefix = null, bool hasNumber
this.priorityLookupPrefix = priorityLookupPrefix;
this.hasNumber = hasNumber;

Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
Size = circle_piece_size;
}

[BackgroundDependencyLoader]
Expand All @@ -68,7 +70,7 @@ private void load()
// 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.GetTextureWithMaxSize(circleName, circle_piece_size) })
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Expand All @@ -77,7 +79,7 @@ private void load()
{
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: circle_piece_size))
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions osu.Game.Rulesets.Taiko/Skinning/Legacy/LegacyCirclePiece.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -52,9 +54,9 @@ private void load(ISkinSource skin, DrawableHitObject drawableHitObject, IBeatSy

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.
Expand Down Expand Up @@ -96,7 +98,7 @@ protected override void Update()
// 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);
Expand Down
3 changes: 2 additions & 1 deletion osu.Game/Skinning/IAnimationTimeReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics.Textures;
using osu.Framework.Timing;
using osuTK;

namespace osu.Game.Skinning
{
Expand All @@ -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
Expand Down
35 changes: 27 additions & 8 deletions osu.Game/Skinning/LegacySkinExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,24 @@
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
{
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)
{
Expand All @@ -53,7 +54,7 @@ public static partial class LegacySkinExtensions
}
}

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;

Expand All @@ -78,7 +79,9 @@ public static Texture[] GetTextures(this ISkin? source, string componentName, Wr
}

// if an animation was not allowed or not found, fall back to a sprite retrieval.
var singleTexture = retrievalSource.GetTexture(componentName, wrapModeS, wrapModeT);
var singleTexture = maxSize != null
? retrievalSource.GetTextureWithMaxSize(componentName, maxSize.Value, wrapModeS, wrapModeT)
: retrievalSource.GetTexture(componentName, wrapModeS, wrapModeT);

return singleTexture != null
? new[] { singleTexture }
Expand All @@ -88,9 +91,11 @@ IEnumerable<Texture> getTextures(ISkin skin)
{
for (int i = 0; true; i++)
{
Texture? texture;
var texture = maxSize != null
? skin.GetTextureWithMaxSize(getFrameName(i), maxSize.Value, wrapModeS, wrapModeT)
: skin.GetTexture(getFrameName(i), wrapModeS, wrapModeT);

if ((texture = skin.GetTexture(getFrameName(i), wrapModeS, wrapModeT)) == null)
if (texture == null)
break;

yield return texture;
Expand All @@ -100,6 +105,20 @@ IEnumerable<Texture> getTextures(ISkin skin)
string getFrameName(int frameIndex) => $"{componentName}{animationSeparator}{frameIndex}";
}

public static Texture? GetTextureWithMaxSize(this ISkin source, string componentName, Vector2 maxSize, WrapMode wrapModeS = WrapMode.None, WrapMode wrapModeT = WrapMode.None)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More to the code side of things, why is this a separate method, but GetAnimation() gets an optional maxSize param? Should be one or the other all the way.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done some code mashing and removed this overload / new method. See if it reads better to you.

Note that I did this as a prelim requirement. I haven't yet assessed whether the overall direction is correct yet.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just quickly going over source without getting too deep into it, definitely seems much closer to what I'd expect to see.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done some code mashing and removed this overload / new method. See if it reads better to you.

It would've been better presenting the change as a proposal first before pushing. I'm not in favour with the new code as it means every skin implementation must respect the maxSize parameter & perform the same exact code of trimming the texture, which is better achieved with an extension method rather than providing that as part of the core method itself, especially since the "maximum size" logic can be executed outside of the core method. Not to mention that this massively increases the diff of this PR.

Both of the reasons above are precisely why I haven't considered doing this.

As an alternative, I wouldn't mind something like skin.GetTexture().WithMaximumSize() or just keep everything as is and rename GetTextureWithMaxSize to GetTexture. Whichever feels better (I would prefer the first, because it's very explicit and reads well in code).

Copy link
Collaborator

@bdach bdach Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it means every skin implementation must respect the maxSize parameter & perform the same exact code of trimming the texture

I don't get why this is a concern... If maxSize is null then the method is a no-op, first of all, so there's no performance consideration there. Secondly, we probably want the max size logic in all implementations for future-proofing. (We were even musing briefly in twitch chat about what happens when user skins are not legacy-texture-based but markup-drawable-based in the future, but dismissed that as unimportant for now.) The diff size concern is like basically irrelevant to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the change has already been pushed, and if you're both on board with it then I wouldn't bother to mind it.

{
var texture = source.GetTexture(componentName, wrapModeS, wrapModeT);
if (texture == null)
return texture;

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);
Comment on lines +115 to +116
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're going to have to be very conscious about this, to ensure we don't have any local usages overriding ScaleAdjust themselves.

I've checked all usages in the project right now and it seems okay. For now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, an alternative way to achieve this could be to have something like a "maximum texture size" property in SkinnableSprite, and if the sprite exceeds that property then the scale of it is adjusted accordingly.

That might be better as to avoid tinkering around with low properties like Texture.ScaleAdjust. Also saves from having to add extra properties to GetTexture/GetAnimation. @peppy thoughts? would it be worth the effort?

return texture;
}

public static bool HasFont(this ISkin source, LegacyFont font)
{
return source.GetTexture($"{source.GetFontPrefix(font)}-0") != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void skinSourceChanged()

// 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);
}

Expand Down