mirror of
https://github.com/ppy/osu.git
synced 2025-01-07 16:12:55 +08:00
Merge pull request #29187 from peppy/daily-challenge-pieces-not-always-present
Favour updating daily challenge statistics when they come on screen
This commit is contained in:
commit
5032a149e7
@ -6,6 +6,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.ObjectExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Utils;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Rooms;
|
||||
@ -20,11 +21,11 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
||||
[Cached]
|
||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
|
||||
|
||||
[Test]
|
||||
public void TestBasicAppearance()
|
||||
{
|
||||
DailyChallengeScoreBreakdown breakdown = null!;
|
||||
private DailyChallengeScoreBreakdown breakdown = null!;
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("create content", () => Children = new Drawable[]
|
||||
{
|
||||
new Box
|
||||
@ -50,7 +51,14 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
||||
breakdown.Height = height;
|
||||
});
|
||||
|
||||
AddToggleStep("toggle visible", v => breakdown.Alpha = v ? 1 : 0);
|
||||
|
||||
AddStep("set initial data", () => breakdown.SetInitialCounts([1, 4, 9, 16, 25, 36, 49, 36, 25, 16, 9, 4, 1]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasicAppearance()
|
||||
{
|
||||
AddStep("add new score", () =>
|
||||
{
|
||||
var ev = new NewScoreEvent(1, new APIUser
|
||||
@ -65,5 +73,24 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
||||
AddStep("set user score", () => breakdown.UserBestScore.Value = new MultiplayerScore { TotalScore = RNG.Next(1_000_000) });
|
||||
AddStep("unset user score", () => breakdown.UserBestScore.Value = null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestMassAdd()
|
||||
{
|
||||
AddStep("add 1000 scores at once", () =>
|
||||
{
|
||||
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), null);
|
||||
|
||||
breakdown.AddNewScore(ev);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -55,6 +55,8 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
||||
if (ring.IsNotNull())
|
||||
ring.Height = height;
|
||||
});
|
||||
AddToggleStep("toggle visible", v => ring.Alpha = v ? 1 : 0);
|
||||
|
||||
AddStep("just started", () =>
|
||||
{
|
||||
room.Value.StartDate.Value = DateTimeOffset.Now.AddMinutes(-1);
|
||||
|
@ -49,6 +49,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
||||
if (totals.IsNotNull())
|
||||
totals.Height = height;
|
||||
});
|
||||
AddToggleStep("toggle visible", v => totals.Alpha = v ? 1 : 0);
|
||||
|
||||
AddStep("set counts", () => totals.SetInitialCounts(totalPassCount: 9650, cumulativeTotalScore: 10_000_000_000));
|
||||
|
||||
|
@ -50,7 +50,6 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
||||
{
|
||||
drawable.RelativeSizeAxes = Axes.Both;
|
||||
drawable.Size = Vector2.One;
|
||||
drawable.AlwaysPresent = true;
|
||||
drawable.Alpha = 0;
|
||||
|
||||
base.Add(drawable);
|
||||
|
@ -2,6 +2,7 @@
|
||||
// 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.Bindables;
|
||||
@ -27,9 +28,6 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
||||
|
||||
private FillFlowContainer<Bar> barsContainer = null!;
|
||||
|
||||
// we're always present so that we can update while hidden, but we don't want tooltips to be displayed, therefore directly use alpha comparison here.
|
||||
public override bool PropagatePositionalInputSubTree => base.PropagatePositionalInputSubTree && Alpha > 0;
|
||||
|
||||
private const int bin_count = MultiplayerPlaylistItemStats.TOTAL_SCORE_DISTRIBUTION_BINS;
|
||||
private long[] bins = new long[bin_count];
|
||||
|
||||
@ -70,34 +68,61 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
||||
});
|
||||
}
|
||||
|
||||
private readonly Queue<NewScoreEvent> newScores = new Queue<NewScoreEvent>();
|
||||
|
||||
public void AddNewScore(NewScoreEvent newScoreEvent)
|
||||
{
|
||||
int targetBin = (int)Math.Clamp(Math.Floor((float)newScoreEvent.TotalScore / 100000), 0, bin_count - 1);
|
||||
bins[targetBin] += 1;
|
||||
updateCounts();
|
||||
newScores.Enqueue(newScoreEvent);
|
||||
|
||||
var text = new OsuSpriteText
|
||||
// ensure things don't get too out-of-hand.
|
||||
if (newScores.Count > 25)
|
||||
{
|
||||
Text = newScoreEvent.TotalScore.ToString(@"N0"),
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Font = OsuFont.Default.With(size: 30),
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = (targetBin + 0.5f) / bin_count - 0.5f,
|
||||
Alpha = 0,
|
||||
};
|
||||
AddInternal(text);
|
||||
bins[getTargetBin(newScores.Dequeue())] += 1;
|
||||
Scheduler.AddOnce(updateCounts);
|
||||
}
|
||||
}
|
||||
|
||||
Scheduler.AddDelayed(() =>
|
||||
private double lastScoreDisplay;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (Time.Current - lastScoreDisplay > 150 && newScores.TryDequeue(out var newScore))
|
||||
{
|
||||
float startY = ToLocalSpace(barsContainer[targetBin].CircularBar.ScreenSpaceDrawQuad.TopLeft).Y;
|
||||
text.FadeInFromZero()
|
||||
.ScaleTo(new Vector2(0.8f), 500, Easing.OutElasticHalf)
|
||||
.MoveToY(startY)
|
||||
.MoveToOffset(new Vector2(0, -50), 2500, Easing.OutQuint)
|
||||
.FadeOut(2500, Easing.OutQuint)
|
||||
.Expire();
|
||||
}, 150);
|
||||
if (lastScoreDisplay < Time.Current)
|
||||
lastScoreDisplay = Time.Current;
|
||||
|
||||
int targetBin = getTargetBin(newScore);
|
||||
bins[targetBin] += 1;
|
||||
|
||||
updateCounts();
|
||||
|
||||
var text = new OsuSpriteText
|
||||
{
|
||||
Text = newScore.TotalScore.ToString(@"N0"),
|
||||
Anchor = Anchor.TopCentre,
|
||||
Origin = Anchor.BottomCentre,
|
||||
Font = OsuFont.Default.With(size: 30),
|
||||
RelativePositionAxes = Axes.X,
|
||||
X = (targetBin + 0.5f) / bin_count - 0.5f,
|
||||
Alpha = 0,
|
||||
};
|
||||
AddInternal(text);
|
||||
|
||||
Scheduler.AddDelayed(() =>
|
||||
{
|
||||
float startY = ToLocalSpace(barsContainer[targetBin].CircularBar.ScreenSpaceDrawQuad.TopLeft).Y;
|
||||
text.FadeInFromZero()
|
||||
.ScaleTo(new Vector2(0.8f), 500, Easing.OutElasticHalf)
|
||||
.MoveToY(startY)
|
||||
.MoveToOffset(new Vector2(0, -50), 2500, Easing.OutQuint)
|
||||
.FadeOut(2500, Easing.OutQuint)
|
||||
.Expire();
|
||||
}, 150);
|
||||
|
||||
lastScoreDisplay = Time.Current;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetInitialCounts(long[] counts)
|
||||
@ -109,6 +134,9 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
||||
updateCounts();
|
||||
}
|
||||
|
||||
private static int getTargetBin(NewScoreEvent score) =>
|
||||
(int)Math.Clamp(Math.Floor((float)score.TotalScore / 100000), 0, bin_count - 1);
|
||||
|
||||
private void updateCounts()
|
||||
{
|
||||
long max = Math.Max(bins.Max(), 1);
|
||||
|
Loading…
Reference in New Issue
Block a user