From 4ddf3cb1d9293d9e374a3c945bbfcb74d9fbe1c1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 26 Mar 2022 19:18:41 +0900 Subject: [PATCH] Add ability to cycle between clock display modes --- osu.Game/Configuration/OsuConfigManager.cs | 3 + .../Configuration/ToolbarClockDisplayMode.cs | 13 +++ osu.Game/Overlays/Toolbar/ToolbarClock.cs | 85 ++++++++++++++++++- 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 osu.Game/Configuration/ToolbarClockDisplayMode.cs diff --git a/osu.Game/Configuration/OsuConfigManager.cs b/osu.Game/Configuration/OsuConfigManager.cs index c279ce1220..e8f13ba902 100644 --- a/osu.Game/Configuration/OsuConfigManager.cs +++ b/osu.Game/Configuration/OsuConfigManager.cs @@ -44,6 +44,8 @@ protected override void InitialiseDefaults() SetDefault(OsuSetting.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2f, 1f); + SetDefault(OsuSetting.ToolbarClockDisplayMode, ToolbarClockDisplayMode.Full); + // Online settings SetDefault(OsuSetting.Username, string.Empty); SetDefault(OsuSetting.Token, string.Empty); @@ -295,6 +297,7 @@ public enum OsuSetting RandomSelectAlgorithm, ShowFpsDisplay, ChatDisplayHeight, + ToolbarClockDisplayMode, Version, ShowConvertedBeatmaps, Skin, diff --git a/osu.Game/Configuration/ToolbarClockDisplayMode.cs b/osu.Game/Configuration/ToolbarClockDisplayMode.cs new file mode 100644 index 0000000000..2f42f7a9b5 --- /dev/null +++ b/osu.Game/Configuration/ToolbarClockDisplayMode.cs @@ -0,0 +1,13 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Configuration +{ + public enum ToolbarClockDisplayMode + { + Analog, + Digital, + DigitalWithRuntime, + Full + } +} diff --git a/osu.Game/Overlays/Toolbar/ToolbarClock.cs b/osu.Game/Overlays/Toolbar/ToolbarClock.cs index 1cbad6a471..68772d8fc3 100644 --- a/osu.Game/Overlays/Toolbar/ToolbarClock.cs +++ b/osu.Game/Overlays/Toolbar/ToolbarClock.cs @@ -3,9 +3,12 @@ using System; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Shapes; +using osu.Framework.Input.Events; +using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osuTK; @@ -15,6 +18,11 @@ namespace osu.Game.Overlays.Toolbar { public class ToolbarClock : CompositeDrawable { + private Bindable clockDisplayMode; + + private DigitalDisplay digital; + private AnalogDisplay analog; + private const float hand_thickness = 2.4f; public ToolbarClock() @@ -26,8 +34,10 @@ public ToolbarClock() } [BackgroundDependencyLoader] - private void load() + private void load(OsuConfigManager config) { + clockDisplayMode = config.GetBindable(OsuSetting.ToolbarClockDisplayMode); + InternalChild = new FillFlowContainer { RelativeSizeAxes = Axes.Y, @@ -36,12 +46,12 @@ private void load() Spacing = new Vector2(5), Children = new Drawable[] { - new AnalogDisplay + analog = new AnalogDisplay { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, }, - new DigitalDisplay + digital = new DigitalDisplay { Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, @@ -50,16 +60,75 @@ private void load() }; } + 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; + } + } + private class DigitalDisplay : ClockDisplay { private OsuSpriteText realTime; private OsuSpriteText gameTime; + private bool showRuntime = true; + + public bool ShowRuntime + { + get => showRuntime; + set + { + if (showRuntime == value) + return; + + showRuntime = value; + updateMetrics(); + } + } + [BackgroundDependencyLoader] private void load(OsuColour colours) { AutoSizeAxes = Axes.Y; - Width = 66; // Allows for space for game time up to 99 days (in the padding area since this is quite rare). InternalChildren = new Drawable[] { @@ -71,6 +140,8 @@ private void load(OsuColour colours) Scale = new Vector2(0.6f) } }; + + updateMetrics(); } protected override void UpdateDisplay(DateTimeOffset now) @@ -78,6 +149,12 @@ protected override void UpdateDisplay(DateTimeOffset now) realTime.Text = $"{now:HH:mm:ss}"; gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}"; } + + private void updateMetrics() + { + Width = showRuntime ? 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); + } } private class AnalogDisplay : ClockDisplay