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 16 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
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.GetTexture("fruit-bananas")?.WithMaximumSize(banana_max_size);
Texture? overlayTexture = Skin.GetTexture("fruit-bananas-overlay")?.WithMaximumSize(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.GetTexture("fruit-drop")?.WithMaximumSize(droplet_max_size);
Texture? overlayTexture = Skin.GetTexture("fruit-drop-overlay")?.WithMaximumSize(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.GetTexture("fruit-pear")?.WithMaximumSize(fruit_max_size), Skin.GetTexture("fruit-pear-overlay")?.WithMaximumSize(fruit_max_size));
break;

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

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

case FruitVisualRepresentation.Raspberry:
SetTexture(Skin.GetTexture("fruit-orange"), Skin.GetTexture("fruit-orange-overlay"));
SetTexture(Skin.GetTexture("fruit-orange")?.WithMaximumSize(fruit_max_size), Skin.GetTexture("fruit-orange-overlay")?.WithMaximumSize(fruit_max_size));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
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>();
Expand All @@ -19,7 +21,7 @@ public partial class LegacyApproachCircle : SkinnableSprite
private DrawableHitObject drawableObject { get; set; } = null!;

public LegacyApproachCircle()
: base("Gameplay/osu/approachcircle")
: base("Gameplay/osu/approachcircle", new Vector2(OsuHitObject.OBJECT_RADIUS * 2))
{
}

Expand Down
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.GetTexture(circleName)?.WithMaximumSize(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
4 changes: 3 additions & 1 deletion osu.Game.Rulesets.Osu/Skinning/Legacy/LegacyReverseArrow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
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;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Osu.Skinning.Legacy
Expand All @@ -35,7 +37,7 @@ private void load(ISkinSource skinSource)

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: new Vector2(OsuHitObject.OBJECT_RADIUS * 2)) ?? Empty());
textureIsDefaultSkin = skin is ISkinTransformer transformer && transformer.Skin is DefaultLegacySkin;
}

Expand Down
6 changes: 4 additions & 2 deletions osu.Game.Rulesets.Osu/Skinning/Legacy/LegacySliderBall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
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;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Osu.Skinning.Legacy
Expand Down Expand Up @@ -46,7 +48,7 @@ private void load()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin.GetTexture("sliderb-nd"),
Texture = skin.GetTexture("sliderb-nd")?.WithMaximumSize(new Vector2(OsuHitObject.OBJECT_RADIUS * 2)),
Colour = new Color4(5, 5, 5, 255),
},
LegacyColourCompatibility.ApplyWithDoubledAlpha(animationContent.With(d =>
Expand All @@ -58,7 +60,7 @@ private void load()
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Texture = skin.GetTexture("sliderb-spec"),
Texture = skin.GetTexture("sliderb-spec")?.WithMaximumSize(new Vector2(OsuHitObject.OBJECT_RADIUS * 2)),
Blending = BlendingParameters.Additive,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,7 +21,7 @@ public class OsuLegacySkinTransformer : LegacySkinTransformer
/// 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)
Expand All @@ -41,14 +42,14 @@ public OsuLegacySkinTransformer(ISkin skin)
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));
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 this 308 come from?

Copy link
Member Author

Choose a reason for hiding this comment

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

Wiki, maximum effective follow circle size (https://osu.ppy.sh/wiki/en/Skinning/osu%21#slider, see sliderfollowcircle.png).

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: new Vector2(OsuHitObject.OBJECT_RADIUS * 2));

// todo: slider ball has a custom frame delay based on velocity
// Math.Max((150 / Velocity) * GameBase.SIXTY_FRAME_TIME, GameBase.SIXTY_FRAME_TIME);
Expand Down Expand Up @@ -138,7 +139,7 @@ public OsuLegacySkinTransformer(ISkin skin)
if (!this.HasFont(LegacyFont.HitCircle))
return null;

return new LegacySpriteText(LegacyFont.HitCircle)
return new LegacySpriteText(LegacyFont.HitCircle, new Vector2(OsuHitObject.OBJECT_RADIUS * 2))
{
// stable applies a blanket 0.8x scale to hitcircle fonts
Scale = new Vector2(0.8f),
Expand Down
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
5 changes: 3 additions & 2 deletions osu.Game.Rulesets.Taiko/Skinning/Legacy/LegacyDrumRoll.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using osu.Framework.Graphics.Textures;
using osu.Game.Graphics;
using osu.Game.Skinning;
using osuTK;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
Expand Down Expand Up @@ -47,13 +48,13 @@ private void load(ISkinSource skin, OsuColour colours)
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
Texture = skin.GetTexture("taiko-roll-end", WrapMode.ClampToEdge, WrapMode.ClampToEdge),
Texture = skin.GetTexture("taiko-roll-end", WrapMode.ClampToEdge, WrapMode.ClampToEdge)?.WithMaximumSize(new Vector2(128, 256)),
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Why are these 256 based, not 128?

Also adjusting this doesn't affect the test scene at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uhh...9d17539

And yes, adjusting doesn't affect because the sprite is resized regardless of the texture, see #24706 (comment).

FillMode = FillMode.Fit,
},
body = new Sprite
{
RelativeSizeAxes = Axes.Both,
Texture = skin.GetTexture("taiko-roll-middle", WrapMode.ClampToEdge, WrapMode.ClampToEdge),
Texture = skin.GetTexture("taiko-roll-middle", WrapMode.ClampToEdge, WrapMode.ClampToEdge)?.WithMaximumSize(new Vector2(2, 256)),
},
headCircle = new LegacyCirclePiece
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// 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
{
public partial class TestSceneGameplayElementDimensions : TestSceneAllRulesetPlayers
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

What on earth is this naming..

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...don't know?

{
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 /= 5f;

return texture;
}

public ISkin? FindProvider(Func<ISkin, bool> lookupFunction) => this;

Check failure on line 69 in osu.Game.Tests/Visual/Gameplay/TestSceneGameplayElementDimensions.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Return type of 'FindProvider' can be non-nullable in osu.Game.Tests\Visual\Gameplay\TestSceneGameplayElementDimensions.cs on line 69
public IEnumerable<ISkin> AllSources => new[] { this };
}
}
}
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