143 lines
5.3 KiB
GDScript
143 lines
5.3 KiB
GDScript
extends Control
|
|
|
|
#var taskbar_height : int = 50
|
|
#@export var bar_size : int = 10
|
|
@export var bar: TextureProgressBar
|
|
@export var label: Label
|
|
@export var options_window: Window
|
|
@export var background: ColorRect
|
|
|
|
#
|
|
#@export var bar_position : Position
|
|
#
|
|
#enum Position {
|
|
#Bottom,
|
|
#Right,
|
|
#Top,
|
|
#Left,
|
|
#}
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
setup_window()
|
|
|
|
|
|
func setup_window():
|
|
|
|
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
|
|
if Data.save.position == Data.Position.Bottom:
|
|
|
|
|
|
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)
|
|
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
|
|
position.y = 0 # set position of bar to be where it should be (moves when we change the window size)
|
|
position.x = 0
|
|
rotation_degrees = 0
|
|
label.label_settings.font_size = (float(Data.save.size)/10)*10
|
|
if Data.save.position == Data.Position.Right:
|
|
|
|
|
|
get_window().size = Vector2i(Data.save.size, screen_size.y) # set window size to be 10 high and screen width wide
|
|
size.x = screen_size.y - Data.save.safe_bottom
|
|
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
|
|
position.y = 0 # set position of bar to be where it should be (moves when we change the window size)
|
|
position.x = Data.save.size
|
|
rotation_degrees = 90
|
|
|
|
background.color = Data.save.background_color
|
|
modulate = Color(1,1,1,Data.save.bar_transparency)
|
|
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
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
var unix : float = Time.get_unix_time_from_system()
|
|
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))
|
|
|
|
## need to do different behaviour depending on if target time has passed for the particular day
|
|
var next_end : float = 0
|
|
|
|
# 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
|
|
|
|
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
|
|
#print("bar value: " + str(bar.value))
|
|
#label.text = Time.get_datetime_string_from_system()
|
|
#Time.
|
|
#print(current_day)
|
|
|
|
if (seconds_left <= Data.save.warning_time):
|
|
bar.modulate = Data.save.warning_color
|
|
else:
|
|
bar.modulate = Data.save.bar_color
|
|
|
|
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"
|
|
#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
|
|
|
|
|
|
func _on_popup_menu_id_pressed(id: int) -> void:
|
|
if id == 0:
|
|
get_tree().quit()
|
|
if id == 1:
|
|
options_window.show()
|