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

Merge pull request #26287 from wooster0/no-scores-yet

Don't leave scores screen empty if no scores are present yet
This commit is contained in:
Bartłomiej Dach 2024-01-15 19:49:20 +01:00 committed by GitHub
commit a41108057f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 68 additions and 10 deletions

View File

@ -17,6 +17,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Placeholders;
using osu.Game.Online.Rooms;
using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Scoring;
@ -49,8 +50,8 @@ namespace osu.Game.Tests.Visual.Playlists
// Previous test instances of the results screen may still exist at this point so wait for
// those screens to be cleaned up by the base SetUpSteps before re-initialising test state.
// The the screen also holds a leased Beatmap bindable so reassigning it must happen after
// the screen as been exited.
// The screen also holds a leased Beatmap bindable so reassigning it must happen after
// the screen has been exited.
AddStep("initialise user scores and beatmap", () =>
{
lowestScoreId = 1;
@ -63,8 +64,6 @@ namespace osu.Game.Tests.Visual.Playlists
userScore.Statistics = new Dictionary<HitResult, int>();
userScore.MaximumStatistics = new Dictionary<HitResult, int>();
bindHandler();
// Beatmap is required to be an actual beatmap so the scores can get their scores correctly
// calculated for standardised scoring, else the tests that rely on ordering will fall over.
Beatmap.Value = CreateWorkingBeatmap(Ruleset.Value);
@ -77,6 +76,7 @@ namespace osu.Game.Tests.Visual.Playlists
AddStep("bind user score info handler", () => bindHandler(userScore: userScore));
createResults(() => userScore);
waitForDisplay();
AddAssert("user score selected", () => this.ChildrenOfType<ScorePanel>().Single(p => p.Score.OnlineID == userScore.OnlineID).State == PanelState.Expanded);
AddAssert($"score panel position is {real_user_position}",
@ -86,7 +86,10 @@ namespace osu.Game.Tests.Visual.Playlists
[Test]
public void TestShowNullUserScore()
{
AddStep("bind user score info handler", () => bindHandler());
createResults();
waitForDisplay();
AddAssert("top score selected", () => this.ChildrenOfType<ScorePanel>().OrderByDescending(p => p.Score.TotalScore).First().State == PanelState.Expanded);
}
@ -97,6 +100,7 @@ namespace osu.Game.Tests.Visual.Playlists
AddStep("bind user score info handler", () => bindHandler(true, userScore));
createResults(() => userScore);
waitForDisplay();
AddAssert("more than 1 panel displayed", () => this.ChildrenOfType<ScorePanel>().Count() > 1);
AddAssert("user score selected", () => this.ChildrenOfType<ScorePanel>().Single(p => p.Score.OnlineID == userScore.OnlineID).State == PanelState.Expanded);
@ -108,6 +112,7 @@ namespace osu.Game.Tests.Visual.Playlists
AddStep("bind delayed handler", () => bindHandler(true));
createResults();
waitForDisplay();
AddAssert("top score selected", () => this.ChildrenOfType<ScorePanel>().OrderByDescending(p => p.Score.TotalScore).First().State == PanelState.Expanded);
}
@ -115,10 +120,11 @@ namespace osu.Game.Tests.Visual.Playlists
[Test]
public void TestFetchWhenScrolledToTheRight()
{
createResults();
AddStep("bind delayed handler", () => bindHandler(true));
createResults();
waitForDisplay();
for (int i = 0; i < 2; i++)
{
int beforePanelCount = 0;
@ -134,12 +140,44 @@ namespace osu.Game.Tests.Visual.Playlists
}
}
[Test]
public void TestNoMoreScoresToTheRight()
{
AddStep("bind delayed handler with scores", () => bindHandler(delayed: true));
createResults();
waitForDisplay();
int beforePanelCount = 0;
AddStep("get panel count", () => beforePanelCount = this.ChildrenOfType<ScorePanel>().Count());
AddStep("scroll to right", () => resultsScreen.ScorePanelList.ChildrenOfType<OsuScrollContainer>().Single().ScrollToEnd(false));
AddAssert("right loading spinner shown", () => resultsScreen.RightSpinner.State.Value == Visibility.Visible);
waitForDisplay();
AddAssert($"count increased by {scores_per_result}", () => this.ChildrenOfType<ScorePanel>().Count() >= beforePanelCount + scores_per_result);
AddAssert("right loading spinner hidden", () => resultsScreen.RightSpinner.State.Value == Visibility.Hidden);
AddStep("get panel count", () => beforePanelCount = this.ChildrenOfType<ScorePanel>().Count());
AddStep("bind delayed handler with no scores", () => bindHandler(delayed: true, noScores: true));
AddStep("scroll to right", () => resultsScreen.ScorePanelList.ChildrenOfType<OsuScrollContainer>().Single().ScrollToEnd(false));
AddAssert("right loading spinner shown", () => resultsScreen.RightSpinner.State.Value == Visibility.Visible);
waitForDisplay();
AddAssert("count not increased", () => this.ChildrenOfType<ScorePanel>().Count() == beforePanelCount);
AddAssert("right loading spinner hidden", () => resultsScreen.RightSpinner.State.Value == Visibility.Hidden);
AddAssert("no placeholders shown", () => this.ChildrenOfType<MessagePlaceholder>().Count(), () => Is.Zero);
}
[Test]
public void TestFetchWhenScrolledToTheLeft()
{
AddStep("bind user score info handler", () => bindHandler(userScore: userScore));
createResults(() => userScore);
waitForDisplay();
AddStep("bind delayed handler", () => bindHandler(true));
@ -158,6 +196,15 @@ namespace osu.Game.Tests.Visual.Playlists
}
}
[Test]
public void TestShowWithNoScores()
{
AddStep("bind user score info handler", () => bindHandler(noScores: true));
createResults();
AddAssert("no scores visible", () => !resultsScreen.ScorePanelList.GetScorePanels().Any());
AddAssert("placeholder shown", () => this.ChildrenOfType<MessagePlaceholder>().Count(), () => Is.EqualTo(1));
}
private void createResults(Func<ScoreInfo> getScore = null)
{
AddStep("load results", () =>
@ -169,7 +216,6 @@ namespace osu.Game.Tests.Visual.Playlists
});
AddUntilStep("wait for screen to load", () => resultsScreen.IsLoaded);
waitForDisplay();
}
private void waitForDisplay()
@ -183,7 +229,7 @@ namespace osu.Game.Tests.Visual.Playlists
AddWaitStep("wait for display", 5);
}
private void bindHandler(bool delayed = false, ScoreInfo userScore = null, bool failRequests = false) => ((DummyAPIAccess)API).HandleRequest = request =>
private void bindHandler(bool delayed = false, ScoreInfo userScore = null, bool failRequests = false, bool noScores = false) => ((DummyAPIAccess)API).HandleRequest = request =>
{
// pre-check for requests we should be handling (as they are scheduled below).
switch (request)
@ -219,7 +265,7 @@ namespace osu.Game.Tests.Visual.Playlists
break;
case IndexPlaylistScoresRequest i:
triggerSuccess(i, createIndexResponse(i));
triggerSuccess(i, createIndexResponse(i, noScores));
break;
}
}, delay);
@ -301,10 +347,12 @@ namespace osu.Game.Tests.Visual.Playlists
return multiplayerUserScore;
}
private IndexedMultiplayerScores createIndexResponse(IndexPlaylistScoresRequest req)
private IndexedMultiplayerScores createIndexResponse(IndexPlaylistScoresRequest req, bool noScores = false)
{
var result = new IndexedMultiplayerScores();
if (noScores) return result;
string sort = req.IndexParams?.Properties["sort"].ToObject<string>() ?? "score_desc";
for (int i = 1; i <= scores_per_result; i++)

View File

@ -21,7 +21,9 @@ using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Localisation;
using osu.Game.Online.API;
using osu.Game.Online.Placeholders;
using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Screens.Ranking.Statistics;
@ -245,6 +247,12 @@ namespace osu.Game.Screens.Ranking
addScore(s);
lastFetchCompleted = true;
if (ScorePanelList.IsEmpty)
{
// This can happen if for example a beatmap that is part of a playlist hasn't been played yet.
VerticalScrollContent.Add(new MessagePlaceholder(LeaderboardStrings.NoRecordsYet));
}
});
public override void OnEntering(ScreenTransitionEvent e)

View File

@ -49,6 +49,8 @@ namespace osu.Game.Screens.Ranking
public bool AllPanelsVisible => flow.All(p => p.IsPresent);
public bool IsEmpty => flow.Count == 0;
/// <summary>
/// The current scroll position.
/// </summary>