namespace UIWidgets
{
using System;
using UIWidgets.Styles;
using UnityEngine;
///
/// DatePicker.
///
public class DatePicker : Picker
{
///
/// Calendar.
///
[SerializeField]
public DateBase Calendar;
///
/// If true select date only when date changes; otherwise select date on click.
///
[SerializeField]
public bool DateChangeOnly = false;
///
/// Prepare picker to open.
///
/// Default value.
public override void BeforeOpen(DateTime defaultValue)
{
Calendar.Date = defaultValue;
Calendar.OnDateChanged.AddListener(DateChange);
Calendar.OnDateClick.AddListener(DateClick);
}
///
/// Process date time change.
///
/// Selected value.
protected void DateChange(DateTime dt)
{
if (DateChangeOnly)
{
Selected(dt);
}
}
///
/// Process date time click.
///
/// Selected value.
protected void DateClick(DateTime dt)
{
if (!DateChangeOnly)
{
Selected(dt);
}
}
///
/// Prepare picker to close.
///
public override void BeforeClose()
{
Calendar.OnDateChanged.RemoveListener(DateChange);
Calendar.OnDateClick.RemoveListener(DateClick);
}
#region IStylable implementation
///
public override bool SetStyle(Style style)
{
base.SetStyle(style);
Calendar.SetStyle(style);
style.Dialog.Button.ApplyTo(transform.Find("Buttons/Cancel"));
return true;
}
///
public override bool GetStyle(Style style)
{
base.GetStyle(style);
Calendar.GetStyle(style);
style.Dialog.Button.GetFrom(transform.Find("Buttons/Cancel"));
return true;
}
#endregion
}
}