From 4f208416bedfd8cb3cd11474d7de2dca5aa40c8d Mon Sep 17 00:00:00 2001 From: Drison64 Date: Fri, 16 Sep 2022 13:50:18 +1400 Subject: [PATCH] Fixed irresponsiveness of score panel timestamp to time format --- .../Expanded/ExpandedPanelMiddleContent.cs | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Ranking/Expanded/ExpandedPanelMiddleContent.cs b/osu.Game/Screens/Ranking/Expanded/ExpandedPanelMiddleContent.cs index b496f4242d..e212dad65f 100644 --- a/osu.Game/Screens/Ranking/Expanded/ExpandedPanelMiddleContent.cs +++ b/osu.Game/Screens/Ranking/Expanded/ExpandedPanelMiddleContent.cs @@ -7,12 +7,14 @@ using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Drawables; +using osu.Game.Configuration; using osu.Game.Graphics; using osu.Game.Graphics.Containers; using osu.Game.Graphics.Sprites; @@ -34,6 +36,7 @@ namespace osu.Game.Screens.Ranking.Expanded private const float padding = 10; private readonly ScoreInfo score; + private Bindable bindableUse24HourDisplay; private readonly bool withFlair; private readonly List statisticDisplays = new List(); @@ -61,8 +64,9 @@ namespace osu.Game.Screens.Ranking.Expanded } [BackgroundDependencyLoader] - private void load(BeatmapDifficultyCache beatmapDifficultyCache) + private void load(BeatmapDifficultyCache beatmapDifficultyCache, OsuConfigManager config) { + bindableUse24HourDisplay = config.GetBindable(OsuSetting.Prefer24HourTime); var beatmap = score.BeatmapInfo; var metadata = beatmap.BeatmapSet?.Metadata ?? beatmap.Metadata; string creator = metadata.Author.Username; @@ -224,7 +228,7 @@ namespace osu.Game.Screens.Ranking.Expanded }); if (score.Date != default) - AddInternal(new PlayedOnText(score.Date)); + AddInternal(new PlayedOnText(score.Date, bindableUse24HourDisplay)); var starDifficulty = beatmapDifficultyCache.GetDifficultyAsync(beatmap, score.Ruleset, score.Mods).GetResultSafely(); @@ -280,12 +284,25 @@ namespace osu.Game.Screens.Ranking.Expanded public class PlayedOnText : OsuSpriteText { - public PlayedOnText(DateTimeOffset time) + private bool use24HourDisplay; + + public PlayedOnText(DateTimeOffset time, Bindable bindableUse24HourDisplay) { + use24HourDisplay = bindableUse24HourDisplay.Value; + bindableUse24HourDisplay.BindValueChanged(prefer24H => + { + use24HourDisplay = prefer24H.NewValue; + UpdateHourDisplay(time); + }, true); Anchor = Anchor.BottomCentre; Origin = Anchor.BottomCentre; Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold); - Text = $"Played on {time.ToLocalTime():d MMMM yyyy HH:mm}"; + UpdateHourDisplay(time); + } + + public void UpdateHourDisplay(DateTimeOffset time) + { + Text = use24HourDisplay ? $"Played on {time.ToLocalTime():d MMMM yyyy HH:mm}" : $"Played on {time.ToLocalTime():d MMMM yyyy h:mm tt}"; } } }