-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Implement component for displaying running totals in daily challenge #29099
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
174dc91
Implement component for displaying running totals in daily challenge
bdach 1ad0b31
Add required pieces to `MultiplayerPlaylistItemStats` for total score…
peppy 2e37f3b
Hook up score totals display to daily challenge screen
bdach 19affa7
Rename new property to match true usage (per item)
peppy a870722
Adjust easings and reduce character spacing slightly
peppy 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
86 changes: 86 additions & 0 deletions
86
osu.Game.Tests/Visual/DailyChallenge/TestSceneDailyChallengeTotalsDisplay.cs
This file contains 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,86 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. 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.Extensions.ObjectExtensions; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Utils; | ||
using osu.Game.Online.API.Requests.Responses; | ||
using osu.Game.Overlays; | ||
using osu.Game.Screens.OnlinePlay.DailyChallenge; | ||
using osu.Game.Screens.OnlinePlay.DailyChallenge.Events; | ||
using osu.Game.Tests.Resources; | ||
|
||
namespace osu.Game.Tests.Visual.DailyChallenge | ||
{ | ||
public partial class TestSceneDailyChallengeTotalsDisplay : OsuTestScene | ||
{ | ||
[Cached] | ||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum); | ||
|
||
[Test] | ||
public void TestBasicAppearance() | ||
{ | ||
DailyChallengeTotalsDisplay totals = null!; | ||
|
||
AddStep("create content", () => Children = new Drawable[] | ||
{ | ||
new Box | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Colour = colourProvider.Background4, | ||
}, | ||
totals = new DailyChallengeTotalsDisplay | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
} | ||
}); | ||
AddSliderStep("adjust width", 0.1f, 1, 1, width => | ||
{ | ||
if (totals.IsNotNull()) | ||
totals.Width = width; | ||
}); | ||
AddSliderStep("adjust height", 0.1f, 1, 1, height => | ||
{ | ||
if (totals.IsNotNull()) | ||
totals.Height = height; | ||
}); | ||
|
||
AddStep("set counts", () => totals.SetInitialCounts(totalPassCount: 9650, cumulativeTotalScore: 10_000_000_000)); | ||
|
||
AddStep("add normal score", () => | ||
{ | ||
var ev = new NewScoreEvent(1, new APIUser | ||
{ | ||
Id = 2, | ||
Username = "peppy", | ||
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", | ||
}, RNG.Next(1_000_000), null); | ||
totals.AddNewScore(ev); | ||
}); | ||
|
||
AddStep("spam scores", () => | ||
{ | ||
for (int i = 0; i < 1000; ++i) | ||
{ | ||
var ev = new NewScoreEvent(1, new APIUser | ||
{ | ||
Id = 2, | ||
Username = "peppy", | ||
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", | ||
}, RNG.Next(1_000_000), RNG.Next(11, 1000)); | ||
var testScore = TestResources.CreateTestScoreInfo(); | ||
testScore.TotalScore = RNG.Next(1_000_000); | ||
totals.AddNewScore(ev); | ||
} | ||
}); | ||
} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallengeTotalsDisplay.cs
This file contains 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,126 @@ | ||
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Extensions.LocalisationExtensions; | ||
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.Graphics.UserInterface; | ||
using osu.Game.Screens.OnlinePlay.DailyChallenge.Events; | ||
using osuTK; | ||
|
||
namespace osu.Game.Screens.OnlinePlay.DailyChallenge | ||
{ | ||
public partial class DailyChallengeTotalsDisplay : CompositeDrawable | ||
{ | ||
private Container passCountContainer = null!; | ||
private TotalRollingCounter passCounter = null!; | ||
private Container totalScoreContainer = null!; | ||
private TotalRollingCounter totalScoreCounter = null!; | ||
|
||
private long totalPassCountInstantaneous; | ||
private long cumulativeTotalScoreInstantaneous; | ||
|
||
[BackgroundDependencyLoader] | ||
private void load() | ||
{ | ||
InternalChild = new GridContainer | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
RowDimensions = | ||
[ | ||
new Dimension(GridSizeMode.AutoSize), | ||
new Dimension(), | ||
new Dimension(GridSizeMode.AutoSize), | ||
new Dimension(), | ||
], | ||
Content = new[] | ||
{ | ||
new Drawable[] | ||
{ | ||
new SectionHeader("Total pass count") | ||
}, | ||
new Drawable[] | ||
{ | ||
passCountContainer = new Container | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Child = passCounter = new TotalRollingCounter | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
} | ||
} | ||
}, | ||
new Drawable[] | ||
{ | ||
new SectionHeader("Cumulative total score") | ||
}, | ||
new Drawable[] | ||
{ | ||
totalScoreContainer = new Container | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Child = totalScoreCounter = new TotalRollingCounter | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
} | ||
} | ||
}, | ||
} | ||
}; | ||
} | ||
|
||
public void SetInitialCounts(long totalPassCount, long cumulativeTotalScore) | ||
{ | ||
totalPassCountInstantaneous = totalPassCount; | ||
cumulativeTotalScoreInstantaneous = cumulativeTotalScore; | ||
} | ||
|
||
public void AddNewScore(NewScoreEvent ev) | ||
{ | ||
totalPassCountInstantaneous += 1; | ||
cumulativeTotalScoreInstantaneous += ev.TotalScore; | ||
} | ||
|
||
protected override void Update() | ||
{ | ||
base.Update(); | ||
|
||
passCounter.Current.Value = totalPassCountInstantaneous; | ||
totalScoreCounter.Current.Value = cumulativeTotalScoreInstantaneous; | ||
} | ||
|
||
protected override void UpdateAfterChildren() | ||
{ | ||
base.UpdateAfterChildren(); | ||
|
||
var totalPassCountProportionOfParent = Vector2.Divide(passCountContainer.DrawSize, passCounter.DrawSize); | ||
passCounter.Scale = new Vector2(Math.Min(Math.Min(totalPassCountProportionOfParent.X, totalPassCountProportionOfParent.Y) * 0.8f, 1)); | ||
|
||
var totalScoreTextProportionOfParent = Vector2.Divide(totalScoreContainer.DrawSize, totalScoreCounter.DrawSize); | ||
totalScoreCounter.Scale = new Vector2(Math.Min(Math.Min(totalScoreTextProportionOfParent.X, totalScoreTextProportionOfParent.Y) * 0.8f, 1)); | ||
} | ||
|
||
private partial class TotalRollingCounter : RollingCounter<long> | ||
{ | ||
protected override double RollingDuration => 400; | ||
|
||
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText | ||
{ | ||
Font = OsuFont.Default.With(size: 80f, fixedWidth: true), | ||
}; | ||
|
||
protected override LocalisableString FormatCount(long count) => count.ToLocalisableString(@"N0"); | ||
} | ||
} | ||
} |
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.
just passing by and very unrelated but this file doesn't exist anymore
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.
There's a whole bunch of this in other tests too so I'd rather fix separately in one fell swoop.
Is there even a static URL for a cover that we can use for a test like this anymore? I was probably going to yoink something like https://assets.ppy.sh/user-cover-presets/1/df28696b58541a9e67f6755918951d542d93bdf1da41720fcca2fd2c1ea8cf51.jpeg randomly, is that gonna break?
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.
that one should be fine yeah. alternatively can put some static assets like osu-web's placeholder I guess (opening that link is not recommended)