From 1a117d1511d48523a7103693e4340a8bd858141d Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Sun, 7 Jul 2019 17:05:53 +0200 Subject: [PATCH 01/14] Closes #5277 --- osu.Game/Screens/Edit/Editor.cs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 89da9ae063..69fbf7d387 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -168,6 +168,8 @@ namespace osu.Game.Screens.Edit menuBar.Mode.ValueChanged += onModeChanged; + host.Exiting += onQuittingGame; + bottomBackground.Colour = colours.Gray2; } @@ -235,16 +237,27 @@ namespace osu.Game.Screens.Edit Beatmap.Value.Track?.Stop(); } + private bool isExitingGame = false; + public override bool OnExiting(IScreen next) { Background.FadeColour(Color4.White, 500); if (Beatmap.Value.Track != null) { - Beatmap.Value.Track.Tempo.Value = 1; - Beatmap.Value.Track.Start(); + if (isExitingGame) + { + Beatmap.Value.Track.Stop(); + } + else + { + Beatmap.Value.Track.Tempo.Value = 1; + Beatmap.Value.Track.Start(); + } } + host.Exiting -= onQuittingGame; + return base.OnExiting(next); } @@ -281,5 +294,7 @@ namespace osu.Game.Screens.Edit else clock.SeekForward(!clock.IsRunning, amount); } + + private bool onQuittingGame() => isExitingGame = true; } } From 84cadc688a4f12df27485e7ec4c1b570acf065bf Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Sun, 7 Jul 2019 17:11:54 +0200 Subject: [PATCH 02/14] Change method name --- osu.Game/Screens/Edit/Editor.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 69fbf7d387..0a9f7672d3 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -168,7 +168,7 @@ namespace osu.Game.Screens.Edit menuBar.Mode.ValueChanged += onModeChanged; - host.Exiting += onQuittingGame; + host.Exiting += onExitingGame; bottomBackground.Colour = colours.Gray2; } @@ -256,7 +256,7 @@ namespace osu.Game.Screens.Edit } } - host.Exiting -= onQuittingGame; + host.Exiting -= onExitingGame; return base.OnExiting(next); } @@ -295,6 +295,6 @@ namespace osu.Game.Screens.Edit clock.SeekForward(!clock.IsRunning, amount); } - private bool onQuittingGame() => isExitingGame = true; + private bool onExitingGame() => isExitingGame = true; } } From 39f04e497d5734ec57393b7a974cb255540f4ae6 Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Mon, 8 Jul 2019 11:24:06 +0200 Subject: [PATCH 03/14] Add UserRequestedPause --- osu.Game/Overlays/MusicController.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 29ae5983be..3db71d39ee 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -66,6 +66,8 @@ namespace osu.Game.Overlays /// public Func GetToolbarHeight; + public bool UserRequestedPause { get; private set; } + public MusicController() { Width = 400; @@ -287,6 +289,8 @@ namespace osu.Game.Overlays return; } + UserRequestedPause = track.IsRunning; + if (track.IsRunning) track.Stop(); else From 338371c3fcec0e9c45ac7ec440e732e083eae972 Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Tue, 9 Jul 2019 00:08:18 +0200 Subject: [PATCH 04/14] Fix music playing while exiting from editor --- osu.Game/OsuGame.cs | 6 +++--- osu.Game/Screens/Edit/Editor.cs | 6 ------ osu.Game/Screens/Menu/MainMenu.cs | 4 +++- osu.Game/Screens/OsuScreen.cs | 11 ++++++++++- osu.Game/Screens/Select/SongSelect.cs | 2 ++ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 0a472d4dc1..325d2cbd85 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -306,7 +306,7 @@ namespace osu.Game private void currentTrackCompleted() { if (!Beatmap.Value.Track.Looping && !Beatmap.Disabled) - musicController.NextTrack(); + MusicController.NextTrack(); } #endregion @@ -484,7 +484,7 @@ namespace osu.Game Origin = Anchor.TopRight, }, rightFloatingOverlayContent.Add, true); - loadComponentSingleFile(musicController = new MusicController + loadComponentSingleFile(MusicController = new MusicController { GetToolbarHeight = () => ToolbarOffset, Anchor = Anchor.TopRight, @@ -752,7 +752,7 @@ namespace osu.Game private ScalingContainer screenContainer; - private MusicController musicController; + public MusicController MusicController { get; private set; } protected override bool OnExiting() { diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 89da9ae063..676e060433 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -239,12 +239,6 @@ namespace osu.Game.Screens.Edit { Background.FadeColour(Color4.White, 500); - if (Beatmap.Value.Track != null) - { - Beatmap.Value.Track.Tempo.Value = 1; - Beatmap.Value.Track.Start(); - } - return base.OnExiting(next); } diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index c64bea840f..dcce49179d 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -120,7 +120,7 @@ namespace osu.Game.Screens.Menu var track = Beatmap.Value.Track; var metadata = Beatmap.Value.Metadata; - if (last is Intro && track != null) + if (last is Intro && track != null && !Game.MusicController.UserRequestedPause) { if (!track.IsRunning) { @@ -189,6 +189,8 @@ namespace osu.Game.Screens.Menu //we may have consumed our preloaded instance, so let's make another. preloadSongSelect(); + + ResumeIfNoUserPauseRequested(); } public override bool OnExiting(IScreen next) diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index 328631ff9c..0682710133 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -50,7 +50,7 @@ namespace osu.Game.Screens public virtual bool CursorVisible => true; - protected new OsuGameBase Game => base.Game as OsuGameBase; + protected new OsuGame Game => base.Game as OsuGame; /// /// The to set the user's activity automatically to when this screen is entered @@ -179,6 +179,15 @@ namespace osu.Game.Screens api.Activity.Value = activity; } + protected void ResumeIfNoUserPauseRequested() + { + if (Beatmap.Value.Track != null && !Game.MusicController.UserRequestedPause) + { + Beatmap.Value.Track.Tempo.Value = 1; + Beatmap.Value.Track.Start(); + } + } + /// /// Fired when this screen was entered or resumed and the logo state is required to be adjusted. /// diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index bf5857f725..17b2ae376f 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -426,6 +426,8 @@ namespace osu.Game.Screens.Select { base.OnEntering(last); + ResumeIfNoUserPauseRequested(); + this.FadeInFromZero(250); FilterControl.Activate(); } From 8f7476e9ccf2f8dd3744315cb56a852d5ff4197a Mon Sep 17 00:00:00 2001 From: Oskar Solecki <31374466+Desconocidosmh@users.noreply.github.com> Date: Tue, 9 Jul 2019 00:26:57 +0200 Subject: [PATCH 05/14] Remove unused stuff --- osu.Game/Screens/Edit/Editor.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index cffe756548..676e060433 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -168,8 +168,6 @@ namespace osu.Game.Screens.Edit menuBar.Mode.ValueChanged += onModeChanged; - host.Exiting += onExitingGame; - bottomBackground.Colour = colours.Gray2; } @@ -237,8 +235,6 @@ namespace osu.Game.Screens.Edit Beatmap.Value.Track?.Stop(); } - private bool isExitingGame = false; - public override bool OnExiting(IScreen next) { Background.FadeColour(Color4.White, 500); @@ -279,7 +275,5 @@ namespace osu.Game.Screens.Edit else clock.SeekForward(!clock.IsRunning, amount); } - - private bool onExitingGame() => isExitingGame = true; } } From 2546f647be43d3e44477fa962a22f6dcd768e510 Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Tue, 9 Jul 2019 11:32:49 +0200 Subject: [PATCH 06/14] Completely change the way we fix the bug --- osu.Game/OsuGame.cs | 6 +++--- osu.Game/Overlays/MusicController.cs | 4 ++-- osu.Game/Screens/Menu/MainMenu.cs | 18 ++++++++---------- osu.Game/Screens/OsuScreen.cs | 11 +---------- osu.Game/Screens/Select/SongSelect.cs | 7 ++++--- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 325d2cbd85..0a472d4dc1 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -306,7 +306,7 @@ namespace osu.Game private void currentTrackCompleted() { if (!Beatmap.Value.Track.Looping && !Beatmap.Disabled) - MusicController.NextTrack(); + musicController.NextTrack(); } #endregion @@ -484,7 +484,7 @@ namespace osu.Game Origin = Anchor.TopRight, }, rightFloatingOverlayContent.Add, true); - loadComponentSingleFile(MusicController = new MusicController + loadComponentSingleFile(musicController = new MusicController { GetToolbarHeight = () => ToolbarOffset, Anchor = Anchor.TopRight, @@ -752,7 +752,7 @@ namespace osu.Game private ScalingContainer screenContainer; - public MusicController MusicController { get; private set; } + private MusicController musicController; protected override bool OnExiting() { diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 3db71d39ee..ad0c0717ac 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -55,6 +55,8 @@ namespace osu.Game.Overlays private Container dragContainer; private Container playerContainer; + public bool UserRequestedPause { get; private set; } + [Resolved] private Bindable beatmap { get; set; } @@ -66,8 +68,6 @@ namespace osu.Game.Overlays /// public Func GetToolbarHeight; - public bool UserRequestedPause { get; private set; } - public MusicController() { Width = 400; diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index dcce49179d..078f9c5a15 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -42,6 +42,9 @@ namespace osu.Game.Screens.Menu [Resolved] private GameHost host { get; set; } + [Resolved] + private MusicController musicController { get; set; } + private BackgroundScreenDefault background; protected override BackgroundScreen CreateBackground() => background; @@ -120,15 +123,6 @@ namespace osu.Game.Screens.Menu var track = Beatmap.Value.Track; var metadata = Beatmap.Value.Metadata; - if (last is Intro && track != null && !Game.MusicController.UserRequestedPause) - { - if (!track.IsRunning) - { - track.Seek(metadata.PreviewTime != -1 ? metadata.PreviewTime : 0.4f * track.Length); - track.Start(); - } - } - Beatmap.ValueChanged += beatmap_ValueChanged; } @@ -190,7 +184,11 @@ namespace osu.Game.Screens.Menu //we may have consumed our preloaded instance, so let's make another. preloadSongSelect(); - ResumeIfNoUserPauseRequested(); + if (Beatmap.Value.Track != null && !musicController.UserRequestedPause) + { + Beatmap.Value.Track.Tempo.Value = 1; + Beatmap.Value.Track.Start(); + } } public override bool OnExiting(IScreen next) diff --git a/osu.Game/Screens/OsuScreen.cs b/osu.Game/Screens/OsuScreen.cs index 0682710133..328631ff9c 100644 --- a/osu.Game/Screens/OsuScreen.cs +++ b/osu.Game/Screens/OsuScreen.cs @@ -50,7 +50,7 @@ namespace osu.Game.Screens public virtual bool CursorVisible => true; - protected new OsuGame Game => base.Game as OsuGame; + protected new OsuGameBase Game => base.Game as OsuGameBase; /// /// The to set the user's activity automatically to when this screen is entered @@ -179,15 +179,6 @@ namespace osu.Game.Screens api.Activity.Value = activity; } - protected void ResumeIfNoUserPauseRequested() - { - if (Beatmap.Value.Track != null && !Game.MusicController.UserRequestedPause) - { - Beatmap.Value.Track.Tempo.Value = 1; - Beatmap.Value.Track.Start(); - } - } - /// /// Fired when this screen was entered or resumed and the logo state is required to be adjusted. /// diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 17b2ae376f..dd115e04d4 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -87,6 +87,9 @@ namespace osu.Game.Screens.Select private readonly Bindable decoupledRuleset = new Bindable(); + [Resolved] + private MusicController musicController { get; set; } + [Cached] [Cached(Type = typeof(IBindable>))] private readonly Bindable> mods = new Bindable>(Array.Empty()); // Bound to the game's mods, but is not reset on exiting @@ -426,8 +429,6 @@ namespace osu.Game.Screens.Select { base.OnEntering(last); - ResumeIfNoUserPauseRequested(); - this.FadeInFromZero(250); FilterControl.Activate(); } @@ -572,7 +573,7 @@ namespace osu.Game.Screens.Select { Track track = Beatmap.Value.Track; - if (!track.IsRunning || restart) + if ((!track.IsRunning || restart) && !musicController.UserRequestedPause) { track.RestartPoint = Beatmap.Value.Metadata.PreviewTime; track.Restart(); From 3472979d0b4d9d2d652ded1a3b9f9c56e2642e1f Mon Sep 17 00:00:00 2001 From: Oskar Solecki <31374466+Desconocidosmh@users.noreply.github.com> Date: Tue, 9 Jul 2019 12:53:40 +0200 Subject: [PATCH 07/14] Make sure exiting editor doesn't unpause the music --- osu.Game/Screens/Edit/Editor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 676e060433..8b3cf1ec90 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -238,7 +238,7 @@ namespace osu.Game.Screens.Edit public override bool OnExiting(IScreen next) { Background.FadeColour(Color4.White, 500); - + Beatmap.Value.Track?.Stop(); return base.OnExiting(next); } From 8b8e67fd726d5b1a2ae2380a3afd62ecbeb38ddc Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Wed, 10 Jul 2019 10:41:52 +0200 Subject: [PATCH 08/14] Add accidentally deleted code --- osu.Game/Screens/Menu/MainMenu.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 078f9c5a15..b67801f9ba 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -123,6 +123,15 @@ namespace osu.Game.Screens.Menu var track = Beatmap.Value.Track; var metadata = Beatmap.Value.Metadata; + if (last is Intro && track != null) + { + if (!track.IsRunning) + { + track.Seek(metadata.PreviewTime != -1 ? metadata.PreviewTime : 0.4f * track.Length); + track.Start(); + } + } + Beatmap.ValueChanged += beatmap_ValueChanged; } From 100d15e651f3c8d27de36a689d6660c7a4e89083 Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Wed, 10 Jul 2019 10:43:02 +0200 Subject: [PATCH 09/14] Move reseting tempo to Editor --- osu.Game/Screens/Edit/Editor.cs | 8 +++++++- osu.Game/Screens/Menu/MainMenu.cs | 3 --- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 8b3cf1ec90..310ce27d45 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -238,7 +238,13 @@ namespace osu.Game.Screens.Edit public override bool OnExiting(IScreen next) { Background.FadeColour(Color4.White, 500); - Beatmap.Value.Track?.Stop(); + + if (Beatmap.Value.Track != null) + { + Beatmap.Value.Track.Tempo.Value = 1; + Beatmap.Value.Track.Stop(); + } + return base.OnExiting(next); } diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index b67801f9ba..6e1c471c1a 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -194,10 +194,7 @@ namespace osu.Game.Screens.Menu preloadSongSelect(); if (Beatmap.Value.Track != null && !musicController.UserRequestedPause) - { - Beatmap.Value.Track.Tempo.Value = 1; Beatmap.Value.Track.Start(); - } } public override bool OnExiting(IScreen next) From fae3348a69127b10fcadff6437c1823ab8c9ade4 Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Wed, 10 Jul 2019 13:20:23 +0200 Subject: [PATCH 10/14] Add caching MusicController in tests --- .../Visual/Background/TestSceneBackgroundScreenBeatmap.cs | 3 ++- osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/Background/TestSceneBackgroundScreenBeatmap.cs index 8b941e4633..a4bb5a38f0 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneBackgroundScreenBeatmap.cs @@ -20,6 +20,7 @@ using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; +using osu.Game.Overlays; using osu.Game.Rulesets; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Scoring; @@ -71,7 +72,7 @@ namespace osu.Game.Tests.Visual.Background Dependencies.Cache(rulesets = new RulesetStore(factory)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, audio, host, Beatmap.Default)); Dependencies.Cache(new OsuConfigManager(LocalStorage)); - + Dependencies.Cache(new MusicController()); manager.Import(TestResources.GetTestBeatmapForImport()).Wait(); Beatmap.SetDefault(); diff --git a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs index 962e0fb362..446a632b31 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs @@ -16,6 +16,7 @@ using osu.Framework.Platform; using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Database; +using osu.Game.Overlays; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu; @@ -96,6 +97,7 @@ namespace osu.Game.Tests.Visual.SongSelect Dependencies.Cache(rulesets = new RulesetStore(factory)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, audio, host, defaultBeatmap = Beatmap.Default)); + Dependencies.Cache(new MusicController()); Beatmap.SetDefault(); } From 9986178bf41b051c2c288549ed8087f630e2331b Mon Sep 17 00:00:00 2001 From: Desconocidosmh Date: Wed, 10 Jul 2019 13:20:23 +0200 Subject: [PATCH 11/14] Revert "Add caching MusicController in tests" This reverts commit fae3348a69127b10fcadff6437c1823ab8c9ade4. --- .../Visual/Background/TestSceneBackgroundScreenBeatmap.cs | 3 +-- osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/osu.Game.Tests/Visual/Background/TestSceneBackgroundScreenBeatmap.cs b/osu.Game.Tests/Visual/Background/TestSceneBackgroundScreenBeatmap.cs index a4bb5a38f0..8b941e4633 100644 --- a/osu.Game.Tests/Visual/Background/TestSceneBackgroundScreenBeatmap.cs +++ b/osu.Game.Tests/Visual/Background/TestSceneBackgroundScreenBeatmap.cs @@ -20,7 +20,6 @@ using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; -using osu.Game.Overlays; using osu.Game.Rulesets; using osu.Game.Rulesets.Osu.Mods; using osu.Game.Scoring; @@ -72,7 +71,7 @@ namespace osu.Game.Tests.Visual.Background Dependencies.Cache(rulesets = new RulesetStore(factory)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, audio, host, Beatmap.Default)); Dependencies.Cache(new OsuConfigManager(LocalStorage)); - Dependencies.Cache(new MusicController()); + manager.Import(TestResources.GetTestBeatmapForImport()).Wait(); Beatmap.SetDefault(); diff --git a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs index 446a632b31..962e0fb362 100644 --- a/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/SongSelect/TestScenePlaySongSelect.cs @@ -16,7 +16,6 @@ using osu.Framework.Platform; using osu.Framework.Screens; using osu.Game.Beatmaps; using osu.Game.Database; -using osu.Game.Overlays; using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu; @@ -97,7 +96,6 @@ namespace osu.Game.Tests.Visual.SongSelect Dependencies.Cache(rulesets = new RulesetStore(factory)); Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, audio, host, defaultBeatmap = Beatmap.Default)); - Dependencies.Cache(new MusicController()); Beatmap.SetDefault(); } From b225b2eb3958cf7c3f1d4fd245a1703885d3d228 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 00:18:19 +0900 Subject: [PATCH 12/14] Rename to IsUserPaused --- osu.Game/Overlays/MusicController.cs | 14 +++++++++----- osu.Game/Screens/Menu/MainMenu.cs | 2 +- osu.Game/Screens/Select/SongSelect.cs | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index ad0c0717ac..abbcec5094 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -55,7 +55,7 @@ namespace osu.Game.Overlays private Container dragContainer; private Container playerContainer; - public bool UserRequestedPause { get; private set; } + public bool IsUserPaused { get; private set; } [Resolved] private Bindable beatmap { get; set; } @@ -159,7 +159,7 @@ namespace osu.Game.Overlays Origin = Anchor.Centre, Scale = new Vector2(1.4f), IconScale = new Vector2(1.4f), - Action = play, + Action = togglePause, Icon = FontAwesome.Regular.PlayCircle, }, nextButton = new MusicIconButton @@ -278,7 +278,7 @@ namespace osu.Game.Overlays } } - private void play() + private void togglePause() { var track = current?.Track; @@ -289,12 +289,16 @@ namespace osu.Game.Overlays return; } - UserRequestedPause = track.IsRunning; - if (track.IsRunning) + { + IsUserPaused = true; track.Stop(); + } else + { track.Start(); + IsUserPaused = false; + } } private void prev() diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 6e1c471c1a..93c413452d 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -193,7 +193,7 @@ namespace osu.Game.Screens.Menu //we may have consumed our preloaded instance, so let's make another. preloadSongSelect(); - if (Beatmap.Value.Track != null && !musicController.UserRequestedPause) + if (Beatmap.Value.Track != null && !musicController.IsUserPaused) Beatmap.Value.Track.Start(); } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index dd115e04d4..085232b27f 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -573,7 +573,7 @@ namespace osu.Game.Screens.Select { Track track = Beatmap.Value.Track; - if ((!track.IsRunning || restart) && !musicController.UserRequestedPause) + if ((!track.IsRunning || restart) && !musicController.IsUserPaused) { track.RestartPoint = Beatmap.Value.Metadata.PreviewTime; track.Restart(); From 6819c528db75c4d88f75ab35c837f1f3e81e13bd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 00:20:01 +0900 Subject: [PATCH 13/14] Use canBeNull instead of needlessly caching MusicController for tests --- osu.Game/Screens/Menu/MainMenu.cs | 6 +++--- osu.Game/Screens/Select/SongSelect.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 93c413452d..5999cbdfb5 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -42,8 +42,8 @@ namespace osu.Game.Screens.Menu [Resolved] private GameHost host { get; set; } - [Resolved] - private MusicController musicController { get; set; } + [Resolved(canBeNull: true)] + private MusicController music { get; set; } private BackgroundScreenDefault background; @@ -193,7 +193,7 @@ namespace osu.Game.Screens.Menu //we may have consumed our preloaded instance, so let's make another. preloadSongSelect(); - if (Beatmap.Value.Track != null && !musicController.IsUserPaused) + if (Beatmap.Value.Track != null && music?.IsUserPaused != true) Beatmap.Value.Track.Start(); } diff --git a/osu.Game/Screens/Select/SongSelect.cs b/osu.Game/Screens/Select/SongSelect.cs index 085232b27f..0eeffda5eb 100644 --- a/osu.Game/Screens/Select/SongSelect.cs +++ b/osu.Game/Screens/Select/SongSelect.cs @@ -87,8 +87,8 @@ namespace osu.Game.Screens.Select private readonly Bindable decoupledRuleset = new Bindable(); - [Resolved] - private MusicController musicController { get; set; } + [Resolved(canBeNull: true)] + private MusicController music { get; set; } [Cached] [Cached(Type = typeof(IBindable>))] @@ -573,7 +573,7 @@ namespace osu.Game.Screens.Select { Track track = Beatmap.Value.Track; - if ((!track.IsRunning || restart) && !musicController.IsUserPaused) + if ((!track.IsRunning || restart) && music?.IsUserPaused != true) { track.RestartPoint = Beatmap.Value.Metadata.PreviewTime; track.Restart(); From ad873b542a09334a86956be8b34249bce849b2f3 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 11 Jul 2019 00:22:40 +0900 Subject: [PATCH 14/14] Simplify editor logic --- osu.Game/Screens/Edit/Editor.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Edit/Editor.cs b/osu.Game/Screens/Edit/Editor.cs index 310ce27d45..8cc227d9be 100644 --- a/osu.Game/Screens/Edit/Editor.cs +++ b/osu.Game/Screens/Edit/Editor.cs @@ -224,30 +224,32 @@ namespace osu.Game.Screens.Edit public override void OnResuming(IScreen last) { - Beatmap.Value.Track?.Stop(); base.OnResuming(last); + Beatmap.Value.Track?.Stop(); } public override void OnEntering(IScreen last) { base.OnEntering(last); + Background.FadeColour(Color4.DarkGray, 500); - Beatmap.Value.Track?.Stop(); + resetTrack(); } public override bool OnExiting(IScreen next) { Background.FadeColour(Color4.White, 500); - - if (Beatmap.Value.Track != null) - { - Beatmap.Value.Track.Tempo.Value = 1; - Beatmap.Value.Track.Stop(); - } + resetTrack(); return base.OnExiting(next); } + private void resetTrack() + { + Beatmap.Value.Track?.ResetSpeedAdjustments(); + Beatmap.Value.Track?.Stop(); + } + private void exportBeatmap() => host.OpenFileExternally(Beatmap.Value.Save()); private void onModeChanged(ValueChangedEvent e)