PreviewTrack.Owner

This commit is contained in:
Roman Kapustin 2018-06-01 21:06:37 +03:00
parent 572c3f5189
commit 88ac427ba6
5 changed files with 26 additions and 6 deletions

View File

@ -3,23 +3,27 @@
using System; using System;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Audio namespace osu.Game.Audio
{ {
public class PreviewTrack public class PreviewTrack
{ {
public readonly Track Track; public readonly Track Track;
public readonly OverlayContainer Owner;
private readonly Action<PreviewTrack> onStart; private readonly Action<PreviewTrack> onStart;
private readonly Action onStop; private readonly Action onStop;
public event Action Stopped; public event Action Stopped;
public event Action Started; public event Action Started;
public PreviewTrack(Track track, Action<PreviewTrack> onStart, Action onStop) public PreviewTrack(Track track, Action<PreviewTrack> onStart, Action onStop, OverlayContainer owner)
{ {
Track = track; Track = track;
this.onStart = onStart; this.onStart = onStart;
this.onStop = onStop; this.onStop = onStop;
Owner = owner;
} }
public void Start() public void Start()

View File

@ -7,6 +7,7 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Configuration; using osu.Framework.Configuration;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.IO.Stores; using osu.Framework.IO.Stores;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
@ -45,11 +46,12 @@ namespace osu.Game.Audio
}; };
} }
public PreviewTrack Get(BeatmapSetInfo beatmapSetInfo) => public PreviewTrack Get(BeatmapSetInfo beatmapSetInfo, OverlayContainer previewOwner) =>
new PreviewTrack( new PreviewTrack(
trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo?.OnlineBeatmapSetID}.mp3"), trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo?.OnlineBeatmapSetID}.mp3"),
onTrackStart, onTrackStart,
onTrackStop); onTrackStop,
previewOwner);
protected override void Update() protected override void Update()
{ {

View File

@ -127,7 +127,8 @@ namespace osu.Game.Overlays
protected override void PopOut() protected override void PopOut()
{ {
base.PopOut(); base.PopOut();
previewTrackManager.CurrentTrack?.Stop(); if (previewTrackManager.CurrentTrack?.Owner == this)
previewTrackManager.CurrentTrack?.Stop();
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out).OnComplete(_ => BeatmapSet = null); FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out).OnComplete(_ => BeatmapSet = null);
} }

View File

@ -35,6 +35,18 @@ namespace osu.Game.Overlays.Direct
} }
} }
private OverlayContainer parentOverlayContainer
{
get
{
var d = Parent;
while (!(d is OverlayContainer))
d = d.Parent;
return (OverlayContainer)d;
}
}
private PreviewTrackManager previewTrackManager; private PreviewTrackManager previewTrackManager;
private Color4 hoverColour; private Color4 hoverColour;
@ -95,7 +107,7 @@ namespace osu.Game.Overlays.Direct
Task.Run(() => Task.Run(() =>
{ {
loading = true; loading = true;
return Preview = previewTrackManager.Get(beatmapSet); return Preview = previewTrackManager.Get(beatmapSet, parentOverlayContainer);
}) })
.ContinueWith(t => .ContinueWith(t =>
{ {

View File

@ -302,7 +302,8 @@ namespace osu.Game.Overlays
protected override void PopOut() protected override void PopOut()
{ {
previewTrackManager.CurrentTrack?.Stop(); if (previewTrackManager.CurrentTrack?.Owner == this)
previewTrackManager.CurrentTrack?.Stop();
base.PopOut(); base.PopOut();
} }