1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-16 10:52:55 +08:00

Merge pull request #1924 from peppy/mute-global-track-when-preview

Mute global track volume when a beatmap preview is playing
This commit is contained in:
Dan Balasescu 2018-01-18 00:48:46 +09:00 committed by GitHub
commit afb55b5c43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@ using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Input; using osu.Framework.Input;
using osu.Framework.IO.Stores;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
@ -39,6 +40,8 @@ namespace osu.Game.Overlays.Direct
private readonly SpriteIcon icon; private readonly SpriteIcon icon;
private readonly LoadingAnimation loadingAnimation; private readonly LoadingAnimation loadingAnimation;
private readonly BindableDouble muteBindable = new BindableDouble();
private const float transition_duration = 500; private const float transition_duration = 500;
private bool loading private bool loading
@ -83,9 +86,10 @@ namespace osu.Game.Overlays.Direct
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colour) private void load(OsuColour colour, AudioManager audio)
{ {
hoverColour = colour.Yellow; hoverColour = colour.Yellow;
this.audio = audio;
} }
protected override bool OnClick(InputState state) protected override bool OnClick(InputState state)
@ -128,17 +132,21 @@ namespace osu.Game.Overlays.Direct
return; return;
} }
Preview.Seek(0); Preview.Restart();
Preview.Start();
audio.Track.AddAdjustment(AdjustableProperty.Volume, muteBindable);
} }
else else
{ {
audio.Track.RemoveAdjustment(AdjustableProperty.Volume, muteBindable);
Preview?.Stop(); Preview?.Stop();
loading = false; loading = false;
} }
} }
private TrackLoader trackLoader; private TrackLoader trackLoader;
private AudioManager audio;
private void beginAudioLoad() private void beginAudioLoad()
{ {
@ -164,6 +172,7 @@ namespace osu.Game.Overlays.Direct
private readonly string preview; private readonly string preview;
public Track Preview; public Track Preview;
private TrackManager trackManager;
public TrackLoader(string preview) public TrackLoader(string preview)
{ {
@ -171,10 +180,22 @@ namespace osu.Game.Overlays.Direct
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(AudioManager audio) private void load(AudioManager audio, FrameworkConfigManager config)
{ {
// create a local trackManager to bypass the mute we are applying above.
audio.AddItem(trackManager = new TrackManager(new OnlineStore()));
// add back the user's music volume setting (since we are no longer in the global TrackManager's hierarchy).
config.BindWith(FrameworkSetting.VolumeMusic, trackManager.Volume);
if (!string.IsNullOrEmpty(preview)) if (!string.IsNullOrEmpty(preview))
Preview = audio.Track.Get(preview); Preview = trackManager.Get(preview);
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
trackManager?.Dispose();
} }
} }
} }