From 70372dd03d1e1735de241d431b629bdb684ae9c1 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:14:04 +0200 Subject: [PATCH 01/15] Add global actions for game-wide music jukebox manipulation --- osu.Game/Input/Bindings/GlobalActionContainer.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index 14d356f889..6d85a69804 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -38,6 +38,10 @@ namespace osu.Game.Input.Bindings new KeyBinding(InputKey.MouseWheelDown, GlobalAction.DecreaseVolume), new KeyBinding(InputKey.F4, GlobalAction.ToggleMute), + new KeyBinding(InputKey.F5, GlobalAction.MusicPrev), + new KeyBinding(InputKey.F6, GlobalAction.MusicNext), + new KeyBinding(InputKey.X, GlobalAction.MusicPlay), + new KeyBinding(InputKey.Escape, GlobalAction.Back), new KeyBinding(InputKey.MouseButton1, GlobalAction.Back), @@ -88,6 +92,16 @@ namespace osu.Game.Input.Bindings [Description("Toggle mute")] ToggleMute, + // Game-wide beatmap jukebox keybindings + [Description("Jukebox next track")] + MusicNext, + + [Description("Jukebox previous track")] + MusicPrev, + + [Description("Jukebox play / pause current track")] + MusicPlay, + // In-Game Keybindings [Description("Skip cutscene")] SkipCutscene, From b5bd863dd080d25f0c01f9cdd30c0d6cde4a9c5d Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:21:50 +0200 Subject: [PATCH 02/15] Add methods to MusicController to play or pause, select next or previous track --- osu.Game/Overlays/MusicController.cs | 31 +++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 29ae5983be..91fa2f5a95 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -529,6 +529,35 @@ namespace osu.Game.Overlays /// /// Play the next random or playlist track. /// - public void NextTrack() => next(); + /// Returns whether the track could be changed or not + public bool NextTrack() + { + if (beatmap.Disabled) return false; + + next(); + return true; + } + + /// + /// Play the previous random or playlist track. + /// + public bool PreviousTrack() + { + if (beatmap.Disabled) return false; + + prev(); + return true; + } + + /// + /// Play or pause the current beatmap track. + /// Returns whether the current track could be played / paused or not + public bool PlayTrack() + { + if (beatmap.Disabled) return false; + + play(); + return true; + } } } From c9e44e5e34aa481ce0210898616829c1770a67c0 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:25:09 +0200 Subject: [PATCH 03/15] Add OsdIconToast + test --- .../UserInterface/TestSceneOnScreenDisplay.cs | 2 + osu.Game/Overlays/OSD/OsdIconToast.cs | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 osu.Game/Overlays/OSD/OsdIconToast.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs index b28f794a58..047c89ae54 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneOnScreenDisplay.cs @@ -6,6 +6,7 @@ using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Configuration.Tracking; using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; using osu.Game.Overlays; namespace osu.Game.Tests.Visual.UserInterface @@ -23,6 +24,7 @@ namespace osu.Game.Tests.Visual.UserInterface Add(osd); AddStep("Display empty osd toast", () => osd.Display(new Overlays.OSD.OsdToast())); + AddStep("Display osd toast with icon and message", () => osd.Display(new Overlays.OSD.OsdIconToast("Hey there !", FontAwesome.Solid.HandSpock))); AddRepeatStep("Change toggle (no bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingNoKeybind), 2); AddRepeatStep("Change toggle (with bind)", () => config.ToggleSetting(TestConfigSetting.ToggleSettingWithKeybind), 2); AddRepeatStep("Change enum (no bind)", () => config.IncrementEnumSetting(TestConfigSetting.EnumSettingNoKeybind), 3); diff --git a/osu.Game/Overlays/OSD/OsdIconToast.cs b/osu.Game/Overlays/OSD/OsdIconToast.cs new file mode 100644 index 0000000000..c00949d48b --- /dev/null +++ b/osu.Game/Overlays/OSD/OsdIconToast.cs @@ -0,0 +1,42 @@ +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; + +namespace osu.Game.Overlays.OSD +{ + public class OsdIconToast : OsdToast + { + public OsdIconToast(string message, IconUsage icon) + { + Children = new Drawable[] + { + new FillFlowContainer() + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + Direction = FillDirection.Vertical, + Spacing = new osuTK.Vector2(10), + Children = new Drawable[] + { + new OsuSpriteText + { + Anchor = Anchor.Centre, + Origin = Anchor.BottomCentre, + Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light), + Text = message + }, + new SpriteIcon + { + Icon = icon, + Size = new osuTK.Vector2(45), + Anchor = Anchor.Centre, + Origin = Anchor.BottomCentre, + } + } + } + }; + } + } +} From 5cad2b21927199dd4baf026c5d27baf85c29c43b Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:28:37 +0200 Subject: [PATCH 04/15] Add missing function to MusicController --- osu.Game/Overlays/MusicController.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 91fa2f5a95..f6d67e9981 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -559,5 +559,10 @@ namespace osu.Game.Overlays play(); return true; } + + /// + /// Returns whether the current beatmap track is playing. + /// + public bool IsPlaying => beatmap.Value.Track.IsRunning; } } From 89acd9da3e0c9e5aa55d1bdc2647c5349ec1a556 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:33:13 +0200 Subject: [PATCH 05/15] Add game-wide jukebox keybindings handling to OsuGame --- osu.Game/OsuGame.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 0a472d4dc1..32539055a7 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -67,6 +67,8 @@ namespace osu.Game private BeatmapSetOverlay beatmapSetOverlay; + private OnScreenDisplay osd; + [Cached] private readonly ScreenshotManager screenshotManager = new ScreenshotManager(); @@ -456,7 +458,7 @@ namespace osu.Game }); loadComponentSingleFile(volume = new VolumeOverlay(), leftFloatingOverlayContent.Add); - loadComponentSingleFile(new OnScreenDisplay(), Add, true); + loadComponentSingleFile(osd = new OnScreenDisplay(), Add, true); loadComponentSingleFile(notifications = new NotificationOverlay { @@ -719,6 +721,24 @@ namespace osu.Game case GlobalAction.ToggleGameplayMouseButtons: LocalConfig.Set(OsuSetting.MouseDisableButtons, !LocalConfig.Get(OsuSetting.MouseDisableButtons)); return true; + + case GlobalAction.MusicPlay: + if (!musicController.IsLoaded) return true; + if (musicController.PlayTrack()) + osd.Display(new Overlays.OSD.OsdIconToast(musicController.IsPlaying ? "Play track" : "Pause track", musicController.IsPlaying ? FontAwesome.Solid.PlayCircle : FontAwesome.Solid.PauseCircle)); + return true; + + case GlobalAction.MusicNext: + if (!musicController.IsLoaded) return true; + if (musicController.NextTrack()) + osd.Display(new Overlays.OSD.OsdIconToast("Next track", FontAwesome.Solid.FastForward)); + return true; + + case GlobalAction.MusicPrev: + if (!musicController.IsLoaded) return true; + if (musicController.PreviousTrack()) + osd.Display(new Overlays.OSD.OsdIconToast("Previous track", FontAwesome.Solid.FastForward)); + return true; } return false; From 5f8bd6eca7a7e0f43b890ef1726da86d41cb0c82 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Fri, 5 Jul 2019 16:37:37 +0200 Subject: [PATCH 06/15] Fix CI issues + minor issues --- osu.Game/Input/Bindings/GlobalActionContainer.cs | 8 ++++---- osu.Game/OsuGame.cs | 5 ++++- osu.Game/Overlays/MusicController.cs | 1 + osu.Game/Overlays/OSD/OsdIconToast.cs | 7 +++++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index 6d85a69804..e756694285 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -38,16 +38,16 @@ namespace osu.Game.Input.Bindings new KeyBinding(InputKey.MouseWheelDown, GlobalAction.DecreaseVolume), new KeyBinding(InputKey.F4, GlobalAction.ToggleMute), - new KeyBinding(InputKey.F5, GlobalAction.MusicPrev), - new KeyBinding(InputKey.F6, GlobalAction.MusicNext), - new KeyBinding(InputKey.X, GlobalAction.MusicPlay), - new KeyBinding(InputKey.Escape, GlobalAction.Back), new KeyBinding(InputKey.MouseButton1, GlobalAction.Back), new KeyBinding(InputKey.Space, GlobalAction.Select), new KeyBinding(InputKey.Enter, GlobalAction.Select), new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select), + + new KeyBinding(InputKey.F5, GlobalAction.MusicPrev), + new KeyBinding(InputKey.F6, GlobalAction.MusicNext), + new KeyBinding(InputKey.X, GlobalAction.MusicPlay), }; public IEnumerable InGameKeyBindings => new[] diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 32539055a7..bae301a8a6 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -724,20 +724,23 @@ namespace osu.Game case GlobalAction.MusicPlay: if (!musicController.IsLoaded) return true; + if (musicController.PlayTrack()) osd.Display(new Overlays.OSD.OsdIconToast(musicController.IsPlaying ? "Play track" : "Pause track", musicController.IsPlaying ? FontAwesome.Solid.PlayCircle : FontAwesome.Solid.PauseCircle)); return true; case GlobalAction.MusicNext: if (!musicController.IsLoaded) return true; + if (musicController.NextTrack()) osd.Display(new Overlays.OSD.OsdIconToast("Next track", FontAwesome.Solid.FastForward)); return true; case GlobalAction.MusicPrev: if (!musicController.IsLoaded) return true; + if (musicController.PreviousTrack()) - osd.Display(new Overlays.OSD.OsdIconToast("Previous track", FontAwesome.Solid.FastForward)); + osd.Display(new Overlays.OSD.OsdIconToast("Previous track", FontAwesome.Solid.FastBackward)); return true; } diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index f6d67e9981..618187069d 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -551,6 +551,7 @@ namespace osu.Game.Overlays /// /// Play or pause the current beatmap track. + /// /// Returns whether the current track could be played / paused or not public bool PlayTrack() { diff --git a/osu.Game/Overlays/OSD/OsdIconToast.cs b/osu.Game/Overlays/OSD/OsdIconToast.cs index c00949d48b..0e2bcd377f 100644 --- a/osu.Game/Overlays/OSD/OsdIconToast.cs +++ b/osu.Game/Overlays/OSD/OsdIconToast.cs @@ -1,4 +1,7 @@ -using osu.Framework.Graphics; +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Game.Graphics; @@ -12,7 +15,7 @@ namespace osu.Game.Overlays.OSD { Children = new Drawable[] { - new FillFlowContainer() + new FillFlowContainer { Anchor = Anchor.Centre, Origin = Anchor.Centre, From b32b078e48d38a88cfd222c085cb5e9d648e98e8 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Wed, 10 Jul 2019 21:55:43 +0200 Subject: [PATCH 07/15] Set default keybindings for jukebox to stable's ones. --- osu.Game/Input/Bindings/GlobalActionContainer.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index e756694285..cdd821c173 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -45,9 +45,9 @@ namespace osu.Game.Input.Bindings new KeyBinding(InputKey.Enter, GlobalAction.Select), new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select), - new KeyBinding(InputKey.F5, GlobalAction.MusicPrev), - new KeyBinding(InputKey.F6, GlobalAction.MusicNext), - new KeyBinding(InputKey.X, GlobalAction.MusicPlay), + new KeyBinding(InputKey.F1, GlobalAction.MusicPrev), + new KeyBinding(InputKey.F5, GlobalAction.MusicNext), + new KeyBinding(InputKey.F3, GlobalAction.MusicPlay), }; public IEnumerable InGameKeyBindings => new[] From 2926932a1acf5adc8da8125ba83b05a7960ebb60 Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 20 Jul 2019 21:10:17 +0200 Subject: [PATCH 08/15] Add MusicControllerToast used to display current music playback status on OSD --- osu.Game/OsuGame.cs | 6 +-- osu.Game/Overlays/OSD/MusicControllerToast.cs | 13 ++++++ osu.Game/Overlays/OSD/OsdIconToast.cs | 45 ------------------- 3 files changed, 16 insertions(+), 48 deletions(-) create mode 100644 osu.Game/Overlays/OSD/MusicControllerToast.cs delete mode 100644 osu.Game/Overlays/OSD/OsdIconToast.cs diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index bae301a8a6..dde87cd2ed 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -726,21 +726,21 @@ namespace osu.Game if (!musicController.IsLoaded) return true; if (musicController.PlayTrack()) - osd.Display(new Overlays.OSD.OsdIconToast(musicController.IsPlaying ? "Play track" : "Pause track", musicController.IsPlaying ? FontAwesome.Solid.PlayCircle : FontAwesome.Solid.PauseCircle)); + osd.Display(new Overlays.OSD.MusicControllerToast(musicController.IsPlaying ? "Play track" : "Pause track")); return true; case GlobalAction.MusicNext: if (!musicController.IsLoaded) return true; if (musicController.NextTrack()) - osd.Display(new Overlays.OSD.OsdIconToast("Next track", FontAwesome.Solid.FastForward)); + osd.Display(new Overlays.OSD.MusicControllerToast("Next track")); return true; case GlobalAction.MusicPrev: if (!musicController.IsLoaded) return true; if (musicController.PreviousTrack()) - osd.Display(new Overlays.OSD.OsdIconToast("Previous track", FontAwesome.Solid.FastBackward)); + osd.Display(new Overlays.OSD.MusicControllerToast("Previous track")); return true; } diff --git a/osu.Game/Overlays/OSD/MusicControllerToast.cs b/osu.Game/Overlays/OSD/MusicControllerToast.cs new file mode 100644 index 0000000000..d9e0ad2c07 --- /dev/null +++ b/osu.Game/Overlays/OSD/MusicControllerToast.cs @@ -0,0 +1,13 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Overlays.OSD +{ + public class MusicControllerToast : Toast + { + public MusicControllerToast(string value) + : base("Music Playback", value, "") + { + } + } +} diff --git a/osu.Game/Overlays/OSD/OsdIconToast.cs b/osu.Game/Overlays/OSD/OsdIconToast.cs deleted file mode 100644 index 0e2bcd377f..0000000000 --- a/osu.Game/Overlays/OSD/OsdIconToast.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Sprites; -using osu.Game.Graphics; -using osu.Game.Graphics.Sprites; - -namespace osu.Game.Overlays.OSD -{ - public class OsdIconToast : OsdToast - { - public OsdIconToast(string message, IconUsage icon) - { - Children = new Drawable[] - { - new FillFlowContainer - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - Direction = FillDirection.Vertical, - Spacing = new osuTK.Vector2(10), - Children = new Drawable[] - { - new OsuSpriteText - { - Anchor = Anchor.Centre, - Origin = Anchor.BottomCentre, - Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light), - Text = message - }, - new SpriteIcon - { - Icon = icon, - Size = new osuTK.Vector2(45), - Anchor = Anchor.Centre, - Origin = Anchor.BottomCentre, - } - } - } - }; - } - } -} From 7825923cb63f157e7e9fcd7307ae05b9d3d0b51d Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sat, 10 Aug 2019 16:33:16 +0200 Subject: [PATCH 09/15] Use media keys as default bindings for jukebox. --- osu.Game/Input/Bindings/GlobalActionContainer.cs | 6 +++--- osu.Game/Overlays/MusicController.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index 8c927c2bc6..809ec9a09e 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -45,9 +45,9 @@ namespace osu.Game.Input.Bindings new KeyBinding(InputKey.Enter, GlobalAction.Select), new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select), - new KeyBinding(InputKey.F1, GlobalAction.MusicPrev), - new KeyBinding(InputKey.F5, GlobalAction.MusicNext), - new KeyBinding(InputKey.F3, GlobalAction.MusicPlay), + new KeyBinding(InputKey.TrackPrevious, GlobalAction.MusicPrev), + new KeyBinding(InputKey.TrackNext, GlobalAction.MusicNext), + new KeyBinding(InputKey.PlayPause, GlobalAction.MusicPlay), }; public IEnumerable InGameKeyBindings => new[] diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 724be21957..ed51a80924 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -565,7 +565,7 @@ namespace osu.Game.Overlays { if (beatmap.Disabled) return false; - play(); + togglePause(); return true; } From e4eed83d85bec2274d40c14d4965cde6f3743def Mon Sep 17 00:00:00 2001 From: Lucas A Date: Sun, 11 Aug 2019 19:14:49 +0200 Subject: [PATCH 10/15] Add dual bindings for Jukebox hotkeys --- .../Input/Bindings/GlobalActionContainer.cs | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index 809ec9a09e..b2cbb77087 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -46,8 +46,11 @@ namespace osu.Game.Input.Bindings new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select), new KeyBinding(InputKey.TrackPrevious, GlobalAction.MusicPrev), + new KeyBinding(InputKey.F1, GlobalAction.MusicPrev), new KeyBinding(InputKey.TrackNext, GlobalAction.MusicNext), + new KeyBinding(InputKey.F5, GlobalAction.MusicNext), new KeyBinding(InputKey.PlayPause, GlobalAction.MusicPlay), + new KeyBinding(InputKey.F3, GlobalAction.MusicPlay) }; public IEnumerable InGameKeyBindings => new[] @@ -92,16 +95,6 @@ namespace osu.Game.Input.Bindings [Description("Toggle mute")] ToggleMute, - // Game-wide beatmap jukebox keybindings - [Description("Jukebox next track")] - MusicNext, - - [Description("Jukebox previous track")] - MusicPrev, - - [Description("Jukebox play / pause current track")] - MusicPlay, - // In-Game Keybindings [Description("Skip cutscene")] SkipCutscene, @@ -129,5 +122,15 @@ namespace osu.Game.Input.Bindings [Description("Quick exit (Hold)")] QuickExit, + + // Game-wide beatmap jukebox keybindings + [Description("Jukebox next track")] + MusicNext, + + [Description("Jukebox previous track")] + MusicPrev, + + [Description("Jukebox play / pause current track")] + MusicPlay, } } From f3380c9372c14a2c87db03b832c27001845a1e55 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 13 Aug 2019 12:06:57 +0900 Subject: [PATCH 11/15] Remove "jukebox" terminology --- osu.Game/Input/Bindings/GlobalActionContainer.cs | 6 +++--- osu.Game/OsuGame.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index b2cbb77087..c54e3f596e 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -124,13 +124,13 @@ namespace osu.Game.Input.Bindings QuickExit, // Game-wide beatmap jukebox keybindings - [Description("Jukebox next track")] + [Description("Next track")] MusicNext, - [Description("Jukebox previous track")] + [Description("Previous track")] MusicPrev, - [Description("Jukebox play / pause current track")] + [Description("Play / pause")] MusicPlay, } } diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index af77c8816a..1541d1fa29 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -301,7 +301,7 @@ namespace osu.Game }, $"watch {databasedScoreInfo}", bypassScreenAllowChecks: true); } - #region Beatmap jukebox progression + #region Beatmap progression private void beatmapChanged(ValueChangedEvent beatmap) { From 5dbde38a6b00586a7d7b9223e775ea7b4fddbf61 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 13 Aug 2019 12:40:20 +0900 Subject: [PATCH 12/15] Group key bindings together --- .../Input/Bindings/GlobalActionContainer.cs | 30 +++++++++++-------- .../KeyBinding/GlobalKeyBindingsSection.cs | 12 ++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index c54e3f596e..8073200c47 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -20,7 +20,7 @@ namespace osu.Game.Input.Bindings handler = game; } - public override IEnumerable DefaultKeyBindings => GlobalKeyBindings.Concat(InGameKeyBindings); + public override IEnumerable DefaultKeyBindings => GlobalKeyBindings.Concat(InGameKeyBindings).Concat(AudioControlKeyBindings); public IEnumerable GlobalKeyBindings => new[] { @@ -32,11 +32,6 @@ namespace osu.Game.Input.Bindings new KeyBinding(new[] { InputKey.Control, InputKey.Alt, InputKey.R }, GlobalAction.ResetInputSettings), new KeyBinding(new[] { InputKey.Control, InputKey.T }, GlobalAction.ToggleToolbar), new KeyBinding(new[] { InputKey.Control, InputKey.O }, GlobalAction.ToggleSettings), - new KeyBinding(InputKey.Up, GlobalAction.IncreaseVolume), - new KeyBinding(InputKey.MouseWheelUp, GlobalAction.IncreaseVolume), - new KeyBinding(InputKey.Down, GlobalAction.DecreaseVolume), - new KeyBinding(InputKey.MouseWheelDown, GlobalAction.DecreaseVolume), - new KeyBinding(InputKey.F4, GlobalAction.ToggleMute), new KeyBinding(InputKey.Escape, GlobalAction.Back), new KeyBinding(InputKey.ExtraMouseButton1, GlobalAction.Back), @@ -44,13 +39,6 @@ namespace osu.Game.Input.Bindings new KeyBinding(InputKey.Space, GlobalAction.Select), new KeyBinding(InputKey.Enter, GlobalAction.Select), new KeyBinding(InputKey.KeypadEnter, GlobalAction.Select), - - new KeyBinding(InputKey.TrackPrevious, GlobalAction.MusicPrev), - new KeyBinding(InputKey.F1, GlobalAction.MusicPrev), - new KeyBinding(InputKey.TrackNext, GlobalAction.MusicNext), - new KeyBinding(InputKey.F5, GlobalAction.MusicNext), - new KeyBinding(InputKey.PlayPause, GlobalAction.MusicPlay), - new KeyBinding(InputKey.F3, GlobalAction.MusicPlay) }; public IEnumerable InGameKeyBindings => new[] @@ -62,6 +50,22 @@ namespace osu.Game.Input.Bindings new KeyBinding(new[] { InputKey.Control, InputKey.Minus }, GlobalAction.DecreaseScrollSpeed), }; + public IEnumerable AudioControlKeyBindings => new[] + { + new KeyBinding(InputKey.Up, GlobalAction.IncreaseVolume), + new KeyBinding(InputKey.MouseWheelUp, GlobalAction.IncreaseVolume), + new KeyBinding(InputKey.Down, GlobalAction.DecreaseVolume), + new KeyBinding(InputKey.MouseWheelDown, GlobalAction.DecreaseVolume), + new KeyBinding(InputKey.F4, GlobalAction.ToggleMute), + + new KeyBinding(InputKey.TrackPrevious, GlobalAction.MusicPrev), + new KeyBinding(InputKey.F1, GlobalAction.MusicPrev), + new KeyBinding(InputKey.TrackNext, GlobalAction.MusicNext), + new KeyBinding(InputKey.F5, GlobalAction.MusicNext), + new KeyBinding(InputKey.PlayPause, GlobalAction.MusicPlay), + new KeyBinding(InputKey.F3, GlobalAction.MusicPlay) + }; + protected override IEnumerable KeyBindingInputQueue => handler == null ? base.KeyBindingInputQueue : base.KeyBindingInputQueue.Prepend(handler); } diff --git a/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs b/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs index 7e33d7ba27..56e93b6a1e 100644 --- a/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs +++ b/osu.Game/Overlays/KeyBinding/GlobalKeyBindingsSection.cs @@ -15,6 +15,7 @@ namespace osu.Game.Overlays.KeyBinding public GlobalKeyBindingsSection(GlobalActionContainer manager) { Add(new DefaultBindingsSubsection(manager)); + Add(new AudioControlKeyBindingsSubsection(manager)); Add(new InGameKeyBindingsSubsection(manager)); } @@ -39,5 +40,16 @@ namespace osu.Game.Overlays.KeyBinding Defaults = manager.InGameKeyBindings; } } + + private class AudioControlKeyBindingsSubsection : KeyBindingsSubsection + { + protected override string Header => "Audio"; + + public AudioControlKeyBindingsSubsection(GlobalActionContainer manager) + : base(null) + { + Defaults = manager.AudioControlKeyBindings; + } + } } } From 9aac5efa4e5bf8ff6374731b815ec5e26a8a75d1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 13 Aug 2019 14:38:49 +0900 Subject: [PATCH 13/15] Move logic out of OsuGame --- osu.Game/OsuGame.cs | 25 +------ osu.Game/Overlays/MusicController.cs | 74 +++++++++++++++++-- osu.Game/Overlays/NowPlayingOverlay.cs | 6 +- osu.Game/Overlays/OSD/MusicControllerToast.cs | 13 ---- 4 files changed, 70 insertions(+), 48 deletions(-) delete mode 100644 osu.Game/Overlays/OSD/MusicControllerToast.cs diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index ab7e5b19d1..0e804ecbaf 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -68,8 +68,6 @@ namespace osu.Game private BeatmapSetOverlay beatmapSetOverlay; - private OnScreenDisplay osd; - [Cached] private readonly ScreenshotManager screenshotManager = new ScreenshotManager(); @@ -469,7 +467,7 @@ namespace osu.Game }); loadComponentSingleFile(volume = new VolumeOverlay(), leftFloatingOverlayContent.Add); - loadComponentSingleFile(osd = new OnScreenDisplay(), Add, true); + loadComponentSingleFile(new OnScreenDisplay(), Add, true); loadComponentSingleFile(musicController = new MusicController(), Add, true); @@ -734,27 +732,6 @@ namespace osu.Game case GlobalAction.ToggleGameplayMouseButtons: LocalConfig.Set(OsuSetting.MouseDisableButtons, !LocalConfig.Get(OsuSetting.MouseDisableButtons)); return true; - - case GlobalAction.MusicPlay: - if (!musicController.IsLoaded) return true; - - if (musicController.PlayTrack()) - osd.Display(new Overlays.OSD.MusicControllerToast(musicController.IsPlaying ? "Play track" : "Pause track")); - return true; - - case GlobalAction.MusicNext: - if (!musicController.IsLoaded) return true; - - if (musicController.NextTrack()) - osd.Display(new Overlays.OSD.MusicControllerToast("Next track")); - return true; - - case GlobalAction.MusicPrev: - if (!musicController.IsLoaded) return true; - - if (musicController.PreviousTrack()) - osd.Display(new Overlays.OSD.MusicControllerToast("Previous track")); - return true; } return false; diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index d1086d589d..14f7b574da 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -7,8 +7,11 @@ using System.Linq; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; +using osu.Framework.Input.Bindings; using osu.Framework.Threading; using osu.Game.Beatmaps; +using osu.Game.Input.Bindings; +using osu.Game.Overlays.OSD; using osu.Game.Rulesets.Mods; namespace osu.Game.Overlays @@ -16,7 +19,7 @@ namespace osu.Game.Overlays /// /// Handles playback of the global music track. /// - public class MusicController : Component + public class MusicController : Component, IKeyBindingHandler { [Resolved] private BeatmapManager beatmaps { get; set; } @@ -37,6 +40,9 @@ namespace osu.Game.Overlays [Resolved] private IBindable> mods { get; set; } + [Resolved(canBeNull: true)] + private OnScreenDisplay onScreenDisplay { get; set; } + [BackgroundDependencyLoader] private void load() { @@ -58,11 +64,17 @@ namespace osu.Game.Overlays /// The beatmap to move. /// The new position. public void ChangeBeatmapSetPosition(BeatmapSetInfo beatmapSetInfo, int index) + { beatmapSets.Remove(beatmapSetInfo); beatmapSets.Insert(index, beatmapSetInfo); } + /// + /// Returns whether the current beatmap track is playing. + /// + public bool IsPlaying => beatmap.Value.Track.IsRunning; + private void handleBeatmapAdded(BeatmapSetInfo set) => Schedule(() => beatmapSets.Add(set)); @@ -84,15 +96,17 @@ namespace osu.Game.Overlays /// /// Toggle pause / play. /// - public void TogglePause() + public bool TogglePause() { var track = current?.Track; if (track == null) { - if (!beatmap.Disabled) - next(true); - return; + if (beatmap.Disabled) + return false; + + next(true); + return true; } if (track.IsRunning) @@ -105,12 +119,14 @@ namespace osu.Game.Overlays track.Start(); IsUserPaused = false; } + + return true; } /// /// Play the previous track. /// - public void PrevTrack() + public bool PrevTrack() { queuedDirection = TrackChangeDirection.Prev; @@ -121,15 +137,19 @@ namespace osu.Game.Overlays if (beatmap is Bindable working) working.Value = beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value); beatmap.Value.Track.Restart(); + + return true; } + + return false; } /// /// Play the next random or playlist track. /// - public void NextTrack() => next(); + public bool NextTrack() => next(); - private void next(bool instant = false) + private bool next(bool instant = false) { if (!instant) queuedDirection = TrackChangeDirection.Next; @@ -141,7 +161,10 @@ namespace osu.Game.Overlays if (beatmap is Bindable working) working.Value = beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value); beatmap.Value.Track.Restart(); + return true; } + + return false; } private WorkingBeatmap current; @@ -200,6 +223,41 @@ namespace osu.Game.Overlays beatmaps.ItemAdded -= handleBeatmapAdded; beatmaps.ItemRemoved -= handleBeatmapRemoved; } + + public bool OnPressed(GlobalAction action) + { + switch (action) + { + case GlobalAction.MusicPlay: + if (TogglePause()) + onScreenDisplay?.Display(new MusicControllerToast(IsPlaying ? "Play track" : "Pause track")); + return true; + + case GlobalAction.MusicNext: + if (NextTrack()) + onScreenDisplay?.Display(new MusicControllerToast("Next track")); + + return true; + + case GlobalAction.MusicPrev: + if (PrevTrack()) + onScreenDisplay?.Display(new MusicControllerToast("Previous track")); + + return true; + } + + return false; + } + + public bool OnReleased(GlobalAction action) => false; + + public class MusicControllerToast : Toast + { + public MusicControllerToast(string action) + : base("Music Playback", action, string.Empty) + { + } + } } public enum TrackChangeDirection diff --git a/osu.Game/Overlays/NowPlayingOverlay.cs b/osu.Game/Overlays/NowPlayingOverlay.cs index 98bad5323d..f14adcb53d 100644 --- a/osu.Game/Overlays/NowPlayingOverlay.cs +++ b/osu.Game/Overlays/NowPlayingOverlay.cs @@ -138,7 +138,7 @@ namespace osu.Game.Overlays { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Action = musicController.PrevTrack, + Action = () => musicController.PrevTrack(), Icon = FontAwesome.Solid.StepBackward, }, playButton = new MusicIconButton @@ -147,14 +147,14 @@ namespace osu.Game.Overlays Origin = Anchor.Centre, Scale = new Vector2(1.4f), IconScale = new Vector2(1.4f), - Action = musicController.TogglePause, + Action = () => musicController.TogglePause(), Icon = FontAwesome.Regular.PlayCircle, }, nextButton = new MusicIconButton { Anchor = Anchor.Centre, Origin = Anchor.Centre, - Action = musicController.NextTrack, + Action = () => musicController.NextTrack(), Icon = FontAwesome.Solid.StepForward, }, } diff --git a/osu.Game/Overlays/OSD/MusicControllerToast.cs b/osu.Game/Overlays/OSD/MusicControllerToast.cs deleted file mode 100644 index d9e0ad2c07..0000000000 --- a/osu.Game/Overlays/OSD/MusicControllerToast.cs +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -namespace osu.Game.Overlays.OSD -{ - public class MusicControllerToast : Toast - { - public MusicControllerToast(string value) - : base("Music Playback", value, "") - { - } - } -} From 81f8b5f325702b5d1ae227006b9c26b7d2dd2834 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 13 Aug 2019 14:52:51 +0900 Subject: [PATCH 14/15] Fix merge issue --- osu.Game/Overlays/MusicController.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index b055c7ef1b..91220907a0 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -64,7 +64,6 @@ namespace osu.Game.Overlays /// The beatmap to move. /// The new position. public void ChangeBeatmapSetPosition(BeatmapSetInfo beatmapSetInfo, int index) - { beatmapSets.Remove(beatmapSetInfo); beatmapSets.Insert(index, beatmapSetInfo); From 5963f7d9147e7ead009611f4b90b27e67506433b Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 13 Aug 2019 19:52:40 +0900 Subject: [PATCH 15/15] Update comment --- osu.Game/Input/Bindings/GlobalActionContainer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Input/Bindings/GlobalActionContainer.cs b/osu.Game/Input/Bindings/GlobalActionContainer.cs index 8073200c47..b70072a222 100644 --- a/osu.Game/Input/Bindings/GlobalActionContainer.cs +++ b/osu.Game/Input/Bindings/GlobalActionContainer.cs @@ -127,7 +127,7 @@ namespace osu.Game.Input.Bindings [Description("Quick exit (Hold)")] QuickExit, - // Game-wide beatmap jukebox keybindings + // Game-wide beatmap msi ccotolle keybindings [Description("Next track")] MusicNext,