2017-04-28 02:02:25 +00:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-04-28 01:56:34 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-05-09 03:05:37 +00:00
|
|
|
|
using osu.Framework.Timing;
|
2017-04-28 01:56:34 +00:00
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-05-01 04:00:44 +00:00
|
|
|
|
using System;
|
2017-04-28 01:56:34 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
|
|
|
|
public class SongProgressInfo : Container
|
|
|
|
|
{
|
2017-05-08 16:14:19 +00:00
|
|
|
|
private OsuSpriteText timeCurrent;
|
2017-04-28 13:02:00 +00:00
|
|
|
|
private OsuSpriteText timeLeft;
|
2017-05-08 16:42:36 +00:00
|
|
|
|
private OsuSpriteText progress;
|
2017-05-07 21:16:58 +00:00
|
|
|
|
|
2017-05-09 03:05:37 +00:00
|
|
|
|
private double startTime;
|
|
|
|
|
private double endTime;
|
2017-04-28 01:56:34 +00:00
|
|
|
|
|
2017-05-12 07:16:31 +00:00
|
|
|
|
private int? previousPercent;
|
|
|
|
|
private int? previousSecond;
|
2017-04-28 01:56:34 +00:00
|
|
|
|
|
2017-05-12 05:12:34 +00:00
|
|
|
|
private double songLength => endTime - startTime;
|
2017-05-11 22:48:28 +00:00
|
|
|
|
|
2017-05-09 03:23:03 +00:00
|
|
|
|
private const int margin = 10;
|
2017-05-09 03:05:37 +00:00
|
|
|
|
|
|
|
|
|
public IClock AudioClock;
|
|
|
|
|
|
|
|
|
|
public double StartTime { set { startTime = value; } }
|
|
|
|
|
public double EndTime { set { endTime = value; } }
|
2017-04-28 01:56:34 +00:00
|
|
|
|
|
2017-04-28 13:02:00 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-08 16:14:19 +00:00
|
|
|
|
timeCurrent = new OsuSpriteText
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2017-04-28 13:02:00 +00:00
|
|
|
|
Colour = colours.BlueLighter,
|
|
|
|
|
Font = @"Venera",
|
2017-04-28 01:56:34 +00:00
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Left = margin,
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-05-08 16:42:36 +00:00
|
|
|
|
progress = new OsuSpriteText
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2017-04-28 13:02:00 +00:00
|
|
|
|
Colour = colours.BlueLighter,
|
|
|
|
|
Font = @"Venera",
|
2017-04-28 01:56:34 +00:00
|
|
|
|
},
|
2017-04-28 13:02:00 +00:00
|
|
|
|
timeLeft = new OsuSpriteText
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
2017-04-28 13:02:00 +00:00
|
|
|
|
Colour = colours.BlueLighter,
|
|
|
|
|
Font = @"Venera",
|
2017-04-28 01:56:34 +00:00
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Right = margin,
|
2017-05-08 16:14:19 +00:00
|
|
|
|
},
|
2017-04-28 01:56:34 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-05-09 03:05:37 +00:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
double songCurrentTime = AudioClock.CurrentTime - startTime;
|
2017-05-12 05:12:34 +00:00
|
|
|
|
int currentPercent = Math.Max(0, Math.Min(100, (int)(songCurrentTime / songLength * 100)));
|
|
|
|
|
int currentSecond = (int)Math.Floor(songCurrentTime / 1000.0);
|
2017-05-09 03:05:37 +00:00
|
|
|
|
|
2017-05-12 07:16:31 +00:00
|
|
|
|
if (currentPercent != previousPercent)
|
2017-05-09 03:05:37 +00:00
|
|
|
|
{
|
2017-05-11 22:48:28 +00:00
|
|
|
|
progress.Text = currentPercent.ToString() + @"%";
|
|
|
|
|
previousPercent = currentPercent;
|
|
|
|
|
}
|
2017-05-10 07:33:02 +00:00
|
|
|
|
|
2017-05-12 07:16:31 +00:00
|
|
|
|
if (currentSecond != previousSecond && songCurrentTime < songLength)
|
2017-05-11 22:48:28 +00:00
|
|
|
|
{
|
2017-05-12 05:12:34 +00:00
|
|
|
|
timeCurrent.Text = TimeSpan.FromSeconds(currentSecond).ToString(songCurrentTime < 0 ? @"\-m\:ss" : @"m\:ss");
|
|
|
|
|
timeLeft.Text = TimeSpan.FromMilliseconds(endTime - AudioClock.CurrentTime).ToString(@"\-m\:ss");
|
2017-05-09 03:05:37 +00:00
|
|
|
|
|
2017-05-11 22:48:28 +00:00
|
|
|
|
previousSecond = currentSecond;
|
2017-05-09 03:05:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-28 01:56:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|