2022-03-26 19:34:17 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2022-03-26 19:34:17 +08:00
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
{
|
|
|
|
public class DigitalClockDisplay : ClockDisplay
|
|
|
|
{
|
|
|
|
private OsuSpriteText realTime;
|
|
|
|
private OsuSpriteText gameTime;
|
|
|
|
|
|
|
|
private bool showRuntime = true;
|
|
|
|
|
|
|
|
public bool ShowRuntime
|
|
|
|
{
|
|
|
|
get => showRuntime;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (showRuntime == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
showRuntime = value;
|
|
|
|
updateMetrics();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-07 17:11:30 +08:00
|
|
|
private bool use24HourDisplay;
|
2022-04-06 04:21:28 +08:00
|
|
|
|
2022-04-07 17:11:30 +08:00
|
|
|
public bool Use24HourDisplay
|
2022-04-06 04:21:28 +08:00
|
|
|
{
|
2022-04-07 17:11:30 +08:00
|
|
|
get => use24HourDisplay;
|
2022-04-06 04:21:28 +08:00
|
|
|
set
|
|
|
|
{
|
2022-04-07 17:11:30 +08:00
|
|
|
if (use24HourDisplay == value)
|
2022-04-06 04:21:28 +08:00
|
|
|
return;
|
|
|
|
|
2022-04-07 17:11:30 +08:00
|
|
|
use24HourDisplay = value;
|
2022-04-07 20:56:12 +08:00
|
|
|
|
2022-04-06 04:21:28 +08:00
|
|
|
updateMetrics();
|
|
|
|
UpdateDisplay(DateTimeOffset.Now); //Update realTime.Text immediately instead of waiting until next second
|
|
|
|
}
|
|
|
|
}
|
2022-04-06 03:10:55 +08:00
|
|
|
|
2022-03-26 19:34:17 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
realTime = new OsuSpriteText(),
|
|
|
|
gameTime = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Y = 14,
|
|
|
|
Colour = colours.PinkLight,
|
2022-03-31 18:07:17 +08:00
|
|
|
Font = OsuFont.Default.With(size: 10, weight: FontWeight.SemiBold),
|
2022-03-26 19:34:17 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
updateMetrics();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateDisplay(DateTimeOffset now)
|
|
|
|
{
|
2022-04-07 20:56:12 +08:00
|
|
|
realTime.Text = use24HourDisplay ? $"{now:HH:mm:ss}" : $"{now:h:mm:ss tt}";
|
2022-03-26 19:34:17 +08:00
|
|
|
gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateMetrics()
|
|
|
|
{
|
2022-04-08 00:24:15 +08:00
|
|
|
Width = showRuntime || !use24HourDisplay ? 66 : 45; // Allows for space for game time up to 99 days (in the padding area since this is quite rare).
|
2022-04-06 03:10:55 +08:00
|
|
|
|
2022-03-26 19:34:17 +08:00
|
|
|
gameTime.FadeTo(showRuntime ? 1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|