1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-08 10:03:43 +08:00
Files
osu-lazer/osu.Game/Screens/Ranking/Expanded/PlayedOnText.cs
T
Dean Herbert d0d5d97cfe Add replay / spectator mode scrolling text back (#36911)
As mentioned in https://github.com/ppy/osu/discussions/36883.

This has caught me off-guard a few times.

Was a quick one to make this work like it does on stable. It doesn't fit
as well as stable because we have a lot of elements at the top of the
screen, but I think it's better than nothing, as it lets you know you're
in a replay quick obviously.

I don't think we can easily localise strings with formatting in them
yet. Maybe using a `MarkdownContainer` or something?
2026-03-11 11:08:26 +01:00

56 lines
1.7 KiB
C#

// 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 System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Graphics;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
namespace osu.Game.Screens.Ranking.Expanded
{
public partial class PlayedOnText : OsuSpriteText
{
private readonly DateTimeOffset time;
private readonly bool withPrefix;
private readonly Bindable<bool> prefer24HourTime = new Bindable<bool>();
public PlayedOnText(DateTimeOffset time, bool withPrefix)
{
this.time = time;
this.withPrefix = withPrefix;
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold);
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager configManager)
{
configManager.BindWith(OsuSetting.Prefer24HourTime, prefer24HourTime);
}
protected override void LoadComplete()
{
base.LoadComplete();
prefer24HourTime.BindValueChanged(_ => updateDisplay(), true);
}
private void updateDisplay()
{
var timeText = time.ToLocalTime().ToLocalisableString(prefer24HourTime.Value ? @"d MMMM yyyy HH:mm" : @"d MMMM yyyy h:mm tt");
if (withPrefix)
Text = LocalisableString.Format("Played on {0}", timeText);
else
Text = timeText;
}
}
}