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