diff options
Diffstat (limited to 'ui/date_picker/date_picker.gd')
| -rw-r--r-- | ui/date_picker/date_picker.gd | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/ui/date_picker/date_picker.gd b/ui/date_picker/date_picker.gd new file mode 100644 index 0000000..e2a793f --- /dev/null +++ b/ui/date_picker/date_picker.gd @@ -0,0 +1,64 @@ +extends Control +class_name DatePicker + +const days_per_month: Dictionary = { + 1: 31, + 2: 28, + 3: 31, + 4: 30, + 5: 31, + 6: 30, + 7: 31, + 8: 31, + 9: 30, + 10: 31, + 11: 30, + 12: 31, +} + +onready var year_picker := get_node("year") as ValuePicker +onready var month_picker := get_node("month") as ValuePicker +onready var day_picker := get_node("day") as ValuePicker + + +func _process(delta: float): + var year := year_picker.value + var month := month_picker.value + var day := day_picker.value + var days_on_month: int = days_per_month[month] + + var is_leap_year := (year % 4 == 0 && year % 100 != 0) || year % 400 == 0 + if is_leap_year && month == 2: + days_on_month = 29 + + if day > days_on_month: + day_picker.value = days_on_month + day_picker.max_value = days_on_month + + +func get_day() -> int: + return day_picker.value + + +func get_month() -> int: + return month_picker.value + + +func get_year() -> int: + return year_picker.value + + +func get_date() -> Dictionary: + return { + year = year_picker.value, + month = month_picker.value, + day = day_picker.value, + } + + +func set_date(new_year: int, new_month: int, new_day: int): + year_picker.value = new_year + month_picker.value = new_month + day_picker.value = new_day + + |
