117 lines
4.1 KiB
GDScript
117 lines
4.1 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 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 bar_position == Position.Bottom:
|
|
if screen_size.x > 2560:
|
|
bar_size = 20
|
|
|
|
get_window().size = Vector2i(screen_size.x, bar_size) # set window size to be 10 high and screen width wide
|
|
size = Vector2i(screen_size.x, bar_size)
|
|
DisplayServer.window_set_position(screen_pos + Vector2i(0,screen_size.y-bar_size-taskbar_height)) # 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)
|
|
label.label_settings.font_size = (bar_size/10)*10
|
|
if bar_position == Position.Right:
|
|
if screen_size.y > 1440:
|
|
bar_size = 20
|
|
|
|
get_window().size = Vector2i(bar_size, screen_size.y) # set window size to be 10 high and screen width wide
|
|
size.x = screen_size.y - taskbar_height
|
|
size.y = bar_size
|
|
label.label_settings.font_size = (bar_size/10)*10
|
|
DisplayServer.window_set_position(screen_pos + Vector2i(screen_size.x-bar_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 = bar_size
|
|
rotation_degrees = 90
|
|
|
|
# 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
|
|
bar.value = Data.save.duration - seconds_left
|
|
#print("bar value: " + str(bar.value))
|
|
#label.text = Time.get_datetime_string_from_system()
|
|
#Time.
|
|
#print(current_day)
|
|
|
|
if (seconds_left <= 3600):
|
|
bar.modulate = Color.RED
|
|
else:
|
|
bar.modulate = Color.DODGER_BLUE
|
|
|
|
#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()
|