mirror of
https://github.com/ppy/osu
synced 2025-03-02 09:30:57 +00:00
Move music global action handling to an own component
Due to requiring components that are added at an OsuGame-level
This commit is contained in:
parent
42895e27b6
commit
001509df55
@ -38,6 +38,7 @@ using osu.Game.Input;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Overlays.Music;
|
||||
using osu.Game.Skinning;
|
||||
using osuTK.Graphics;
|
||||
using osu.Game.Overlays.Volume;
|
||||
@ -647,6 +648,7 @@ namespace osu.Game
|
||||
chatOverlay.State.ValueChanged += state => channelManager.HighPollRate.Value = state.NewValue == Visibility.Visible;
|
||||
|
||||
Add(externalLinkOpener = new ExternalLinkOpener());
|
||||
Add(new MusicActionHandler());
|
||||
|
||||
// side overlays which cancel each other.
|
||||
var singleDisplaySideOverlays = new OverlayContainer[] { Settings, notifications };
|
||||
|
82
osu.Game/Overlays/Music/MusicActionHandler.cs
Normal file
82
osu.Game/Overlays/Music/MusicActionHandler.cs
Normal file
@ -0,0 +1,82 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Input.Bindings;
|
||||
using osu.Game.Overlays.OSD;
|
||||
|
||||
namespace osu.Game.Overlays.Music
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles <see cref="GlobalAction"/> relating to music playback, and displays a <see cref="Toast"/> via the cached <see cref="OnScreenDisplay"/> accordingly.
|
||||
/// </summary>
|
||||
public class MusicActionHandler : Component, IKeyBindingHandler<GlobalAction>
|
||||
{
|
||||
[Resolved]
|
||||
private IBindable<WorkingBeatmap> beatmap { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private MusicController musicController { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private OnScreenDisplay onScreenDisplay { get; set; }
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
if (beatmap.Disabled)
|
||||
return false;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.MusicPlay:
|
||||
if (musicController.TogglePause())
|
||||
onScreenDisplay.Display(new MusicActionToast(musicController.IsPlaying ? "Play track" : "Pause track"));
|
||||
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicNext:
|
||||
musicController.NextTrack(() =>
|
||||
{
|
||||
onScreenDisplay.Display(new MusicActionToast("Next track"));
|
||||
}).RunTask();
|
||||
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicPrev:
|
||||
musicController.PreviousTrack(res =>
|
||||
{
|
||||
switch (res)
|
||||
{
|
||||
case PreviousTrackResult.Restart:
|
||||
onScreenDisplay.Display(new MusicActionToast("Restart track"));
|
||||
break;
|
||||
|
||||
case PreviousTrackResult.Previous:
|
||||
onScreenDisplay.Display(new MusicActionToast("Previous track"));
|
||||
break;
|
||||
}
|
||||
}).RunTask();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(GlobalAction action)
|
||||
{
|
||||
}
|
||||
|
||||
private class MusicActionToast : Toast
|
||||
{
|
||||
public MusicActionToast(string action)
|
||||
: base("Music Playback", action, string.Empty)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -12,12 +12,9 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Audio;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Utils;
|
||||
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
|
||||
@ -25,7 +22,7 @@ namespace osu.Game.Overlays
|
||||
/// <summary>
|
||||
/// Handles playback of the global music track.
|
||||
/// </summary>
|
||||
public class MusicController : CompositeDrawable, IKeyBindingHandler<GlobalAction>
|
||||
public class MusicController : CompositeDrawable
|
||||
{
|
||||
[Resolved]
|
||||
private BeatmapManager beatmaps { get; set; }
|
||||
@ -62,9 +59,6 @@ namespace osu.Game.Overlays
|
||||
[Resolved]
|
||||
private IBindable<IReadOnlyList<Mod>> mods { get; set; }
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private OnScreenDisplay onScreenDisplay { get; set; }
|
||||
|
||||
[NotNull]
|
||||
public DrawableTrack CurrentTrack { get; private set; } = new DrawableTrack(new TrackVirtual(1000));
|
||||
|
||||
@ -428,54 +422,6 @@ namespace osu.Game.Overlays
|
||||
mod.ApplyToTrack(CurrentTrack);
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnPressed(GlobalAction action)
|
||||
{
|
||||
if (beatmap.Disabled)
|
||||
return false;
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case GlobalAction.MusicPlay:
|
||||
if (TogglePause())
|
||||
onScreenDisplay?.Display(new MusicControllerToast(IsPlaying ? "Play track" : "Pause track"));
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicNext:
|
||||
if (next())
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Next track"));
|
||||
|
||||
return true;
|
||||
|
||||
case GlobalAction.MusicPrev:
|
||||
switch (prev())
|
||||
{
|
||||
case PreviousTrackResult.Restart:
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Restart track"));
|
||||
break;
|
||||
|
||||
case PreviousTrackResult.Previous:
|
||||
onScreenDisplay?.Display(new MusicControllerToast("Previous track"));
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void OnReleased(GlobalAction action)
|
||||
{
|
||||
}
|
||||
|
||||
public class MusicControllerToast : Toast
|
||||
{
|
||||
public MusicControllerToast(string action)
|
||||
: base("Music Playback", action, string.Empty)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum TrackChangeDirection
|
||||
|
Loading…
Reference in New Issue
Block a user