mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 21:07:33 +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:
commit
afb55b5c43
@ -9,6 +9,7 @@ using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -39,6 +40,8 @@ namespace osu.Game.Overlays.Direct
|
||||
private readonly SpriteIcon icon;
|
||||
private readonly LoadingAnimation loadingAnimation;
|
||||
|
||||
private readonly BindableDouble muteBindable = new BindableDouble();
|
||||
|
||||
private const float transition_duration = 500;
|
||||
|
||||
private bool loading
|
||||
@ -83,9 +86,10 @@ namespace osu.Game.Overlays.Direct
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colour)
|
||||
private void load(OsuColour colour, AudioManager audio)
|
||||
{
|
||||
hoverColour = colour.Yellow;
|
||||
this.audio = audio;
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
@ -128,17 +132,21 @@ namespace osu.Game.Overlays.Direct
|
||||
return;
|
||||
}
|
||||
|
||||
Preview.Seek(0);
|
||||
Preview.Start();
|
||||
Preview.Restart();
|
||||
|
||||
audio.Track.AddAdjustment(AdjustableProperty.Volume, muteBindable);
|
||||
}
|
||||
else
|
||||
{
|
||||
audio.Track.RemoveAdjustment(AdjustableProperty.Volume, muteBindable);
|
||||
|
||||
Preview?.Stop();
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private TrackLoader trackLoader;
|
||||
private AudioManager audio;
|
||||
|
||||
private void beginAudioLoad()
|
||||
{
|
||||
@ -164,6 +172,7 @@ namespace osu.Game.Overlays.Direct
|
||||
private readonly string preview;
|
||||
|
||||
public Track Preview;
|
||||
private TrackManager trackManager;
|
||||
|
||||
public TrackLoader(string preview)
|
||||
{
|
||||
@ -171,10 +180,22 @@ namespace osu.Game.Overlays.Direct
|
||||
}
|
||||
|
||||
[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))
|
||||
Preview = audio.Track.Get(preview);
|
||||
Preview = trackManager.Get(preview);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
trackManager?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user