SleepyClock/options_window.gd

176 lines
5 KiB
GDScript3
Raw Normal View History

extends Window
2026-06-01 12:21:11 +10:00
signal options_changed
@export var sleep_h: SpinBox
@export var sleep_m: SpinBox
@export var duration_h: SpinBox
@export var duration_m: SpinBox
2026-06-01 12:21:11 +10:00
@export var size_label: Label
@export var size_slider: HSlider
@export var bar_color: ColorPickerButton
@export var background_color: ColorPickerButton
@export var warning_color: ColorPickerButton
@export var trans_label: Label
@export var trans_slider: HSlider
2026-06-01 17:10:16 +10:00
@export var warning_h: SpinBox
@export var warning_m: SpinBox
@export var flash_check: CheckButton
@export var before_h: SpinBox
@export var before_m: SpinBox
@export var after_h: SpinBox
@export var after_m: SpinBox
@export var style_dropdown: OptionButton
@export var position_dropdown: OptionButton
2026-06-01 17:52:21 +10:00
@export var safe_top: SpinBox
@export var safe_bottom: SpinBox
func _init() -> void:
hide()
# 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?
2026-06-01 12:21:11 +10:00
if visible:
size_label.text = str(Data.save.size)+"px"
trans_label.text = str(roundi(Data.save.bar_transparency*100))+"%"
pass
func _on_close_requested() -> void:
hide()
pass # Replace with function body.
func _on_cancel_button_pressed() -> void:
2026-06-01 12:21:11 +10:00
Data.load_data()
options_changed.emit()
hide()
func _on_save_button_pressed() -> void:
2026-06-01 12:21:11 +10:00
if Data.save_data():
hide()
pass # Replace with function body.
func _on_visibility_changed() -> void:
#populate form
#print(Data.save.end_time)
2026-06-01 17:10:16 +10:00
var sleep_dict : Dictionary = Tools.seconds_to_time(int(Data.save.end_time))
sleep_h.value = sleep_dict.get("h")
sleep_m.value = sleep_dict.get("m")
var duration_dict : Dictionary = Tools.seconds_to_time(int(Data.save.duration))
duration_h.value = duration_dict.get("h")
duration_m.value = duration_dict.get("m")
var warning_time_dict : Dictionary = Tools.seconds_to_time(int(Data.save.warning_time))
warning_h.value = warning_time_dict.get("h")
warning_m.value = warning_time_dict.get("m")
var before_time_dict : Dictionary = Tools.seconds_to_time(int(Data.save.before_time))
before_h.value = before_time_dict.get("h")
before_m.value = before_time_dict.get("m")
var after_time_dict : Dictionary = Tools.seconds_to_time(int(Data.save.after_time))
after_h.value = after_time_dict.get("h")
after_m.value = after_time_dict.get("m")
2026-06-01 12:21:11 +10:00
size_slider.value = Data.save.size
bar_color.color = Data.save.bar_color
background_color.color = Data.save.background_color
warning_color.color = Data.save.warning_color
trans_slider.value = Data.save.bar_transparency
2026-06-01 17:10:16 +10:00
flash_check.button_pressed = Data.save.flashing
position_dropdown.select(Data.save.position)
style_dropdown.select(Data.save.progress_style)
2026-06-01 17:52:21 +10:00
safe_bottom.value = Data.save.safe_bottom
safe_top.value = Data.save.safe_top
pass # Replace with function body.
2026-06-01 12:21:11 +10:00
func _on_duration_value_changed(value: float) -> void:
2026-06-01 17:10:16 +10:00
Data.save.duration = Tools.time_to_seconds(int(duration_h.value),int(duration_m.value))
2026-06-01 12:21:11 +10:00
func _on_sleep_value_changed(value: float) -> void:
2026-06-01 17:10:16 +10:00
Data.save.end_time = Tools.time_to_seconds(int(sleep_h.value),int(sleep_m.value))
2026-06-01 12:21:11 +10:00
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()
func _on_bar_color_color_changed(color: Color) -> void:
Data.save.bar_color = color
options_changed.emit()
func _on_background_color_color_changed(color: Color) -> void:
Data.save.background_color = color
options_changed.emit()
func _on_warning_color_color_changed(color: Color) -> void:
Data.save.warning_color = color
options_changed.emit()
func _on_trans_slider_value_changed(value: float) -> void:
Data.save.bar_transparency = value
options_changed.emit()
2026-06-01 17:10:16 +10:00
func _on_warning_value_changed(value: float) -> void:
Data.save.warning_time = Tools.time_to_seconds(int(warning_h.value),int(warning_m.value))
func _on_flash_check_toggled(toggled_on: bool) -> void:
Data.save.flashing = toggled_on
func _on_before_value_changed(value: float) -> void:
Data.save.before_time = Tools.time_to_seconds(int(before_h.value),int(before_m.value))
func _on_after_value_changed(value: float) -> void:
Data.save.after_time = Tools.time_to_seconds(int(after_h.value),int(after_m.value))
func _on_style_dropdown_item_selected(index: int) -> void:
if index == 0:
Data.save.progress_style = Data.Styles.Filling
elif index == 1:
Data.save.progress_style = Data.Styles.Filling_Reversed
elif index == 2:
Data.save.progress_style = Data.Styles.Emptying
elif index == 3:
Data.save.progress_style = Data.Styles.Emptying_Reversed
options_changed.emit()
2026-06-01 17:52:21 +10:00
func _on_safe_top_value_changed(value: float) -> void:
Data.save.safe_top = int(value)
options_changed.emit()
func _on_safe_bottom_value_changed(value: float) -> void:
Data.save.safe_bottom = int(value)
options_changed.emit()