Make Beatmap (bindable) non-nullable.

This commit is contained in:
Dean Herbert 2017-07-19 13:32:16 +09:00
parent 0846414c5b
commit d0dea33faa
14 changed files with 139 additions and 161 deletions

View File

@ -81,7 +81,7 @@ namespace osu.Desktop.VisualTests.Tests
{ {
return new Player return new Player
{ {
Beatmap = beatmap InitialBeatmap = beatmap
}; };
} }
} }

View File

@ -59,7 +59,7 @@ namespace osu.Desktop.VisualTests.Tests
} }
}) })
{ {
Beatmap = beatmap InitialBeatmap = beatmap
}); });
} }
} }

View File

@ -16,9 +16,9 @@ namespace osu.Game.Beatmaps
{ {
internal class DummyWorkingBeatmap : WorkingBeatmap internal class DummyWorkingBeatmap : WorkingBeatmap
{ {
private readonly OsuGame game; private readonly OsuGameBase game;
public DummyWorkingBeatmap(OsuGame game) public DummyWorkingBeatmap(OsuGameBase game)
: base(new BeatmapInfo : base(new BeatmapInfo
{ {
Metadata = new BeatmapMetadata Metadata = new BeatmapMetadata

View File

@ -21,7 +21,6 @@ using OpenTK;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
@ -100,8 +99,6 @@ namespace osu.Game
Dependencies.Cache(this); Dependencies.Cache(this);
BeatmapDatabase.DefaultBeatmap = new DummyWorkingBeatmap(this);
configRuleset = LocalConfig.GetBindable<int>(OsuSetting.Ruleset); configRuleset = LocalConfig.GetBindable<int>(OsuSetting.Ruleset);
Ruleset.Value = RulesetDatabase.GetRuleset(configRuleset.Value); Ruleset.Value = RulesetDatabase.GetRuleset(configRuleset.Value);
Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0; Ruleset.ValueChanged += r => configRuleset.Value = r.ID ?? 0;

View File

@ -43,7 +43,7 @@ namespace osu.Game
protected MenuCursor Cursor; protected MenuCursor Cursor;
public readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>(); public Bindable<WorkingBeatmap> Beatmap { get; private set; }
private Bindable<bool> fpsDisplayVisible; private Bindable<bool> fpsDisplayVisible;
@ -121,6 +121,10 @@ namespace osu.Game
Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Venera")); Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Venera"));
Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Venera-Light")); Fonts.AddStore(new GlyphStore(Resources, @"Fonts/Venera-Light"));
var defaultBeatmap = new DummyWorkingBeatmap(this);
Beatmap = new NonNullableBindable<WorkingBeatmap>(defaultBeatmap);
BeatmapDatabase.DefaultBeatmap = defaultBeatmap;
OszArchiveReader.Register(); OszArchiveReader.Register();
Dependencies.Cache(API = new APIAccess Dependencies.Cache(API = new APIAccess

View File

@ -18,7 +18,7 @@ namespace osu.Game.Screens.Edit
protected override void OnResuming(Screen last) protected override void OnResuming(Screen last)
{ {
Beatmap?.Track?.Stop(); Beatmap.Value.Track?.Stop();
base.OnResuming(last); base.OnResuming(last);
} }
@ -26,13 +26,13 @@ namespace osu.Game.Screens.Edit
{ {
base.OnEntering(last); base.OnEntering(last);
Background.FadeColour(Color4.DarkGray, 500); Background.FadeColour(Color4.DarkGray, 500);
Beatmap?.Track?.Stop(); Beatmap.Value.Track?.Stop();
} }
protected override bool OnExiting(Screen next) protected override bool OnExiting(Screen next)
{ {
Background.FadeColour(Color4.White, 500); Background.FadeColour(Color4.White, 500);
Beatmap?.Track?.Start(); Beatmap.Value.Track?.Start();
return base.OnExiting(next); return base.OnExiting(next);
} }
} }

View File

@ -103,9 +103,9 @@ namespace osu.Game.Screens.Menu
} }
beatmaps.GetChildren(setInfo); beatmaps.GetChildren(setInfo);
Beatmap = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]); Beatmap.Value = beatmaps.GetWorkingBeatmap(setInfo.Beatmaps[0]);
track = Beatmap.Track; track = Beatmap.Value.Track;
trackManager.SetExclusive(track); trackManager.SetExclusive(track);
welcome = audio.Sample.Get(@"welcome"); welcome = audio.Sample.Get(@"welcome");

View File

@ -67,12 +67,6 @@ namespace osu.Game.Screens.Menu
preloadSongSelect(); preloadSongSelect();
} }
protected override void OnBeatmapChanged(WorkingBeatmap beatmap)
{
base.OnBeatmapChanged(beatmap);
background.Next();
}
private void preloadSongSelect() private void preloadSongSelect()
{ {
if (songSelect == null) if (songSelect == null)
@ -90,16 +84,30 @@ namespace osu.Game.Screens.Menu
{ {
base.OnEntering(last); base.OnEntering(last);
buttons.FadeInFromZero(500); buttons.FadeInFromZero(500);
if (last is Intro && Beatmap != null)
var track = Beatmap.Value.Track;
var metadata = Beatmap.Value.Metadata;
if (last is Intro && track != null)
{ {
if (!Beatmap.Track.IsRunning) if (!track.IsRunning)
{ {
Beatmap.Track.Seek(Beatmap.Metadata.PreviewTime); track.Seek(metadata.PreviewTime);
if (Beatmap.Metadata.PreviewTime == -1) if (metadata.PreviewTime == -1)
Beatmap.Track.Seek(Beatmap.Track.Length * 0.4f); track.Seek(track.Length * 0.4f);
Beatmap.Track.Start(); track.Start();
} }
} }
Beatmap.ValueChanged += beatmap_ValueChanged;
}
private void beatmap_ValueChanged(WorkingBeatmap newValue)
{
if (!IsCurrentScreen)
return;
background.Next();
} }
protected override void OnSuspending(Screen next) protected override void OnSuspending(Screen next)

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Screens; using osu.Framework.Screens;
@ -35,38 +36,31 @@ namespace osu.Game.Screens
/// </summary> /// </summary>
internal virtual bool AllowBeatmapRulesetChange => true; internal virtual bool AllowBeatmapRulesetChange => true;
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); protected readonly Bindable<WorkingBeatmap> Beatmap = new Bindable<WorkingBeatmap>();
public WorkingBeatmap InitialBeatmap
{
set
{
if (IsLoaded) throw new InvalidOperationException($"Cannot set {nameof(InitialBeatmap)} post-load.");
Beatmap.Value = value;
}
}
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>(); private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
private SampleChannel sampleExit; private SampleChannel sampleExit;
private WorkingBeatmap defaultBeatmap;
public WorkingBeatmap Beatmap
{
get
{
return beatmap.Value;
}
set
{
beatmap.Value = value ?? defaultBeatmap;
}
}
[BackgroundDependencyLoader(permitNulls: true)] [BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuGameBase game, OsuGame osuGame, AudioManager audio, BeatmapDatabase beatmaps) private void load(OsuGameBase game, OsuGame osuGame, AudioManager audio)
{ {
defaultBeatmap = beatmaps.DefaultBeatmap;
if (game != null) if (game != null)
{ {
//if we were given a beatmap at ctor time, we want to pass this on to the game-wide beatmap. //if we were given a beatmap at ctor time, we want to pass this on to the game-wide beatmap.
var localMap = beatmap.Value; var localMap = Beatmap.Value;
beatmap.BindTo(game.Beatmap); Beatmap.BindTo(game.Beatmap);
if (localMap != null) if (localMap != null)
beatmap.Value = localMap; Beatmap.Value = localMap;
} }
if (osuGame != null) if (osuGame != null)
@ -75,20 +69,6 @@ namespace osu.Game.Screens
sampleExit = audio.Sample.Get(@"UI/melodic-1"); sampleExit = audio.Sample.Get(@"UI/melodic-1");
} }
protected override void LoadComplete()
{
base.LoadComplete();
beatmap.ValueChanged += OnBeatmapChanged;
}
/// <summary>
/// The global Beatmap was changed.
/// </summary>
protected virtual void OnBeatmapChanged(WorkingBeatmap beatmap)
{
}
protected override void Update() protected override void Update()
{ {
if (!IsCurrentScreen) return; if (!IsCurrentScreen) return;
@ -98,7 +78,7 @@ namespace osu.Game.Screens
// we only want to apply these restrictions when we are inside a screen stack. // we only want to apply these restrictions when we are inside a screen stack.
// the use case for not applying is in visual/unit tests. // the use case for not applying is in visual/unit tests.
ruleset.Disabled = !AllowBeatmapRulesetChange; ruleset.Disabled = !AllowBeatmapRulesetChange;
beatmap.Disabled = !AllowBeatmapRulesetChange; Beatmap.Disabled = !AllowBeatmapRulesetChange;
} }
} }
@ -114,8 +94,6 @@ namespace osu.Game.Screens
BackgroundScreen bg = CreateBackground(); BackgroundScreen bg = CreateBackground();
OnBeatmapChanged(Beatmap);
if (lastOsu?.Background != null) if (lastOsu?.Background != null)
{ {
if (bg == null || lastOsu.Background.Equals(bg)) if (bg == null || lastOsu.Background.Equals(bg))
@ -160,11 +138,7 @@ namespace osu.Game.Screens
if (base.OnExiting(next)) if (base.OnExiting(next))
return true; return true;
// while this is not necessary as we are constructing our own bindable, there are cases where Beatmap.UnbindAll();
// the GC doesn't run as fast as expected and this is triggered post-exit.
// added to resolve https://github.com/ppy/osu/issues/829
beatmap.ValueChanged -= OnBeatmapChanged;
return false; return false;
} }
} }

