1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-20 13:02:59 +08:00

Cleanup external PlayButton.Playing usage

This commit is contained in:
Roman Kapustin 2018-05-25 22:35:15 +03:00
parent 498244a308
commit a24589f583
6 changed files with 37 additions and 65 deletions

View File

@ -37,14 +37,17 @@ namespace osu.Game.Audio
CurrentTrack?.Stop();
audio.Track.AddAdjustment(AdjustableProperty.Volume, muteBindable);
CurrentTrack = track;
CurrentTrack.Stopped += () => CurrentTrack = null;
};
onTrackStop = () => audio.Track.RemoveAdjustment(AdjustableProperty.Volume, muteBindable);
onTrackStop = () =>
{
audio.Track.RemoveAdjustment(AdjustableProperty.Volume, muteBindable);
CurrentTrack = null;
};
}
public PreviewTrack Get(BeatmapSetInfo beatmapSetInfo) =>
new PreviewTrack(
trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo.OnlineBeatmapSetID}.mp3"),
trackManager.Get($"https://b.ppy.sh/preview/{beatmapSetInfo?.OnlineBeatmapSetID}.mp3"),
onTrackStart,
onTrackStop);

View File

@ -66,7 +66,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
},
};
Action = () => Playing.Value = !Playing.Value;
Action = () => playButton.TriggerOnClick();
Playing.ValueChanged += newValue => progress.FadeTo(newValue ? 1 : 0, 100);
}
@ -89,12 +89,6 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
progress.Width = 0;
}
protected override void Dispose(bool isDisposing)
{
Playing.Value = false;
base.Dispose(isDisposing);
}
protected override bool OnHover(InputState state)
{
bg.FadeColour(Color4.Black.Opacity(0.5f), 100);

View File

@ -102,7 +102,11 @@ namespace osu.Game.Overlays.BeatmapSet
updateDisplay();
}
public void StopPreview() => preview.Playing.Value = false;
public void StopPreview()
{
if (preview.Playing)
preview.TriggerOnClick();
}
private class DetailBox : Container
{

View File

@ -149,7 +149,6 @@ namespace osu.Game.Overlays.Direct
protected override bool OnClick(InputState state)
{
ShowInformation();
PreviewPlaying.Value = false;
return true;
}

View File

@ -31,8 +31,6 @@ namespace osu.Game.Overlays.Direct
beatmapSet = value;
Playing.Value = false;
if (Preview != null)
Preview.Stopped -= preview_Stopped;
Preview = null;
}
}
@ -90,7 +88,30 @@ namespace osu.Game.Overlays.Direct
protected override bool OnClick(InputState state)
{
Playing.Value = !Playing.Value;
if (!Playing.Value)
{
if (Preview == null)
{
Task.Run(() =>
{
loading = true;
return Preview = previewTrackManager.Get(beatmapSet);
})
.ContinueWith(t =>
{
Preview.Started += () => Playing.Value = true;
Preview.Stopped += () => Playing.Value = false;
Preview.Start();
loading = false;
});
return true;
}
Preview.Start();
}
else
Preview?.Stop();
return true;
}
@ -118,35 +139,12 @@ namespace osu.Game.Overlays.Direct
icon.Icon = playing ? FontAwesome.fa_pause : FontAwesome.fa_play;
icon.FadeColour(playing || IsHovered ? hoverColour : Color4.White, 120, Easing.InOutQuint);
if (playing)
if (!playing)
{
if (Preview == null)
{
Task.Run(() =>
{
loading = true;
return Preview = previewTrackManager.Get(beatmapSet);
})
.ContinueWith(t =>
{
Preview.Stopped += preview_Stopped;
playingStateChanged(true);
loading = false;
});
return;
}
Preview.Start();
}
else
{
Preview.Stop();
loading = false;
}
}
private void preview_Stopped() => Playing.Value = false;
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

View File

@ -33,7 +33,6 @@ namespace osu.Game.Overlays
private readonly FillFlowContainer resultCountsContainer;
private readonly OsuSpriteText resultCountsText;
private FillFlowContainer<DirectPanel> panels;
private DirectPanel playing;
protected override Color4 BackgroundColour => OsuColour.FromHex(@"485e74");
protected override Color4 TrianglesColourLight => OsuColour.FromHex(@"465b71");
@ -217,12 +216,6 @@ namespace osu.Game.Overlays
panels.FadeOut(200);
panels.Expire();
panels = null;
if (playing != null)
{
playing.PreviewPlaying.Value = false;
playing = null;
}
}
if (BeatmapSets == null) return;
@ -253,17 +246,6 @@ namespace osu.Game.Overlays
{
if (panels != null) ScrollFlow.Remove(panels);
ScrollFlow.Add(panels = newPanels);
foreach (DirectPanel panel in p.Children)
panel.PreviewPlaying.ValueChanged += newValue =>
{
if (newValue)
{
if (playing != null && playing != panel)
playing.PreviewPlaying.Value = false;
playing = panel;
}
};
});
}
@ -313,14 +295,6 @@ namespace osu.Game.Overlays
api.Queue(getSetsRequest);
}
protected override void PopOut()
{
base.PopOut();
if (playing != null)
playing.PreviewPlaying.Value = false;
}
private int distinctCount(List<string> list) => list.Distinct().ToArray().Length;
protected override void Dispose(bool isDisposing)