From 73c004fb71e9334ba6b6512b09098edac2350f8b Mon Sep 17 00:00:00 2001 From: Jai Sharma Date: Thu, 22 Jun 2017 17:42:29 +0100 Subject: [PATCH] Removed DragBar from song progress --- osu.Game/Overlays/DragBar.cs | 110 ------------------- osu.Game/Overlays/MusicController.cs | 6 +- osu.Game/Screens/Play/SongProgress.cs | 13 +-- osu.Game/Screens/Play/SongProgressBar.cs | 128 +++++++++++++++-------- osu.Game/osu.Game.csproj | 3 +- 5 files changed, 97 insertions(+), 163 deletions(-) delete mode 100644 osu.Game/Overlays/DragBar.cs diff --git a/osu.Game/Overlays/DragBar.cs b/osu.Game/Overlays/DragBar.cs deleted file mode 100644 index 07e0c76396..0000000000 --- a/osu.Game/Overlays/DragBar.cs +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Containers; -using osu.Framework.Graphics.Transforms; -using osu.Framework.Input; -using OpenTK; -using osu.Framework.Graphics.Shapes; - -namespace osu.Game.Overlays -{ - public class DragBar : Container - { - protected readonly Container Fill; - - public Action SeekRequested; - - public bool IsSeeking { get; private set; } - - private bool enabled = true; - public bool IsEnabled - { - get { return enabled; } - set - { - enabled = value; - if (!enabled) - Fill.Width = 0; - } - } - - public DragBar() - { - RelativeSizeAxes = Axes.X; - - Children = new Drawable[] - { - Fill = new Container - { - Name = "FillContainer", - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - RelativeSizeAxes = Axes.Both, - Width = 0, - Children = new Drawable[] - { - new Box - { - RelativeSizeAxes = Axes.Both - } - } - } - }; - } - - public void UpdatePosition(float position) - { - if (IsSeeking || !IsEnabled) return; - - updatePosition(position, false); - } - - private void seek(InputState state) - { - float seekLocation = state.Mouse.Position.X / DrawWidth; - - if (!IsEnabled) return; - - SeekRequested?.Invoke(seekLocation); - updatePosition(seekLocation); - } - - private void updatePosition(float position, bool easing = true) - { - position = MathHelper.Clamp(position, 0, 1); - Fill.TransformTo(() => Fill.Width, position, easing ? 200 : 0, EasingTypes.OutQuint, new TransformSeek()); - } - - protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) - { - seek(state); - return true; - } - - protected override bool OnDrag(InputState state) - { - seek(state); - return true; - } - - protected override bool OnDragStart(InputState state) => IsSeeking = true; - - protected override bool OnDragEnd(InputState state) - { - IsSeeking = false; - return true; - } - - private class TransformSeek : TransformFloat - { - public override void Apply(Drawable d) - { - base.Apply(d); - d.Width = CurrentValue; - } - } - } -} diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 35a683d1d4..8e9ac22925 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -226,7 +226,7 @@ namespace osu.Game.Overlays { var track = current.Track; - progressBar.Progress = track.CurrentTime; + progressBar.CurrentTime = track.CurrentTime; playButton.Icon = track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o; if (track.HasCompleted && !track.Looping) next(); @@ -437,7 +437,7 @@ namespace osu.Game.Overlays set { CurrentNumber.MaxValue = value; } } - public double Progress + public double CurrentTime { set { CurrentNumber.Value = value; } } @@ -445,7 +445,7 @@ namespace osu.Game.Overlays public ProgressBar() { CurrentNumber.MinValue = 0; - CurrentNumber.MaxValue = 1; + CurrentNumber.MinValue = 1; RelativeSizeAxes = Axes.X; Children = new Drawable[] diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index e5b18292ab..5fc83eddb4 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -50,6 +50,9 @@ namespace osu.Game.Screens.Play info.StartTime = firstHitTime; info.EndTime = lastHitTime; + + bar.StartTime = firstHitTime; + bar.EndTime = lastHitTime; } } @@ -89,10 +92,7 @@ namespace osu.Game.Screens.Play Alpha = 0, Anchor = Anchor.BottomLeft, Origin = Anchor.BottomLeft, - SeekRequested = delegate (float position) - { - OnSeek?.Invoke(firstHitTime + position * (lastHitTime - firstHitTime)); - }, + OnSeek = position => this.OnSeek?.Invoke(position), }, }; } @@ -144,11 +144,12 @@ namespace osu.Game.Screens.Play if (objects == null) return; - double progress = ((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime); + double position = audioClock?.CurrentTime ?? Time.Current; + double progress = (position - firstHitTime) / (lastHitTime - firstHitTime); if (progress < 1) { - bar.UpdatePosition((float)progress); + bar.CurrentTime = position; graph.Progress = (int)(graph.ColumnCount * progress); } } diff --git a/osu.Game/Screens/Play/SongProgressBar.cs b/osu.Game/Screens/Play/SongProgressBar.cs index 730cf471da..84928f437a 100644 --- a/osu.Game/Screens/Play/SongProgressBar.cs +++ b/osu.Game/Screens/Play/SongProgressBar.cs @@ -1,74 +1,118 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; using OpenTK; using OpenTK.Graphics; -using osu.Game.Overlays; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics; using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.UserInterface; namespace osu.Game.Screens.Play { - public class SongProgressBar : DragBar + public class SongProgressBar : SliderBar { + public Action OnSeek; + + private Box fill; + private Box background; + private Container handleBase; + public Color4 FillColour { - get { return Fill.Colour; } - set { Fill.Colour = value; } + set { fill.Colour = value; } + } + + public double StartTime + { + set { CurrentNumber.MinValue = value; } + } + + public double EndTime + { + set { CurrentNumber.MaxValue = value; } + } + + public double CurrentTime + { + set { CurrentNumber.Value = value; } } public SongProgressBar(float barHeight, float handleBarHeight, Vector2 handleSize) { + CurrentNumber.MinValue = 0; + CurrentNumber.MaxValue = 1; + + RelativeSizeAxes = Axes.X; Height = barHeight + handleBarHeight + handleSize.Y; - Fill.RelativeSizeAxes = Axes.X; - Fill.Height = barHeight; - - Add(new Box + Children = new Drawable[] { - Name = "Background", - Anchor = Anchor.BottomLeft, - Origin = Anchor.BottomLeft, - RelativeSizeAxes = Axes.X, - Height = barHeight, - Colour = Color4.Black, - Alpha = 0.5f, - Depth = 1 - }); - - Fill.Add(new Container - { - Origin = Anchor.BottomRight, - Anchor = Anchor.BottomRight, - Width = 2, - Height = barHeight + handleBarHeight, - Colour = Color4.White, - Position = new Vector2(2, 0), - Children = new Drawable[] + background = new Box { - new Box + Name = "Background", + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + RelativeSizeAxes = Axes.X, + Height = barHeight, + Colour = Color4.Black, + Alpha = 0.5f, + Depth = 1, + }, + fill = new Box + { + Name = "Fill", + Anchor = Anchor.BottomLeft, + Origin = Anchor.BottomLeft, + Height = barHeight, + }, + handleBase = new Container + { + Name = "HandleBar container", + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Width = 2, + Height = barHeight + handleBarHeight, + Colour = Color4.White, + Position = new Vector2(2, 0), + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both, - }, - new Container - { - Origin = Anchor.BottomCentre, - Anchor = Anchor.TopCentre, - Size = handleSize, - CornerRadius = 5, - Masking = true, - Children = new Drawable[] + new Box { - new Box + Name = "HandleBar box", + RelativeSizeAxes = Axes.Both, + }, + new Container + { + Name = "Handle container", + Origin = Anchor.BottomCentre, + Anchor = Anchor.TopCentre, + Size = handleSize, + CornerRadius = 5, + Masking = true, + Children = new Drawable[] { - RelativeSizeAxes = Axes.Both, - Colour = Color4.White + new Box + { + Name = "Handle box", + RelativeSizeAxes = Axes.Both, + Colour = Color4.White + } } } } } - }); + }; } + + protected override void UpdateValue(float value) + { + var xFill = value * UsableWidth; + fill.Width = xFill; + handleBase.MoveToX(xFill); + } + + protected override void OnUserChange() => OnSeek?.Invoke(Current); } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 45dc47f842..4646eeb79d 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -214,7 +214,6 @@ - @@ -517,4 +516,4 @@ --> - \ No newline at end of file +