Apply suggested changes

This commit is contained in:
EVAST9919 2017-05-09 06:05:37 +03:00
parent de2486b8e6
commit 2826c663fd
2 changed files with 66 additions and 35 deletions

View File

@ -32,7 +32,15 @@ namespace osu.Game.Screens.Play
public Action<double> OnSeek; public Action<double> 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; private double lastHitTime => ((objects.Last() as IHasEndTime)?.EndTime ?? objects.Last().StartTime) + 1;
@ -45,7 +53,9 @@ namespace osu.Game.Screens.Play
set set
{ {
graph.Objects = objects = value; 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, Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Y = -(bottom_bar_height + graph_height), Margin = new MarginPadding { Bottom = bottom_bar_height + graph_height },
}, },
graph = new SongProgressGraph graph = new SongProgressGraph
{ {
@ -140,14 +150,10 @@ namespace osu.Game.Screens.Play
if (objects == null) if (objects == null)
return; return;
double currentTime = (AudioClock?.CurrentTime ?? Time.Current) - firstHitTime; float progress = (float)(((audioClock?.CurrentTime ?? Time.Current) - firstHitTime) / (lastHitTime - firstHitTime));
float progress = (float)(currentTime / (lastHitTime - firstHitTime));
bar.UpdatePosition(progress); bar.UpdatePosition(progress);
graph.Progress = (int)(graph.ColumnCount * progress); graph.Progress = (int)(graph.ColumnCount * progress);
info.Progress = progress;
info.CurrentTime = currentTime;
} }
} }
} }

View File

@ -5,6 +5,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Primitives;
using osu.Framework.Timing;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using System; using System;
@ -17,32 +18,19 @@ namespace osu.Game.Screens.Play
private OsuSpriteText timeLeft; private OsuSpriteText timeLeft;
private OsuSpriteText progress; private OsuSpriteText progress;
private double currentTime; private double startTime;
private double songLenght; private double endTime;
private const int margin = 10; private int previousPercent;
private int previousSecond;
private bool defaultsSetted;
public double SongLenght { set { songLenght = value; } } private const int margin = 10;
public double CurrentTime
{ public IClock AudioClock;
set
{ public double StartTime { set { startTime = value; } }
currentTime = value; public double EndTime { set { endTime = 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");
}
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
@ -59,7 +47,6 @@ namespace osu.Game.Screens.Play
{ {
Left = margin, Left = margin,
}, },
Text = @"0:00",
}, },
progress = new OsuSpriteText progress = new OsuSpriteText
{ {
@ -67,7 +54,6 @@ namespace osu.Game.Screens.Play
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Colour = colours.BlueLighter, Colour = colours.BlueLighter,
Font = @"Venera", Font = @"Venera",
Text = @"0%",
}, },
timeLeft = new OsuSpriteText timeLeft = new OsuSpriteText
{ {
@ -79,9 +65,48 @@ namespace osu.Game.Screens.Play
{ {
Right = margin, 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() + @"%";
}
}
}
}
} }
} }