Present selected difficulty

This commit is contained in:
Endrik Tombak 2020-04-12 16:00:05 +03:00
parent 2393ce5f51
commit ecd25e567d
3 changed files with 19 additions and 6 deletions

View File

@ -315,8 +315,12 @@ namespace osu.Game
/// The user should have already requested this interactively. /// The user should have already requested this interactively.
/// </summary> /// </summary>
/// <param name="beatmap">The beatmap to select.</param> /// <param name="beatmap">The beatmap to select.</param>
public void PresentBeatmap(BeatmapSetInfo beatmap) /// <param name="findPredicate">Predicate used to find a difficulty to select</param>
public void PresentBeatmap(BeatmapSetInfo beatmap, Predicate<BeatmapInfo> findPredicate = null)
{ {
// Use this predicate if non was provided. This will try to find some difficulty from current ruleset so we wouldn't have to change rulesets
findPredicate ??= b => b.Ruleset.Equals(Ruleset.Value);
var databasedSet = beatmap.OnlineBeatmapSetID != null var databasedSet = beatmap.OnlineBeatmapSetID != null
? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID) ? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID)
: BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash); : BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash);
@ -334,13 +338,13 @@ namespace osu.Game
menuScreen.LoadToSolo(); menuScreen.LoadToSolo();
// we might even already be at the song // we might even already be at the song
if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash) if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash && findPredicate(Beatmap.Value.BeatmapInfo))
{ {
return; return;
} }
// Use first beatmap available for current ruleset, else switch ruleset. // Find first beatmap that matches our predicate.
var first = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First(); var first = databasedSet.Beatmaps.Find(findPredicate) ?? databasedSet.Beatmaps.First();
Ruleset.Value = first.Ruleset; Ruleset.Value = first.Ruleset;
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first); Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first);

View File

@ -277,7 +277,8 @@ namespace osu.Game.Overlays.BeatmapSet
downloadButtonsContainer.Child = new PanelDownloadButton(BeatmapSet.Value) downloadButtonsContainer.Child = new PanelDownloadButton(BeatmapSet.Value)
{ {
Width = 50, Width = 50,
RelativeSizeAxes = Axes.Y RelativeSizeAxes = Axes.Y,
CurrentBeatmap = Picker.Beatmap.GetBoundCopy()
}; };
break; break;

View File

@ -1,7 +1,9 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
@ -16,6 +18,8 @@ namespace osu.Game.Overlays.Direct
private readonly bool noVideo; private readonly bool noVideo;
public Bindable<BeatmapInfo> CurrentBeatmap = new Bindable<BeatmapInfo>();
private readonly ShakeContainer shakeContainer; private readonly ShakeContainer shakeContainer;
private readonly DownloadButton button; private readonly DownloadButton button;
@ -62,7 +66,11 @@ namespace osu.Game.Overlays.Direct
break; break;
case DownloadState.LocallyAvailable: case DownloadState.LocallyAvailable:
game?.PresentBeatmap(BeatmapSet.Value); Predicate<BeatmapInfo> findPredicate = null;
if (CurrentBeatmap.Value != null)
findPredicate = b => b.OnlineBeatmapID == CurrentBeatmap.Value.OnlineBeatmapID;
game?.PresentBeatmap(BeatmapSet.Value, findPredicate);
break; break;
default: default: