mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 19:22:56 +08:00
Merge pull request #17670 from perrymacmurray/clock
Add support for 12-hour time on toolbar clock
This commit is contained in:
commit
926710beac
@ -3,6 +3,7 @@
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Configuration.Tracking;
|
||||
using osu.Framework.Extensions;
|
||||
@ -102,6 +103,9 @@ namespace osu.Game.Configuration
|
||||
|
||||
SetDefault(OsuSetting.MenuParallax, true);
|
||||
|
||||
// See https://stackoverflow.com/a/63307411 for default sourcing.
|
||||
SetDefault(OsuSetting.Prefer24HourTime, CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern.Contains(@"tt"));
|
||||
|
||||
// Gameplay
|
||||
SetDefault(OsuSetting.PositionalHitsounds, true); // replaced by level setting below, can be removed 20220703.
|
||||
SetDefault(OsuSetting.PositionalHitsoundsLevel, 0.2f, 0, 1);
|
||||
@ -287,6 +291,7 @@ namespace osu.Game.Configuration
|
||||
MenuVoice,
|
||||
CursorRotation,
|
||||
MenuParallax,
|
||||
Prefer24HourTime,
|
||||
BeatmapDetailTab,
|
||||
BeatmapDetailModsFilter,
|
||||
Username,
|
||||
|
@ -29,6 +29,11 @@ namespace osu.Game.Localisation
|
||||
/// </summary>
|
||||
public static LocalisableString PreferOriginalMetadataLanguage => new TranslatableString(getKey(@"prefer_original"), @"Prefer metadata in original language");
|
||||
|
||||
/// <summary>
|
||||
/// "Prefer 24-hour time display"
|
||||
/// </summary>
|
||||
public static LocalisableString Prefer24HourTimeDisplay => new TranslatableString(getKey(@"prefer_24_hour_time_display"), @"Prefer 24-hour time display");
|
||||
|
||||
/// <summary>
|
||||
/// "Updates"
|
||||
/// </summary>
|
||||
|
@ -6,6 +6,7 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Configuration;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Extensions;
|
||||
using osu.Game.Localisation;
|
||||
|
||||
@ -19,7 +20,7 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
||||
protected override LocalisableString Header => GeneralSettingsStrings.LanguageHeader;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(FrameworkConfigManager frameworkConfig)
|
||||
private void load(FrameworkConfigManager frameworkConfig, OsuConfigManager config)
|
||||
{
|
||||
frameworkLocale = frameworkConfig.GetBindable<string>(FrameworkSetting.Locale);
|
||||
|
||||
@ -34,6 +35,11 @@ namespace osu.Game.Overlays.Settings.Sections.General
|
||||
LabelText = GeneralSettingsStrings.PreferOriginalMetadataLanguage,
|
||||
Current = frameworkConfig.GetBindable<bool>(FrameworkSetting.ShowUnicode)
|
||||
},
|
||||
new SettingsCheckbox
|
||||
{
|
||||
LabelText = GeneralSettingsStrings.Prefer24HourTimeDisplay,
|
||||
Current = config.GetBindable<bool>(OsuSetting.Prefer24HourTime)
|
||||
},
|
||||
};
|
||||
|
||||
if (!LanguageExtensions.TryParseCultureCode(frameworkLocale.Value, out var locale))
|
||||
|
@ -29,6 +29,23 @@ namespace osu.Game.Overlays.Toolbar
|
||||
}
|
||||
}
|
||||
|
||||
private bool use24HourDisplay;
|
||||
|
||||
public bool Use24HourDisplay
|
||||
{
|
||||
get => use24HourDisplay;
|
||||
set
|
||||
{
|
||||
if (use24HourDisplay == value)
|
||||
return;
|
||||
|
||||
use24HourDisplay = value;
|
||||
|
||||
updateMetrics();
|
||||
UpdateDisplay(DateTimeOffset.Now); //Update realTime.Text immediately instead of waiting until next second
|
||||
}
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
@ -50,13 +67,14 @@ namespace osu.Game.Overlays.Toolbar
|
||||
|
||||
protected override void UpdateDisplay(DateTimeOffset now)
|
||||
{
|
||||
realTime.Text = $"{now:HH:mm:ss}";
|
||||
realTime.Text = use24HourDisplay ? $"{now:HH:mm:ss}" : $"{now:h:mm:ss tt}";
|
||||
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).
|
||||
Width = showRuntime || !use24HourDisplay ? 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);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ namespace osu.Game.Overlays.Toolbar
|
||||
public class ToolbarClock : OsuClickableContainer
|
||||
{
|
||||
private Bindable<ToolbarClockDisplayMode> clockDisplayMode;
|
||||
private Bindable<bool> prefer24HourTime;
|
||||
|
||||
private Box hoverBackground;
|
||||
private Box flashBackground;
|
||||
@ -38,6 +39,7 @@ namespace osu.Game.Overlays.Toolbar
|
||||
private void load(OsuConfigManager config)
|
||||
{
|
||||
clockDisplayMode = config.GetBindable<ToolbarClockDisplayMode>(OsuSetting.ToolbarClockDisplayMode);
|
||||
prefer24HourTime = config.GetBindable<bool>(OsuSetting.Prefer24HourTime);
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
@ -94,6 +96,8 @@ namespace osu.Game.Overlays.Toolbar
|
||||
|
||||
analog.FadeTo(showAnalog ? 1 : 0);
|
||||
}, true);
|
||||
|
||||
prefer24HourTime.BindValueChanged(prefer24H => digital.Use24HourDisplay = prefer24H.NewValue, true);
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
|
Loading…
Reference in New Issue
Block a user