SleepyClock/options_window.gd
2026-06-01 12:21:11 +10:00

83 lines
2 KiB
GDScript

extends Window
signal options_changed
@export var sleep_h: SpinBox
@export var sleep_m: SpinBox
@export var duration_h: SpinBox
@export var duration_m: SpinBox
@export var size_label: Label
@export var size_slider: HSlider
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
#validate inputs?, disable save button if somehow invalid?
if visible:
size_label.text = str(Data.save.size)+"px"
pass
func _on_close_requested() -> void:
hide()
pass # Replace with function body.
func _on_cancel_button_pressed() -> void:
Data.load_data()
hide()
func _on_save_button_pressed() -> void:
if Data.save_data():
hide()
pass # Replace with function body.
func _on_visibility_changed() -> void:
#populate form
#print(Data.save.end_time)
sleep_h.value = int(Data.save.end_time/(60*60))
sleep_m.value = int((Data.save.end_time-sleep_h.value*60*60)/60)
duration_h.value = int(Data.save.duration/(60*60))
duration_m.value = int((Data.save.duration-duration_h.value*60*60)/60)
size_slider.value = Data.save.size
pass # Replace with function body.
func _on_duration_value_changed(value: float) -> void:
var duration_seconds : float = 0
duration_seconds += duration_h.value * 60 * 60
duration_seconds += duration_m.value * 60
Data.save.duration = duration_seconds
pass # Replace with function body.
func _on_sleep_value_changed(value: float) -> void:
var end_seconds : float = 0
end_seconds += sleep_h.value * 60 * 60
end_seconds += sleep_m.value * 60
Data.save.end_time = end_seconds
pass # Replace with function body.
func _on_size_slider_value_changed(value: float) -> void:
Data.save.size = int(value)
options_changed.emit()
func _on_position_dropdown_item_selected(index: int) -> void:
if index == 0:
Data.save.position = Data.Position.Bottom
elif index == 1:
Data.save.position = Data.Position.Right
options_changed.emit()