2022-03-26 07:35:53 +00: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-04-05 20:21:28 +00:00
|
|
|
using System.Globalization;
|
2022-03-26 07:35:53 +00:00
|
|
|
using osu.Framework.Allocation;
|
2022-03-26 10:18:41 +00:00
|
|
|
using osu.Framework.Bindables;
|
2022-03-31 14:26:53 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2022-03-26 07:35:53 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-03-31 14:26:53 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2022-03-26 10:18:41 +00:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Configuration;
|
2022-03-31 14:26:53 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2022-03-26 07:35:53 +00:00
|
|
|
using osuTK;
|
2022-03-31 14:26:53 +00:00
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2022-03-26 07:35:53 +00:00
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
{
|
2022-03-31 14:26:53 +00:00
|
|
|
public class ToolbarClock : OsuClickableContainer
|
2022-03-26 07:35:53 +00:00
|
|
|
{
|
2022-03-26 10:18:41 +00:00
|
|
|
private Bindable<ToolbarClockDisplayMode> clockDisplayMode;
|
2022-04-05 20:21:28 +00:00
|
|
|
private Bindable<bool> digitalPrefer24Hour;
|
2022-03-26 10:18:41 +00:00
|
|
|
|
2022-03-31 18:39:26 +00:00
|
|
|
private Box hoverBackground;
|
|
|
|
private Box flashBackground;
|
2022-03-31 14:26:53 +00:00
|
|
|
|
2022-03-26 11:34:17 +00:00
|
|
|
private DigitalClockDisplay digital;
|
|
|
|
private AnalogClockDisplay analog;
|
2022-03-26 08:22:48 +00:00
|
|
|
|
2022-03-26 07:35:53 +00:00
|
|
|
public ToolbarClock()
|
2022-03-31 14:26:53 +00:00
|
|
|
: base(HoverSampleSet.Toolbar)
|
2022-03-26 07:35:53 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2022-03-26 08:55:33 +00:00
|
|
|
AutoSizeAxes = Axes.X;
|
2022-03-31 18:39:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuConfigManager config)
|
|
|
|
{
|
|
|
|
clockDisplayMode = config.GetBindable<ToolbarClockDisplayMode>(OsuSetting.ToolbarClockDisplayMode);
|
2022-04-05 20:21:28 +00:00
|
|
|
digitalPrefer24Hour = config.GetBindable<bool>(OsuSetting.Prefer24HourTime);
|
2022-03-26 07:35:53 +00:00
|
|
|
|
2022-03-31 14:26:53 +00:00
|
|
|
Children = new Drawable[]
|
2022-03-26 07:35:53 +00:00
|
|
|
{
|
2022-03-31 18:39:26 +00:00
|
|
|
hoverBackground = new Box
|
2022-03-26 07:35:53 +00:00
|
|
|
{
|
2022-03-31 14:26:53 +00:00
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.Gray(80).Opacity(180),
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
Alpha = 0,
|
|
|
|
},
|
|
|
|
flashBackground = new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Alpha = 0,
|
|
|
|
Colour = Color4.White.Opacity(100),
|
|
|
|
Blending = BlendingParameters.Additive,
|
|
|
|
},
|
2022-03-31 18:39:26 +00:00
|
|
|
new FillFlowContainer
|
2022-03-31 14:26:53 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Padding = new MarginPadding(10),
|
|
|
|
Children = new Drawable[]
|
2022-03-26 08:55:33 +00:00
|
|
|
{
|
2022-03-31 14:26:53 +00:00
|
|
|
analog = new AnalogClockDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
},
|
|
|
|
digital = new DigitalClockDisplay
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
}
|
2022-03-26 08:55:33 +00:00
|
|
|
}
|
2022-03-26 07:35:53 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-03-26 10:18:41 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
clockDisplayMode.BindValueChanged(displayMode =>
|
|
|
|
{
|
|
|
|
bool showAnalog = displayMode.NewValue == ToolbarClockDisplayMode.Analog || displayMode.NewValue == ToolbarClockDisplayMode.Full;
|
|
|
|
bool showDigital = displayMode.NewValue != ToolbarClockDisplayMode.Analog;
|
|
|
|
bool showRuntime = displayMode.NewValue == ToolbarClockDisplayMode.DigitalWithRuntime || displayMode.NewValue == ToolbarClockDisplayMode.Full;
|
|
|
|
|
|
|
|
digital.FadeTo(showDigital ? 1 : 0);
|
|
|
|
digital.ShowRuntime = showRuntime;
|
|
|
|
|
|
|
|
analog.FadeTo(showAnalog ? 1 : 0);
|
|
|
|
}, true);
|
2022-04-05 20:21:28 +00:00
|
|
|
|
|
|
|
digitalPrefer24Hour.BindValueChanged(prefer24H =>
|
|
|
|
digital.Format12H = prefer24H.NewValue ? false : CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.Contains("tt"), true);
|
2022-03-26 10:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
2022-03-31 14:26:53 +00:00
|
|
|
flashBackground.FadeOutFromOne(800, Easing.OutQuint);
|
|
|
|
|
2022-03-26 10:18:41 +00:00
|
|
|
cycleDisplayMode();
|
2022-03-31 14:26:53 +00:00
|
|
|
|
|
|
|
return base.OnClick(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
2022-03-31 18:39:26 +00:00
|
|
|
hoverBackground.FadeIn(200);
|
2022-03-31 14:26:53 +00:00
|
|
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
2022-03-31 18:39:26 +00:00
|
|
|
hoverBackground.FadeOut(200);
|
|
|
|
|
|
|
|
base.OnHoverLost(e);
|
2022-03-26 10:18:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void cycleDisplayMode()
|
|
|
|
{
|
|
|
|
switch (clockDisplayMode.Value)
|
|
|
|
{
|
|
|
|
case ToolbarClockDisplayMode.Analog:
|
|
|
|
clockDisplayMode.Value = ToolbarClockDisplayMode.Full;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ToolbarClockDisplayMode.Digital:
|
|
|
|
clockDisplayMode.Value = ToolbarClockDisplayMode.Analog;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ToolbarClockDisplayMode.DigitalWithRuntime:
|
|
|
|
clockDisplayMode.Value = ToolbarClockDisplayMode.Digital;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ToolbarClockDisplayMode.Full:
|
|
|
|
clockDisplayMode.Value = ToolbarClockDisplayMode.DigitalWithRuntime;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-03-26 07:35:53 +00:00
|
|
|
}
|
|
|
|
}
|