View File

@ -81,24 +81,24 @@ namespace osu.Game.Screens.Play
try try
{ {
if (Beatmap == null) if (Beatmap.Value == null)
Beatmap = beatmaps.GetWorkingBeatmap(BeatmapInfo, withStoryboard: true); Beatmap.Value = beatmaps.GetWorkingBeatmap(BeatmapInfo, withStoryboard: true);
if (Beatmap?.Beatmap == null) if (Beatmap.Value?.Beatmap == null)
throw new InvalidOperationException("Beatmap was not loaded"); throw new InvalidOperationException("Beatmap was not loaded");
ruleset = osu?.Ruleset.Value ?? Beatmap.BeatmapInfo.Ruleset; ruleset = osu?.Ruleset.Value ?? Beatmap.Value.BeatmapInfo.Ruleset;
rulesetInstance = ruleset.CreateInstance(); rulesetInstance = ruleset.CreateInstance();
try try
{ {
HitRenderer = rulesetInstance.CreateHitRendererWith(Beatmap, ruleset.ID == Beatmap.BeatmapInfo.Ruleset.ID); HitRenderer = rulesetInstance.CreateHitRendererWith(Beatmap, ruleset.ID == Beatmap.Value.BeatmapInfo.Ruleset.ID);
} }
catch (BeatmapInvalidForRulesetException) catch (BeatmapInvalidForRulesetException)
{ {
// we may fail to create a HitRenderer if the beatmap cannot be loaded with the user's preferred ruleset // we may fail to create a HitRenderer if the beatmap cannot be loaded with the user's preferred ruleset
// let's try again forcing the beatmap's ruleset. // let's try again forcing the beatmap's ruleset.
ruleset = Beatmap.BeatmapInfo.Ruleset; ruleset = Beatmap.Value.BeatmapInfo.Ruleset;
rulesetInstance = ruleset.CreateInstance(); rulesetInstance = ruleset.CreateInstance();
HitRenderer = rulesetInstance.CreateHitRendererWith(Beatmap, true); HitRenderer = rulesetInstance.CreateHitRendererWith(Beatmap, true);
} }
@ -115,7 +115,7 @@ namespace osu.Game.Screens.Play
return; return;
} }
Track track = Beatmap.Track; Track track = Beatmap.Value.Track;
if (track != null) if (track != null)
{ {
@ -128,7 +128,7 @@ namespace osu.Game.Screens.Play
decoupledClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; decoupledClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
var firstObjectTime = HitRenderer.Objects.First().StartTime; var firstObjectTime = HitRenderer.Objects.First().StartTime;
decoupledClock.Seek(Math.Min(0, firstObjectTime - Math.Max(Beatmap.Beatmap.ControlPointInfo.TimingPointAt(firstObjectTime).BeatLength * 4, Beatmap.BeatmapInfo.AudioLeadIn))); decoupledClock.Seek(Math.Min(0, firstObjectTime - Math.Max(Beatmap.Value.Beatmap.ControlPointInfo.TimingPointAt(firstObjectTime).BeatLength * 4, Beatmap.Value.BeatmapInfo.AudioLeadIn)));
decoupledClock.ProcessFrame(); decoupledClock.ProcessFrame();
offsetClock = new FramedOffsetClock(decoupledClock); offsetClock = new FramedOffsetClock(decoupledClock);
@ -141,7 +141,7 @@ namespace osu.Game.Screens.Play
{ {
adjustableSourceClock.Reset(); adjustableSourceClock.Reset();
foreach (var mod in Beatmap.Mods.Value.OfType<IApplicableToClock>()) foreach (var mod in Beatmap.Value.Mods.Value.OfType<IApplicableToClock>())
mod.ApplyToClock(adjustableSourceClock); mod.ApplyToClock(adjustableSourceClock);
decoupledClock.ChangeSource(adjustableSourceClock); decoupledClock.ChangeSource(adjustableSourceClock);
@ -209,7 +209,7 @@ namespace osu.Game.Screens.Play
hudOverlay.Progress.AllowSeeking = HitRenderer.HasReplayLoaded; hudOverlay.Progress.AllowSeeking = HitRenderer.HasReplayLoaded;
hudOverlay.Progress.OnSeek = pos => decoupledClock.Seek(pos); hudOverlay.Progress.OnSeek = pos => decoupledClock.Seek(pos);
hudOverlay.ModDisplay.Current.BindTo(Beatmap.Mods); hudOverlay.ModDisplay.Current.BindTo(Beatmap.Value.Mods);
//bind HitRenderer to ScoreProcessor and ourselves (for a pass situation) //bind HitRenderer to ScoreProcessor and ourselves (for a pass situation)
HitRenderer.OnAllJudged += onCompletion; HitRenderer.OnAllJudged += onCompletion;
@ -242,7 +242,7 @@ namespace osu.Game.Screens.Play
{ {
var score = new Score var score = new Score
{ {
Beatmap = Beatmap.BeatmapInfo, Beatmap = Beatmap.Value.BeatmapInfo,
Ruleset = ruleset Ruleset = ruleset
}; };
scoreProcessor.PopulateScore(score); scoreProcessor.PopulateScore(score);

View File

@ -35,7 +35,8 @@ namespace osu.Game.Screens.Play
{ {
this.player = player; this.player = player;
player.RestartRequested = () => { player.RestartRequested = () =>
{
showOverlays = false; showOverlays = false;
ValidForResume = true; ValidForResume = true;
}; };
@ -74,7 +75,6 @@ namespace osu.Game.Screens.Play
{ {
RestartCount = player.RestartCount + 1, RestartCount = player.RestartCount + 1,
RestartRequested = player.RestartRequested, RestartRequested = player.RestartRequested,
Beatmap = player.Beatmap,
}); });
Delay(400); Delay(400);

View File

@ -165,7 +165,7 @@ namespace osu.Game.Screens.Ranking
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Alpha = 0.2f, Alpha = 0.2f,
Texture = Beatmap?.Background, Texture = Beatmap.Value?.Background,
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
FillMode = FillMode.Fill FillMode = FillMode.Fill

View File

@ -51,28 +51,30 @@ namespace osu.Game.Screens.Select
ValidForResume = false; ValidForResume = false;
Push(new Editor()); Push(new Editor());
}, Key.Number3); }, Key.Number3);
Beatmap.ValueChanged += beatmap_ValueChanged;
} }
protected override void OnBeatmapChanged(WorkingBeatmap beatmap) private void beatmap_ValueChanged(WorkingBeatmap beatmap)
{ {
if (!IsCurrentScreen) return;
beatmap?.Mods.BindTo(modSelect.SelectedMods); beatmap?.Mods.BindTo(modSelect.SelectedMods);
if (Beatmap?.Track != null) if (Beatmap.Value?.Track != null)
Beatmap.Track.Looping = false; Beatmap.Value.Track.Looping = false;
beatmapDetails.Beatmap = beatmap; beatmapDetails.Beatmap = beatmap;
if (beatmap?.Track != null) if (beatmap?.Track != null)
beatmap.Track.Looping = true; beatmap.Track.Looping = true;
base.OnBeatmapChanged(beatmap);
} }
protected override void OnResuming(Screen last) protected override void OnResuming(Screen last)
{ {
player = null; player = null;
Beatmap.Track.Looping = true; Beatmap.Value.Track.Looping = true;
base.OnResuming(last); base.OnResuming(last);
} }
@ -95,8 +97,8 @@ namespace osu.Game.Screens.Select
if (base.OnExiting(next)) if (base.OnExiting(next))
return true; return true;
if (Beatmap?.Track != null) if (Beatmap.Value?.Track != null)
Beatmap.Track.Looping = false; Beatmap.Value.Track.Looping = false;
return false; return false;
} }
@ -105,12 +107,9 @@ namespace osu.Game.Screens.Select
{ {
if (player != null) return; if (player != null) return;
Beatmap.Track.Looping = false; Beatmap.Value.Track.Looping = false;
LoadComponentAsync(player = new PlayerLoader(new Player LoadComponentAsync(player = new PlayerLoader(new Player()), l => Push(player));
{
Beatmap = Beatmap, //eagerly set this so it's present before push.
}), l => Push(player));
} }
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Threading; using System.Threading;
using OpenTK; using OpenTK;
using OpenTK.Input; using OpenTK.Input;
@ -107,8 +108,9 @@ namespace osu.Game.Screens.Select
Size = new Vector2(carousel_width, 1), Size = new Vector2(carousel_width, 1),
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
SelectionChanged = selectionChanged, SelectionChanged = carouselSelectionChanged,
StartRequested = raiseSelect BeatmapsChanged = carouselBeatmapsLoaded,
StartRequested = carouselRaisedStart
}); });
Add(FilterControl = new FilterControl Add(FilterControl = new FilterControl
{ {
@ -145,7 +147,7 @@ namespace osu.Game.Screens.Select
Add(Footer = new Footer Add(Footer = new Footer
{ {
OnBack = Exit, OnBack = Exit,
OnStart = raiseSelect, OnStart = carouselRaisedStart,
}); });
FooterPanels.Add(BeatmapOptions = new BeatmapOptionsOverlay()); FooterPanels.Add(BeatmapOptions = new BeatmapOptionsOverlay());
@ -180,34 +182,70 @@ namespace osu.Game.Screens.Select
initialAddSetsTask = new CancellationTokenSource(); initialAddSetsTask = new CancellationTokenSource();
carousel.BeatmapsChanged = beatmapsLoaded;
carousel.Beatmaps = database.GetAllWithChildren<BeatmapSetInfo>(b => !b.DeletePending); carousel.Beatmaps = database.GetAllWithChildren<BeatmapSetInfo>(b => !b.DeletePending);
Beatmap.ValueChanged += beatmap_ValueChanged;
} }
private void beatmapsLoaded() private void carouselBeatmapsLoaded()
{ {
if (Beatmap != null) if (Beatmap.Value != null && !Beatmap.Value.BeatmapSetInfo.DeletePending)
carousel.SelectBeatmap(Beatmap.BeatmapInfo, false); carousel.SelectBeatmap(Beatmap.Value.BeatmapInfo, false);
else else
carousel.SelectNext(); carousel.SelectNext();
} }
private void raiseSelect() private void carouselRaisedStart()
{ {
var pendingSelection = selectionChangedDebounce; var pendingSelection = selectionChangedDebounce;
selectionChangedDebounce = null; selectionChangedDebounce = null;
if (pendingSelection?.Completed == false) if (pendingSelection?.Completed == false)
{ {
pendingSelection?.RunTask(); pendingSelection.RunTask();
pendingSelection?.Cancel(); // cancel the already scheduled task. pendingSelection.Cancel(); // cancel the already scheduled task.
} }
if (Beatmap == null) return;
OnSelected(); OnSelected();
} }
private ScheduledDelegate selectionChangedDebounce;
// We need to keep track of the last selected beatmap ignoring debounce to play the correct selection sounds.
private BeatmapInfo beatmapNoDebounce;
/// <summary>
/// selection has been changed as the result of interaction with the carousel.
/// </summary>
private void carouselSelectionChanged(BeatmapInfo beatmap)
{
selectionChangedDebounce?.Cancel();
if (beatmap.Equals(beatmapNoDebounce))
return;
bool preview = beatmap.BeatmapSetInfoID != Beatmap.Value?.BeatmapInfo.BeatmapSetInfoID;
if (beatmap.BeatmapSetInfoID == beatmapNoDebounce?.BeatmapSetInfoID)
sampleChangeDifficulty.Play();
else
sampleChangeBeatmap.Play();
beatmapNoDebounce = beatmap;
Action performLoad = delegate
{
Beatmap.Value = database.GetWorkingBeatmap(beatmap, Beatmap);
ensurePlayingSelected(preview);
changeBackground(Beatmap.Value);
};
if (beatmap == Beatmap.Value.BeatmapInfo)
performLoad();
else
selectionChangedDebounce = Scheduler.AddDelayed(performLoad, 100);
}
private void triggerRandom(UserInputManager input) private void triggerRandom(UserInputManager input)
{ {
if (input.CurrentState.Keyboard.ShiftPressed) if (input.CurrentState.Keyboard.ShiftPressed)
@ -231,20 +269,21 @@ namespace osu.Game.Screens.Select
{ {
base.OnEntering(last); base.OnEntering(last);
//if (Beatmap != null && !Beatmap.BeatmapSetInfo.DeletePending)
//{
// OnBeatmapChanged(Beatmap);
// ensurePlayingSelected();
//}
Content.FadeInFromZero(250); Content.FadeInFromZero(250);
FilterControl.Activate(); FilterControl.Activate();
} }
private void beatmap_ValueChanged(WorkingBeatmap beatmap)
{
if (!IsCurrentScreen) return;
carousel.SelectBeatmap(beatmap?.BeatmapInfo);
}
protected override void OnResuming(Screen last) protected override void OnResuming(Screen last)
{ {
if (Beatmap != null && !Beatmap.BeatmapSetInfo.DeletePending) if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending)
{ {
changeBackground(Beatmap); changeBackground(Beatmap);
ensurePlayingSelected(); ensurePlayingSelected();
@ -306,58 +345,15 @@ namespace osu.Game.Screens.Select
beatmapInfoWedge.UpdateBeatmap(beatmap); beatmapInfoWedge.UpdateBeatmap(beatmap);
} }
/// <summary>
/// The global Beatmap was changed.
/// </summary>
protected override void OnBeatmapChanged(WorkingBeatmap beatmap)
{
base.OnBeatmapChanged(beatmap);
//todo: change background in selectionChanged instead; support per-difficulty backgrounds.
changeBackground(beatmap);
carousel.SelectBeatmap(beatmap?.BeatmapInfo);
}
private ScheduledDelegate selectionChangedDebounce;
// We need to keep track of the last selected beatmap ignoring debounce to play the correct selection sounds.
private BeatmapInfo selectionChangeNoBounce;
/// <summary>
/// selection has been changed as the result of interaction with the carousel.
/// </summary>
private void selectionChanged(BeatmapInfo beatmap)
{
selectionChangedDebounce?.Cancel();
if (beatmap.Equals(selectionChangeNoBounce))
return;
bool preview = beatmap.BeatmapSetInfoID != Beatmap?.BeatmapInfo.BeatmapSetInfoID;
if (beatmap.BeatmapSetInfoID == selectionChangeNoBounce?.BeatmapSetInfoID)
sampleChangeDifficulty.Play();
else
sampleChangeBeatmap.Play();
selectionChangeNoBounce = beatmap;
selectionChangedDebounce = Scheduler.AddDelayed(delegate
{
Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap);
ensurePlayingSelected(preview);
}, 100);
}
private void ensurePlayingSelected(bool preview = false) private void ensurePlayingSelected(bool preview = false)
{ {
Track track = Beatmap?.Track; Track track = Beatmap.Value?.Track;
trackManager.SetExclusive(track); trackManager.SetExclusive(track);
if (track != null) if (track != null)
{ {
if (preview) track.Seek(Beatmap.Metadata.PreviewTime); if (preview) track.Seek(Beatmap.Value.Metadata.PreviewTime);
track.Start(); track.Start();
} }
} }
@ -366,7 +362,7 @@ namespace osu.Game.Screens.Select
{ {
carousel.RemoveBeatmap(beatmapSet); carousel.RemoveBeatmap(beatmapSet);
if (carousel.SelectedBeatmap == null) if (carousel.SelectedBeatmap == null)
Beatmap = null; Beatmap.SetDefault();
} }
private void promptDelete() private void promptDelete()
@ -383,7 +379,7 @@ namespace osu.Game.Screens.Select
{ {
case Key.KeypadEnter: case Key.KeypadEnter:
case Key.Enter: case Key.Enter:
raiseSelect(); carouselRaisedStart();
return true; return true;
case Key.Delete: case Key.Delete:
if (state.Keyboard.ShiftPressed) if (state.Keyboard.ShiftPressed)