Skip to content

Commit

Permalink
Merge pull request #31885 from peppy/clock-align
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy authored Feb 16, 2025
2 parents 4c851a3 + b21dd01 commit 605979e
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions osu.Game/Overlays/Toolbar/DigitalClockDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
using osu.Framework.Allocation;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;

namespace osu.Game.Overlays.Toolbar
{
Expand All @@ -17,6 +19,8 @@ public partial class DigitalClockDisplay : ClockDisplay
private OsuSpriteText realTime;
private OsuSpriteText gameTime;

private FillFlowContainer runningText;

private bool showRuntime = true;

public bool ShowRuntime
Expand Down Expand Up @@ -52,17 +56,36 @@ public bool Use24HourDisplay
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
AutoSizeAxes = Axes.Y;
AutoSizeAxes = Axes.Both;

InternalChildren = new Drawable[]
{
realTime = new OsuSpriteText(),
gameTime = new OsuSpriteText
realTime = new OsuSpriteText
{
Font = OsuFont.Default.With(fixedWidth: true),
Spacing = new Vector2(-1.5f, 0),
},
runningText = new FillFlowContainer
{
Y = 14,
Colour = colours.PinkLight,
Font = OsuFont.Default.With(size: 10, weight: FontWeight.SemiBold),
}
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(2, 0),
Children = new Drawable[]
{
new OsuSpriteText
{
Text = "running",
Font = OsuFont.Default.With(size: 10, weight: FontWeight.SemiBold),
},
gameTime = new OsuSpriteText
{
Font = OsuFont.Default.With(size: 10, fixedWidth: true, weight: FontWeight.SemiBold),
Spacing = new Vector2(-0.5f, 0),
}
}
},
};

updateMetrics();
Expand All @@ -71,14 +94,12 @@ private void load(OsuColour colours)
protected override void UpdateDisplay(DateTimeOffset now)
{
realTime.Text = now.ToLocalisableString(use24HourDisplay ? @"HH:mm:ss" : @"h:mm:ss tt");
gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
gameTime.Text = $"{new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
}

private void updateMetrics()
{
Width = showRuntime || !use24HourDisplay ? 66 : 45; // Allows for space for game time up to 99 days (in the padding area since this is quite rare).

gameTime.FadeTo(showRuntime ? 1 : 0);
runningText.FadeTo(showRuntime ? 1 : 0);
}
}
}

0 comments on commit 605979e

Please sign in to comment.