Merge pull request #9241 from smoogipoo/timeshift-results-2

Implement per-beatmap results screen for timeshift
This commit is contained in:
Dean Herbert 2020-06-12 13:36:33 +09:00 committed by GitHub
commit 8d550a7b29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 377 additions and 61 deletions

View File

@ -19,6 +19,7 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Scoring;
using osu.Game.Screens;
@ -27,6 +28,7 @@ using osu.Game.Screens.Play;
using osu.Game.Screens.Play.PlayerSettings;
using osu.Game.Screens.Ranking;
using osu.Game.Screens.Select;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Resources;
using osu.Game.Users;
using osuTK;
@ -186,9 +188,15 @@ namespace osu.Game.Tests.Visual.Background
public void TestTransition()
{
performFullSetup();
FadeAccessibleResults results = null;
AddStep("Transition to Results", () => player.Push(results =
new FadeAccessibleResults(new ScoreInfo { User = new User { Username = "osu!" } })));
AddStep("Transition to Results", () => player.Push(results = new FadeAccessibleResults(new ScoreInfo
{
User = new User { Username = "osu!" },
Beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo
})));
AddUntilStep("Wait for results is current", () => results.IsCurrentScreen());
AddUntilStep("Screen is undimmed, original background retained", () =>
songSelect.IsBackgroundUndimmed() && songSelect.IsBackgroundCurrent() && results.IsBlurCorrect());

View File

@ -0,0 +1,124 @@
// 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 System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Ranking;
using osu.Game.Tests.Beatmaps;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.Multiplayer
{
public class TestSceneTimeshiftResultsScreen : ScreenTestScene
{
private bool roomsReceived;
[SetUp]
public void Setup() => Schedule(() =>
{
roomsReceived = false;
bindHandler();
});
[Test]
public void TestShowResultsWithScore()
{
createResults(new TestScoreInfo(new OsuRuleset().RulesetInfo));
AddWaitStep("wait for display", 5);
}
[Test]
public void TestShowResultsNullScore()
{
createResults(null);
AddWaitStep("wait for display", 5);
}
[Test]
public void TestShowResultsNullScoreWithDelay()
{
AddStep("bind delayed handler", () => bindHandler(3000));
createResults(null);
AddUntilStep("wait for rooms to be received", () => roomsReceived);
AddWaitStep("wait for display", 5);
}
private void createResults(ScoreInfo score)
{
AddStep("load results", () =>
{
LoadScreen(new TimeshiftResultsScreen(score, 1, new PlaylistItem
{
Beatmap = { Value = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo },
Ruleset = { Value = new OsuRuleset().RulesetInfo }
}));
});
}
private void bindHandler(double delay = 0)
{
var roomScores = new List<RoomScore>();
for (int i = 0; i < 10; i++)
{
roomScores.Add(new RoomScore
{
ID = i,
Accuracy = 0.9 - 0.01 * i,
EndedAt = DateTimeOffset.Now.Subtract(TimeSpan.FromHours(i)),
Passed = true,
Rank = ScoreRank.B,
MaxCombo = 999,
TotalScore = 999999 - i * 1000,
User = new User
{
Id = 2,
Username = $"peppy{i}",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
},
Statistics =
{
{ HitResult.Miss, 1 },
{ HitResult.Meh, 50 },
{ HitResult.Good, 100 },
{ HitResult.Great, 300 },
}
});
}
((DummyAPIAccess)API).HandleRequest = request =>
{
switch (request)
{
case GetRoomPlaylistScoresRequest r:
if (delay == 0)
success();
else
{
Task.Run(async () =>
{
await Task.Delay(TimeSpan.FromMilliseconds(delay));
Schedule(success);
});
}
void success()
{
r.TriggerSuccess(new RoomPlaylistScores { Scores = roomScores });
roomsReceived = true;
}
break;
}
};
}
}
}

View File

@ -4,7 +4,6 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -33,7 +32,10 @@ namespace osu.Game.Tests.Visual.Ranking
{
var author = new User { Username = "mapper_name" };
AddStep("show example score", () => showPanel(createTestBeatmap(author), new TestScoreInfo(new OsuRuleset().RulesetInfo)));
AddStep("show example score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo)
{
Beatmap = createTestBeatmap(author)
}));
AddAssert("mapper name present", () => this.ChildrenOfType<OsuSpriteText>().Any(spriteText => spriteText.Text == "mapper_name"));
}
@ -41,38 +43,34 @@ namespace osu.Game.Tests.Visual.Ranking
[Test]
public void TestMapWithUnknownMapper()
{
AddStep("show example score", () => showPanel(createTestBeatmap(null), new TestScoreInfo(new OsuRuleset().RulesetInfo)));
AddStep("show example score", () => showPanel(new TestScoreInfo(new OsuRuleset().RulesetInfo)
{
Beatmap = createTestBeatmap(null)
}));
AddAssert("mapped by text not present", () =>
this.ChildrenOfType<OsuSpriteText>().All(spriteText => !containsAny(spriteText.Text, "mapped", "by")));
}
private void showPanel(WorkingBeatmap workingBeatmap, ScoreInfo score)
{
Child = new ExpandedPanelMiddleContentContainer(workingBeatmap, score);
}
private void showPanel(ScoreInfo score) => Child = new ExpandedPanelMiddleContentContainer(score);
private WorkingBeatmap createTestBeatmap(User author)
private BeatmapInfo createTestBeatmap(User author)
{
var beatmap = new TestBeatmap(rulesetStore.GetRuleset(0));
var beatmap = new TestBeatmap(rulesetStore.GetRuleset(0)).BeatmapInfo;
beatmap.Metadata.Author = author;
beatmap.Metadata.Title = "Verrrrrrrrrrrrrrrrrrry looooooooooooooooooooooooong beatmap title";
beatmap.Metadata.Artist = "Verrrrrrrrrrrrrrrrrrry looooooooooooooooooooooooong beatmap artist";
return new TestWorkingBeatmap(beatmap);
return beatmap;
}
private bool containsAny(string text, params string[] stringsToMatch) => stringsToMatch.Any(text.Contains);
private class ExpandedPanelMiddleContentContainer : Container
{
[Cached]
private Bindable<WorkingBeatmap> workingBeatmap { get; set; }
public ExpandedPanelMiddleContentContainer(WorkingBeatmap beatmap, ScoreInfo score)
public ExpandedPanelMiddleContentContainer(ScoreInfo score)
{
workingBeatmap = new Bindable<WorkingBeatmap>(beatmap);
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
Size = new Vector2(ScorePanel.EXPANDED_WIDTH, 700);

View File

@ -38,13 +38,9 @@ namespace osu.Game.Tests.Visual.SongSelect
public class TestScenePlaySongSelect : ScreenTestScene
{
private BeatmapManager manager;
private RulesetStore rulesets;
private MusicController music;
private WorkingBeatmap defaultBeatmap;
private TestSongSelect songSelect;
[BackgroundDependencyLoader]
@ -308,15 +304,13 @@ namespace osu.Game.Tests.Visual.SongSelect
AddAssert("random map selected", () => songSelect.CurrentBeatmap != defaultBeatmap);
var sortMode = config.GetBindable<SortMode>(OsuSetting.SongSelectSortingMode);
AddStep(@"Sort by Artist", delegate { sortMode.Value = SortMode.Artist; });
AddStep(@"Sort by Title", delegate { sortMode.Value = SortMode.Title; });
AddStep(@"Sort by Author", delegate { sortMode.Value = SortMode.Author; });
AddStep(@"Sort by DateAdded", delegate { sortMode.Value = SortMode.DateAdded; });
AddStep(@"Sort by BPM", delegate { sortMode.Value = SortMode.BPM; });
AddStep(@"Sort by Length", delegate { sortMode.Value = SortMode.Length; });
AddStep(@"Sort by Difficulty", delegate { sortMode.Value = SortMode.Difficulty; });
AddStep(@"Sort by Artist", () => config.Set(OsuSetting.SongSelectSortingMode, SortMode.Artist));
AddStep(@"Sort by Title", () => config.Set(OsuSetting.SongSelectSortingMode, SortMode.Title));
AddStep(@"Sort by Author", () => config.Set(OsuSetting.SongSelectSortingMode, SortMode.Author));
AddStep(@"Sort by DateAdded", () => config.Set(OsuSetting.SongSelectSortingMode, SortMode.DateAdded));
AddStep(@"Sort by BPM", () => config.Set(OsuSetting.SongSelectSortingMode, SortMode.BPM));
AddStep(@"Sort by Length", () => config.Set(OsuSetting.SongSelectSortingMode, SortMode.Length));
AddStep(@"Sort by Difficulty", () => config.Set(OsuSetting.SongSelectSortingMode, SortMode.Difficulty));
}
[Test]

View File

@ -0,0 +1,28 @@
// 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.Collections.Generic;
using Newtonsoft.Json;
namespace osu.Game.Online.API.Requests
{
public class GetRoomPlaylistScoresRequest : APIRequest<RoomPlaylistScores>
{
private readonly int roomId;
private readonly int playlistItemId;
public GetRoomPlaylistScoresRequest(int roomId, int playlistItemId)
{
this.roomId = roomId;
this.playlistItemId = playlistItemId;
}
protected override string Target => $@"rooms/{roomId}/playlist/{playlistItemId}/scores";
}
public class RoomPlaylistScores
{
[JsonProperty("scores")]
public List<RoomScore> Scores { get; set; }
}
}

View File

@ -8,7 +8,7 @@ using osu.Game.Scoring;
namespace osu.Game.Online.API.Requests
{
public class SubmitRoomScoreRequest : APIRequest
public class SubmitRoomScoreRequest : APIRequest<RoomScore>
{
private readonly int scoreId;
private readonly int roomId;

View File

@ -0,0 +1,75 @@
// 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 System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
using osu.Game.Users;
namespace osu.Game.Online.API
{
public class RoomScore
{
[JsonProperty("id")]
public int ID { get; set; }
[JsonProperty("user")]
public User User { get; set; }
[JsonProperty("rank")]
[JsonConverter(typeof(StringEnumConverter))]
public ScoreRank Rank { get; set; }
[JsonProperty("total_score")]
public long TotalScore { get; set; }
[JsonProperty("accuracy")]
public double Accuracy { get; set; }
[JsonProperty("max_combo")]
public int MaxCombo { get; set; }
[JsonProperty("mods")]
public APIMod[] Mods { get; set; }
[JsonProperty("statistics")]
public Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>();
[JsonProperty("passed")]
public bool Passed { get; set; }
[JsonProperty("ended_at")]
public DateTimeOffset EndedAt { get; set; }
public ScoreInfo CreateScoreInfo(PlaylistItem playlistItem)
{
var rulesetInstance = playlistItem.Ruleset.Value.CreateInstance();
var scoreInfo = new ScoreInfo
{
OnlineScoreID = ID,
TotalScore = TotalScore,
MaxCombo = MaxCombo,
Beatmap = playlistItem.Beatmap.Value,
BeatmapInfoID = playlistItem.BeatmapID,
Ruleset = playlistItem.Ruleset.Value,
RulesetID = playlistItem.RulesetID,
Statistics = Statistics,
User = User,
Accuracy = Accuracy,
Date = EndedAt,
Hash = string.Empty, // todo: temporary?
Rank = Rank,
Mods = Mods?.Select(m => m.ToMod(rulesetInstance)).ToArray() ?? Array.Empty<Mod>()
};
return scoreInfo;
}
}
}

View File

@ -80,7 +80,7 @@ namespace osu.Game.Screens.Multi.Components
},
new Drawable[]
{
Content = new Container { Margin = new MarginPadding { Top = 5 } }
Content = new Container { Padding = new MarginPadding { Top = 5 } }
}
}
};

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -10,12 +11,16 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Screens;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.Multiplayer.GameTypes;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Multi.Components;
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Multi.Play;
using osu.Game.Screens.Multi.Ranking;
using osu.Game.Screens.Play;
using osu.Game.Screens.Select;
using Footer = osu.Game.Screens.Multi.Match.Components.Footer;
@ -112,10 +117,36 @@ namespace osu.Game.Screens.Multi.Match
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 5 },
Child = new OverlinedPlaylist(true) // Temporarily always allow selection
Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
SelectedItem = { BindTarget = SelectedItem }
Content = new[]
{
new Drawable[]
{
new OverlinedPlaylist(true) // Temporarily always allow selection
{
RelativeSizeAxes = Axes.Both,
SelectedItem = { BindTarget = SelectedItem }
}
},
null,
new Drawable[]
{
new TriangleButton
{
RelativeSizeAxes = Axes.X,
Text = "Show beatmap results",
Action = showBeatmapResults
}
}
},
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.Absolute, 5),
new Dimension(GridSizeMode.AutoSize)
}
}
},
new Container
@ -162,6 +193,9 @@ namespace osu.Game.Screens.Multi.Match
};
}
[Resolved]
private IAPIProvider api { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
@ -225,12 +259,18 @@ namespace osu.Game.Screens.Multi.Match
{
default:
case GameTypeTimeshift _:
multiplayer?.Start(() => new TimeshiftPlayer(SelectedItem.Value)
multiplayer?.Push(new PlayerLoader(() => new TimeshiftPlayer(SelectedItem.Value)
{
Exited = () => leaderboardChatDisplay.RefreshScores()
});
}));
break;
}
}
private void showBeatmapResults()
{
Debug.Assert(roomId.Value != null);
multiplayer?.Push(new TimeshiftResultsScreen(null, roomId.Value.Value, SelectedItem.Value, false));
}
}
}

