mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 04:13:21 +08:00
Simplified logic
This commit is contained in:
parent
1f34cec5ce
commit
79ed92a0d7
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user