From 1418d1369fe76c5e76a0cfaeda57b331334d090f Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 11 Jul 2018 01:32:10 +0900 Subject: [PATCH] Add the ability to click completed download notifications to select beatmap Closes #2731. --- osu.Game/Beatmaps/BeatmapManager.cs | 15 ++++++++++++++- osu.Game/OsuGame.cs | 27 +++++++++++++++++++++++++++ osu.Game/Screens/Menu/MainMenu.cs | 6 +++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/BeatmapManager.cs b/osu.Game/Beatmaps/BeatmapManager.cs index fd24e4297b..e63f70610e 100644 --- a/osu.Game/Beatmaps/BeatmapManager.cs +++ b/osu.Game/Beatmaps/BeatmapManager.cs @@ -45,6 +45,11 @@ namespace osu.Game.Beatmaps /// public event Action BeatmapDownloadBegan; + /// + /// Fired when a beatmap load is requested (into the interactive game UI). + /// + public Action PresentBeatmap; + /// /// A default representation of a WorkingBeatmap to use when no beatmap is available. /// @@ -163,12 +168,20 @@ namespace osu.Game.Beatmaps Task.Factory.StartNew(() => { + BeatmapSetInfo importedBeatmap; + // This gets scheduled back to the update thread, but we want the import to run in the background. using (var stream = new MemoryStream(data)) using (var archive = new ZipArchiveReader(stream, beatmapSetInfo.ToString())) - Import(archive); + importedBeatmap = Import(archive); + downloadNotification.CompletionClickAction = () => + { + PresentBeatmap?.Invoke(importedBeatmap); + return true; + }; downloadNotification.State = ProgressNotificationState.Completed; + currentDownloads.Remove(request); }, TaskCreationOptions.LongRunning); }; diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 922d228701..f8fdaf368c 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -23,6 +23,7 @@ using osu.Framework.Input; using osu.Framework.Input.Bindings; using osu.Framework.Platform; using osu.Framework.Threading; +using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Rulesets.Scoring; using osu.Game.Overlays.Notifications; @@ -33,6 +34,7 @@ using osu.Game.Rulesets.Mods; using osu.Game.Skinning; using OpenTK.Graphics; using osu.Game.Overlays.Volume; +using osu.Game.Screens.Select; namespace osu.Game { @@ -178,6 +180,30 @@ namespace osu.Game /// The set to display. public void ShowBeatmapSet(int setId) => beatmapSetOverlay.FetchAndShowBeatmapSet(setId); + /// + /// Present a beatmap at song select. + /// + /// The beatmap to select. + public void PresentBeatmap(BeatmapSetInfo beatmap) + { + CloseAllOverlays(); + + Beatmap.Value = BeatmapManager.GetWorkingBeatmap(beatmap.Beatmaps.First()); + + switch (currentScreen) + { + case SongSelect _: + break; + default: + // navigate to song select if we are not already there. + var menu = (MainMenu)intro.ChildScreen; + + menu.MakeCurrent(); + menu.LoadToSolo(); + break; + } + } + /// /// Show a user's profile as an overlay. /// @@ -244,6 +270,7 @@ namespace osu.Game BeatmapManager.PostNotification = n => notifications?.Post(n); BeatmapManager.GetStableStorage = GetStorageForStableInstall; + BeatmapManager.PresentBeatmap = PresentBeatmap; AddRange(new Drawable[] { diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index d922f49ce3..4790996833 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -55,7 +55,7 @@ namespace osu.Game.Screens.Menu OnChart = delegate { Push(new ChartListing()); }, OnDirect = delegate { Push(new OnlineListing()); }, OnEdit = delegate { Push(new Editor()); }, - OnSolo = delegate { Push(consumeSongSelect()); }, + OnSolo = onSolo, OnMulti = delegate { Push(new Multiplayer()); }, OnExit = Exit, } @@ -85,6 +85,10 @@ namespace osu.Game.Screens.Menu LoadComponentAsync(songSelect = new PlaySongSelect()); } + public void LoadToSolo() => Schedule(onSolo); + + private void onSolo() => Push(consumeSongSelect()); + private Screen consumeSongSelect() { var s = songSelect;