View File

@ -1,7 +1,6 @@
// 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.Bindables;
using osu.Framework.Extensions.Color4Extensions;
@ -24,7 +23,6 @@ using osu.Game.Screens.Multi.Lounge;
using osu.Game.Screens.Multi.Lounge.Components;
using osu.Game.Screens.Multi.Match;
using osu.Game.Screens.Multi.Match.Components;
using osu.Game.Screens.Play;
using osuTK;
namespace osu.Game.Screens.Multi
@ -197,18 +195,6 @@ namespace osu.Game.Screens.Multi
Logger.Log($"Polling adjusted (listing: {roomManager.TimeBetweenListingPolls}, selection: {roomManager.TimeBetweenSelectionPolls})");
}
/// <summary>
/// Push a <see cref="Player"/> to the main screen stack to begin gameplay.
/// Generally called from a <see cref="MatchSubScreen"/> via DI resolution.
/// </summary>
public void Start(Func<Player> player)
{
if (!this.IsCurrentScreen())
return;
this.Push(new PlayerLoader(player));
}
public void APIStateChanged(IAPIProvider api, APIState state)
{
if (state != APIState.Online)

View File

@ -14,7 +14,9 @@ using osu.Game.Online.API.Requests;
using osu.Game.Online.Multiplayer;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using osu.Game.Screens.Multi.Ranking;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking;
namespace osu.Game.Screens.Multi.Play
{
@ -88,23 +90,25 @@ namespace osu.Game.Screens.Multi.Play
return false;
}
protected override ScoreInfo CreateScore()
protected override ResultsScreen CreateResults(ScoreInfo score)
{
submitScore();
return base.CreateScore();
Debug.Assert(roomId.Value != null);
return new TimeshiftResultsScreen(score, roomId.Value.Value, playlistItem);
}
private void submitScore()
protected override ScoreInfo CreateScore()
{
var score = base.CreateScore();
score.TotalScore = (int)Math.Round(ScoreProcessor.GetStandardisedScore());
Debug.Assert(token != null);
var request = new SubmitRoomScoreRequest(token.Value, roomId.Value ?? 0, playlistItem.ID, score);
request.Success += s => score.OnlineScoreID = s.ID;
request.Failure += e => Logger.Error(e, "Failed to submit score");
api.Queue(request);
return score;
}
protected override void Dispose(bool isDisposing)

View File

@ -0,0 +1,61 @@
// 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 System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.Multiplayer;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking;
namespace osu.Game.Screens.Multi.Ranking
{
public class TimeshiftResultsScreen : ResultsScreen
{
private readonly int roomId;
private readonly PlaylistItem playlistItem;
private LoadingSpinner loadingLayer;
public TimeshiftResultsScreen(ScoreInfo score, int roomId, PlaylistItem playlistItem, bool allowRetry = true)
: base(score, allowRetry)
{
this.roomId = roomId;
this.playlistItem = playlistItem;
}
[BackgroundDependencyLoader]
private void load()
{
AddInternal(loadingLayer = new LoadingLayer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
X = -10,
State = { Value = Score == null ? Visibility.Visible : Visibility.Hidden },
Padding = new MarginPadding { Bottom = TwoLayerButton.SIZE_EXTENDED.Y }
});
}
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
var req = new GetRoomPlaylistScoresRequest(roomId, playlistItem.ID);
req.Success += r =>
{
scoresCallback?.Invoke(r.Scores.Where(s => s.ID != Score?.OnlineScoreID).Select(s => s.CreateScoreInfo(playlistItem)));
loadingLayer.Hide();
};
req.Failure += _ => loadingLayer.Hide();
return req;
}
}
}

View File

@ -4,11 +4,9 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
@ -52,10 +50,10 @@ namespace osu.Game.Screens.Ranking.Expanded
}
[BackgroundDependencyLoader]
private void load(Bindable<WorkingBeatmap> working)
private void load()
{
var beatmap = working.Value.BeatmapInfo;
var metadata = beatmap.Metadata;
var beatmap = score.Beatmap;
var metadata = beatmap.BeatmapSet?.Metadata ?? beatmap.Metadata;
var creator = metadata.Author?.Username;
var topStatistics = new List<StatisticDisplay>