From eacf2045f0c1bf5ef817fcfd88f22dd44dc639dc Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Fri, 28 Apr 2017 04:56:34 +0300 Subject: [PATCH 01/25] Initial commit --- osu.Game/Screens/Play/SongProgress.cs | 16 ++++- osu.Game/Screens/Play/SongProgressInfo.cs | 87 +++++++++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Screens/Play/SongProgressInfo.cs diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index ed57dad644..db81d22844 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -28,6 +28,7 @@ namespace osu.Game.Screens.Play private readonly SongProgressBar bar; private readonly SongProgressGraph graph; + private readonly SongProgressInfo info; public Action OnSeek; @@ -62,6 +63,14 @@ namespace osu.Game.Screens.Play Children = new Drawable[] { + info = new SongProgressInfo + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Y = -(bottom_bar_height + graph_height), + }, graph = new SongProgressGraph { RelativeSizeAxes = Axes.X, @@ -130,10 +139,15 @@ namespace osu.Game.Screens.Play if (objects == null) return; - double progress = ((AudioClock?.CurrentTime ?? Time.Current) - firstHitTime) / lastHitTime; + double currentTime = (AudioClock?.CurrentTime ?? Time.Current); + double progress = (currentTime - firstHitTime) / lastHitTime; bar.UpdatePosition((float)progress); graph.Progress = (int)(graph.ColumnCount * progress); + + info.TimeCurrent = TimeSpan.FromMilliseconds(currentTime).ToString(@"m\:ss"); + info.TimeLeft = TimeSpan.FromMilliseconds(lastHitTime - currentTime).ToString(@"m\:ss"); + info.Progress = ((int)(currentTime / lastHitTime * 100)).ToString(); } } } diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs new file mode 100644 index 0000000000..7f32c18957 --- /dev/null +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -0,0 +1,87 @@ +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Primitives; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; + +namespace osu.Game.Screens.Play +{ + public class SongProgressInfo : Container + { + private InfoText timeCurrent; + private InfoText timeLeft; + private InfoText progress; + + private const int margin = 10; + + public string TimeCurrent + { + set + { + timeCurrent.Text = value; + } + } + + public string TimeLeft + { + set + { + timeLeft.Text = @"-" + value; + } + } + public string Progress + { + set + { + progress.Text = value + @"%"; + } + } + + public SongProgressInfo() + { + Children = new Drawable[] + { + timeCurrent = new InfoText + { + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Margin = new MarginPadding + { + Left = margin, + }, + }, + progress = new InfoText + { + Origin = Anchor.BottomCentre, + Anchor = Anchor.BottomCentre, + }, + timeLeft = new InfoText + { + Origin = Anchor.BottomRight, + Anchor = Anchor.BottomRight, + Margin = new MarginPadding + { + Right = margin, + } + } + }; + } + + private class InfoText : OsuSpriteText + { + [BackgroundDependencyLoader] + private void load(OsuColour colours) + { + Colour = colours.BlueLighter; + Font = @"Venera"; + EdgeEffect = new EdgeEffect + { + Colour = colours.BlueDarker, + Type = EdgeEffectType.Glow, + Radius = 5, + }; + } + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index cb491055c4..6d7a1c43cd 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -224,6 +224,7 @@ + From c27909d53c0bb6b5d611b89670bd93e33333204c Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Fri, 28 Apr 2017 05:02:25 +0300 Subject: [PATCH 02/25] CI fixes --- osu.Game/Screens/Play/SongProgress.cs | 2 +- osu.Game/Screens/Play/SongProgressInfo.cs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index db81d22844..4fdc4710ac 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -139,7 +139,7 @@ namespace osu.Game.Screens.Play if (objects == null) return; - double currentTime = (AudioClock?.CurrentTime ?? Time.Current); + double currentTime = AudioClock?.CurrentTime ?? Time.Current; double progress = (currentTime - firstHitTime) / lastHitTime; bar.UpdatePosition((float)progress); diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 7f32c18957..127a87f3bf 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -1,4 +1,7 @@ -using osu.Framework.Allocation; +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; From c4bd21914d3a4908933ece0f7458af2378a77e31 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Fri, 28 Apr 2017 15:37:22 +0300 Subject: [PATCH 03/25] warning fixes --- osu.Game/Screens/Play/SongProgressInfo.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 127a87f3bf..fa179d05c1 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -12,9 +12,9 @@ namespace osu.Game.Screens.Play { public class SongProgressInfo : Container { - private InfoText timeCurrent; - private InfoText timeLeft; - private InfoText progress; + private readonly InfoText timeCurrent; + private readonly InfoText timeLeft; + private readonly InfoText progress; private const int margin = 10; From f8faea8da28644b5d10c27a06304acfc4b1ffc72 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Fri, 28 Apr 2017 16:02:00 +0300 Subject: [PATCH 04/25] Removed unnecessary nested class --- osu.Game/Screens/Play/SongProgressInfo.cs | 37 +++++++++-------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index fa179d05c1..1a36f1bd42 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -12,9 +12,9 @@ namespace osu.Game.Screens.Play { public class SongProgressInfo : Container { - private readonly InfoText timeCurrent; - private readonly InfoText timeLeft; - private readonly InfoText progress; + private OsuSpriteText timeCurrent; + private OsuSpriteText timeLeft; + private OsuSpriteText progress; private const int margin = 10; @@ -41,28 +41,35 @@ namespace osu.Game.Screens.Play } } - public SongProgressInfo() + [BackgroundDependencyLoader] + private void load(OsuColour colours) { Children = new Drawable[] { - timeCurrent = new InfoText + timeCurrent = new OsuSpriteText { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, + Colour = colours.BlueLighter, + Font = @"Venera", Margin = new MarginPadding { Left = margin, }, }, - progress = new InfoText + progress = new OsuSpriteText { Origin = Anchor.BottomCentre, Anchor = Anchor.BottomCentre, + Colour = colours.BlueLighter, + Font = @"Venera", }, - timeLeft = new InfoText + timeLeft = new OsuSpriteText { Origin = Anchor.BottomRight, Anchor = Anchor.BottomRight, + Colour = colours.BlueLighter, + Font = @"Venera", Margin = new MarginPadding { Right = margin, @@ -70,21 +77,5 @@ namespace osu.Game.Screens.Play } }; } - - private class InfoText : OsuSpriteText - { - [BackgroundDependencyLoader] - private void load(OsuColour colours) - { - Colour = colours.BlueLighter; - Font = @"Venera"; - EdgeEffect = new EdgeEffect - { - Colour = colours.BlueDarker, - Type = EdgeEffectType.Glow, - Radius = 5, - }; - } - } } } From 698ae0832f86037150f1987272360464ce2203d9 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 1 May 2017 07:00:44 +0300 Subject: [PATCH 05/25] Move string formatting inside the class --- osu.Game/Screens/Play/SongProgress.cs | 6 +++--- osu.Game/Screens/Play/SongProgressInfo.cs | 26 ++++------------------- 2 files changed, 7 insertions(+), 25 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 4fdc4710ac..35aeb33528 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -145,9 +145,9 @@ namespace osu.Game.Screens.Play bar.UpdatePosition((float)progress); graph.Progress = (int)(graph.ColumnCount * progress); - info.TimeCurrent = TimeSpan.FromMilliseconds(currentTime).ToString(@"m\:ss"); - info.TimeLeft = TimeSpan.FromMilliseconds(lastHitTime - currentTime).ToString(@"m\:ss"); - info.Progress = ((int)(currentTime / lastHitTime * 100)).ToString(); + info.TimeCurrent = currentTime; + info.TimeLeft = lastHitTime - currentTime; + info.Progress = (int)(currentTime / lastHitTime * 100); } } } diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 1a36f1bd42..ffee4e4094 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; +using System; namespace osu.Game.Screens.Play { @@ -18,28 +19,9 @@ namespace osu.Game.Screens.Play private const int margin = 10; - public string TimeCurrent - { - set - { - timeCurrent.Text = value; - } - } - - public string TimeLeft - { - set - { - timeLeft.Text = @"-" + value; - } - } - public string Progress - { - set - { - progress.Text = value + @"%"; - } - } + public double TimeCurrent { set { timeCurrent.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } } + public double TimeLeft { set { timeLeft.Text = @"- " + TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } } + public int Progress { set { progress.Text = value.ToString() + @"%"; } } [BackgroundDependencyLoader] private void load(OsuColour colours) From ea28a9f7ce2dfcba262710137478e46d543a6c8a Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 00:16:58 +0300 Subject: [PATCH 06/25] Adjust values --- osu.Game/Screens/Play/SongProgress.cs | 11 +++--- osu.Game/Screens/Play/SongProgressInfo.cs | 48 +++++++++++++++++++---- 2 files changed, 47 insertions(+), 12 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 35aeb33528..b0a77afa51 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -139,15 +139,16 @@ namespace osu.Game.Screens.Play if (objects == null) return; - double currentTime = AudioClock?.CurrentTime ?? Time.Current; - double progress = (currentTime - firstHitTime) / lastHitTime; + double drawableCurrentTime = AudioClock?.CurrentTime ?? Time.Current; + double songCurrentTime = drawableCurrentTime - firstHitTime; + double progress = songCurrentTime / lastHitTime; bar.UpdatePosition((float)progress); graph.Progress = (int)(graph.ColumnCount * progress); - info.TimeCurrent = currentTime; - info.TimeLeft = lastHitTime - currentTime; - info.Progress = (int)(currentTime / lastHitTime * 100); + info.Progress = (int)(progress * 100); + info.TimeCurrent = songCurrentTime; + info.TimeLeft = lastHitTime - firstHitTime - songCurrentTime; } } } diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index ffee4e4094..17623ca9f7 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -13,22 +13,54 @@ namespace osu.Game.Screens.Play { public class SongProgressInfo : Container { - private OsuSpriteText timeCurrent; + private OsuSpriteText timeCurrentText; private OsuSpriteText timeLeft; - private OsuSpriteText progress; + private OsuSpriteText progressText; + + private int progress; + private double timeCurrent; private const int margin = 10; - public double TimeCurrent { set { timeCurrent.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } } - public double TimeLeft { set { timeLeft.Text = @"- " + TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } } - public int Progress { set { progress.Text = value.ToString() + @"%"; } } + public double TimeCurrent + { + set + { + timeCurrent = value; + + if (value > 0) + timeCurrentText.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); + } + } + public double TimeLeft + { + set + { + if(timeCurrent < 0) + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(value + timeCurrent).ToString(@"m\:ss"); + else + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); + } + } + public int Progress + { + set + { + if (progress == value) + return; + + progress = value; + if (value > 0) + progressText.Text = value.ToString() + @"%"; + } + } [BackgroundDependencyLoader] private void load(OsuColour colours) { Children = new Drawable[] { - timeCurrent = new OsuSpriteText + timeCurrentText = new OsuSpriteText { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, @@ -38,13 +70,15 @@ namespace osu.Game.Screens.Play { Left = margin, }, + Text = @"0:00", }, - progress = new OsuSpriteText + progressText = new OsuSpriteText { Origin = Anchor.BottomCentre, Anchor = Anchor.BottomCentre, Colour = colours.BlueLighter, Font = @"Venera", + Text = @"0%", }, timeLeft = new OsuSpriteText { From 531f2c410a3a9145ba7b08cd2d4b11b0d3098458 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 00:26:34 +0300 Subject: [PATCH 07/25] removed useless variable --- osu.Game/Screens/Play/SongProgress.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index b0a77afa51..6489391d6a 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -139,16 +139,15 @@ namespace osu.Game.Screens.Play if (objects == null) return; - double drawableCurrentTime = AudioClock?.CurrentTime ?? Time.Current; - double songCurrentTime = drawableCurrentTime - firstHitTime; - double progress = songCurrentTime / lastHitTime; + double currentTime = (AudioClock?.CurrentTime ?? Time.Current) - firstHitTime; + double progress = currentTime / lastHitTime; bar.UpdatePosition((float)progress); graph.Progress = (int)(graph.ColumnCount * progress); info.Progress = (int)(progress * 100); - info.TimeCurrent = songCurrentTime; - info.TimeLeft = lastHitTime - firstHitTime - songCurrentTime; + info.TimeCurrent = currentTime; + info.TimeLeft = lastHitTime - firstHitTime - currentTime; } } } From c3a42ded361f647055774a3ac3284555cdf0f32d Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 01:23:51 +0300 Subject: [PATCH 08/25] Fixed Graph/seeking offset --- osu.Game/Screens/Play/SongProgress.cs | 2 +- osu.Game/Screens/Play/SongProgressGraph.cs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 6489391d6a..737c65397c 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -140,7 +140,7 @@ namespace osu.Game.Screens.Play return; double currentTime = (AudioClock?.CurrentTime ?? Time.Current) - firstHitTime; - double progress = currentTime / lastHitTime; + double progress = currentTime / (lastHitTime-firstHitTime); bar.UpdatePosition((float)progress); graph.Progress = (int)(graph.ColumnCount * progress); diff --git a/osu.Game/Screens/Play/SongProgressGraph.cs b/osu.Game/Screens/Play/SongProgressGraph.cs index 20548970e5..4e56f60c31 100644 --- a/osu.Game/Screens/Play/SongProgressGraph.cs +++ b/osu.Game/Screens/Play/SongProgressGraph.cs @@ -20,12 +20,13 @@ namespace osu.Game.Screens.Play const int granularity = 200; + var firstHit = objects.First().StartTime; var lastHit = (objects.Last() as IHasEndTime)?.EndTime ?? 0; if (lastHit == 0) lastHit = objects.Last().StartTime; - var interval = (lastHit + 1) / granularity; + var interval = (lastHit - firstHit + 1) / granularity; var values = new int[granularity]; @@ -33,8 +34,8 @@ namespace osu.Game.Screens.Play { IHasEndTime end = h as IHasEndTime; - int startRange = (int)(h.StartTime / interval); - int endRange = (int)((end?.EndTime > 0 ? end.EndTime : h.StartTime) / interval); + int startRange = (int)((h.StartTime - firstHit)/ interval); + int endRange = (int)(((end?.EndTime > 0 ? end.EndTime : h.StartTime) - firstHit) / interval); for (int i = startRange; i <= endRange; i++) values[i]++; } From dda25219bc07efba77c22e02856536d471ff976e Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 01:54:31 +0300 Subject: [PATCH 09/25] code fixes --- osu.Game/Screens/Play/SongProgress.cs | 2 +- osu.Game/Screens/Play/SongProgressInfo.cs | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 737c65397c..020a26f703 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -140,7 +140,7 @@ namespace osu.Game.Screens.Play return; double currentTime = (AudioClock?.CurrentTime ?? Time.Current) - firstHitTime; - double progress = currentTime / (lastHitTime-firstHitTime); + double progress = currentTime / (lastHitTime - firstHitTime); bar.UpdatePosition((float)progress); graph.Progress = (int)(graph.ColumnCount * progress); diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 17623ca9f7..d2b236035d 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -32,16 +32,7 @@ namespace osu.Game.Screens.Play timeCurrentText.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } } - public double TimeLeft - { - set - { - if(timeCurrent < 0) - timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(value + timeCurrent).ToString(@"m\:ss"); - else - timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); - } - } + public double TimeLeft { set { timeLeft.Text = @"-" + TimeSpan.FromMilliseconds((timeCurrent < 0) ? (value + timeCurrent) : value).ToString(@"m\:ss"); } } public int Progress { set From 926ed907c26cdc3d18de40efa38c1c71beab37ff Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 02:00:21 +0300 Subject: [PATCH 10/25] CI fixes --- osu.Game/Screens/Play/SongProgressInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index d2b236035d..12752e09c3 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -32,7 +32,7 @@ namespace osu.Game.Screens.Play timeCurrentText.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } } - public double TimeLeft { set { timeLeft.Text = @"-" + TimeSpan.FromMilliseconds((timeCurrent < 0) ? (value + timeCurrent) : value).ToString(@"m\:ss"); } } + public double TimeLeft { set { timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(timeCurrent < 0 ? value + timeCurrent : value).ToString(@"m\:ss"); } } public int Progress { set From f0145c7f4f6ab6cb533b39e009e80d6942cc9515 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 02:16:56 +0300 Subject: [PATCH 11/25] Trying to woke up AppVeyor --- osu.Game/Screens/Play/SongProgressInfo.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 12752e09c3..5b33e6d8af 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -27,7 +27,6 @@ namespace osu.Game.Screens.Play set { timeCurrent = value; - if (value > 0) timeCurrentText.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } From 4b5e24cc36086467809060ebb316cbfc46252cea Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 19:14:19 +0300 Subject: [PATCH 12/25] Changed logic a bit --- osu.Game/Screens/Play/SongProgress.cs | 4 ++-- osu.Game/Screens/Play/SongProgressInfo.cs | 28 +++++++++++++++-------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 020a26f703..6a0bc64de9 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -45,6 +45,7 @@ namespace osu.Game.Screens.Play set { graph.Objects = objects = value; + info.SongLenght = lastHitTime - firstHitTime; } } @@ -146,8 +147,7 @@ namespace osu.Game.Screens.Play graph.Progress = (int)(graph.ColumnCount * progress); info.Progress = (int)(progress * 100); - info.TimeCurrent = currentTime; - info.TimeLeft = lastHitTime - firstHitTime - currentTime; + info.CurrentTime = currentTime; } } } diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 5b33e6d8af..cf73a0d10a 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -13,25 +13,26 @@ namespace osu.Game.Screens.Play { public class SongProgressInfo : Container { - private OsuSpriteText timeCurrentText; + private OsuSpriteText timeCurrent; private OsuSpriteText timeLeft; private OsuSpriteText progressText; + private double currentTime; + private double songLenght; private int progress; - private double timeCurrent; private const int margin = 10; - public double TimeCurrent + public double SongLenght { set { songLenght = value; } } + public double CurrentTime { set { - timeCurrent = value; + currentTime = value; if (value > 0) - timeCurrentText.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); + timeCurrent.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } } - public double TimeLeft { set { timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(timeCurrent < 0 ? value + timeCurrent : value).ToString(@"m\:ss"); } } public int Progress { set @@ -40,7 +41,7 @@ namespace osu.Game.Screens.Play return; progress = value; - if (value > 0) + if (currentTime > 0) progressText.Text = value.ToString() + @"%"; } } @@ -50,7 +51,7 @@ namespace osu.Game.Screens.Play { Children = new Drawable[] { - timeCurrentText = new OsuSpriteText + timeCurrent = new OsuSpriteText { Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, @@ -79,9 +80,18 @@ namespace osu.Game.Screens.Play Margin = new MarginPadding { Right = margin, - } + }, + Text = @"-" + TimeSpan.FromMilliseconds(songLenght).ToString(@"m\:ss"), } }; } + + protected override void Update() + { + base.Update(); + + if(currentTime > 0) + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(songLenght - currentTime).ToString(@"m\:ss"); + } } } From 17d1ecb8f592d5c630c17c49892720561bdf130c Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 19:42:36 +0300 Subject: [PATCH 13/25] Use float type for progress value --- osu.Game/Screens/Play/SongProgress.cs | 6 +++--- osu.Game/Screens/Play/SongProgressInfo.cs | 13 ++++--------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 6a0bc64de9..e3f96bd395 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -141,12 +141,12 @@ namespace osu.Game.Screens.Play return; double currentTime = (AudioClock?.CurrentTime ?? Time.Current) - firstHitTime; - double progress = currentTime / (lastHitTime - firstHitTime); + float progress = (float)(currentTime / (lastHitTime - firstHitTime)); - bar.UpdatePosition((float)progress); + bar.UpdatePosition(progress); graph.Progress = (int)(graph.ColumnCount * progress); - info.Progress = (int)(progress * 100); + info.Progress = progress; info.CurrentTime = currentTime; } } diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index cf73a0d10a..6719ddfb6b 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -15,11 +15,10 @@ namespace osu.Game.Screens.Play { private OsuSpriteText timeCurrent; private OsuSpriteText timeLeft; - private OsuSpriteText progressText; + private OsuSpriteText progress; private double currentTime; private double songLenght; - private int progress; private const int margin = 10; @@ -33,16 +32,12 @@ namespace osu.Game.Screens.Play timeCurrent.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); } } - public int Progress + public float Progress { set { - if (progress == value) - return; - - progress = value; if (currentTime > 0) - progressText.Text = value.ToString() + @"%"; + progress.Text = value.ToString("P0"); } } @@ -63,7 +58,7 @@ namespace osu.Game.Screens.Play }, Text = @"0:00", }, - progressText = new OsuSpriteText + progress = new OsuSpriteText { Origin = Anchor.BottomCentre, Anchor = Anchor.BottomCentre, From de2486b8e61481f518db0b7d1075b54f4209c261 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Mon, 8 May 2017 20:36:02 +0300 Subject: [PATCH 14/25] Moved timeLeft recalculation to property --- osu.Game/Screens/Play/SongProgressInfo.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 6719ddfb6b..d805dc2cbd 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -29,7 +29,10 @@ namespace osu.Game.Screens.Play { currentTime = value; if (value > 0) + { timeCurrent.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(songLenght - value).ToString(@"m\:ss"); + } } } public float Progress @@ -80,13 +83,5 @@ namespace osu.Game.Screens.Play } }; } - - protected override void Update() - { - base.Update(); - - if(currentTime > 0) - timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(songLenght - currentTime).ToString(@"m\:ss"); - } } } From 2826c663fd665f6f32b8da7c00504defef631a59 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 9 May 2017 06:05:37 +0300 Subject: [PATCH 15/25] Apply suggested changes --- osu.Game/Screens/Play/SongProgress.cs | 22 ++++--- osu.Game/Screens/Play/SongProgressInfo.cs | 79 +++++++++++++++-------- 2 files changed, 66 insertions(+), 35 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index e3f96bd395..3d192b990c 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -32,7 +32,15 @@ namespace osu.Game.Screens.Play public Action OnSeek; - public IClock AudioClock; + private IClock audioClock; + public IClock AudioClock + { + set + { + audioClock = value; + info.AudioClock = value; + } + } private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1; @@ -45,7 +53,9 @@ namespace osu.Game.Screens.Play set { graph.Objects = objects = value; - info.SongLenght = lastHitTime - firstHitTime; + + info.StartTime = firstHitTime; + info.EndTime = lastHitTime; } } @@ -70,7 +80,7 @@ namespace osu.Game.Screens.Play Anchor = Anchor.BottomLeft, RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, - Y = -(bottom_bar_height + graph_height), + Margin = new MarginPadding { Bottom = bottom_bar_height + graph_height }, }, graph = new SongProgressGraph { @@ -140,14 +150,10 @@ namespace osu.Game.Screens.Play if (objects == null) return; - double currentTime = (AudioClock?.CurrentTime ?? Time.Current) - firstHitTime; - float progress = (float)(currentTime / (lastHitTime - firstHitTime)); + float progress = (float)(((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime)); bar.UpdatePosition(progress); graph.Progress = (int)(graph.ColumnCount * progress); - - info.Progress = progress; - info.CurrentTime = currentTime; } } } diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index d805dc2cbd..069c977bf2 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -5,6 +5,7 @@ using osu.Framework.Allocation; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; +using osu.Framework.Timing; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using System; @@ -17,32 +18,19 @@ namespace osu.Game.Screens.Play private OsuSpriteText timeLeft; private OsuSpriteText progress; - private double currentTime; - private double songLenght; + private double startTime; + private double endTime; - private const int margin = 10; + private int previousPercent; + private int previousSecond; + private bool defaultsSetted; - public double SongLenght { set { songLenght = value; } } - public double CurrentTime - { - set - { - currentTime = value; - if (value > 0) - { - timeCurrent.Text = TimeSpan.FromMilliseconds(value).ToString(@"m\:ss"); - timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(songLenght - value).ToString(@"m\:ss"); - } - } - } - public float Progress - { - set - { - if (currentTime > 0) - progress.Text = value.ToString("P0"); - } - } + private const int margin = 10; + + public IClock AudioClock; + + public double StartTime { set { startTime = value; } } + public double EndTime { set { endTime = value; } } [BackgroundDependencyLoader] private void load(OsuColour colours) @@ -59,7 +47,6 @@ namespace osu.Game.Screens.Play { Left = margin, }, - Text = @"0:00", }, progress = new OsuSpriteText { @@ -67,7 +54,6 @@ namespace osu.Game.Screens.Play Anchor = Anchor.BottomCentre, Colour = colours.BlueLighter, Font = @"Venera", - Text = @"0%", }, timeLeft = new OsuSpriteText { @@ -79,9 +65,48 @@ namespace osu.Game.Screens.Play { Right = margin, }, - Text = @"-" + TimeSpan.FromMilliseconds(songLenght).ToString(@"m\:ss"), } }; } + + protected override void Update() + { + base.Update(); + + double songCurrentTime = AudioClock.CurrentTime - startTime; + + if (!defaultsSetted) + { + timeCurrent.Text = @"0:00"; + timeLeft.Text = TimeSpan.FromMilliseconds(endTime - startTime).ToString(@"m\:ss"); + progress.Text = @"0%"; + + defaultsSetted = true; + } + else + { + if(songCurrentTime >= 0) + { + int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; + + if (currentSecond != previousSecond) + { + previousSecond = currentSecond; + + timeCurrent.Text = TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); + } + + int currentPercent = (int)((songCurrentTime / (endTime - startTime)) * 100); + + if (currentPercent != previousPercent) + { + previousPercent = currentPercent; + + progress.Text = currentPercent.ToString() + @"%"; + } + } + } + } } } From 315f1f1256e2295ed2675921d43b32a43c4ffaf2 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 9 May 2017 06:23:03 +0300 Subject: [PATCH 16/25] CI fixes --- osu.Game/Screens/Play/SongProgressInfo.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 069c977bf2..6483a0b017 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -25,7 +25,7 @@ namespace osu.Game.Screens.Play private int previousSecond; private bool defaultsSetted; - private const int margin = 10; + private const int margin = 10; public IClock AudioClock; @@ -97,7 +97,7 @@ namespace osu.Game.Screens.Play timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); } - int currentPercent = (int)((songCurrentTime / (endTime - startTime)) * 100); + int currentPercent = (int)(songCurrentTime / (endTime - startTime) * 100); if (currentPercent != previousPercent) { From 7b17e331c46d98bcbf2a563317d98d98f74529d6 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Wed, 10 May 2017 03:45:31 +0300 Subject: [PATCH 17/25] cleanups --- osu.Game/Screens/Play/SongProgress.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 3d192b990c..548befdb36 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -33,14 +33,7 @@ namespace osu.Game.Screens.Play public Action OnSeek; private IClock audioClock; - public IClock AudioClock - { - set - { - audioClock = value; - info.AudioClock = value; - } - } + public IClock AudioClock { set { audioClock = info.AudioClock = value; } } private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1; @@ -150,9 +143,9 @@ namespace osu.Game.Screens.Play if (objects == null) return; - float progress = (float)(((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime)); + double progress = ((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime); - bar.UpdatePosition(progress); + bar.UpdatePosition((float)progress); graph.Progress = (int)(graph.ColumnCount * progress); } } From d8f9e71b846e9f822f3d9841525f89bd6a64d431 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Wed, 10 May 2017 10:14:44 +0300 Subject: [PATCH 18/25] Applied suggested changes --- osu.Game/Screens/Play/SongProgressInfo.cs | 43 ++++++++--------------- 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 6483a0b017..54a645aa99 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -23,7 +23,7 @@ namespace osu.Game.Screens.Play private int previousPercent; private int previousSecond; - private bool defaultsSetted; + private double previousTimespan; private const int margin = 10; @@ -75,37 +75,24 @@ namespace osu.Game.Screens.Play double songCurrentTime = AudioClock.CurrentTime - startTime; - if (!defaultsSetted) - { - timeCurrent.Text = @"0:00"; - timeLeft.Text = TimeSpan.FromMilliseconds(endTime - startTime).ToString(@"m\:ss"); - progress.Text = @"0%"; + int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; - defaultsSetted = true; + if (currentSecond != previousSecond || (previousTimespan < 0 && songCurrentTime > 0)) + { + previousTimespan = songCurrentTime; + previousSecond = currentSecond; + + timeCurrent.Text = ((songCurrentTime < 0) ? @"-" : @"") + TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); } - else + + int currentPercent = (int)(songCurrentTime / (endTime - startTime) * 100); + + if (currentPercent != previousPercent) { - if(songCurrentTime >= 0) - { - int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; + previousPercent = currentPercent; - if (currentSecond != previousSecond) - { - previousSecond = currentSecond; - - timeCurrent.Text = TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); - timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); - } - - int currentPercent = (int)(songCurrentTime / (endTime - startTime) * 100); - - if (currentPercent != previousPercent) - { - previousPercent = currentPercent; - - progress.Text = currentPercent.ToString() + @"%"; - } - } + progress.Text = ((currentPercent <= 0) ? @"0" : currentPercent.ToString()) + @"%"; } } } From 5b469eff6990f8f7126f424c010e8bae5e90b71a Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Wed, 10 May 2017 10:33:02 +0300 Subject: [PATCH 19/25] Fixes --- osu.Game/Screens/Play/SongProgressInfo.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 54a645aa99..88ef358fbc 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -77,12 +77,16 @@ namespace osu.Game.Screens.Play int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; - if (currentSecond != previousSecond || (previousTimespan < 0 && songCurrentTime > 0)) + if (currentSecond != previousSecond || previousTimespan < 0 && songCurrentTime > 0) { previousTimespan = songCurrentTime; previousSecond = currentSecond; - timeCurrent.Text = ((songCurrentTime < 0) ? @"-" : @"") + TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); + if(songCurrentTime < 0) + timeCurrent.Text = @"-" + TimeSpan.FromMilliseconds(songCurrentTime - 1000).ToString(@"m\:ss"); + else + timeCurrent.Text = TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); } @@ -92,7 +96,7 @@ namespace osu.Game.Screens.Play { previousPercent = currentPercent; - progress.Text = ((currentPercent <= 0) ? @"0" : currentPercent.ToString()) + @"%"; + progress.Text = (currentPercent <= 0 ? @"0" : currentPercent.ToString()) + @"%"; } } } From d55c97a08ad2cf93127022523d853c24700d1eaa Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 11 May 2017 01:48:46 +0300 Subject: [PATCH 20/25] Stop progress as soon as we at 100% --- osu.Game/Screens/Play/SongProgress.cs | 7 +++-- osu.Game/Screens/Play/SongProgressInfo.cs | 35 ++++++++++++----------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index 548befdb36..c10248e97d 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -145,8 +145,11 @@ namespace osu.Game.Screens.Play double progress = ((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime); - bar.UpdatePosition((float)progress); - graph.Progress = (int)(graph.ColumnCount * progress); + if((int)progress * 100 < 100) + { + bar.UpdatePosition((float)progress); + graph.Progress = (int)(graph.ColumnCount * progress); + } } } } diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 88ef358fbc..2767e4ec63 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -75,28 +75,31 @@ namespace osu.Game.Screens.Play double songCurrentTime = AudioClock.CurrentTime - startTime; - int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; - - if (currentSecond != previousSecond || previousTimespan < 0 && songCurrentTime > 0) + if(songCurrentTime < endTime - startTime) { - previousTimespan = songCurrentTime; - previousSecond = currentSecond; + int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; - if(songCurrentTime < 0) - timeCurrent.Text = @"-" + TimeSpan.FromMilliseconds(songCurrentTime - 1000).ToString(@"m\:ss"); - else - timeCurrent.Text = TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); + if (currentSecond != previousSecond || previousTimespan < 0 && songCurrentTime > 0) + { + previousTimespan = songCurrentTime; + previousSecond = currentSecond; - timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); - } + if (songCurrentTime < 0) + timeCurrent.Text = @"-" + TimeSpan.FromMilliseconds(songCurrentTime - 1000).ToString(@"m\:ss"); + else + timeCurrent.Text = TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); - int currentPercent = (int)(songCurrentTime / (endTime - startTime) * 100); + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); + } - if (currentPercent != previousPercent) - { - previousPercent = currentPercent; + int currentPercent = (int)(songCurrentTime / (endTime - startTime) * 100) + 1; - progress.Text = (currentPercent <= 0 ? @"0" : currentPercent.ToString()) + @"%"; + if (currentPercent != previousPercent) + { + previousPercent = currentPercent; + + progress.Text = (currentPercent <= 0 ? @"0" : currentPercent.ToString()) + @"%"; + } } } } From c0acc1799b5841d129444647b2ba687e233ccb40 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 11 May 2017 01:49:57 +0300 Subject: [PATCH 21/25] Now progress testcase has it's own clock --- osu.Desktop.VisualTests/Tests/TestCaseSongProgress.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseSongProgress.cs b/osu.Desktop.VisualTests/Tests/TestCaseSongProgress.cs index 6d8aac1d09..e3c343f5f8 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseSongProgress.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseSongProgress.cs @@ -18,10 +18,14 @@ namespace osu.Desktop.VisualTests.Tests private SongProgress progress; private SongProgressGraph graph; + private StopwatchClock clock; + public override void Reset() { base.Reset(); + clock = new StopwatchClock(true); + Add(progress = new SongProgress { RelativeSizeAxes = Axes.X, @@ -55,6 +59,9 @@ namespace osu.Desktop.VisualTests.Tests progress.Objects = objects; graph.Objects = objects; + + progress.AudioClock = clock; + progress.OnSeek = pos => clock.Seek(pos); } } } From ea0add2354cc73cf2ed8ac5650ba4e396d40e303 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Thu, 11 May 2017 02:34:57 +0300 Subject: [PATCH 22/25] Fixed update condition --- osu.Game/Screens/Play/SongProgress.cs | 2 +- osu.Game/Screens/Play/SongProgressInfo.cs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgress.cs b/osu.Game/Screens/Play/SongProgress.cs index c10248e97d..8cead0684e 100644 --- a/osu.Game/Screens/Play/SongProgress.cs +++ b/osu.Game/Screens/Play/SongProgress.cs @@ -145,7 +145,7 @@ namespace osu.Game.Screens.Play double progress = ((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime); - if((int)progress * 100 < 100) + if(progress < 1) { bar.UpdatePosition((float)progress); graph.Progress = (int)(graph.ColumnCount * progress); diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 2767e4ec63..ae6436bc6c 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -74,8 +74,9 @@ namespace osu.Game.Screens.Play base.Update(); double songCurrentTime = AudioClock.CurrentTime - startTime; + int currentPercent = (int)(songCurrentTime / (endTime - startTime) * 100); - if(songCurrentTime < endTime - startTime) + if (currentPercent <= 100) { int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; @@ -92,8 +93,6 @@ namespace osu.Game.Screens.Play timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); } - int currentPercent = (int)(songCurrentTime / (endTime - startTime) * 100) + 1; - if (currentPercent != previousPercent) { previousPercent = currentPercent; From 79ed92a0d7d3fa9d15a4a02e8e577b28654e3c4a Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Fri, 12 May 2017 01:48:28 +0300 Subject: [PATCH 23/25] Simplified logic --- osu.Game/Screens/Play/SongProgressInfo.cs | 49 ++++++++++++----------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index ae6436bc6c..0303d024b4 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -25,6 +25,11 @@ namespace osu.Game.Screens.Play private int previousSecond; private double previousTimespan; + private double songLenght => endTime - startTime; + + private bool percentHasChanged = true; + private bool secondHasChanged = true; + private const int margin = 10; public IClock AudioClock; @@ -74,32 +79,30 @@ namespace osu.Game.Screens.Play base.Update(); double songCurrentTime = AudioClock.CurrentTime - startTime; - int currentPercent = (int)(songCurrentTime / (endTime - startTime) * 100); + int currentPercent = songCurrentTime < 0 ? 0 : songCurrentTime > songLenght ? 100 : (int)(songCurrentTime / songLenght * 100); + int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; - if (currentPercent <= 100) + if (percentHasChanged) { - int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; - - if (currentSecond != previousSecond || previousTimespan < 0 && songCurrentTime > 0) - { - previousTimespan = songCurrentTime; - previousSecond = currentSecond; - - if (songCurrentTime < 0) - timeCurrent.Text = @"-" + TimeSpan.FromMilliseconds(songCurrentTime - 1000).ToString(@"m\:ss"); - else - timeCurrent.Text = TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); - - timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); - } - - if (currentPercent != previousPercent) - { - previousPercent = currentPercent; - - progress.Text = (currentPercent <= 0 ? @"0" : currentPercent.ToString()) + @"%"; - } + progress.Text = currentPercent.ToString() + @"%"; + previousPercent = currentPercent; } + + if (secondHasChanged && songCurrentTime < songLenght || previousTimespan < 0 && songCurrentTime > 0) + { + if (songCurrentTime < 0) + timeCurrent.Text = @"-" + TimeSpan.FromMilliseconds(songCurrentTime - 1000).ToString(@"m\:ss"); + else + timeCurrent.Text = TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); + + timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); + + previousSecond = currentSecond; + previousTimespan = songCurrentTime; + } + + percentHasChanged = currentPercent != previousPercent; + secondHasChanged = currentSecond != previousSecond; } } } From 34b4efc4e9ce0676258882fa4e65a06228804aa2 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Fri, 12 May 2017 08:12:34 +0300 Subject: [PATCH 24/25] Applied suggested changes --- osu.Game/Screens/Play/SongProgressInfo.cs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 0303d024b4..36bb344dab 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -23,9 +23,8 @@ namespace osu.Game.Screens.Play private int previousPercent; private int previousSecond; - private double previousTimespan; - private double songLenght => endTime - startTime; + private double songLength => endTime - startTime; private bool percentHasChanged = true; private bool secondHasChanged = true; @@ -79,8 +78,8 @@ namespace osu.Game.Screens.Play base.Update(); double songCurrentTime = AudioClock.CurrentTime - startTime; - int currentPercent = songCurrentTime < 0 ? 0 : songCurrentTime > songLenght ? 100 : (int)(songCurrentTime / songLenght * 100); - int currentSecond = TimeSpan.FromMilliseconds(songCurrentTime).Seconds; + int currentPercent = Math.Max(0, Math.Min(100, (int)(songCurrentTime / songLength * 100))); + int currentSecond = (int)Math.Floor(songCurrentTime / 1000.0); if (percentHasChanged) { @@ -88,17 +87,12 @@ namespace osu.Game.Screens.Play previousPercent = currentPercent; } - if (secondHasChanged && songCurrentTime < songLenght || previousTimespan < 0 && songCurrentTime > 0) + if (secondHasChanged && songCurrentTime < songLength) { - if (songCurrentTime < 0) - timeCurrent.Text = @"-" + TimeSpan.FromMilliseconds(songCurrentTime - 1000).ToString(@"m\:ss"); - else - timeCurrent.Text = TimeSpan.FromMilliseconds(songCurrentTime).ToString(@"m\:ss"); - - timeLeft.Text = @"-" + TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"m\:ss"); + timeCurrent.Text = TimeSpan.FromSeconds(currentSecond).ToString(songCurrentTime < 0 ? @"\-m\:ss" : @"m\:ss"); + timeLeft.Text = TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"\-m\:ss"); previousSecond = currentSecond; - previousTimespan = songCurrentTime; } percentHasChanged = currentPercent != previousPercent; From 9a040691238ab2d377128efe00a72200e178a279 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Fri, 12 May 2017 10:16:31 +0300 Subject: [PATCH 25/25] removed useless booleans, using nullables instead --- osu.Game/Screens/Play/SongProgressInfo.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/Play/SongProgressInfo.cs b/osu.Game/Screens/Play/SongProgressInfo.cs index 36bb344dab..4c53b61313 100644 --- a/osu.Game/Screens/Play/SongProgressInfo.cs +++ b/osu.Game/Screens/Play/SongProgressInfo.cs @@ -21,14 +21,11 @@ namespace osu.Game.Screens.Play private double startTime; private double endTime; - private int previousPercent; - private int previousSecond; + private int? previousPercent; + private int? previousSecond; private double songLength => endTime - startTime; - private bool percentHasChanged = true; - private bool secondHasChanged = true; - private const int margin = 10; public IClock AudioClock; @@ -81,22 +78,19 @@ namespace osu.Game.Screens.Play int currentPercent = Math.Max(0, Math.Min(100, (int)(songCurrentTime / songLength * 100))); int currentSecond = (int)Math.Floor(songCurrentTime / 1000.0); - if (percentHasChanged) + if (currentPercent != previousPercent) { progress.Text = currentPercent.ToString() + @"%"; previousPercent = currentPercent; } - if (secondHasChanged && songCurrentTime < songLength) + if (currentSecond != previousSecond && songCurrentTime < songLength) { timeCurrent.Text = TimeSpan.FromSeconds(currentSecond).ToString(songCurrentTime < 0 ? @"\-m\:ss" : @"m\:ss"); timeLeft.Text = TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"\-m\:ss"); previousSecond = currentSecond; } - - percentHasChanged = currentPercent != previousPercent; - secondHasChanged = currentSecond != previousSecond; } } }