-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Extract score and statistics components from BeatmapLeaderboardScore
#37056
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
133 changes: 133 additions & 0 deletions
133
osu.Game.Tests/Visual/Online/TestSceneLeaderboardScoreDisplay.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,133 @@ | ||
| // 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.Linq; | ||
| using NUnit.Framework; | ||
| using osu.Framework.Allocation; | ||
| using osu.Framework.Bindables; | ||
| using osu.Framework.Graphics; | ||
| using osu.Framework.Graphics.Containers; | ||
| using osu.Framework.Graphics.Shapes; | ||
| using osu.Framework.Graphics.Sprites; | ||
| using osu.Framework.Testing; | ||
| using osu.Game.Graphics; | ||
| using osu.Game.Online.Leaderboards; | ||
| using osu.Game.Overlays; | ||
| using osu.Game.Rulesets.Mods; | ||
| using osu.Game.Rulesets.Osu.Mods; | ||
| using osu.Game.Rulesets.UI; | ||
| using osuTK; | ||
|
|
||
| namespace osu.Game.Tests.Visual.Online | ||
| { | ||
| public partial class TestSceneLeaderboardScoreDisplay : OsuTestScene | ||
| { | ||
| private Container content = null!; | ||
| protected override Container<Drawable> Content => content; | ||
|
|
||
| [Resolved] | ||
| private OsuColour colours { get; set; } = null!; | ||
|
|
||
| [Cached] | ||
| private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum); | ||
|
|
||
| [SetUpSteps] | ||
| public void SetUpSteps() | ||
| { | ||
| AddStep("create components", () => base.Content.Child = new Container | ||
| { | ||
| Anchor = Anchor.Centre, | ||
| Origin = Anchor.Centre, | ||
| Width = 200, | ||
| Height = 50, | ||
| Children = new Drawable[] | ||
| { | ||
| new Box | ||
| { | ||
| RelativeSizeAxes = Axes.Both, | ||
| Colour = colours.Gray5, | ||
| }, | ||
| content = new Container | ||
| { | ||
| RelativeSizeAxes = Axes.Both, | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestBasic() | ||
| { | ||
| AddStep("create content", () => Child = new LeaderboardScoreDisplay | ||
| { | ||
| Anchor = Anchor.CentreRight, | ||
| Origin = Anchor.CentreRight, | ||
| Current = { Value = "1,000,000" }, | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestCustomContent() | ||
| { | ||
| AddStep("create content", () => Child = new LeaderboardScoreDisplay | ||
| { | ||
| Anchor = Anchor.CentreRight, | ||
| Origin = Anchor.CentreRight, | ||
| Current = { Value = "1,000,000" }, | ||
| Child = new FillFlowContainer | ||
| { | ||
| AutoSizeAxes = Axes.Both, | ||
| Direction = FillDirection.Horizontal, | ||
| Spacing = new Vector2(-10, 0), | ||
| Padding = new MarginPadding { Top = 4 }, | ||
| ChildrenEnumerable = new Mod[] { new OsuModDoubleTime(), new OsuModHardRock() }.Select(mod => new ModIcon(mod) | ||
| { | ||
| Scale = new Vector2(0.3f), | ||
| Height = ModIcon.MOD_ICON_SIZE.Y * 3 / 4f, | ||
| }), | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestCustomContent2() | ||
| { | ||
| AddStep("create content", () => Child = new LeaderboardScoreDisplay | ||
| { | ||
| Anchor = Anchor.CentreRight, | ||
| Origin = Anchor.CentreRight, | ||
| Current = { Value = "1,000,000" }, | ||
| Child = new LeaderboardStatistic("Completed Beatmaps".ToUpperInvariant(), "2", false, 0) | ||
| { | ||
| Anchor = Anchor.TopRight, | ||
| Origin = Anchor.TopRight, | ||
| AutoSizeAxes = Axes.Both, | ||
| Direction = FillDirection.Horizontal, | ||
| Margin = new MarginPadding { Top = 5, Right = 1.5f }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| [Test] | ||
| public void TestUpdateScore() | ||
| { | ||
| LeaderboardScoreDisplay display = null!; | ||
| Bindable<string> score = null!; | ||
|
|
||
| AddStep("create content", () => | ||
| { | ||
| score = new Bindable<string>("1,000,000"); | ||
|
|
||
| Child = display = new LeaderboardScoreDisplay | ||
| { | ||
| Anchor = Anchor.CentreRight, | ||
| Origin = Anchor.CentreRight, | ||
| Current = { BindTarget = score }, | ||
| }; | ||
| }); | ||
| AddUntilStep("score text is correct", () => display.ChildrenOfType<IHasText>().Single().Text.ToString(), () => Is.EqualTo("1,000,000")); | ||
| AddStep("update score", () => score.Value = "1,234,567"); | ||
| AddUntilStep("score text is correct", () => display.ChildrenOfType<IHasText>().Single().Text.ToString(), () => Is.EqualTo("1,234,567")); | ||
| } | ||
| } | ||
| } |
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,65 @@ | ||
| // 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.Bindables; | ||
| using osu.Framework.Graphics; | ||
| using osu.Framework.Graphics.Containers; | ||
| using osu.Framework.Graphics.UserInterface; | ||
| using osu.Game.Graphics; | ||
| using osu.Game.Graphics.Sprites; | ||
| using osuTK; | ||
|
|
||
| namespace osu.Game.Online.Leaderboards | ||
| { | ||
| public partial class LeaderboardScoreDisplay : Container, IHasCurrentValue<string> | ||
| { | ||
| private readonly BindableWithCurrent<string> current = new BindableWithCurrent<string>(); | ||
|
|
||
| public Bindable<string> Current | ||
| { | ||
| get => current.Current; | ||
| set => current.Current = value; | ||
| } | ||
|
|
||
| private readonly Container content; | ||
| protected override Container<Drawable> Content => content; | ||
|
|
||
| private readonly OsuSpriteText scoreText; | ||
|
|
||
| public LeaderboardScoreDisplay() | ||
| { | ||
| AutoSizeAxes = Axes.Both; | ||
|
|
||
| InternalChild = new FillFlowContainer | ||
| { | ||
| AutoSizeAxes = Axes.Both, | ||
| Direction = FillDirection.Vertical, | ||
| Spacing = new Vector2(0f, -2f), | ||
| Children = new Drawable[] | ||
| { | ||
| scoreText = new OsuSpriteText | ||
| { | ||
| Anchor = Anchor.TopRight, | ||
| Origin = Anchor.TopRight, | ||
| UseFullGlyphHeight = false, | ||
| Spacing = new Vector2(-1.5f), | ||
| Font = OsuFont.Style.Subtitle.With(weight: FontWeight.Light, fixedWidth: true), | ||
| }, | ||
| content = new Container | ||
| { | ||
| Anchor = Anchor.TopRight, | ||
| Origin = Anchor.TopRight, | ||
| AutoSizeAxes = Axes.Both, | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| protected override void LoadComplete() | ||
| { | ||
| base.LoadComplete(); | ||
|
|
||
| Current.BindValueChanged(score => scoreText.Text = score.NewValue, true); | ||
| } | ||
| } | ||
| } |
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,106 @@ | ||
| // 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.Sprites; | ||
| using osu.Game.Overlays; | ||
| using osuTK; | ||
| using osuTK.Graphics; | ||
|
|
||
| namespace osu.Game.Online.Leaderboards | ||
| { | ||
| public partial class LeaderboardStatistic : Container | ||
| { | ||
| public FillDirection Direction | ||
| { | ||
| get => fillFlowContainer.Direction; | ||
| set | ||
| { | ||
| fillFlowContainer.Direction = value; | ||
| updateDirection(); | ||
| } | ||
| } | ||
|
|
||
| private readonly bool perfect; | ||
|
|
||
| private readonly Container content; | ||
| private readonly FillFlowContainer fillFlowContainer; | ||
|
|
||
| private readonly OsuSpriteText nameText; | ||
| private readonly OsuSpriteText valueText; | ||
|
|
||
| public override bool Contains(Vector2 screenSpacePos) => content.Contains(screenSpacePos); | ||
|
|
||
| public LeaderboardStatistic(LocalisableString name, LocalisableString value, bool perfect, float? minWidth = null) | ||
| { | ||
| this.perfect = perfect; | ||
|
|
||
| AutoSizeAxes = Axes.Both; | ||
| Child = content = new Container | ||
| { | ||
| AutoSizeAxes = Axes.Both, | ||
| Children = new[] | ||
| { | ||
| fillFlowContainer = new FillFlowContainer | ||
| { | ||
| AutoSizeAxes = Axes.Both, | ||
| Direction = FillDirection.Vertical, | ||
| Children = new[] | ||
| { | ||
| nameText = new OsuSpriteText | ||
| { | ||
| Text = name, | ||
| Font = OsuFont.Style.Caption2.With(weight: FontWeight.SemiBold), | ||
| }, | ||
| valueText = new OsuSpriteText | ||
| { | ||
| BypassAutoSizeAxes = Axes.X, | ||
| Text = value, | ||
| Font = OsuFont.Style.Body, | ||
| }, | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| if (minWidth != null) | ||
| Add(Empty().With(d => d.Width = minWidth.Value)); | ||
| } | ||
|
|
||
| [BackgroundDependencyLoader] | ||
| private void load(OsuColour colours, OverlayColourProvider colourProvider) | ||
| { | ||
| nameText.Colour = colourProvider.Content2; | ||
| valueText.Colour = perfect ? colours.Lime1 : Color4.White; | ||
| } | ||
|
|
||
| private void updateDirection() | ||
| { | ||
| if (Direction == FillDirection.Vertical) | ||
| { | ||
| // We don't want the value setting the horizontal size, since it leads to wonky accuracy container length, | ||
| // since the accuracy is sometimes longer than its name. | ||
| valueText.BypassAutoSizeAxes = Axes.X; | ||
|
|
||
| nameText.Anchor = nameText.Origin = Anchor.TopLeft; | ||
| valueText.Anchor = valueText.Origin = Anchor.TopLeft; | ||
|
|
||
| fillFlowContainer.Spacing = Vector2.Zero; | ||
| } | ||
| else | ||
| { | ||
| // When laid out horizontally, both name and value need to contribute to the horizontal size. | ||
| valueText.BypassAutoSizeAxes = Axes.None; | ||
|
|
||
| nameText.Anchor = nameText.Origin = Anchor.BottomLeft; | ||
| valueText.Anchor = valueText.Origin = Anchor.BottomLeft; | ||
|
|
||
| fillFlowContainer.Spacing = new Vector2(5); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
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.