diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index e1e920ec0f..35a683d1d4 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -8,12 +8,14 @@ using System.Threading.Tasks; using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; +using osu.Framework.Audio.Track; using osu.Framework.Configuration; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; +using osu.Framework.Graphics.UserInterface; using osu.Framework.Input; using osu.Framework.Localisation; using osu.Game.Beatmaps; @@ -38,7 +40,7 @@ namespace osu.Game.Overlays private const float bottom_black_area_height = 55; private Drawable currentBackground; - private DragBar progressBar; + private ProgressBar progressBar; private IconButton playButton; private IconButton playlistButton; @@ -183,13 +185,13 @@ namespace osu.Game.Overlays }, } }, - progressBar = new DragBar + progressBar = new ProgressBar { Origin = Anchor.BottomCentre, Anchor = Anchor.BottomCentre, Height = progress_height, - Colour = colours.Yellow, - SeekRequested = seek + FillColour = colours.Yellow, + OnSeek = progress => current?.Track.Seek(progress) } }, }, @@ -224,7 +226,7 @@ namespace osu.Game.Overlays { var track = current.Track; - progressBar.UpdatePosition(track.Length == 0 ? 0 : (float)(track.CurrentTime / track.Length)); + progressBar.Progress = track.CurrentTime; playButton.Icon = track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o; if (track.HasCompleted && !track.Looping) next(); @@ -266,8 +268,6 @@ namespace osu.Game.Overlays private void beatmapChanged(WorkingBeatmap beatmap) { - progressBar.IsEnabled = beatmap != null; - TransformDirection direction = TransformDirection.None; if (current != null) @@ -293,10 +293,19 @@ namespace osu.Game.Overlays current = beatmapBacking.Value; + updateProgressBar(current?.Track); updateDisplay(beatmapBacking, direction); queuedDirection = null; } + private void updateProgressBar(Track t) + { + if (t?.IsLoaded ?? false) + progressBar.EndTime = t.Length; + else if (t != null) + t.OnLoaded += loadedTrack => progressBar.EndTime = loadedTrack.Length; + } + private ScheduledDelegate pendingBeatmapSwitch; private void updateDisplay(WorkingBeatmap beatmap, TransformDirection direction) @@ -352,12 +361,6 @@ namespace osu.Game.Overlays }); } - private void seek(float position) - { - var track = current?.Track; - track?.Seek(track.Length * position); - } - protected override void PopIn() { base.PopIn(); @@ -417,5 +420,49 @@ namespace osu.Game.Overlays sprite.Texture = beatmap?.Background ?? textures.Get(@"Backgrounds/bg4"); } } + + private class ProgressBar : SliderBar + { + public Action OnSeek; + + private Box fill; + + public Color4 FillColour + { + set { fill.Colour = value; } + } + + public double EndTime + { + set { CurrentNumber.MaxValue = value; } + } + + public double Progress + { + set { CurrentNumber.Value = value; } + } + + public ProgressBar() + { + CurrentNumber.MinValue = 0; + CurrentNumber.MaxValue = 1; + RelativeSizeAxes = Axes.X; + + Children = new Drawable[] + { + fill = new Box + { + RelativeSizeAxes = Axes.Y + } + }; + } + + protected override void UpdateValue(float value) + { + fill.Width = value * UsableWidth; + } + + protected override void OnUserChange() => OnSeek?.Invoke(Current); + } } }