mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Tidy up clock logic using DI and a GameplayClock
This commit is contained in:
@ -4,7 +4,6 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Timing;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using System;
|
||||
@ -27,8 +26,6 @@ namespace osu.Game.Screens.Play
|
||||
|
||||
private const int margin = 10;
|
||||
|
||||
public IClock AudioClock;
|
||||
|
||||
public double StartTime
|
||||
{
|
||||
set => startTime = value;
|
||||
@ -39,9 +36,14 @@ namespace osu.Game.Screens.Play
|
||||
set => endTime = value;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
private GameplayClock gameplayClock;
|
||||
|
||||
[BackgroundDependencyLoader(true)]
|
||||
private void load(OsuColour colours, GameplayClock clock)
|
||||
{
|
||||
if (clock != null)
|
||||
gameplayClock = clock;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
timeCurrent = new OsuSpriteText
|
||||
@ -80,7 +82,9 @@ namespace osu.Game.Screens.Play
|
||||
{
|
||||
base.Update();
|
||||
|
||||
double songCurrentTime = AudioClock.CurrentTime - startTime;
|
||||
var time = gameplayClock?.CurrentTime ?? Time.Current;
|
||||
|
||||
double songCurrentTime = time - startTime;
|
||||
int currentPercent = Math.Max(0, Math.Min(100, (int)(songCurrentTime / songLength * 100)));
|
||||
int currentSecond = (int)Math.Floor(songCurrentTime / 1000.0);
|
||||
|
||||
@ -93,7 +97,7 @@ namespace osu.Game.Screens.Play
|
||||
if (currentSecond != previousSecond && songCurrentTime < songLength)
|
||||
{
|
||||
timeCurrent.Text = formatTime(TimeSpan.FromSeconds(currentSecond));
|
||||
timeLeft.Text = formatTime(TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime));
|
||||
timeLeft.Text = formatTime(TimeSpan.FromMilliseconds(endTime - time));
|
||||
|
||||
previousSecond = currentSecond;
|
||||
}
|
||||
|
Reference in New Issue
Block a user