mirror of
https://github.com/ppy/osu
synced 2025-01-19 20:40:52 +00:00
PreviewTrack.Owner
This commit is contained in:
parent
572c3f5189
commit
88ac427ba6
@ -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()
|
||||||
|
@ -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()
|
||||||
{
|
{
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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 =>
|
||||||
{
|
{
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user