2022-03-26 15:35:53 +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.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-03-26 16:22:48 +08:00
|
|
|
using osu.Game.Graphics;
|
2022-03-26 15:35:53 +08:00
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
{
|
|
|
|
public class ToolbarClock : CompositeDrawable
|
|
|
|
{
|
2022-03-26 16:22:48 +08:00
|
|
|
private const float hand_thickness = 2.2f;
|
|
|
|
|
2022-03-26 15:35:53 +08:00
|
|
|
public ToolbarClock()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2022-03-26 16:55:33 +08:00
|
|
|
AutoSizeAxes = Axes.X;
|
2022-03-26 15:35:53 +08:00
|
|
|
|
|
|
|
Padding = new MarginPadding(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
2022-03-26 16:55:33 +08:00
|
|
|
InternalChild = new FillFlowContainer
|
2022-03-26 15:35:53 +08:00
|
|
|
{
|
2022-03-26 16:55:33 +08:00
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Children = new Drawable[]
|
2022-03-26 15:35:53 +08:00
|
|
|
{
|
2022-03-26 16:55:33 +08:00
|
|
|
new AnalogDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
},
|
|
|
|
new DigitalDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
}
|
2022-03-26 15:35:53 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private class DigitalDisplay : ClockDisplay
|
|
|
|
{
|
2022-03-26 16:55:33 +08:00
|
|
|
private OsuSpriteText realTime;
|
|
|
|
private OsuSpriteText gameTime;
|
2022-03-26 15:35:53 +08:00
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-03-26 16:55:33 +08:00
|
|
|
private void load(OsuColour colours)
|
2022-03-26 15:35:53 +08:00
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
2022-03-26 16:55:33 +08:00
|
|
|
Width = 70; // Allows for space for game time up to 99 days.
|
2022-03-26 15:35:53 +08:00
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
2022-03-26 16:55:33 +08:00
|
|
|
realTime = new OsuSpriteText(),
|
|
|
|
gameTime = new OsuSpriteText
|
2022-03-26 15:35:53 +08:00
|
|
|
{
|
2022-03-26 16:55:33 +08:00
|
|
|
Y = 14,
|
|
|
|
Colour = colours.PurpleLight,
|
|
|
|
Scale = new Vector2(0.6f)
|
2022-03-26 15:35:53 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateDisplay(DateTimeOffset now)
|
|
|
|
{
|
2022-03-26 16:55:33 +08:00
|
|
|
realTime.Text = $"{now:HH:mm:ss}";
|
|
|
|
gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}";
|
2022-03-26 15:35:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class AnalogDisplay : ClockDisplay
|
|
|
|
{
|
|
|
|
private Drawable hour;
|
|
|
|
private Drawable minute;
|
|
|
|
private Drawable second;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-03-26 16:55:33 +08:00
|
|
|
private void load()
|
2022-03-26 15:35:53 +08:00
|
|
|
{
|
|
|
|
Size = new Vector2(30);
|
|
|
|
|
|
|
|
InternalChildren = new[]
|
|
|
|
{
|
|
|
|
new Circle
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
2022-03-26 16:22:48 +08:00
|
|
|
hour = new LargeHand(0.3f),
|
|
|
|
minute = new LargeHand(0.45f),
|
|
|
|
second = new SecondHand(),
|
|
|
|
new CentreCircle
|
2022-03-26 15:35:53 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2022-03-26 16:22:48 +08:00
|
|
|
}
|
2022-03-26 15:35:53 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-26 16:22:48 +08:00
|
|
|
private class CentreCircle : CompositeDrawable
|
|
|
|
{
|
|
|
|
public CentreCircle()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Circle
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(hand_thickness),
|
|
|
|
Colour = Color4.Black,
|
|
|
|
},
|
|
|
|
new Circle
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(hand_thickness * 0.7f),
|
|
|
|
Colour = Color4.White,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class SecondHand : CompositeDrawable
|
2022-03-26 15:35:53 +08:00
|
|
|
{
|
2022-03-26 16:22:48 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
Width = 0.54f;
|
|
|
|
|
|
|
|
Height = hand_thickness / 2;
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Custom;
|
|
|
|
|
|
|
|
OriginPosition = new Vector2(Height * 2, Height / 2);
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Circle
|
|
|
|
{
|
|
|
|
Colour = colours.YellowDark,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class LargeHand : CompositeDrawable
|
|
|
|
{
|
|
|
|
public LargeHand(float length)
|
|
|
|
{
|
|
|
|
Width = length;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
2022-03-26 15:35:53 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.CentreLeft;
|
|
|
|
|
2022-03-26 16:22:48 +08:00
|
|
|
Origin = Anchor.Custom;
|
|
|
|
OriginPosition = new Vector2(hand_thickness / 2); // offset x also, to ensure the centre of the line is centered on the face.
|
|
|
|
Height = hand_thickness;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Circle
|
|
|
|
{
|
|
|
|
Colour = colours.PurpleLight,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
BorderThickness = 0.5f,
|
|
|
|
BorderColour = colours.Purple,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-03-26 15:35:53 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateDisplay(DateTimeOffset now)
|
|
|
|
{
|
|
|
|
float secondFractional = now.Second / 60f;
|
|
|
|
float minuteFractional = (now.Minute + secondFractional) / 60f;
|
|
|
|
float hourFractional = ((minuteFractional + now.Hour) % 12) / 12f;
|
|
|
|
|
|
|
|
updateRotation(hour, hourFractional);
|
|
|
|
updateRotation(minute, minuteFractional);
|
|
|
|
updateRotation(second, secondFractional);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateRotation(Drawable hand, float fraction)
|
|
|
|
{
|
|
|
|
const float duration = 320;
|
|
|
|
|
|
|
|
float rotation = fraction * 360 - 90;
|
|
|
|
|
|
|
|
if (Math.Abs(hand.Rotation - rotation) > 180)
|
|
|
|
hand.RotateTo(rotation);
|
|
|
|
else
|
|
|
|
hand.RotateTo(rotation, duration, Easing.OutElastic);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private abstract class ClockDisplay : CompositeDrawable
|
|
|
|
{
|
2022-03-26 16:22:48 +08:00
|
|
|
private int? lastSecond;
|
2022-03-26 15:35:53 +08:00
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
var now = DateTimeOffset.Now;
|
|
|
|
|
|
|
|
if (now.Second != lastSecond)
|
|
|
|
{
|
|
|
|
lastSecond = now.Second;
|
|
|
|
UpdateDisplay(now);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract void UpdateDisplay(DateTimeOffset now);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|