1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 21:02:54 +08:00

Add ability to cycle between clock display modes

This commit is contained in:
Dean Herbert 2022-03-26 19:18:41 +09:00
parent 97e9049a2c
commit 4ddf3cb1d9
3 changed files with 97 additions and 4 deletions

View File

@ -44,6 +44,8 @@ namespace osu.Game.Configuration
SetDefault(OsuSetting.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2f, 1f); SetDefault(OsuSetting.ChatDisplayHeight, ChatOverlay.DEFAULT_HEIGHT, 0.2f, 1f);
SetDefault(OsuSetting.ToolbarClockDisplayMode, ToolbarClockDisplayMode.Full);
// Online settings // Online settings
SetDefault(OsuSetting.Username, string.Empty); SetDefault(OsuSetting.Username, string.Empty);
SetDefault(OsuSetting.Token, string.Empty); SetDefault(OsuSetting.Token, string.Empty);
@ -295,6 +297,7 @@ namespace osu.Game.Configuration
RandomSelectAlgorithm, RandomSelectAlgorithm,
ShowFpsDisplay, ShowFpsDisplay,
ChatDisplayHeight, ChatDisplayHeight,
ToolbarClockDisplayMode,
Version, Version,
ShowConvertedBeatmaps, ShowConvertedBeatmaps,
Skin, Skin,

View File

@ -0,0 +1,13 @@
// 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.
namespace osu.Game.Configuration
{
public enum ToolbarClockDisplayMode
{
Analog,
Digital,
DigitalWithRuntime,
Full
}
}

View File

@ -3,9 +3,12 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables;
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.Input.Events;
using osu.Game.Configuration;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osuTK; using osuTK;
@ -15,6 +18,11 @@ namespace osu.Game.Overlays.Toolbar
{ {
public class ToolbarClock : CompositeDrawable public class ToolbarClock : CompositeDrawable
{ {
private Bindable<ToolbarClockDisplayMode> clockDisplayMode;
private DigitalDisplay digital;
private AnalogDisplay analog;
private const float hand_thickness = 2.4f; private const float hand_thickness = 2.4f;
public ToolbarClock() public ToolbarClock()
@ -26,8 +34,10 @@ namespace osu.Game.Overlays.Toolbar
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(OsuConfigManager config)
{ {
clockDisplayMode = config.GetBindable<ToolbarClockDisplayMode>(OsuSetting.ToolbarClockDisplayMode);
InternalChild = new FillFlowContainer InternalChild = new FillFlowContainer
{ {
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
@ -36,12 +46,12 @@ namespace osu.Game.Overlays.Toolbar
Spacing = new Vector2(5), Spacing = new Vector2(5),
Children = new Drawable[] Children = new Drawable[]
{ {
new AnalogDisplay analog = new AnalogDisplay
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
}, },
new DigitalDisplay digital = new DigitalDisplay
{ {
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
@ -50,16 +60,75 @@ namespace osu.Game.Overlays.Toolbar
}; };
} }
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 class DigitalDisplay : ClockDisplay
{ {
private OsuSpriteText realTime; private OsuSpriteText realTime;
private OsuSpriteText gameTime; private OsuSpriteText gameTime;
private bool showRuntime = true;
public bool ShowRuntime
{
get => showRuntime;
set
{
if (showRuntime == value)
return;
showRuntime = value;
updateMetrics();
}
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colours) private void load(OsuColour colours)
{ {
AutoSizeAxes = Axes.Y; 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[] InternalChildren = new Drawable[]
{ {
@ -71,6 +140,8 @@ namespace osu.Game.Overlays.Toolbar
Scale = new Vector2(0.6f) Scale = new Vector2(0.6f)
} }
}; };
updateMetrics();
} }
protected override void UpdateDisplay(DateTimeOffset now) protected override void UpdateDisplay(DateTimeOffset now)
@ -78,6 +149,12 @@ namespace osu.Game.Overlays.Toolbar
realTime.Text = $"{now:HH:mm:ss}"; realTime.Text = $"{now:HH:mm:ss}";
gameTime.Text = $"running {new TimeSpan(TimeSpan.TicksPerSecond * (int)(Clock.CurrentTime / 1000)):c}"; 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 private class AnalogDisplay : ClockDisplay