Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix daily challenge results screen fetching scores beginning from the user's highest #30852

Merged
merged 8 commits into from
Nov 28, 2024
138 changes: 97 additions & 41 deletions osu.Game.Tests/Visual/Playlists/TestScenePlaylistsResultsScreen.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ [new MatchChatDisplay(room) { RelativeSizeAxes = Axes.Both }]
private void presentScore(long id)
{
if (this.IsCurrentScreen())
this.Push(new PlaylistItemScoreResultsScreen(room.RoomID!.Value, playlistItem, id));
this.Push(new PlaylistItemScoreResultsScreen(id, room.RoomID!.Value, playlistItem));
}

private void onRoomScoreSet(MultiplayerRoomScoreSetEvent e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace osu.Game.Screens.OnlinePlay.Multiplayer
{
public partial class MultiplayerResultsScreen : PlaylistItemUserResultsScreen
public partial class MultiplayerResultsScreen : PlaylistItemScoreResultsScreen
{
public MultiplayerResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem)
: base(score, roomId, playlistItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ protected virtual ScoreInfo[] PerformSuccessCallback(Action<IEnumerable<ScoreInf
{
var scoreInfos = scores.Select(s => s.CreateScoreInfo(ScoreManager, Rulesets, PlaylistItem, Beatmap.Value.BeatmapInfo)).OrderByTotalScore().ToArray();

// Invoke callback to add the scores.
callback.Invoke(scoreInfos);
// Invoke callback to add the scores. Exclude the score provided to this screen since it's added already.
callback.Invoke(scoreInfos.Where(s => s.OnlineID != Score?.OnlineID));

return scoreInfos;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
namespace osu.Game.Screens.OnlinePlay.Playlists
{
/// <summary>
/// Shows a selected arbitrary score for a playlist item, with scores around included.
/// Shows a given score in a playlist item, with scores around included.
/// </summary>
public partial class PlaylistItemScoreResultsScreen : PlaylistItemResultsScreen
{
private readonly long scoreId;

public PlaylistItemScoreResultsScreen(long roomId, PlaylistItem playlistItem, long scoreId)
public PlaylistItemScoreResultsScreen(ScoreInfo score, long roomId, PlaylistItem playlistItem)
: base(score, roomId, playlistItem)
{
scoreId = score.OnlineID;
}

public PlaylistItemScoreResultsScreen(long scoreId, long roomId, PlaylistItem playlistItem)
: base(null, roomId, playlistItem)
{
this.scoreId = scoreId;
Expand All @@ -28,9 +34,7 @@ public PlaylistItemScoreResultsScreen(long roomId, PlaylistItem playlistItem, lo
protected override ScoreInfo[] PerformSuccessCallback(Action<IEnumerable<ScoreInfo>> callback, List<MultiplayerScore> scores, MultiplayerScores? pivot = null)
{
var scoreInfos = base.PerformSuccessCallback(callback, scores, pivot);

Schedule(() => SelectedScore.Value ??= scoreInfos.SingleOrDefault(score => score.OnlineID == scoreId));

Schedule(() => SelectedScore.Value ??= scoreInfos.SingleOrDefault(s => s.OnlineID == scoreId));
return scoreInfos;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Scoring;

namespace osu.Game.Screens.OnlinePlay.Playlists
{
/// <summary>
/// Shows a user's best score in a playlist item, with scores around included.
/// </summary>
public partial class PlaylistItemUserBestResultsScreen : PlaylistItemResultsScreen
{
private readonly int userId;

public PlaylistItemUserBestResultsScreen(long roomId, PlaylistItem playlistItem, int userId)
: base(null, roomId, playlistItem)
{
this.userId = userId;
}

protected override APIRequest<MultiplayerScore> CreateScoreRequest() => new ShowPlaylistUserScoreRequest(RoomId, PlaylistItem.ID, userId);

protected override ScoreInfo[] PerformSuccessCallback(Action<IEnumerable<ScoreInfo>> callback, List<MultiplayerScore> scores, MultiplayerScores? pivot = null)
{
var scoreInfos = base.PerformSuccessCallback(callback, scores, pivot);

Schedule(() =>
{
// Prefer selecting the local user's score, or otherwise default to the first visible score.
SelectedScore.Value ??= scoreInfos.FirstOrDefault(s => s.UserID == userId) ?? scoreInfos.FirstOrDefault();
});

return scoreInfos;
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion osu.Game/Screens/OnlinePlay/Playlists/PlaylistsPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override bool OnExiting(ScreenExitEvent e)
protected override ResultsScreen CreateResults(ScoreInfo score)
{
Debug.Assert(Room.RoomID != null);
return new PlaylistItemUserResultsScreen(score, Room.RoomID.Value, PlaylistItem)
return new PlaylistItemScoreResultsScreen(score, Room.RoomID.Value, PlaylistItem)
{
AllowRetry = true,
ShowUserStatistics = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using osu.Framework.Screens;
using osu.Game.Graphics.Cursor;
using osu.Game.Input;
using osu.Game.Online.API;
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Components;
using osu.Game.Screens.OnlinePlay.Match;
Expand All @@ -32,6 +33,9 @@ public partial class PlaylistsRoomSubScreen : RoomSubScreen

private readonly IBindable<bool> isIdle = new BindableBool();

[Resolved]
private IAPIProvider api { get; set; } = null!;

[Resolved(CanBeNull = true)]
private IdleTracker? idleTracker { get; set; }

Expand Down Expand Up @@ -143,7 +147,7 @@ private void updateRoomPlaylist()
RequestResults = item =>
{
Debug.Assert(Room.RoomID != null);
ParentScreen?.Push(new PlaylistItemUserResultsScreen(null, Room.RoomID.Value, item));
ParentScreen?.Push(new PlaylistItemUserBestResultsScreen(Room.RoomID.Value, item, api.LocalUser.Value.Id));
}
}
},
Expand Down
Loading