mirror of
https://github.com/ppy/osu.git
synced 2025-01-23 20:32: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.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
|
using osu.Framework.Testing;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
@ -20,11 +21,11 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
|||||||
[Cached]
|
[Cached]
|
||||||
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
|
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);
|
||||||
|
|
||||||
[Test]
|
private DailyChallengeScoreBreakdown breakdown = null!;
|
||||||
public void TestBasicAppearance()
|
|
||||||
{
|
|
||||||
DailyChallengeScoreBreakdown breakdown = null!;
|
|
||||||
|
|
||||||
|
[SetUpSteps]
|
||||||
|
public void SetUpSteps()
|
||||||
|
{
|
||||||
AddStep("create content", () => Children = new Drawable[]
|
AddStep("create content", () => Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new Box
|
new Box
|
||||||
@ -50,7 +51,14 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
|||||||
breakdown.Height = height;
|
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]));
|
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", () =>
|
AddStep("add new score", () =>
|
||||||
{
|
{
|
||||||
var ev = new NewScoreEvent(1, new APIUser
|
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("set user score", () => breakdown.UserBestScore.Value = new MultiplayerScore { TotalScore = RNG.Next(1_000_000) });
|
||||||
AddStep("unset user score", () => breakdown.UserBestScore.Value = null);
|
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())
|
if (ring.IsNotNull())
|
||||||
ring.Height = height;
|
ring.Height = height;
|
||||||
});
|
});
|
||||||
|
AddToggleStep("toggle visible", v => ring.Alpha = v ? 1 : 0);
|
||||||
|
|
||||||
AddStep("just started", () =>
|
AddStep("just started", () =>
|
||||||
{
|
{
|
||||||
room.Value.StartDate.Value = DateTimeOffset.Now.AddMinutes(-1);
|
room.Value.StartDate.Value = DateTimeOffset.Now.AddMinutes(-1);
|
||||||
|
@ -49,6 +49,7 @@ namespace osu.Game.Tests.Visual.DailyChallenge
|
|||||||
if (totals.IsNotNull())
|
if (totals.IsNotNull())
|
||||||
totals.Height = height;
|
totals.Height = height;
|
||||||
});
|
});
|
||||||
|
AddToggleStep("toggle visible", v => totals.Alpha = v ? 1 : 0);
|
||||||
|
|
||||||
AddStep("set counts", () => totals.SetInitialCounts(totalPassCount: 9650, cumulativeTotalScore: 10_000_000_000));
|
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.RelativeSizeAxes = Axes.Both;
|
||||||
drawable.Size = Vector2.One;
|
drawable.Size = Vector2.One;
|
||||||
drawable.AlwaysPresent = true;
|
|
||||||
drawable.Alpha = 0;
|
drawable.Alpha = 0;
|
||||||
|
|
||||||
base.Add(drawable);
|
base.Add(drawable);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
@ -27,9 +28,6 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
|||||||
|
|
||||||
private FillFlowContainer<Bar> barsContainer = null!;
|
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 const int bin_count = MultiplayerPlaylistItemStats.TOTAL_SCORE_DISTRIBUTION_BINS;
|
||||||
private long[] bins = new long[bin_count];
|
private long[] bins = new long[bin_count];
|
||||||
|
|
||||||
@ -70,15 +68,39 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private readonly Queue<NewScoreEvent> newScores = new Queue<NewScoreEvent>();
|
||||||
|
|
||||||
public void AddNewScore(NewScoreEvent newScoreEvent)
|
public void AddNewScore(NewScoreEvent newScoreEvent)
|
||||||
{
|
{
|
||||||
int targetBin = (int)Math.Clamp(Math.Floor((float)newScoreEvent.TotalScore / 100000), 0, bin_count - 1);
|
newScores.Enqueue(newScoreEvent);
|
||||||
|
|
||||||
|
// ensure things don't get too out-of-hand.
|
||||||
|
if (newScores.Count > 25)
|
||||||
|
{
|
||||||
|
bins[getTargetBin(newScores.Dequeue())] += 1;
|
||||||
|
Scheduler.AddOnce(updateCounts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private double lastScoreDisplay;
|
||||||
|
|
||||||
|
protected override void Update()
|
||||||
|
{
|
||||||
|
base.Update();
|
||||||
|
|
||||||
|
if (Time.Current - lastScoreDisplay > 150 && newScores.TryDequeue(out var newScore))
|
||||||
|
{
|
||||||
|
if (lastScoreDisplay < Time.Current)
|
||||||
|
lastScoreDisplay = Time.Current;
|
||||||
|
|
||||||
|
int targetBin = getTargetBin(newScore);
|
||||||
bins[targetBin] += 1;
|
bins[targetBin] += 1;
|
||||||
|
|
||||||
updateCounts();
|
updateCounts();
|
||||||
|
|
||||||
var text = new OsuSpriteText
|
var text = new OsuSpriteText
|
||||||
{
|
{
|
||||||
Text = newScoreEvent.TotalScore.ToString(@"N0"),
|
Text = newScore.TotalScore.ToString(@"N0"),
|
||||||
Anchor = Anchor.TopCentre,
|
Anchor = Anchor.TopCentre,
|
||||||
Origin = Anchor.BottomCentre,
|
Origin = Anchor.BottomCentre,
|
||||||
Font = OsuFont.Default.With(size: 30),
|
Font = OsuFont.Default.With(size: 30),
|
||||||
@ -98,6 +120,9 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
|||||||
.FadeOut(2500, Easing.OutQuint)
|
.FadeOut(2500, Easing.OutQuint)
|
||||||
.Expire();
|
.Expire();
|
||||||
}, 150);
|
}, 150);
|
||||||
|
|
||||||
|
lastScoreDisplay = Time.Current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetInitialCounts(long[] counts)
|
public void SetInitialCounts(long[] counts)
|
||||||
@ -109,6 +134,9 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
|||||||
updateCounts();
|
updateCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getTargetBin(NewScoreEvent score) =>
|
||||||
|
(int)Math.Clamp(Math.Floor((float)score.TotalScore / 100000), 0, bin_count - 1);
|
||||||
|
|
||||||
private void updateCounts()
|
private void updateCounts()
|
||||||
{
|
{
|
||||||
long max = Math.Max(bins.Max(), 1);
|
long max = Math.Max(bins.Max(), 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user