Get rid of PreviewTrackManager.onTrackStart and PreviewTrackManager.onTrackStop delegates

This commit is contained in:
Roman Kapustin 2018-06-01 21:36:30 +03:00
parent 88ac427ba6
commit 5566732664
2 changed files with 23 additions and 29 deletions

View File

@ -12,30 +12,23 @@ namespace osu.Game.Audio
public readonly Track Track;
public readonly OverlayContainer Owner;
private readonly Action<PreviewTrack> onStart;
private readonly Action onStop;
public event Action Stopped;
public event Action Started;
public PreviewTrack(Track track, Action<PreviewTrack> onStart, Action onStop, OverlayContainer owner)
public PreviewTrack(Track track, OverlayContainer owner)
{
Track = track;
this.onStart = onStart;
this.onStop = onStop;
Owner = owner;
}
public void Start()
{
onStart?.Invoke(this);
Track.Restart();
Started?.Invoke();
}
public void Stop()
{
onStop?.Invoke();
Track.Stop();
Stopped?.Invoke();
}

View File

@ -1,7 +1,6 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
@ -15,9 +14,7 @@ namespace osu.Game.Audio
{
public class PreviewTrackManager : Component
{
private Action<PreviewTrack> onTrackStart;
private Action onTrackStop;
private AudioManager audio;
private TrackManager trackManager;
private BindableDouble muteBindable;
@ -27,32 +24,36 @@ namespace osu.Game.Audio
private void load(AudioManager audio, FrameworkConfigManager config)
{
trackManager = new TrackManager(new OnlineStore());
muteBindable = new BindableDouble();
this.audio = audio;
audio.AddItem(trackManager);
config.BindWith(FrameworkSetting.VolumeMusic, trackManager.Volume);
onTrackStart = track =>
{
CurrentTrack?.Stop();
audio.Track.AddAdjustment(AdjustableProperty.Volume, muteBindable);
CurrentTrack = track;
};
onTrackStop = () =>
{
audio.Track.RemoveAdjustment(AdjustableProperty.Volume, muteBindable);
CurrentTrack = null;
};
config.BindWith(FrameworkSetting.VolumeMusic, trackManager.Volume);
}
public PreviewTrack Get(BeatmapSetInfo beatmapSetInfo, OverlayContainer previewOwner) =>
new PreviewTrack(
public PreviewTrack Get(BeatmapSetInfo beatmapSetInfo, OverlayContainer previewOwner)
{
var previewTrack = new PreviewTrack(
trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo?.OnlineBeatmapSetID}.mp3"),
onTrackStart,
onTrackStop,
previewOwner);
previewTrack.Started += () =>
{
CurrentTrack?.Stop();
CurrentTrack = previewTrack;
audio.Track.AddAdjustment(AdjustableProperty.Volume, muteBindable);
};
previewTrack.Stopped += () =>
{
CurrentTrack = null;
audio.Track.RemoveAdjustment(AdjustableProperty.Volume, muteBindable);
};
return previewTrack;
}
protected override void Update()
{
if (CurrentTrack?.Track.HasCompleted ?? false)