From 2826c663fd665f6f32b8da7c00504defef631a59 Mon Sep 17 00:00:00 2001 From: EVAST9919 Date: Tue, 9 May 2017 06:05:37 +0300 Subject: [PATCH] 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() + @"%"; + } + } + } + } } }