mirror of
https://github.com/ppy/osu
synced 2025-01-01 20:02:14 +00:00
PreviewTrack.Owner
This commit is contained in:
parent
572c3f5189
commit
88ac427ba6
@ -3,23 +3,27 @@
|
||||
|
||||
using System;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
|
||||
namespace osu.Game.Audio
|
||||
{
|
||||
public class PreviewTrack
|
||||
{
|
||||
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)
|
||||
public PreviewTrack(Track track, Action<PreviewTrack> onStart, Action onStop, OverlayContainer owner)
|
||||
{
|
||||
Track = track;
|
||||
this.onStart = onStart;
|
||||
this.onStop = onStop;
|
||||
Owner = owner;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
|
@ -7,6 +7,7 @@ using osu.Framework.Audio;
|
||||
using osu.Framework.Audio.Track;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.IO.Stores;
|
||||
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(
|
||||
trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo?.OnlineBeatmapSetID}.mp3"),
|
||||
onTrackStart,
|
||||
onTrackStop);
|
||||
onTrackStop,
|
||||
previewOwner);
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
|
@ -127,7 +127,8 @@ namespace osu.Game.Overlays
|
||||
protected override void PopOut()
|
||||
{
|
||||
base.PopOut();
|
||||
previewTrackManager.CurrentTrack?.Stop();
|
||||
if (previewTrackManager.CurrentTrack?.Owner == this)
|
||||
previewTrackManager.CurrentTrack?.Stop();
|
||||
|
||||
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out).OnComplete(_ => BeatmapSet = null);
|
||||
}
|
||||
|
@ -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 Color4 hoverColour;
|
||||
@ -95,7 +107,7 @@ namespace osu.Game.Overlays.Direct
|
||||
Task.Run(() =>
|
||||
{
|
||||
loading = true;
|
||||
return Preview = previewTrackManager.Get(beatmapSet);
|
||||
return Preview = previewTrackManager.Get(beatmapSet, parentOverlayContainer);
|
||||
})
|
||||
.ContinueWith(t =>
|
||||
{
|
||||
|
@ -302,7 +302,8 @@ namespace osu.Game.Overlays
|
||||
|
||||
protected override void PopOut()
|
||||
{
|
||||
previewTrackManager.CurrentTrack?.Stop();
|
||||
if (previewTrackManager.CurrentTrack?.Owner == this)
|
||||
previewTrackManager.CurrentTrack?.Stop();
|
||||
base.PopOut();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user