1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 02:17:46 +08:00
osu-lazer/osu.Game.Tournament/Components/DateTextBox.cs
Bartłomiej Dach caf5673b68
Revert nullability enables in tournament client
Not trivial to fix right now and I'm not fixing in a 1k-line changeset.
2023-06-24 16:05:19 +02:00

48 lines
1.4 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.
#nullable disable
using System;
using osu.Framework.Bindables;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
namespace osu.Game.Tournament.Components
{
public partial class DateTextBox : SettingsTextBox
{
public new Bindable<DateTimeOffset> Current
{
get => current;
set
{
current = value.GetBoundCopy();
current.BindValueChanged(dto =>
base.Current.Value = dto.NewValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), true);
}
}
// hold a reference to the provided bindable so we don't have to in every settings section.
private Bindable<DateTimeOffset> current = new Bindable<DateTimeOffset>();
public DateTextBox()
{
base.Current = new Bindable<string>(string.Empty);
((OsuTextBox)Control).OnCommit += (sender, _) =>
{
try
{
current.Value = DateTimeOffset.Parse(sender.Text);
}
catch
{
// reset textbox content to its last valid state on a parse failure.
current.TriggerChange();
}
};
}
}
}