-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Refactor leaderboard statistics component to use text flows #37069
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
Open
LiquidPL
wants to merge
1
commit into
ppy:master
Choose a base branch
from
LiquidPL:leaderboard-statistic-refactor
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+209
−51
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
osu.Game.Tests/Visual/Online/TestSceneLeaderboardStatistic.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // 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 NUnit.Framework; | ||
| using osu.Framework.Allocation; | ||
| using osu.Framework.Graphics; | ||
| using osu.Framework.Graphics.Containers; | ||
| using osu.Framework.Graphics.Shapes; | ||
| using osu.Framework.Testing; | ||
| using osu.Game.Graphics; | ||
| using osu.Game.Online.Leaderboards; | ||
| using osu.Game.Overlays; | ||
| using osuTK; | ||
|
|
||
| namespace osu.Game.Tests.Visual.Online | ||
| { | ||
| public partial class TestSceneLeaderboardStatistic : OsuTestScene | ||
| { | ||
| [Cached] | ||
| private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Aquamarine); | ||
|
|
||
| [Cached] | ||
| private OsuColour colours = new OsuColour(); | ||
|
|
||
| private FillFlowContainer container = null!; | ||
| private LeaderboardStatistic[] statistics = []; | ||
|
|
||
| [SetUpSteps] | ||
| public void SetUpSteps() | ||
| { | ||
| AddStep("create container", () => | ||
| { | ||
| Child = new Container | ||
| { | ||
| Masking = true, | ||
| Anchor = Anchor.Centre, | ||
| Origin = Anchor.Centre, | ||
| AutoSizeAxes = Axes.X, | ||
| Height = 50, | ||
| Children = new Drawable[] | ||
| { | ||
| new Box | ||
| { | ||
| RelativeSizeAxes = Axes.Both, | ||
| Colour = colours.Gray3, | ||
| }, | ||
| container = new FillFlowContainer | ||
| { | ||
| Anchor = Anchor.CentreLeft, | ||
| Origin = Anchor.CentreLeft, | ||
| Direction = FillDirection.Horizontal, | ||
| AutoSizeAxes = Axes.Both, | ||
| Margin = new MarginPadding { Horizontal = 20 }, | ||
| Spacing = new Vector2(20, 0) | ||
| }, | ||
| }, | ||
| }; | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestTwoElements() | ||
| { | ||
| AddStep("create content", () => | ||
| { | ||
| container.AddRange(statistics = new[] | ||
| { | ||
| new LeaderboardStatistic("COMBO", "123x", false), | ||
| new LeaderboardStatistic("ACCURACY", "100.00%", true), | ||
| }); | ||
| }); | ||
| AddStep("change to vertical", () => | ||
| { | ||
| container.Direction = FillDirection.Vertical; | ||
| container.ScaleTo(0.8f, 200, Easing.OutQuint); | ||
| }); | ||
| AddStep("change to horizontal", () => | ||
| { | ||
| container.Direction = FillDirection.Horizontal; | ||
| container.ScaleTo(1, 200, Easing.OutQuint); | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestThreeElements() | ||
| { | ||
| AddStep("create content", () => | ||
| { | ||
| container.AddRange(statistics = new[] | ||
| { | ||
| new LeaderboardStatistic("COMBO", "123x", false), | ||
| new LeaderboardStatistic("ACCURACY", "100.00%", true), | ||
| new LeaderboardStatistic("TEST", "12345", false), | ||
| }); | ||
| }); | ||
| AddStep("change to vertical", () => | ||
| { | ||
| container.Direction = FillDirection.Vertical; | ||
| container.ScaleTo(0.8f, 200, Easing.OutQuint); | ||
|
|
||
| foreach (var statistic in statistics) | ||
| statistic.Direction = Direction.Vertical; | ||
| }); | ||
| AddStep("change to horizontal", () => | ||
| { | ||
| container.Direction = FillDirection.Horizontal; | ||
| container.ScaleTo(1, 200, Easing.OutQuint); | ||
|
|
||
| foreach (var statistic in statistics) | ||
| statistic.Direction = Direction.Horizontal; | ||
| }); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // 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 osu.Framework.Allocation; | ||
| using osu.Framework.Graphics; | ||
| using osu.Framework.Graphics.Containers; | ||
| using osu.Framework.Localisation; | ||
| using osu.Game.Graphics; | ||
| using osu.Game.Graphics.Containers; | ||
| using osu.Game.Overlays; | ||
| using osuTK; | ||
| using osuTK.Graphics; | ||
|
|
||
| namespace osu.Game.Online.Leaderboards | ||
| { | ||
| public partial class LeaderboardStatistic : Container | ||
| { | ||
| private readonly LocalisableString name; | ||
| private readonly LocalisableString value; | ||
|
|
||
| private readonly bool perfect; | ||
|
|
||
| private Direction direction; | ||
|
|
||
| public Direction Direction | ||
| { | ||
| get => direction; | ||
| set | ||
| { | ||
| direction = value; | ||
|
|
||
| if (IsLoaded) | ||
| recreateText(); | ||
| } | ||
| } | ||
|
|
||
| [Resolved] | ||
| private OsuColour colours { get; set; } = null!; | ||
|
|
||
| [Resolved] | ||
| private OverlayColourProvider colourProvider { get; set; } = null!; | ||
|
|
||
| private readonly Container content; | ||
| private readonly OsuTextFlowContainer textFlow; | ||
|
|
||
| public override bool Contains(Vector2 screenSpacePos) => content.Contains(screenSpacePos); | ||
|
|
||
| public LeaderboardStatistic(LocalisableString name, LocalisableString value, bool perfect, float? minWidth = null) | ||
| { | ||
| this.name = name; | ||
| this.value = value; | ||
| this.perfect = perfect; | ||
|
|
||
| AutoSizeAxes = Axes.Both; | ||
| Child = content = new Container | ||
| { | ||
| AutoSizeAxes = Axes.Both, | ||
| Child = textFlow = new OsuTextFlowContainer | ||
| { | ||
| AutoSizeAxes = Axes.Both, | ||
| ParagraphSpacing = 0.1f, | ||
| }, | ||
| }; | ||
|
|
||
| if (minWidth != null) | ||
| Add(Empty().With(d => d.Width = minWidth.Value)); | ||
| } | ||
|
|
||
| protected override void LoadComplete() | ||
| { | ||
| base.LoadComplete(); | ||
| recreateText(); | ||
| } | ||
|
|
||
| private void recreateText() | ||
| { | ||
| textFlow.Clear(); | ||
|
|
||
| textFlow.AddText($"{name}{(direction == Direction.Horizontal ? "\n" : "")}", t => | ||
| { | ||
| t.Font = OsuFont.Style.Caption2.With(weight: FontWeight.SemiBold); | ||
| t.Colour = colourProvider.Content2; | ||
| }); | ||
|
|
||
| textFlow.AddText(value, t => | ||
| { | ||
| t.Font = OsuFont.Style.Body; | ||
| t.Colour = perfect ? colours.Lime1 : Color4.White; | ||
| t.Padding = new MarginPadding { Left = direction == Direction.Horizontal ? 0 : 5 }; | ||
| }); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized this is going to cause every word in
valueto have padding if there's multiple words in it. I wonder if this is even likely to happen, given that in most cases what goes intovalueis going to be a single number.Alternatively I could just insert a single space between name and value instead of messing around with padding.