osu/osu.Game.Tournament/Components/DateTextBox.cs

44 lines
1.3 KiB
C#
Raw Normal View History

2019-03-04 04:24:19 +00:00
// 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.
2018-11-17 05:05:22 +00:00
using System;
2019-03-02 04:40:43 +00:00
using osu.Framework.Bindables;
2018-11-17 05:05:22 +00:00
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays.Settings;
namespace osu.Game.Tournament.Components
{
public class DateTextBox : SettingsTextBox
{
public new Bindable<DateTimeOffset> Bindable
{
2019-03-02 04:40:43 +00:00
get => bindable;
2018-11-17 05:05:22 +00:00
set
{
bindable = value;
bindable.BindValueChanged(dto =>
2019-03-02 04:40:43 +00:00
base.Bindable.Value = dto.NewValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), true);
2018-11-17 05:05:22 +00:00
}
}
// hold a reference to the provided bindable so we don't have to in every settings section.
private Bindable<DateTimeOffset> bindable;
public DateTextBox()
{
base.Bindable = new Bindable<string>();
((OsuTextBox)Control).OnCommit = (sender, newText) =>
{
try
{
bindable.Value = DateTimeOffset.Parse(sender.Text);
}
catch
{
bindable.TriggerChange();
}
};
}
}
}