573 lines
20 KiB
C#
573 lines
20 KiB
C#
|
|
#nullable enable
|
||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UIElements;
|
||
|
|
using UVC.Locale;
|
||
|
|
using UVC.UIToolkit.Input;
|
||
|
|
|
||
|
|
namespace UVC.UIToolkit.Modal
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// UIToolkit 기반 날짜/시간 피커 모달
|
||
|
|
/// 캘린더 그리드 + 시간 선택 지원
|
||
|
|
/// </summary>
|
||
|
|
[UxmlElement]
|
||
|
|
public partial class UTKDatePicker : VisualElement, IDisposable
|
||
|
|
{
|
||
|
|
#region Enums
|
||
|
|
public enum PickerMode
|
||
|
|
{
|
||
|
|
DateOnly,
|
||
|
|
DateAndTime
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region Constants
|
||
|
|
private const string UXML_PATH = "UIToolkit/Modal/UTKDatePicker";
|
||
|
|
private const string USS_PATH = "UIToolkit/Modal/UTKDatePicker";
|
||
|
|
private const int DAYS_IN_GRID = 42; // 6 rows x 7 columns
|
||
|
|
private static readonly string[] DAY_NAME_KEYS = { "day_sun", "day_mon", "day_tue", "day_wed", "day_thu", "day_fri", "day_sat" };
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region Fields
|
||
|
|
private bool _disposed;
|
||
|
|
private PickerMode _mode;
|
||
|
|
private DateTime _selectedDate = DateTime.Today;
|
||
|
|
private DateTime _displayMonth = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1);
|
||
|
|
|
||
|
|
private UTKModalBlocker? _blocker;
|
||
|
|
private readonly List<Button> _dayButtons = new();
|
||
|
|
|
||
|
|
// UI 요소
|
||
|
|
private Label? _titleLabel;
|
||
|
|
private Button? _closeButton;
|
||
|
|
private Label? _yearMonthLabel;
|
||
|
|
private Button? _prevYearButton;
|
||
|
|
private Button? _prevMonthButton;
|
||
|
|
private Button? _nextMonthButton;
|
||
|
|
private Button? _nextYearButton;
|
||
|
|
private VisualElement? _dayNamesRow;
|
||
|
|
private VisualElement? _timeRow;
|
||
|
|
private UTKNumberStepper? _hourStepper;
|
||
|
|
private UTKNumberStepper? _minuteStepper;
|
||
|
|
private Button? _cancelButton;
|
||
|
|
private Button? _confirmButton;
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region Events
|
||
|
|
/// <summary>날짜가 선택되었을 때 발생</summary>
|
||
|
|
public event Action<DateTime>? OnDateSelected;
|
||
|
|
|
||
|
|
/// <summary>피커가 닫힐 때 발생</summary>
|
||
|
|
public event Action? OnClosed;
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region Constructor
|
||
|
|
public UTKDatePicker()
|
||
|
|
{
|
||
|
|
// 테마 스타일시트 적용
|
||
|
|
UTKThemeManager.Instance.ApplyThemeToElement(this);
|
||
|
|
|
||
|
|
// 컴포넌트 스타일시트 로드
|
||
|
|
var styleSheet = Resources.Load<StyleSheet>(USS_PATH);
|
||
|
|
if (styleSheet != null)
|
||
|
|
{
|
||
|
|
styleSheets.Add(styleSheet);
|
||
|
|
}
|
||
|
|
|
||
|
|
var visualTree = Resources.Load<VisualTreeAsset>(UXML_PATH);
|
||
|
|
if (visualTree != null)
|
||
|
|
{
|
||
|
|
visualTree.CloneTree(this);
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
CreateUI();
|
||
|
|
}
|
||
|
|
|
||
|
|
QueryElements();
|
||
|
|
SetupEvents();
|
||
|
|
SubscribeToThemeChanges();
|
||
|
|
|
||
|
|
// 캘린더 초기화
|
||
|
|
UpdateCalendar();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SubscribeToThemeChanges()
|
||
|
|
{
|
||
|
|
UTKThemeManager.Instance.OnThemeChanged += OnThemeChanged;
|
||
|
|
|
||
|
|
// 패널에서 분리될 때 이벤트 구독 해제
|
||
|
|
RegisterCallback<DetachFromPanelEvent>(_ =>
|
||
|
|
{
|
||
|
|
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnThemeChanged(UTKTheme theme)
|
||
|
|
{
|
||
|
|
UTKThemeManager.Instance.ApplyThemeToElement(this);
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region Static Factory
|
||
|
|
/// <summary>
|
||
|
|
/// 날짜 피커를 표시합니다.
|
||
|
|
/// </summary>
|
||
|
|
public static UTKDatePicker Show(
|
||
|
|
VisualElement parent,
|
||
|
|
DateTime initialDate,
|
||
|
|
PickerMode mode = PickerMode.DateOnly,
|
||
|
|
string title = "Select Date")
|
||
|
|
{
|
||
|
|
var picker = new UTKDatePicker();
|
||
|
|
picker._mode = mode;
|
||
|
|
picker._selectedDate = initialDate;
|
||
|
|
picker._displayMonth = new DateTime(initialDate.Year, initialDate.Month, 1);
|
||
|
|
|
||
|
|
// 블로커 추가
|
||
|
|
picker._blocker = UTKModalBlocker.Show(parent, 0.5f, false);
|
||
|
|
picker._blocker.OnBlockerClicked += picker.Close;
|
||
|
|
|
||
|
|
// 피커 추가
|
||
|
|
parent.Add(picker);
|
||
|
|
|
||
|
|
// UI 초기화
|
||
|
|
picker.SetTitle(title);
|
||
|
|
picker.SetTimeVisible(mode == PickerMode.DateAndTime);
|
||
|
|
picker.UpdateTimeFields();
|
||
|
|
picker.UpdateCalendar();
|
||
|
|
picker.CenterOnScreen();
|
||
|
|
|
||
|
|
return picker;
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region Public Methods
|
||
|
|
public void SetDate(DateTime date)
|
||
|
|
{
|
||
|
|
_selectedDate = date;
|
||
|
|
_displayMonth = new DateTime(date.Year, date.Month, 1);
|
||
|
|
UpdateTimeFields();
|
||
|
|
UpdateCalendar();
|
||
|
|
}
|
||
|
|
|
||
|
|
public DateTime GetDate()
|
||
|
|
{
|
||
|
|
if (_mode == PickerMode.DateAndTime)
|
||
|
|
{
|
||
|
|
int hour = _hourStepper?.Value ?? 0;
|
||
|
|
int minute = _minuteStepper?.Value ?? 0;
|
||
|
|
return new DateTime(
|
||
|
|
_selectedDate.Year,
|
||
|
|
_selectedDate.Month,
|
||
|
|
_selectedDate.Day,
|
||
|
|
hour,
|
||
|
|
minute,
|
||
|
|
0
|
||
|
|
);
|
||
|
|
}
|
||
|
|
return _selectedDate.Date;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void PreviousYear() => NavigateMonth(-12);
|
||
|
|
public void NextYear() => NavigateMonth(12);
|
||
|
|
public void PreviousMonth() => NavigateMonth(-1);
|
||
|
|
public void NextMonth() => NavigateMonth(1);
|
||
|
|
|
||
|
|
public void Close()
|
||
|
|
{
|
||
|
|
OnClosed?.Invoke();
|
||
|
|
_blocker?.Hide();
|
||
|
|
RemoveFromHierarchy();
|
||
|
|
Dispose();
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region Private Methods - UI Creation
|
||
|
|
private void CreateUI()
|
||
|
|
{
|
||
|
|
AddToClassList("utk-date-picker");
|
||
|
|
|
||
|
|
// Header
|
||
|
|
var header = new VisualElement { name = "header" };
|
||
|
|
header.AddToClassList("utk-date-picker__header");
|
||
|
|
|
||
|
|
_titleLabel = new Label("Select Date") { name = "title" };
|
||
|
|
_titleLabel.AddToClassList("utk-date-picker__title");
|
||
|
|
|
||
|
|
_closeButton = new Button { name = "close-btn", text = "\u2715" }; // X
|
||
|
|
_closeButton.AddToClassList("utk-date-picker__close-btn");
|
||
|
|
|
||
|
|
header.Add(_titleLabel);
|
||
|
|
header.Add(_closeButton);
|
||
|
|
Add(header);
|
||
|
|
|
||
|
|
// Navigation
|
||
|
|
var navRow = new VisualElement { name = "nav-row" };
|
||
|
|
navRow.AddToClassList("utk-date-picker__nav-row");
|
||
|
|
|
||
|
|
var leftNav = new VisualElement();
|
||
|
|
leftNav.AddToClassList("utk-date-picker__nav-group");
|
||
|
|
|
||
|
|
_prevYearButton = CreateNavButton("prev-year", "\u00AB"); // <<
|
||
|
|
_prevYearButton.AddToClassList("utk-date-picker__nav-btn--prev-year");
|
||
|
|
|
||
|
|
_prevMonthButton = CreateNavButton("prev-month", "\u2039"); // <
|
||
|
|
|
||
|
|
leftNav.Add(_prevYearButton);
|
||
|
|
leftNav.Add(_prevMonthButton);
|
||
|
|
|
||
|
|
_yearMonthLabel = new Label { name = "year-month" };
|
||
|
|
_yearMonthLabel.AddToClassList("utk-date-picker__year-month-label");
|
||
|
|
|
||
|
|
var rightNav = new VisualElement();
|
||
|
|
rightNav.AddToClassList("utk-date-picker__nav-group");
|
||
|
|
|
||
|
|
_nextMonthButton = CreateNavButton("next-month", "\u203A"); // >
|
||
|
|
|
||
|
|
_nextYearButton = CreateNavButton("next-year", "\u00BB"); // >>
|
||
|
|
_nextYearButton.AddToClassList("utk-date-picker__nav-btn--next-year");
|
||
|
|
|
||
|
|
rightNav.Add(_nextMonthButton);
|
||
|
|
rightNav.Add(_nextYearButton);
|
||
|
|
|
||
|
|
navRow.Add(leftNav);
|
||
|
|
navRow.Add(_yearMonthLabel);
|
||
|
|
navRow.Add(rightNav);
|
||
|
|
Add(navRow);
|
||
|
|
|
||
|
|
// Day names row
|
||
|
|
_dayNamesRow = new VisualElement { name = "day-names" };
|
||
|
|
_dayNamesRow.AddToClassList("utk-date-picker__day-names");
|
||
|
|
|
||
|
|
for (int i = 0; i < DAY_NAME_KEYS.Length; i++)
|
||
|
|
{
|
||
|
|
var dayText = LocalizationManager.Instance.GetString(DAY_NAME_KEYS[i]);
|
||
|
|
var label = new Label(dayText) { name = $"day-name-{i}" };
|
||
|
|
label.AddToClassList("utk-date-picker__day-name");
|
||
|
|
|
||
|
|
// 요일별 색상 클래스 (0=일요일, 6=토요일)
|
||
|
|
if (i == 0) label.AddToClassList("utk-date-picker__day-name--sunday");
|
||
|
|
else if (i == 6) label.AddToClassList("utk-date-picker__day-name--saturday");
|
||
|
|
|
||
|
|
_dayNamesRow.Add(label);
|
||
|
|
}
|
||
|
|
Add(_dayNamesRow);
|
||
|
|
|
||
|
|
// Calendar grid - 6 rows
|
||
|
|
for (int row = 0; row < 6; row++)
|
||
|
|
{
|
||
|
|
var rowContainer = new VisualElement { name = $"calendar-row-{row}" };
|
||
|
|
rowContainer.AddToClassList("utk-date-picker__calendar-row");
|
||
|
|
|
||
|
|
for (int col = 0; col < 7; col++)
|
||
|
|
{
|
||
|
|
var dayButton = new Button { name = $"day-{row * 7 + col}" };
|
||
|
|
dayButton.AddToClassList("utk-date-picker__day-btn");
|
||
|
|
|
||
|
|
int index = row * 7 + col;
|
||
|
|
dayButton.clicked += () => OnDayClicked(index);
|
||
|
|
|
||
|
|
_dayButtons.Add(dayButton);
|
||
|
|
rowContainer.Add(dayButton);
|
||
|
|
}
|
||
|
|
Add(rowContainer);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Time row (optional)
|
||
|
|
_timeRow = new VisualElement { name = "time-row" };
|
||
|
|
_timeRow.AddToClassList("utk-date-picker__time-row");
|
||
|
|
|
||
|
|
var timeLabel = new Label("시간:");
|
||
|
|
timeLabel.AddToClassList("utk-date-picker__time-label");
|
||
|
|
|
||
|
|
_hourStepper = new UTKNumberStepper(0, 23, 0, 1) { name = "hour-stepper" };
|
||
|
|
_hourStepper.AddToClassList("utk-date-picker__time-stepper");
|
||
|
|
_hourStepper.WrapAround = true;
|
||
|
|
|
||
|
|
var colonLabel = new Label(":");
|
||
|
|
colonLabel.AddToClassList("utk-date-picker__time-separator");
|
||
|
|
|
||
|
|
_minuteStepper = new UTKNumberStepper(0, 59, 0, 1) { name = "minute-stepper" };
|
||
|
|
_minuteStepper.AddToClassList("utk-date-picker__time-stepper");
|
||
|
|
_minuteStepper.WrapAround = true;
|
||
|
|
|
||
|
|
// Tab 키로 시간 <-> 분 이동
|
||
|
|
_hourStepper.OnTabPressed += () => _minuteStepper?.Focus();
|
||
|
|
_minuteStepper.OnShiftTabPressed += () => _hourStepper?.Focus();
|
||
|
|
|
||
|
|
_timeRow.Add(timeLabel);
|
||
|
|
_timeRow.Add(_hourStepper);
|
||
|
|
_timeRow.Add(colonLabel);
|
||
|
|
_timeRow.Add(_minuteStepper);
|
||
|
|
Add(_timeRow);
|
||
|
|
|
||
|
|
// Buttons
|
||
|
|
var buttonRow = new VisualElement { name = "button-row" };
|
||
|
|
buttonRow.AddToClassList("utk-date-picker__button-row");
|
||
|
|
|
||
|
|
_cancelButton = new Button { name = "cancel-btn", text = "Cancel" };
|
||
|
|
_cancelButton.AddToClassList("utk-date-picker__cancel-btn");
|
||
|
|
|
||
|
|
_confirmButton = new Button { name = "confirm-btn", text = "OK" };
|
||
|
|
_confirmButton.AddToClassList("utk-date-picker__confirm-btn");
|
||
|
|
|
||
|
|
buttonRow.Add(_cancelButton);
|
||
|
|
buttonRow.Add(_confirmButton);
|
||
|
|
Add(buttonRow);
|
||
|
|
}
|
||
|
|
|
||
|
|
private Button CreateNavButton(string name, string text)
|
||
|
|
{
|
||
|
|
var btn = new Button { name = name, text = text };
|
||
|
|
btn.AddToClassList("utk-date-picker__nav-btn");
|
||
|
|
return btn;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void QueryElements()
|
||
|
|
{
|
||
|
|
_titleLabel ??= this.Q<Label>("title");
|
||
|
|
_closeButton ??= this.Q<Button>("close-btn");
|
||
|
|
_yearMonthLabel ??= this.Q<Label>("year-month");
|
||
|
|
_prevYearButton ??= this.Q<Button>("prev-year");
|
||
|
|
_prevMonthButton ??= this.Q<Button>("prev-month");
|
||
|
|
_nextMonthButton ??= this.Q<Button>("next-month");
|
||
|
|
_nextYearButton ??= this.Q<Button>("next-year");
|
||
|
|
_dayNamesRow ??= this.Q<VisualElement>("day-names");
|
||
|
|
_timeRow ??= this.Q<VisualElement>("time-row");
|
||
|
|
_hourStepper ??= this.Q<UTKNumberStepper>("hour-stepper");
|
||
|
|
_minuteStepper ??= this.Q<UTKNumberStepper>("minute-stepper");
|
||
|
|
_cancelButton ??= this.Q<Button>("cancel-btn");
|
||
|
|
_confirmButton ??= this.Q<Button>("confirm-btn");
|
||
|
|
|
||
|
|
// Day buttons 쿼리
|
||
|
|
if (_dayButtons.Count == 0)
|
||
|
|
{
|
||
|
|
for (int i = 0; i < DAYS_IN_GRID; i++)
|
||
|
|
{
|
||
|
|
var btn = this.Q<Button>($"day-{i}");
|
||
|
|
if (btn != null)
|
||
|
|
{
|
||
|
|
_dayButtons.Add(btn);
|
||
|
|
int index = i;
|
||
|
|
btn.clicked += () => OnDayClicked(index);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SetupEvents()
|
||
|
|
{
|
||
|
|
_closeButton?.RegisterCallback<ClickEvent>(_ => Close());
|
||
|
|
_cancelButton?.RegisterCallback<ClickEvent>(_ => Close());
|
||
|
|
_confirmButton?.RegisterCallback<ClickEvent>(_ => Confirm());
|
||
|
|
|
||
|
|
_prevYearButton?.RegisterCallback<ClickEvent>(_ => PreviousYear());
|
||
|
|
_prevMonthButton?.RegisterCallback<ClickEvent>(_ => PreviousMonth());
|
||
|
|
_nextMonthButton?.RegisterCallback<ClickEvent>(_ => NextMonth());
|
||
|
|
_nextYearButton?.RegisterCallback<ClickEvent>(_ => NextYear());
|
||
|
|
|
||
|
|
// 언어 변경 이벤트 구독
|
||
|
|
LocalizationManager.Instance.OnLanguageChanged += OnLanguageChanged;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnLanguageChanged(string newLanguage)
|
||
|
|
{
|
||
|
|
UpdateDayNameLabels();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void UpdateDayNameLabels()
|
||
|
|
{
|
||
|
|
if (_dayNamesRow == null) return;
|
||
|
|
|
||
|
|
for (int i = 0; i < DAY_NAME_KEYS.Length; i++)
|
||
|
|
{
|
||
|
|
var label = _dayNamesRow.Q<Label>($"day-name-{i}");
|
||
|
|
if (label != null)
|
||
|
|
{
|
||
|
|
label.text = LocalizationManager.Instance.GetString(DAY_NAME_KEYS[i]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region Private Methods - Logic
|
||
|
|
private void NavigateMonth(int months)
|
||
|
|
{
|
||
|
|
_displayMonth = _displayMonth.AddMonths(months);
|
||
|
|
UpdateCalendar();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void UpdateCalendar()
|
||
|
|
{
|
||
|
|
if (_yearMonthLabel != null)
|
||
|
|
{
|
||
|
|
_yearMonthLabel.text = $"{_displayMonth.Year}년 {_displayMonth.Month:D2}월";
|
||
|
|
}
|
||
|
|
|
||
|
|
// 첫째 날의 요일
|
||
|
|
DateTime firstDay = new DateTime(_displayMonth.Year, _displayMonth.Month, 1);
|
||
|
|
int startDayOfWeek = (int)firstDay.DayOfWeek; // 0=Sunday
|
||
|
|
|
||
|
|
// 해당 월의 일 수
|
||
|
|
int daysInMonth = DateTime.DaysInMonth(_displayMonth.Year, _displayMonth.Month);
|
||
|
|
|
||
|
|
DateTime today = DateTime.Today;
|
||
|
|
|
||
|
|
for (int i = 0; i < DAYS_IN_GRID; i++)
|
||
|
|
{
|
||
|
|
var btn = _dayButtons[i];
|
||
|
|
|
||
|
|
// 동적 클래스 초기화
|
||
|
|
btn.RemoveFromClassList("utk-date-picker__day-btn--sunday");
|
||
|
|
btn.RemoveFromClassList("utk-date-picker__day-btn--saturday");
|
||
|
|
btn.RemoveFromClassList("utk-date-picker__day-btn--today");
|
||
|
|
btn.RemoveFromClassList("utk-date-picker__day-btn--selected");
|
||
|
|
btn.RemoveFromClassList("utk-date-picker__day-btn--other-month");
|
||
|
|
|
||
|
|
int dayNumber = i - startDayOfWeek + 1;
|
||
|
|
|
||
|
|
if (dayNumber < 1 || dayNumber > daysInMonth)
|
||
|
|
{
|
||
|
|
// 이번 달이 아닌 날
|
||
|
|
btn.text = "";
|
||
|
|
btn.SetEnabled(false);
|
||
|
|
btn.AddToClassList("utk-date-picker__day-btn--other-month");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
btn.text = dayNumber.ToString();
|
||
|
|
btn.SetEnabled(true);
|
||
|
|
|
||
|
|
DateTime currentDate = new DateTime(_displayMonth.Year, _displayMonth.Month, dayNumber);
|
||
|
|
DayOfWeek dow = currentDate.DayOfWeek;
|
||
|
|
|
||
|
|
// 선택된 날짜인지 확인
|
||
|
|
bool isSelected = currentDate.Date == _selectedDate.Date;
|
||
|
|
|
||
|
|
// 오늘인지 확인
|
||
|
|
bool isToday = currentDate.Date == today;
|
||
|
|
|
||
|
|
// 선택 상태 클래스
|
||
|
|
if (isSelected)
|
||
|
|
{
|
||
|
|
btn.AddToClassList("utk-date-picker__day-btn--selected");
|
||
|
|
}
|
||
|
|
|
||
|
|
// 오늘 클래스 (선택되지 않은 경우에만)
|
||
|
|
if (isToday && !isSelected)
|
||
|
|
{
|
||
|
|
btn.AddToClassList("utk-date-picker__day-btn--today");
|
||
|
|
}
|
||
|
|
|
||
|
|
// 요일별 클래스 (선택되지 않은 경우에만)
|
||
|
|
if (!isSelected)
|
||
|
|
{
|
||
|
|
if (dow == DayOfWeek.Sunday)
|
||
|
|
{
|
||
|
|
btn.AddToClassList("utk-date-picker__day-btn--sunday");
|
||
|
|
}
|
||
|
|
else if (dow == DayOfWeek.Saturday)
|
||
|
|
{
|
||
|
|
btn.AddToClassList("utk-date-picker__day-btn--saturday");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnDayClicked(int index)
|
||
|
|
{
|
||
|
|
// 첫째 날의 요일
|
||
|
|
DateTime firstDay = new DateTime(_displayMonth.Year, _displayMonth.Month, 1);
|
||
|
|
int startDayOfWeek = (int)firstDay.DayOfWeek;
|
||
|
|
|
||
|
|
int dayNumber = index - startDayOfWeek + 1;
|
||
|
|
int daysInMonth = DateTime.DaysInMonth(_displayMonth.Year, _displayMonth.Month);
|
||
|
|
|
||
|
|
if (dayNumber >= 1 && dayNumber <= daysInMonth)
|
||
|
|
{
|
||
|
|
// 시간 유지
|
||
|
|
int hour = _hourStepper?.Value ?? _selectedDate.Hour;
|
||
|
|
int minute = _minuteStepper?.Value ?? _selectedDate.Minute;
|
||
|
|
|
||
|
|
_selectedDate = new DateTime(
|
||
|
|
_displayMonth.Year,
|
||
|
|
_displayMonth.Month,
|
||
|
|
dayNumber,
|
||
|
|
hour,
|
||
|
|
minute,
|
||
|
|
0
|
||
|
|
);
|
||
|
|
|
||
|
|
UpdateCalendar();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
private void Confirm()
|
||
|
|
{
|
||
|
|
OnDateSelected?.Invoke(GetDate());
|
||
|
|
Close();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SetTitle(string title)
|
||
|
|
{
|
||
|
|
if (_titleLabel != null)
|
||
|
|
_titleLabel.text = title;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void SetTimeVisible(bool visible)
|
||
|
|
{
|
||
|
|
if (_timeRow != null)
|
||
|
|
_timeRow.style.display = visible ? DisplayStyle.Flex : DisplayStyle.None;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void UpdateTimeFields()
|
||
|
|
{
|
||
|
|
if (_hourStepper != null)
|
||
|
|
_hourStepper.SetValue(_selectedDate.Hour, notify: false);
|
||
|
|
|
||
|
|
if (_minuteStepper != null)
|
||
|
|
_minuteStepper.SetValue(_selectedDate.Minute, notify: false);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void CenterOnScreen()
|
||
|
|
{
|
||
|
|
schedule.Execute(() =>
|
||
|
|
{
|
||
|
|
var parent = this.parent;
|
||
|
|
if (parent == null) return;
|
||
|
|
|
||
|
|
float parentWidth = parent.resolvedStyle.width;
|
||
|
|
float parentHeight = parent.resolvedStyle.height;
|
||
|
|
float selfWidth = resolvedStyle.width;
|
||
|
|
float selfHeight = resolvedStyle.height;
|
||
|
|
|
||
|
|
style.left = (parentWidth - selfWidth) / 2;
|
||
|
|
style.top = (parentHeight - selfHeight) / 2;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
|
||
|
|
#region IDisposable
|
||
|
|
public void Dispose()
|
||
|
|
{
|
||
|
|
if (_disposed) return;
|
||
|
|
_disposed = true;
|
||
|
|
|
||
|
|
// 언어 변경 이벤트 구독 해제
|
||
|
|
LocalizationManager.Instance.OnLanguageChanged -= OnLanguageChanged;
|
||
|
|
|
||
|
|
_dayButtons.Clear();
|
||
|
|
|
||
|
|
OnDateSelected = null;
|
||
|
|
OnClosed = null;
|
||
|
|
|
||
|
|
_blocker = null;
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
}
|
||
|
|
}
|