1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Show user statistics after completing a playlists / multiplayer score

This commit is contained in:
Bartłomiej Dach 2024-02-22 19:49:14 +01:00
parent 0074bdc5a1
commit 1e53503608
No known key found for this signature in database
6 changed files with 46 additions and 52 deletions

View File

@ -82,12 +82,12 @@ namespace osu.Game.Tests.Visual.Ranking
private void loadPanel(ScoreInfo score) => AddStep("load panel", () =>
{
Child = new SoloStatisticsPanel(score)
Child = new UserStatisticsPanel(score)
{
RelativeSizeAxes = Axes.Both,
State = { Value = Visibility.Visible },
Score = { Value = score },
StatisticsUpdate =
DisplayedUserStatisticsUpdate =
{
Value = new SoloStatisticsUpdate(score, new UserStatistics
{

View File

@ -200,7 +200,13 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
return multiplayerLeaderboard.TeamScores.Count == 2
? new MultiplayerTeamResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem, multiplayerLeaderboard.TeamScores)
: new MultiplayerResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem);
{
ShowUserStatistics = true,
}
: new MultiplayerResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem)
{
ShowUserStatistics = true
};
}
protected override void Dispose(bool isDisposing)

View File

@ -61,6 +61,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
return new PlaylistsResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem)
{
AllowRetry = true,
ShowUserStatistics = true,
};
}

View File

@ -73,6 +73,13 @@ namespace osu.Game.Screens.Ranking
/// </summary>
public bool AllowWatchingReplay { get; init; } = true;
/// <summary>
/// Whether the user's personal statistics should be shown on the extended statistics panel
/// after clicking the score panel associated with the <see cref="ResultsScreen.Score"/> being presented.
/// Requires <see cref="Score"/> to be present.
/// </summary>
public bool ShowUserStatistics { get; init; }
private Sample popInSample;
protected ResultsScreen([CanBeNull] ScoreInfo score)
@ -105,7 +112,7 @@ namespace osu.Game.Screens.Ranking
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
StatisticsPanel = CreateStatisticsPanel().With(panel =>
StatisticsPanel = createStatisticsPanel().With(panel =>
{
panel.RelativeSizeAxes = Axes.Both;
panel.Score.BindTarget = SelectedScore;
@ -243,7 +250,12 @@ namespace osu.Game.Screens.Ranking
/// <summary>
/// Creates the <see cref="Statistics.StatisticsPanel"/> to be used to display extended information about scores.
/// </summary>
protected virtual StatisticsPanel CreateStatisticsPanel() => new StatisticsPanel();
private StatisticsPanel createStatisticsPanel()
{
return ShowUserStatistics && Score != null
? new UserStatisticsPanel(Score)
: new StatisticsPanel();
}
private void fetchScoresCallback(IEnumerable<ScoreInfo> scores) => Schedule(() =>
{

View File

@ -6,70 +6,27 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Extensions;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Solo;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics;
namespace osu.Game.Screens.Ranking
{
public partial class SoloResultsScreen : ResultsScreen
{
/// <summary>
/// Whether the user's personal statistics should be shown on the extended statistics panel
/// after clicking the score panel associated with the <see cref="ResultsScreen.Score"/> being presented.
/// </summary>
public bool ShowUserStatistics { get; init; }
private GetScoresRequest? getScoreRequest;
[Resolved]
private RulesetStore rulesets { get; set; } = null!;
private IBindable<SoloStatisticsUpdate?> latestUpdate = null!;
private readonly Bindable<SoloStatisticsUpdate?> statisticsUpdate = new Bindable<SoloStatisticsUpdate?>();
public SoloResultsScreen(ScoreInfo score)
: base(score)
{
}
[BackgroundDependencyLoader]
private void load(SoloStatisticsWatcher? soloStatisticsWatcher)
{
if (ShowUserStatistics && soloStatisticsWatcher != null)
{
Debug.Assert(Score != null);
latestUpdate = soloStatisticsWatcher.LatestUpdate.GetBoundCopy();
latestUpdate.BindValueChanged(update =>
{
if (update.NewValue?.Score.MatchesOnlineID(Score) == true)
statisticsUpdate.Value = update.NewValue;
});
}
}
protected override StatisticsPanel CreateStatisticsPanel()
{
Debug.Assert(Score != null);
if (ShowUserStatistics)
{
return new SoloStatisticsPanel(Score)
{
StatisticsUpdate = { BindTarget = statisticsUpdate }
};
}
return base.CreateStatisticsPanel();
}
protected override APIRequest? FetchScores(Action<IEnumerable<ScoreInfo>>? scoresCallback)
{
Debug.Assert(Score != null);

View File

@ -3,25 +3,43 @@
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.Solo;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Statistics.User;
namespace osu.Game.Screens.Ranking.Statistics
{
public partial class SoloStatisticsPanel : StatisticsPanel
public partial class UserStatisticsPanel : StatisticsPanel
{
private readonly ScoreInfo achievedScore;
public SoloStatisticsPanel(ScoreInfo achievedScore)
internal readonly Bindable<SoloStatisticsUpdate?> DisplayedUserStatisticsUpdate = new Bindable<SoloStatisticsUpdate?>();
private IBindable<SoloStatisticsUpdate?> latestGlobalStatisticsUpdate = null!;
public UserStatisticsPanel(ScoreInfo achievedScore)
{
this.achievedScore = achievedScore;
}
public Bindable<SoloStatisticsUpdate?> StatisticsUpdate { get; } = new Bindable<SoloStatisticsUpdate?>();
[BackgroundDependencyLoader]
private void load(SoloStatisticsWatcher? soloStatisticsWatcher)
{
if (soloStatisticsWatcher != null)
{
latestGlobalStatisticsUpdate = soloStatisticsWatcher.LatestUpdate.GetBoundCopy();
latestGlobalStatisticsUpdate.BindValueChanged(update =>
{
if (update.NewValue?.Score.MatchesOnlineID(achievedScore) == true)
DisplayedUserStatisticsUpdate.Value = update.NewValue;
});
}
}
protected override ICollection<StatisticItem> CreateStatisticItems(ScoreInfo newScore, IBeatmap playableBeatmap)
{
@ -37,7 +55,7 @@ namespace osu.Game.Screens.Ranking.Statistics
RelativeSizeAxes = Axes.X,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
StatisticsUpdate = { BindTarget = StatisticsUpdate }
StatisticsUpdate = { BindTarget = DisplayedUserStatisticsUpdate }
})).ToArray();
}