2026-05-27 01:42:45 +10:00
extends Control
2026-06-01 17:52:21 +10:00
#var taskbar_height : int = 50
2026-06-01 12:21:11 +10:00
#@export var bar_size : int = 10
2026-05-27 01:42:45 +10:00
@ export var bar : TextureProgressBar
2026-05-29 02:00:57 +10:00
@ export var label : Label
2026-05-31 21:28:25 +10:00
@ export var options_window : Window
2026-06-01 12:45:42 +10:00
@ export var background : ColorRect
2026-05-31 21:28:25 +10:00
2026-06-01 12:21:11 +10:00
#
#@export var bar_position : Position
#
#enum Position {
#Bottom,
#Right,
#Top,
#Left,
#}
2026-05-30 12:37:59 +10:00
2026-05-31 15:03:22 +10:00
# Called when the node enters the scene tree for the first time.
2026-05-27 01:42:45 +10:00
func _ready ( ) - > void :
2026-05-30 12:37:59 +10:00
setup_window ( )
2026-05-27 01:42:45 +10:00
2026-05-30 12:37:59 +10:00
func setup_window ( ) :
2026-06-01 00:13:23 +10:00
2026-05-30 12:37:59 +10:00
var screen_size : Vector2i = DisplayServer . screen_get_size ( ) # get current screen size
var screen_pos : Vector2i = DisplayServer . screen_get_position ( DisplayServer . SCREEN_OF_MAIN_WINDOW ) # get the posiiton of the window on the virtual display
get_window ( ) . min_size = Vector2i ( 1 , 1 ) # weird godot bug where the min screen size is 64x64 unless set in code
2026-06-01 12:21:11 +10:00
if Data . save . position == Data . Position . Bottom :
2026-06-01 00:13:23 +10:00
2026-06-01 12:21:11 +10:00
get_window ( ) . size = Vector2i ( screen_size . x , Data . save . size ) # set window size to be 10 high and screen width wide
size = Vector2i ( screen_size . x , Data . save . size )
2026-06-01 17:52:21 +10:00
DisplayServer . window_set_position ( screen_pos + Vector2i ( 0 , screen_size . y - Data . save . size - Data . save . safe_bottom ) ) # set position of window to be just above the taskbar
2026-05-30 12:37:59 +10:00
position . y = 0 # set position of bar to be where it should be (moves when we change the window size)
2026-06-01 12:21:11 +10:00
position . x = 0
rotation_degrees = 0
label . label_settings . font_size = ( float ( Data . save . size ) / 10 ) * 10
if Data . save . position == Data . Position . Right :
2026-06-01 00:13:23 +10:00
2026-06-01 12:21:11 +10:00
get_window ( ) . size = Vector2i ( Data . save . size , screen_size . y ) # set window size to be 10 high and screen width wide
2026-06-01 17:52:21 +10:00
size . x = screen_size . y - Data . save . safe_bottom
2026-06-01 12:21:11 +10:00
size . y = Data . save . size
label . label_settings . font_size = ( float ( Data . save . size ) / 10 ) * 10
DisplayServer . window_set_position ( screen_pos + Vector2i ( screen_size . x - Data . save . size , 0 ) ) # set position of window to be just above the taskbar
2026-05-30 12:37:59 +10:00
position . y = 0 # set position of bar to be where it should be (moves when we change the window size)
2026-06-01 12:21:11 +10:00
position . x = Data . save . size
2026-05-30 12:41:16 +10:00
rotation_degrees = 90
2026-06-01 12:45:42 +10:00
background . color = Data . save . background_color
modulate = Color ( 1 , 1 , 1 , Data . save . bar_transparency )
2026-06-01 17:40:48 +10:00
if Data . save . progress_style == Data . Styles . Filling or Data . save . progress_style == Data . Styles . Emptying :
bar . fill_mode = bar . FillMode . FILL_LEFT_TO_RIGHT
else :
bar . fill_mode = bar . FillMode . FILL_RIGHT_TO_LEFT
2026-05-27 01:42:45 +10:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process ( delta : float ) - > void :
2026-05-31 21:28:25 +10:00
var unix : float = Time . get_unix_time_from_system ( )
2026-05-31 23:34:29 +10:00
var timezone_minutes = Time . get_time_zone_from_system ( ) . bias
var timezone_seconds = timezone_minutes * 60
var aus_unix : float = unix + ( timezone_seconds )
var aus_days : float = ( aus_unix / 86400 ) # days since unix
#print("curr: " + Time.get_datetime_string_from_unix_time(aus_unix))
2026-05-31 21:28:25 +10:00
2026-05-31 23:34:29 +10:00
## need to do different behaviour depending on if target time has passed for the particular day
var next_end : float = 0
2026-05-31 21:28:25 +10:00
2026-05-31 23:34:29 +10:00
# compare todays seconds to end time
var todays_seconds = aus_unix - ( int ( aus_days ) * 86400 )
#print("todays secs:" + str(todays_seconds))
#print("left: " + str(int(aus_days+1)*86400))
#print("righ: " + str(aus_unix + Data.save.end_time) )
if ( todays_seconds > Data . save . end_time ) :
#print("running if")
#target passed for the current day, use the next day
next_end = ( int ( aus_days + 1 ) * 86400 ) + ( Data . save . end_time )
pass
else :
#print("running else")
# target NOT passed for the current day, use current day
next_end = ( int ( aus_days ) * 86400 ) + ( Data . save . end_time )
pass
# need to find next timestamp of the clock end, int(days) * end_time
#var next_end : float = (int(aus_days)*86400) + (Data.save.end_time)
#var next_end : float = int(aus_unix)%86400 + Data.save.end_time
#print("next: " + Time.get_datetime_string_from_unix_time(next_end))
#print(str(unix) + " --> " + str(next_end))
var seconds_left : float = next_end - aus_unix
#print("seconds until end: " + str(seconds_left))
## dont worry about anything below here yet
bar . max_value = Data . save . duration
bar . min_value = 0
2026-06-01 17:40:48 +10:00
if Data . save . progress_style == Data . Styles . Filling or Data . save . progress_style == Data . Styles . Filling_Reversed :
bar . value = Data . save . duration - seconds_left
else :
bar . value = seconds_left
2026-05-31 23:34:29 +10:00
#print("bar value: " + str(bar.value))
2026-05-29 02:00:57 +10:00
#label.text = Time.get_datetime_string_from_system()
#Time.
2026-05-27 01:42:45 +10:00
#print(current_day)
2026-06-01 17:40:48 +10:00
if ( seconds_left < = Data . save . warning_time ) :
2026-06-01 12:45:42 +10:00
bar . modulate = Data . save . warning_color
2026-05-30 12:37:59 +10:00
else :
2026-06-01 12:45:42 +10:00
bar . modulate = Data . save . bar_color
2026-05-27 01:42:45 +10:00
2026-06-01 17:40:48 +10:00
if seconds_left > 82800 and Data . save . flashing :
var effect : float = ( sin ( seconds_left * 3 ) )
modulate = Color ( effect , effect , effect , effect )
else :
modulate = Color ( 1 , 1 , 1 , Data . save . bar_transparency )
if seconds_left > Data . save . duration + Data . save . before_time and seconds_left < 86400 - Data . save . after_time :
hide ( )
else :
show ( )
var time_left_dict : Dictionary = Tools . seconds_to_time ( int ( seconds_left ) )
var time_string : String = str ( time_left_dict . get ( " h " ) ) + " : " + str ( time_left_dict . get ( " m " ) ) . pad_zeros ( 2 ) + " : " + str ( time_left_dict . get ( " s " ) ) . pad_zeros ( 2 )
label . text = time_string + " Remaining until sleepytime "
2026-05-27 01:42:45 +10:00
#var screen_size : Vector2i = DisplayServer.screen_get_size()
#DisplayServer.window_set_size(Vector2i(screen_size.x, 10))
#get_window().size = Vector2i(screen_size.x, 10)
pass
2026-05-31 21:28:25 +10:00
func _on_popup_menu_id_pressed ( id : int ) - > void :
if id == 0 :
get_tree ( ) . quit ( )
if id == 1 :
options_window . show ( )
2026-06-01 19:21:45 +10:00
func _on_status_indicator_pressed ( mouse_button : int , mouse_position : Vector2i ) - > void :
if ( mouse_button == 1 ) :
options_window . show ( )