Rework preview tracks to reduce usage complexities

This commit is contained in:
smoogipoo
2018-06-21 16:19:07 +09:00
parent ab2889da1f
commit b2066c5d73
10 changed files with 172 additions and 90 deletions

View File

@ -83,7 +83,7 @@ namespace osu.Game.Overlays.BeatmapSet.Buttons
if (Playing.Value && preview != null)
{
// prevent negative (potential infinite) width if a track without length was loaded
progress.Width = preview.Track.Length > 0 ? (float)(preview.Track.CurrentTime / preview.Track.Length) : 0f;
progress.Width = preview.Length > 0 ? (float)(preview.CurrentTime / preview.Length) : 0f;
}
else
progress.Width = 0;

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
@ -38,7 +37,6 @@ namespace osu.Game.Overlays
private readonly ScrollContainer scroll;
private BeatmapSetInfo beatmapSet;
private PreviewTrackManager previewTrackManager;
public BeatmapSetInfo BeatmapSet
{
@ -111,11 +109,10 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader]
private void load(APIAccess api, RulesetStore rulesets, PreviewTrackManager previewTrackManager)
private void load(APIAccess api, RulesetStore rulesets)
{
this.api = api;
this.rulesets = rulesets;
this.previewTrackManager = previewTrackManager;
}
protected override void PopIn()
@ -127,8 +124,6 @@ namespace osu.Game.Overlays
protected override void PopOut()
{
base.PopOut();
previewTrackManager.CurrentTrack?.Stop(this);
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out).OnComplete(_ => BeatmapSet = null);
}

View File

@ -113,9 +113,9 @@ namespace osu.Game.Overlays.Direct
{
base.Update();
if (PreviewPlaying && Preview != null && Preview.Track.IsLoaded)
if (PreviewPlaying && Preview != null && Preview.TrackLoaded)
{
PreviewBar.Width = (float)(Preview.Track.CurrentTime / Preview.Track.Length);
PreviewBar.Width = (float)(Preview.CurrentTime / Preview.Length);
}
}

View File

@ -29,21 +29,14 @@ namespace osu.Game.Overlays.Direct
if (value == beatmapSet) return;
beatmapSet = value;
Preview?.Stop(parentOverlayContainer);
if (Preview != null)
{
Preview.Stop();
RemoveInternal(Preview);
Preview = null;
}
Playing.Value = false;
Preview = null;
}
}
private OverlayContainer parentOverlayContainer
{
get
{
var d = Parent;
while (!(d is OverlayContainer))
d = d.Parent;
return (OverlayContainer)d;
}
}
@ -89,9 +82,13 @@ namespace osu.Game.Overlays.Direct
Playing.ValueChanged += playingStateChanged;
}
private PreviewTrackManager previewTrackManager;
[BackgroundDependencyLoader]
private void load(OsuColour colour)
private void load(OsuColour colour, PreviewTrackManager previewTrackManager)
{
this.previewTrackManager = previewTrackManager;
hoverColour = colour.Yellow;
}
@ -103,15 +100,18 @@ namespace osu.Game.Overlays.Direct
{
loading = true;
LoadComponentAsync(
Preview = new PreviewTrack(beatmapSet, parentOverlayContainer),
t =>
{
Preview.Started += () => Playing.Value = true;
Preview.Stopped += () => Playing.Value = false;
Preview.Start();
loading = false;
});
Preview = previewTrackManager.Get(beatmapSet);
Preview.Started += () => Playing.Value = true;
Preview.Stopped += () => Playing.Value = false;
LoadComponentAsync(Preview, t =>
{
AddInternal(t);
Preview.Start();
loading = false;
});
return true;
}

View File

@ -262,7 +262,7 @@ namespace osu.Game.Overlays
if (Header.Tabs.Current.Value == DirectTab.Search && (Filter.Search.Text == string.Empty || currentQuery == string.Empty)) return;
previewTrackManager.CurrentTrack?.Stop(this);
previewTrackManager.Stop(this);
getSetsRequest = new SearchBeatmapSetsRequest(currentQuery.Value ?? string.Empty,
((FilterControl)Filter).Ruleset.Value,
@ -289,12 +289,6 @@ namespace osu.Game.Overlays
private int distinctCount(List<string> list) => list.Distinct().ToArray().Length;
protected override void PopOut()
{
previewTrackManager.CurrentTrack?.Stop(this);
base.PopOut();
}
public class ResultCounts
{
public readonly int Artists;

View File

@ -8,7 +8,6 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Game.Audio;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
@ -31,7 +30,6 @@ namespace osu.Game.Overlays
protected ProfileHeader Header;
private SectionsContainer<ProfileSection> sectionsContainer;
private ProfileTabControl tabs;
private PreviewTrackManager previewTrackManager;
public const float CONTENT_X_MARGIN = 50;
@ -58,10 +56,9 @@ namespace osu.Game.Overlays
}
[BackgroundDependencyLoader]
private void load(APIAccess api, PreviewTrackManager previewTrackManager)
private void load(APIAccess api)
{
this.api = api;
this.previewTrackManager = previewTrackManager;
}
protected override void PopIn()
@ -73,7 +70,6 @@ namespace osu.Game.Overlays
protected override void PopOut()
{
base.PopOut();
previewTrackManager.CurrentTrack?.Stop(this);
FadeEdgeEffectTo(0, WaveContainer.DISAPPEAR_DURATION, Easing.Out);
}