1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 15:33:21 +08:00

Show game time display in clock

This commit is contained in:
Dean Herbert 2022-03-26 17:55:33 +09:00
parent e8f5a8e3d6
commit 999ae88af2
2 changed files with 45 additions and 18 deletions

View File

@ -5,6 +5,7 @@ using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Timing;
using osu.Game.Overlays.Toolbar; using osu.Game.Overlays.Toolbar;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
@ -14,11 +15,13 @@ namespace osu.Game.Tests.Visual.Menus
[TestFixture] [TestFixture]
public class TestSceneToolbarClock : OsuManualInputManagerTestScene public class TestSceneToolbarClock : OsuManualInputManagerTestScene
{ {
private readonly Container mainContainer;
public TestSceneToolbarClock() public TestSceneToolbarClock()
{ {
Children = new Drawable[] Children = new Drawable[]
{ {
new Container mainContainer = new Container
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
@ -60,5 +63,17 @@ namespace osu.Game.Tests.Visual.Menus
}, },
}; };
} }
[Test]
public void TestRealGameTime()
{
AddStep("Set game time real", () => mainContainer.Clock = Clock);
}
[Test]
public void TestLongGameTime()
{
AddStep("Set game time long", () => mainContainer.Clock = new FramedOffsetClock(Clock, false) { Offset = 3600.0 * 24 * 1000 * 98 });
}
} }
} }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Toolbar
public ToolbarClock() public ToolbarClock()
{ {
RelativeSizeAxes = Axes.Y; RelativeSizeAxes = Axes.Y;
Width = 110; AutoSizeAxes = Axes.X;
Padding = new MarginPadding(10); Padding = new MarginPadding(10);
} }
@ -28,43 +28,55 @@ namespace osu.Game.Overlays.Toolbar
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
InternalChildren = new Drawable[] InternalChild = new FillFlowContainer
{ {
new AnalogDisplay RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(5),
Children = new Drawable[]
{ {
Anchor = Anchor.CentreLeft, new AnalogDisplay
Origin = Anchor.CentreLeft, {
}, Anchor = Anchor.CentreLeft,
new DigitalDisplay Origin = Anchor.CentreLeft,
{ },
Anchor = Anchor.CentreRight, new DigitalDisplay
Origin = Anchor.CentreRight, {
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
}
} }
}; };
} }
private class DigitalDisplay : ClockDisplay private class DigitalDisplay : ClockDisplay
{ {
private OsuSpriteText text; private OsuSpriteText realTime;
private OsuSpriteText gameTime;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(OsuColour colours)
{ {
AutoSizeAxes = Axes.Y; AutoSizeAxes = Axes.Y;
Width = 50; Width = 70; // Allows for space for game time up to 99 days.
InternalChildren = new Drawable[] InternalChildren = new Drawable[]
{ {
text = new OsuSpriteText realTime = new OsuSpriteText(),
gameTime = new OsuSpriteText
{ {
Text = "00:00:00", Y = 14,
Colour = colours.PurpleLight,
Scale = new Vector2(0.6f)
} }
}; };
} }
protected override void UpdateDisplay(DateTimeOffset now) protected override void UpdateDisplay(DateTimeOffset now)
{ {
text.Text = $"{now:HH:mm:ss}"; realTime.Text = $"{now:HH:mm:ss}";
gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
} }
} }
@ -75,7 +87,7 @@ namespace osu.Game.Overlays.Toolbar
private Drawable second; private Drawable second;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load()
{ {
Size = new Vector2(30); Size = new Vector2(30);