2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-04-28 02:02:25 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2017-04-28 01:56:34 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
2022-08-05 11:56:08 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2017-04-28 01:56:34 +00:00
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2017-05-01 04:00:44 +00:00
|
|
|
|
using System;
|
2023-01-09 20:57:32 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-07-27 07:19:21 +00:00
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class SongProgressInfo : Container
|
|
|
|
|
{
|
2022-08-31 21:05:06 +00:00
|
|
|
|
private SizePreservingSpriteText timeCurrent;
|
|
|
|
|
private SizePreservingSpriteText timeLeft;
|
|
|
|
|
private SizePreservingSpriteText progress;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-09 03:05:37 +00:00
|
|
|
|
private double startTime;
|
|
|
|
|
private double endTime;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-12 07:16:31 +00:00
|
|
|
|
private int? previousPercent;
|
|
|
|
|
private int? previousSecond;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-12 05:12:34 +00:00
|
|
|
|
private double songLength => endTime - startTime;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2023-01-09 20:57:32 +00:00
|
|
|
|
public FontUsage Font
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
timeCurrent.Font = value;
|
|
|
|
|
timeLeft.Font = value;
|
|
|
|
|
progress.Font = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Colour4 TextColour
|
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
timeCurrent.Colour = value;
|
|
|
|
|
timeLeft.Colour = value;
|
|
|
|
|
progress.Colour = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public double StartTime
|
|
|
|
|
{
|
2019-02-28 05:32:57 +00:00
|
|
|
|
set => startTime = value;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 22:35:02 +00:00
|
|
|
|
public bool ShowProgress { get; init; } = true;
|
2023-01-09 20:57:32 +00:00
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public double EndTime
|
|
|
|
|
{
|
2019-02-28 05:32:57 +00:00
|
|
|
|
set => endTime = value;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2022-08-15 08:11:22 +00:00
|
|
|
|
private IGameplayClock gameplayClock;
|
2019-03-05 04:26:54 +00:00
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2022-08-15 08:11:22 +00:00
|
|
|
|
private void load(OsuColour colours, IGameplayClock clock)
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
2019-03-05 04:26:54 +00:00
|
|
|
|
if (clock != null)
|
|
|
|
|
gameplayClock = clock;
|
|
|
|
|
|
2022-09-15 10:11:58 +00:00
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2017-04-28 01:56:34 +00:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2022-08-01 20:46:37 +00:00
|
|
|
|
new Container
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
2022-08-05 11:56:08 +00:00
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
2022-08-01 20:46:37 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2022-08-26 06:56:47 +00:00
|
|
|
|
Child = new UprightAspectMaintainingContainer
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
2022-08-05 11:56:08 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2022-08-07 12:20:22 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2022-08-26 00:30:44 +00:00
|
|
|
|
Scaling = ScaleMode.Vertical,
|
|
|
|
|
ScalingFactor = 0.5f,
|
2022-08-31 21:05:06 +00:00
|
|
|
|
Child = timeCurrent = new SizePreservingSpriteText
|
2022-08-01 20:46:37 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2022-08-22 13:24:52 +00:00
|
|
|
|
Colour = colours.BlueLighter,
|
|
|
|
|
Font = OsuFont.Numeric,
|
2022-08-01 20:46:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-28 01:56:34 +00:00
|
|
|
|
},
|
2022-08-01 20:46:37 +00:00
|
|
|
|
new Container
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
2022-08-05 11:56:08 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2022-08-01 20:46:37 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2023-01-09 20:57:32 +00:00
|
|
|
|
Alpha = ShowProgress ? 1 : 0,
|
2022-08-26 06:56:47 +00:00
|
|
|
|
Child = new UprightAspectMaintainingContainer
|
2022-08-01 20:46:37 +00:00
|
|
|
|
{
|
2022-08-05 11:56:08 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2022-08-07 12:20:22 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2022-08-26 00:30:44 +00:00
|
|
|
|
Scaling = ScaleMode.Vertical,
|
|
|
|
|
ScalingFactor = 0.5f,
|
2022-08-31 21:05:06 +00:00
|
|
|
|
Child = progress = new SizePreservingSpriteText
|
2022-08-01 20:46:37 +00:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2022-08-22 13:24:52 +00:00
|
|
|
|
Colour = colours.BlueLighter,
|
|
|
|
|
Font = OsuFont.Numeric,
|
2022-08-07 12:20:22 +00:00
|
|
|
|
}
|
2022-08-01 20:46:37 +00:00
|
|
|
|
}
|
2017-04-28 01:56:34 +00:00
|
|
|
|
},
|
2022-08-01 20:46:37 +00:00
|
|
|
|
new Container
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
2022-08-05 11:56:08 +00:00
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
2022-08-01 20:46:37 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2022-08-26 06:56:47 +00:00
|
|
|
|
Child = new UprightAspectMaintainingContainer
|
2017-04-28 01:56:34 +00:00
|
|
|
|
{
|
2023-02-10 16:58:48 +00:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
2022-08-07 12:20:22 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2022-08-26 00:30:44 +00:00
|
|
|
|
Scaling = ScaleMode.Vertical,
|
|
|
|
|
ScalingFactor = 0.5f,
|
2022-08-31 21:05:06 +00:00
|
|
|
|
Child = timeLeft = new SizePreservingSpriteText
|
2022-08-01 20:46:37 +00:00
|
|
|
|
{
|
2023-01-09 20:57:32 +00:00
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
2022-08-22 13:24:52 +00:00
|
|
|
|
Colour = colours.BlueLighter,
|
|
|
|
|
Font = OsuFont.Numeric,
|
2022-08-01 20:46:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-28 01:56:34 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-09 03:05:37 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-10-27 04:04:41 +00:00
|
|
|
|
double time = gameplayClock?.CurrentTime ?? Time.Current;
|
2019-03-05 04:26:54 +00:00
|
|
|
|
|
|
|
|
|
double songCurrentTime = time - 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);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-12 07:16:31 +00:00
|
|
|
|
if (currentPercent != previousPercent)
|
2017-05-09 03:05:37 +00:00
|
|
|
|
{
|
2023-01-09 20:57:32 +00:00
|
|
|
|
progress.Text = currentPercent + @"%";
|
2017-05-11 22:48:28 +00:00
|
|
|
|
previousPercent = currentPercent;
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-12 07:16:31 +00:00
|
|
|
|
if (currentSecond != previousSecond && songCurrentTime < songLength)
|
2017-05-11 22:48:28 +00:00
|
|
|
|
{
|
2018-05-11 13:09:53 +00:00
|
|
|
|
timeCurrent.Text = formatTime(TimeSpan.FromSeconds(currentSecond));
|
2019-03-05 04:26:54 +00:00
|
|
|
|
timeLeft.Text = formatTime(TimeSpan.FromMilliseconds(endTime - time));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-05-11 22:48:28 +00:00
|
|
|
|
previousSecond = currentSecond;
|
2017-05-09 03:05:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-11 13:09:53 +00:00
|
|
|
|
|
2018-06-02 09:25:49 +00:00
|
|
|
|
private string formatTime(TimeSpan timeSpan) => $"{(timeSpan < TimeSpan.Zero ? "-" : "")}{Math.Floor(timeSpan.Duration().TotalMinutes)}:{timeSpan.Duration().Seconds:D2}";
|
2017-04-28 01:56:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|