Skip to content

Commit

Permalink
Merge pull request ppy#31435 from peppy/star-range-display-quality
Browse files Browse the repository at this point in the history
Fix star range display looking a bit bad when changing opacity
  • Loading branch information
bdach authored Jan 7, 2025
2 parents d291889 + 383fda7 commit 5431a08
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,82 @@

using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Tests.Visual.OnlinePlay;
using osu.Game.Tests.Resources;
using osuTK;

namespace osu.Game.Tests.Visual.Multiplayer
{
public partial class TestSceneStarRatingRangeDisplay : OnlinePlayTestScene
public partial class TestSceneStarRatingRangeDisplay : OsuTestScene
{
public override void SetUpSteps()
private readonly Room room = new Room();

protected override void LoadComplete()
{
base.SetUpSteps();
base.LoadComplete();

AddStep("create display", () =>
Child = new FillFlowContainer
{
SelectedRoom.Value = new Room();

Child = new StarRatingRangeDisplay(SelectedRoom.Value)
RelativeSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(10),
Children = new Drawable[]
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
});
new StarRatingRangeDisplay(room)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(5),
},
new StarRatingRangeDisplay(room)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(2),
},
new StarRatingRangeDisplay(room)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Scale = new Vector2(1),
},
new StarRatingRangeDisplay(room)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0.2f,
Scale = new Vector2(5),
},
new StarRatingRangeDisplay(room)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0.2f,
Scale = new Vector2(2),
},
new StarRatingRangeDisplay(room)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Alpha = 0.2f,
Scale = new Vector2(1),
},
}
};
}

[Test]
public void TestRange([Values(0, 2, 3, 4, 6, 7)] double min, [Values(0, 2, 3, 4, 6, 7)] double max)
{
AddStep("set playlist", () =>
{
SelectedRoom.Value!.Playlist =
room.Playlist =
[
new PlaylistItem(new BeatmapInfo { StarRating = min }),
new PlaylistItem(new BeatmapInfo { StarRating = max }),
new PlaylistItem(new BeatmapInfo { StarRating = min }) { ID = TestResources.GetNextTestID() },
new PlaylistItem(new BeatmapInfo { StarRating = max }) { ID = TestResources.GetNextTestID() },
];
});
}
Expand Down
62 changes: 35 additions & 27 deletions osu.Game/Screens/OnlinePlay/Components/StarRatingRangeDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using osu.Game.Graphics;
using osu.Game.Online.Rooms;
using osuTK;
using Container = osu.Framework.Graphics.Containers.Container;

namespace osu.Game.Screens.OnlinePlay.Components
{
Expand All @@ -30,6 +29,8 @@ public partial class StarRatingRangeDisplay : CompositeDrawable
private StarRatingDisplay maxDisplay = null!;
private Drawable maxBackground = null!;

private BufferedContainer bufferedContent = null!;

public StarRatingRangeDisplay(Room room)
{
this.room = room;
Expand All @@ -41,38 +42,43 @@ private void load()
{
InternalChildren = new Drawable[]
{
new Container
new CircularContainer
{
RelativeSizeAxes = Axes.Both,
AutoSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 1,
Children = new[]
// Stops artifacting from boxes drawn behind wrong colour boxes (and edge pixels adding up to higher opacity).
Padding = new MarginPadding(-0.1f),
Child = bufferedContent = new BufferedContainer(pixelSnapping: true, cachedFrameBuffer: true)
{
minBackground = new Box
AutoSizeAxes = Axes.Both,
Children = new[]
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.5f),
},
maxBackground = new Box
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(0.5f),
},
minBackground = new Box
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(1, 0.5f),
},
maxBackground = new Box
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(1, 0.5f),
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
minDisplay = new StarRatingDisplay(default, StarRatingDisplaySize.Range),
maxDisplay = new StarRatingDisplay(default, StarRatingDisplaySize.Range)
}
}
}
}
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
minDisplay = new StarRatingDisplay(default, StarRatingDisplaySize.Range),
maxDisplay = new StarRatingDisplay(default, StarRatingDisplaySize.Range)
}
}
};
}

Expand Down Expand Up @@ -121,6 +127,8 @@ private void updateRange()

minBackground.Colour = colours.ForStarDifficulty(minDifficulty.Stars);
maxBackground.Colour = colours.ForStarDifficulty(maxDifficulty.Stars);

bufferedContent.ForceRedraw();
}

protected override void Dispose(bool isDisposing)
Expand Down

0 comments on commit 5431a08

Please sign in to comment.