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
|
|
|
|
{
|
2020-10-06 08:18:41 +00:00
|
|
|
public new Bindable<DateTimeOffset> Current
|
2018-11-17 05:05:22 +00:00
|
|
|
{
|
2020-10-06 08:18:41 +00:00
|
|
|
get => current;
|
2018-11-17 05:05:22 +00:00
|
|
|
set
|
|
|
|
{
|
2020-10-06 08:18:41 +00:00
|
|
|
current = value.GetBoundCopy();
|
|
|
|
current.BindValueChanged(dto =>
|
|
|
|
base.Current.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.
|
2020-10-06 08:18:41 +00:00
|
|
|
private Bindable<DateTimeOffset> current = new Bindable<DateTimeOffset>();
|
2018-11-17 05:05:22 +00:00
|
|
|
|
|
|
|
public DateTextBox()
|
|
|
|
{
|
2021-10-01 17:54:10 +00:00
|
|
|
base.Current = new Bindable<string>(string.Empty);
|
2020-09-02 04:17:17 +00:00
|
|
|
|
2020-10-01 03:51:33 +00:00
|
|
|
((OsuTextBox)Control).OnCommit += (sender, newText) =>
|
2018-11-17 05:05:22 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-10-06 08:18:41 +00:00
|
|
|
current.Value = DateTimeOffset.Parse(sender.Text);
|
2018-11-17 05:05:22 +00:00
|
|
|
}
|
|
|
|
catch
|
|
|
|
{
|
2019-06-13 08:04:57 +00:00
|
|
|
// reset textbox content to its last valid state on a parse failure.
|
2020-10-06 08:18:41 +00:00
|
|
|
current.TriggerChange();
|
2018-11-17 05:05:22 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|