mirror of
https://github.com/ppy/osu
synced 2024-12-14 19:06:07 +00:00
Merge pull request #29099 from bdach/daily-challenge/totals-display
Implement component for displaying running totals in daily challenge
This commit is contained in:
commit
1607075e0c
@ -0,0 +1,86 @@
|
||||
// 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.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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -25,5 +25,17 @@ namespace osu.Game.Online.Metadata
|
||||
/// </summary>
|
||||
[Key(1)]
|
||||
public long[] TotalScoreDistribution { get; set; } = new long[TOTAL_SCORE_DISTRIBUTION_BINS];
|
||||
|
||||
/// <summary>
|
||||
/// The cumulative total of all passing scores (across all users) for the playlist item so far.
|
||||
/// </summary>
|
||||
[Key(2)]
|
||||
public long CumulativeScore { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The last score to have been processed into provided statistics. Generally only for server-side accounting purposes.
|
||||
/// </summary>
|
||||
[Key(3)]
|
||||
public ulong LastProcessedScoreID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
||||
private IDisposable? userModsSelectOverlayRegistration;
|
||||
|
||||
private DailyChallengeScoreBreakdown breakdown = null!;
|
||||
private DailyChallengeTotalsDisplay totals = null!;
|
||||
private DailyChallengeEventFeed feed = null!;
|
||||
|
||||
[Cached]
|
||||
@ -211,6 +212,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
||||
{
|
||||
new DailyChallengeTimeRemainingRing(),
|
||||
breakdown = new DailyChallengeScoreBreakdown(),
|
||||
totals = new DailyChallengeTotalsDisplay(),
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -352,6 +354,7 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
||||
Schedule(() =>
|
||||
{
|
||||
breakdown.AddNewScore(ev);
|
||||
totals.AddNewScore(ev);
|
||||
feed.AddNewScore(ev);
|
||||
|
||||
if (e.NewRank <= 50)
|
||||
@ -423,7 +426,11 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
||||
var itemStats = stats.SingleOrDefault(item => item.PlaylistItemID == playlistItem.ID);
|
||||
if (itemStats == null) return;
|
||||
|
||||
Schedule(() => breakdown.SetInitialCounts(itemStats.TotalScoreDistribution));
|
||||
Schedule(() =>
|
||||
{
|
||||
breakdown.SetInitialCounts(itemStats.TotalScoreDistribution);
|
||||
totals.SetInitialCounts(itemStats.TotalScoreDistribution.Sum(c => c), itemStats.CumulativeScore);
|
||||
});
|
||||
});
|
||||
|
||||
beatmapAvailabilityTracker.SelectedItem.Value = playlistItem;
|
||||
|
@ -0,0 +1,141 @@
|
||||
// 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;
|
||||
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 => 1000;
|
||||
|
||||
protected override Easing RollingEasing => Easing.OutPow10;
|
||||
|
||||
protected override bool IsRollingProportional => true;
|
||||
|
||||
protected override double GetProportionalDuration(long currentValue, long newValue)
|
||||
{
|
||||
long change = Math.Abs(newValue - currentValue);
|
||||
|
||||
if (change < 10)
|
||||
return 0;
|
||||
|
||||
return Math.Min(6000, RollingDuration * Math.Sqrt(change) / 100);
|
||||
}
|
||||
|
||||
protected override OsuSpriteText CreateSpriteText() => new OsuSpriteText
|
||||
{
|
||||
Font = OsuFont.Default.With(size: 80f, fixedWidth: true),
|
||||
Spacing = new Vector2(-2, 0)
|
||||
};
|
||||
|
||||
protected override LocalisableString FormatCount(long count) => count.ToLocalisableString(@"N0");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user