1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 16:27:26 +08:00

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 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;
}
}
}

View File

@ -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() + @"%";
}
}
}
}
}
}