2019-03-04 12:24:19 +08: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 13:05:22 +08:00
|
|
|
|
|
|
|
using System;
|
2019-03-02 12:40:43 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-11-17 13:05:22 +08: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 12:40:43 +08:00
|
|
|
get => bindable;
|
2018-11-17 13:05:22 +08:00
|
|
|
set
|
|
|
|
{
|
2019-06-13 16:04:57 +08:00
|
|
|
bindable = value.GetBoundCopy();
|
2018-11-17 13:05:22 +08:00
|
|
|
bindable.BindValueChanged(dto =>
|
2019-03-02 12:40:43 +08:00
|
|
|
base.Bindable.Value = dto.NewValue.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"), true);
|
2018-11-17 13:05:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// hold a reference to the provided bindable so we don't have to in every settings section.
|
2020-09-02 12:17:17 +08:00
|
|
|
private Bindable<DateTimeOffset> bindable = new Bindable<DateTimeOffset>();
|
2018-11-17 13:05:22 +08:00
|
|
|
|
|
|
|
public DateTextBox()
|
|
|
|
{
|
|
|
|
base.Bindable = new Bindable<string>();
|
2020-09-02 12:17:17 +08:00
|
|
|
|
2020-10-01 11:51:33 +08:00
|
|
|
((OsuTextBox)Control).OnCommit += (sender, newText) =>
|
2018-11-17 13:05:22 +08:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
bindable.Value = DateTimeOffset.Parse(sender.Text);
|
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2019-06-13 16:04:57 +08:00
|
|
|
// reset textbox content to its last valid state on a parse failure.
|
2018-11-17 13:05:22 +08:00
|
|
|
bindable.TriggerChange();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|