2019-01-24 17:43:03 +09:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2022-06-17 16:37:17 +09:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-04-28 05:02:25 +03:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-04-28 04:56:34 +03:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-05-01 07:00:44 +03:00
|
|
|
|
using System;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2022-07-27 15:19:21 +08:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2017-04-28 04:56:34 +03:00
|
|
|
|
{
|
|
|
|
|
public class SongProgressInfo : Container
|
|
|
|
|
{
|
2017-05-08 19:14:19 +03:00
|
|
|
|
private OsuSpriteText timeCurrent;
|
2017-04-28 16:02:00 +03:00
|
|
|
|
private OsuSpriteText timeLeft;
|
2017-05-08 19:42:36 +03:00
|
|
|
|
private OsuSpriteText progress;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-09 06:05:37 +03:00
|
|
|
|
private double startTime;
|
|
|
|
|
private double endTime;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-12 10:16:31 +03:00
|
|
|
|
private int? previousPercent;
|
|
|
|
|
private int? previousSecond;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-12 08:12:34 +03:00
|
|
|
|
private double songLength => endTime - startTime;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-09 06:23:03 +03:00
|
|
|
|
private const int margin = 10;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-02-28 13:31:40 +09:00
|
|
|
|
public double StartTime
|
|
|
|
|
{
|
2019-02-28 14:32:57 +09:00
|
|
|
|
set => startTime = value;
|
2019-02-28 13:31:40 +09:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public double EndTime
|
|
|
|
|
{
|
2019-02-28 14:32:57 +09:00
|
|
|
|
set => endTime = value;
|
2019-02-28 13:31:40 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2022-08-15 17:11:22 +09:00
|
|
|
|
private IGameplayClock gameplayClock;
|
2019-03-05 13:26:54 +09:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-08-15 17:11:22 +09:00
|
|
|
|
private void load(OsuColour colours, IGameplayClock clock)
|
2017-04-28 04:56:34 +03:00
|
|
|
|
{
|
2019-03-05 13:26:54 +09:00
|
|
|
|
if (clock != null)
|
|
|
|
|
gameplayClock = clock;
|
|
|
|
|
|
2017-04-28 04:56:34 +03:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2017-05-08 19:14:19 +03:00
|
|
|
|
timeCurrent = new OsuSpriteText
|
2017-04-28 04:56:34 +03:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomLeft,
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2017-04-28 16:02:00 +03:00
|
|
|
|
Colour = colours.BlueLighter,
|
2019-02-22 19:42:09 +09:00
|
|
|
|
Font = OsuFont.Numeric,
|
2017-04-28 04:56:34 +03:00
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Left = margin,
|
|
|
|
|
},
|
|
|
|
|
},
|
2017-05-08 19:42:36 +03:00
|
|
|
|
progress = new OsuSpriteText
|
2017-04-28 04:56:34 +03:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2017-04-28 16:02:00 +03:00
|
|
|
|
Colour = colours.BlueLighter,
|
2019-02-22 19:42:09 +09:00
|
|
|
|
Font = OsuFont.Numeric,
|
2017-04-28 04:56:34 +03:00
|
|
|
|
},
|
2017-04-28 16:02:00 +03:00
|
|
|
|
timeLeft = new OsuSpriteText
|
2017-04-28 04:56:34 +03:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomRight,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
2017-04-28 16:02:00 +03:00
|
|
|
|
Colour = colours.BlueLighter,
|
2019-02-22 19:42:09 +09:00
|
|
|
|
Font = OsuFont.Numeric,
|
2017-04-28 04:56:34 +03:00
|
|
|
|
Margin = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Right = margin,
|
2017-05-08 19:14:19 +03:00
|
|
|
|
},
|
2017-04-28 04:56:34 +03:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-09 06:05:37 +03:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-10-27 13:04:41 +09:00
|
|
|
|
double time = gameplayClock?.CurrentTime ?? Time.Current;
|
2019-03-05 13:26:54 +09:00
|
|
|
|
|
|
|
|
|
double songCurrentTime = time - startTime;
|
2017-05-12 08:12:34 +03:00
|
|
|
|
int currentPercent = Math.Max(0, Math.Min(100, (int)(songCurrentTime / songLength * 100)));
|
|
|
|
|
int currentSecond = (int)Math.Floor(songCurrentTime / 1000.0);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-12 10:16:31 +03:00
|
|
|
|
if (currentPercent != previousPercent)
|
2017-05-09 06:05:37 +03:00
|
|
|
|
{
|
2017-05-12 01:48:28 +03:00
|
|
|
|
progress.Text = currentPercent.ToString() + @"%";
|
|
|
|
|
previousPercent = currentPercent;
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-12 10:16:31 +03:00
|
|
|
|
if (currentSecond != previousSecond && songCurrentTime < songLength)
|
2017-05-12 01:48:28 +03:00
|
|
|
|
{
|
2018-05-11 22:09:53 +09:00
|
|
|
|
timeCurrent.Text = formatTime(TimeSpan.FromSeconds(currentSecond));
|
2019-03-05 13:26:54 +09:00
|
|
|
|
timeLeft.Text = formatTime(TimeSpan.FromMilliseconds(endTime - time));
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2017-05-12 01:48:28 +03:00
|
|
|
|
previousSecond = currentSecond;
|
2017-05-09 06:05:37 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-11 22:09:53 +09:00
|
|
|
|
|
2018-06-02 11:25:49 +02:00
|
|
|
|
private string formatTime(TimeSpan timeSpan) => $"{(timeSpan < TimeSpan.Zero ? "-" : "")}{Math.Floor(timeSpan.Duration().TotalMinutes)}:{timeSpan.Duration().Seconds:D2}";
|
2017-04-28 04:56:34 +03:00
|
|
|
|
}
|
|
|
|
|
}
|