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

Create abstract implementation

This commit is contained in:
smoogipoo 2020-05-26 17:00:41 +09:00
parent c86a003ef9
commit de0b6ec9f1
5 changed files with 49 additions and 16 deletions

View File

@ -479,7 +479,7 @@ namespace osu.Game.Screens.Play
protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !GameplayClockContainer.IsPaused.Value; protected override bool OnScroll(ScrollEvent e) => mouseWheelDisabled.Value && !GameplayClockContainer.IsPaused.Value;
protected virtual ResultsScreen CreateResults(ScoreInfo score) => new ResultsScreen(score); protected virtual ResultsScreen CreateResults(ScoreInfo score) => new SoloResultsScreen(score);
#region Fail Logic #region Fail Logic

View File

@ -30,7 +30,7 @@ namespace osu.Game.Screens.Play
this.Push(CreateResults(DrawableRuleset.ReplayScore.ScoreInfo)); this.Push(CreateResults(DrawableRuleset.ReplayScore.ScoreInfo));
} }
protected override ResultsScreen CreateResults(ScoreInfo score) => new ResultsScreen(score, false); protected override ResultsScreen CreateResults(ScoreInfo score) => new SoloResultsScreen(score, false);
protected override ScoreInfo CreateScore() => score.ScoreInfo; protected override ScoreInfo CreateScore() => score.ScoreInfo;
} }

View File

@ -2,7 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Linq; using System.Collections.Generic;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -12,8 +12,6 @@ using osu.Framework.Screens;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Backgrounds; using osu.Game.Screens.Backgrounds;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
@ -21,7 +19,7 @@ using osuTK;
namespace osu.Game.Screens.Ranking namespace osu.Game.Screens.Ranking
{ {
public class ResultsScreen : OsuScreen public abstract class ResultsScreen : OsuScreen
{ {
protected const float BACKGROUND_BLUR = 20; protected const float BACKGROUND_BLUR = 20;
@ -38,9 +36,6 @@ namespace osu.Game.Screens.Ranking
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
[Resolved]
private RulesetStore rulesets { get; set; }
public readonly ScoreInfo Score; public readonly ScoreInfo Score;
private readonly bool allowRetry; private readonly bool allowRetry;
@ -133,22 +128,28 @@ namespace osu.Game.Screens.Ranking
{ {
base.LoadComplete(); base.LoadComplete();
var req = new GetScoresRequest(Score.Beatmap, Score.Ruleset); var req = FetchScores(scores => Schedule(() =>
req.Success += r => Schedule(() =>
{ {
foreach (var s in r.Scores.Select(s => s.CreateScoreInfo(rulesets))) foreach (var s in scores)
{ {
if (s.OnlineScoreID == Score.OnlineScoreID) if (s.OnlineScoreID == Score.OnlineScoreID)
continue; continue;
panels.AddScore(s); panels.AddScore(s);
} }
}); }));
api.Queue(req); if (req != null)
api.Queue(req);
} }
/// <summary>
/// Performs a fetch/refresh of scores to be displayed.
/// </summary>
/// <param name="scoresCallback">A callback which should be called when fetching is completed. Scheduling is not required.</param>
/// <returns>An <see cref="APIRequest"/> responsible for the fetch operation. This will be queued and performed automatically.</returns>
protected virtual APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback) => null;
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)
{ {
base.OnEntering(last); base.OnEntering(last);

View File

@ -0,0 +1,32 @@
// 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.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Rulesets;
using osu.Game.Scoring;
namespace osu.Game.Screens.Ranking
{
public class SoloResultsScreen : ResultsScreen
{
[Resolved]
private RulesetStore rulesets { get; set; }
public SoloResultsScreen(ScoreInfo score, bool allowRetry = true)
: base(score, allowRetry)
{
}
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
{
var req = new GetScoresRequest(Score.Beatmap, Score.Ruleset);
req.Success += r => scoresCallback?.Invoke(r.Scores.Select(s => s.CreateScoreInfo(rulesets)));
return req;
}
}
}

View File

@ -37,7 +37,7 @@ namespace osu.Game.Screens.Select
} }
protected void PresentScore(ScoreInfo score) => protected void PresentScore(ScoreInfo score) =>
FinaliseSelection(score.Beatmap, score.Ruleset, () => this.Push(new ResultsScreen(score))); FinaliseSelection(score.Beatmap, score.Ruleset, () => this.Push(new SoloResultsScreen(score)));
protected override BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea(); protected override BeatmapDetailArea CreateBeatmapDetailArea() => new PlayBeatmapDetailArea();