1
0
mirror of https://github.com/ppy/osu.git synced 2026-05-20 03:19:52 +08:00

Rewrite OverallRanking to interface directly with UserStatisticsWatcher

This commit is contained in:
Bartłomiej Dach
2025-03-12 11:29:31 +01:00
Unverified
parent 4633f635a4
commit 0ffb233796
4 changed files with 42 additions and 77 deletions
@@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using NUnit.Framework;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Online;
using osu.Game.Scoring;
@@ -12,7 +13,7 @@ namespace osu.Game.Tests.Visual.Ranking
{
public partial class TestSceneOverallRanking : OsuTestScene
{
private OverallRanking overallRanking = null!;
private readonly Bindable<ScoreBasedUserStatisticsUpdate?> statisticsUpdate = new Bindable<ScoreBasedUserStatisticsUpdate?>();
[Test]
public void TestUpdatePending()
@@ -104,14 +105,19 @@ namespace osu.Game.Tests.Visual.Ranking
displayUpdate(statistics, statistics);
}
private void createDisplay() => AddStep("create display", () => Child = overallRanking = new OverallRanking
private void createDisplay() => AddStep("create display", () =>
{
Width = 400,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
statisticsUpdate.Value = null;
Child = new OverallRanking(new ScoreInfo())
{
Width = 400,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
DisplayedUpdate = { BindTarget = statisticsUpdate }
};
});
private void displayUpdate(UserStatistics before, UserStatistics after) =>
AddStep("display update", () => overallRanking.StatisticsUpdate.Value = new ScoreBasedUserStatisticsUpdate(new ScoreInfo(), before, after));
AddStep("display update", () => statisticsUpdate.Value = new ScoreBasedUserStatisticsUpdate(new ScoreInfo(), before, after));
}
}
@@ -155,44 +155,6 @@ namespace osu.Game.Tests.Visual.Ranking
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible },
Score = { Value = score },
DisplayedUserStatisticsUpdate =
{
Value = new ScoreBasedUserStatisticsUpdate(score, new UserStatistics
{
Level = new UserStatistics.LevelInfo
{
Current = 5,
Progress = 20,
},
GlobalRank = 38000,
CountryRank = 12006,
PP = 2134,
RankedScore = 21123849,
Accuracy = 0.985,
PlayCount = 13375,
PlayTime = 354490,
TotalScore = 128749597,
TotalHits = 0,
MaxCombo = 1233,
}, new UserStatistics
{
Level = new UserStatistics.LevelInfo
{
Current = 5,
Progress = 30,
},
GlobalRank = 36000,
CountryRank = 12000,
PP = (decimal)2134.5,
RankedScore = 23897015,
Accuracy = 0.984,
PlayCount = 13376,
PlayTime = 35789,
TotalScore = 132218497,
TotalHits = 0,
MaxCombo = 1233,
})
}
};
});
@@ -5,8 +5,10 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Extensions;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
using osu.Game.Scoring;
namespace osu.Game.Screens.Ranking.Statistics.User
{
@@ -14,13 +16,21 @@ namespace osu.Game.Screens.Ranking.Statistics.User
{
private const float transition_duration = 300;
public Bindable<ScoreBasedUserStatisticsUpdate?> StatisticsUpdate { get; } = new Bindable<ScoreBasedUserStatisticsUpdate?>();
public Bindable<ScoreBasedUserStatisticsUpdate?> DisplayedUpdate { get; } = new Bindable<ScoreBasedUserStatisticsUpdate?>();
private readonly IBindable<ScoreBasedUserStatisticsUpdate?> latestGlobalStatisticsUpdate = new Bindable<ScoreBasedUserStatisticsUpdate?>();
private readonly ScoreInfo scoreInfo;
private LoadingLayer loadingLayer = null!;
private GridContainer content = null!;
public OverallRanking(ScoreInfo scoreInfo)
{
this.scoreInfo = scoreInfo;
}
[BackgroundDependencyLoader]
private void load()
private void load(UserStatisticsWatcher? userStatisticsWatcher)
{
AutoSizeAxes = Axes.Y;
AutoSizeEasing = Easing.OutQuint;
@@ -55,34 +65,44 @@ namespace osu.Game.Screens.Ranking.Statistics.User
{
new Drawable[]
{
new GlobalRankChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
new GlobalRankChangeRow { StatisticsUpdate = { BindTarget = DisplayedUpdate } },
new SimpleStatisticTable.Spacer(),
new PerformancePointsChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
new PerformancePointsChangeRow { StatisticsUpdate = { BindTarget = DisplayedUpdate } },
},
[],
new Drawable[]
{
new MaximumComboChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
new MaximumComboChangeRow { StatisticsUpdate = { BindTarget = DisplayedUpdate } },
new SimpleStatisticTable.Spacer(),
new AccuracyChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
new AccuracyChangeRow { StatisticsUpdate = { BindTarget = DisplayedUpdate } },
},
[],
new Drawable[]
{
new RankedScoreChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
new RankedScoreChangeRow { StatisticsUpdate = { BindTarget = DisplayedUpdate } },
new SimpleStatisticTable.Spacer(),
new TotalScoreChangeRow { StatisticsUpdate = { BindTarget = StatisticsUpdate } },
new TotalScoreChangeRow { StatisticsUpdate = { BindTarget = DisplayedUpdate } },
}
}
}
};
if (userStatisticsWatcher != null)
{
latestGlobalStatisticsUpdate.BindTo(userStatisticsWatcher.LatestUpdate);
latestGlobalStatisticsUpdate.BindValueChanged(update =>
{
if (update.NewValue?.Score.MatchesOnlineID(scoreInfo) == true)
DisplayedUpdate.Value = update.NewValue;
}, true);
}
}
protected override void LoadComplete()
{
base.LoadComplete();
StatisticsUpdate.BindValueChanged(onUpdateReceived, true);
DisplayedUpdate.BindValueChanged(onUpdateReceived, true);
FinishTransforms(true);
}
@@ -3,12 +3,8 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
using osu.Game.Extensions;
using osu.Game.Online;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics.User;
@@ -18,29 +14,11 @@ namespace osu.Game.Screens.Ranking.Statistics
{
private readonly ScoreInfo achievedScore;
internal readonly Bindable<ScoreBasedUserStatisticsUpdate?> DisplayedUserStatisticsUpdate = new Bindable<ScoreBasedUserStatisticsUpdate?>();
private IBindable<ScoreBasedUserStatisticsUpdate?> latestGlobalStatisticsUpdate = null!;
public UserStatisticsPanel(ScoreInfo achievedScore)
{
this.achievedScore = achievedScore;
}
[BackgroundDependencyLoader]
private void load(UserStatisticsWatcher? userStatisticsWatcher)
{
if (userStatisticsWatcher != null)
{
latestGlobalStatisticsUpdate = userStatisticsWatcher.LatestUpdate.GetBoundCopy();
latestGlobalStatisticsUpdate.BindValueChanged(update =>
{
if (update.NewValue?.Score.MatchesOnlineID(achievedScore) == true)
DisplayedUserStatisticsUpdate.Value = update.NewValue;
}, true);
}
}
protected override ICollection<StatisticItem> CreateStatisticItems(ScoreInfo newScore, IBeatmap playableBeatmap)
{
var items = base.CreateStatisticItems(newScore, playableBeatmap);
@@ -50,12 +28,11 @@ namespace osu.Game.Screens.Ranking.Statistics
&& newScore.OnlineID > 0
&& newScore.OnlineID == achievedScore.OnlineID)
{
items = items.Append(new StatisticItem("Overall Ranking", () => new OverallRanking
items = items.Append(new StatisticItem("Overall Ranking", () => new OverallRanking(newScore)
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
StatisticsUpdate = { BindTarget = DisplayedUserStatisticsUpdate }
})).ToArray();
}