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.
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2022-03-26 10:18:41 +00:00
|
|
|
using osu.Framework.Bindables;
|
2022-03-26 07:35:53 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-03-26 10:18:41 +00:00
|
|
|
using osu.Framework.Input.Events;
|
|
|
|
using osu.Game.Configuration;
|
2022-03-26 07:35:53 +00:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
{
|
|
|
|
public class ToolbarClock : CompositeDrawable
|
|
|
|
{
|
2022-03-26 10:18:41 +00:00
|
|
|
private Bindable<ToolbarClockDisplayMode> clockDisplayMode;
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2022-03-26 08:55:33 +00:00
|
|
|
AutoSizeAxes = Axes.X;
|
2022-03-26 07:35:53 +00:00
|
|
|
|
2022-03-26 09:13:33 +00:00
|
|
|
Padding = new MarginPadding(5);
|
2022-03-26 07:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-03-26 10:18:41 +00:00
|
|
|
private void load(OsuConfigManager config)
|
2022-03-26 07:35:53 +00:00
|
|
|
{
|
2022-03-26 10:18:41 +00:00
|
|
|
clockDisplayMode = config.GetBindable<ToolbarClockDisplayMode>(OsuSetting.ToolbarClockDisplayMode);
|
|
|
|
|
2022-03-26 08:55:33 +00:00
|
|
|
InternalChild = new FillFlowContainer
|
2022-03-26 07:35:53 +00:00
|
|
|
{
|
2022-03-26 08:55:33 +00:00
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Children = new Drawable[]
|
2022-03-26 07:35:53 +00:00
|
|
|
{
|
2022-03-26 11:34:17 +00:00
|
|
|
analog = new AnalogClockDisplay
|
2022-03-26 08:55:33 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
},
|
2022-03-26 11:34:17 +00:00
|
|
|
digital = new DigitalClockDisplay
|
2022-03-26 08:55:33 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
|
|
{
|
|
|
|
cycleDisplayMode();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|