131 lines
3.9 KiB
GDScript
131 lines
3.9 KiB
GDScript
extends Control
|
|
|
|
enum State{
|
|
Working,
|
|
OffTask,
|
|
Break
|
|
}
|
|
|
|
@export var colors : Array[Color]
|
|
|
|
@export_group("Node References")
|
|
@export var on_task_panel : Control
|
|
@export var off_task_panel : Control
|
|
@export var break_panel : Control
|
|
@export var background : ColorRect
|
|
@export var on_clock : RichTextLabel
|
|
@export var off_clock : RichTextLabel
|
|
@export var break_clock : RichTextLabel
|
|
@export var next_break_text : RichTextLabel
|
|
@export var time_spent_text : RichTextLabel
|
|
|
|
var state : State = State.Working
|
|
var total_working_time : float = 0
|
|
var total_off_time : float = 0
|
|
var off_time : float = 0
|
|
var break_time : float = 0
|
|
var update : float = 0.5
|
|
|
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
func _ready() -> void:
|
|
pass # Replace with function body.
|
|
print(get_next_break_time())
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _process(delta: float) -> void:
|
|
update -= delta
|
|
background.color = colors[state]
|
|
on_task_panel.visible = state == State.Working
|
|
off_task_panel.visible = state == State.OffTask
|
|
break_panel.visible = state == State.Break
|
|
if(state == State.Working):
|
|
total_working_time += delta
|
|
time_spent_text.text = seconds_to_time(total_working_time) + " Spent working"
|
|
on_clock.text = get_next_break_time()
|
|
next_break_text.text = "Until " + get_next_break_name()
|
|
elif(state == State.OffTask):
|
|
off_time += delta
|
|
total_off_time += delta
|
|
#off_clock.text = "[wave amp="+str(off_time/5)+" freq="+str(off_time/20)+"]"
|
|
#off_clock.text += seconds_to_time(off_time,false)
|
|
elif(state == State.Break):
|
|
break_time += delta
|
|
break_clock.text = seconds_to_time(break_time,false)
|
|
|
|
if(update <= 0): #every time the clock is updated it resets the animation, this prevent sit from updating too often
|
|
update += 0.5
|
|
off_clock.text = "[shake rate="+str(off_time/5)+" level="+str(off_time/20)+"]"
|
|
off_clock.text += seconds_to_time(off_time,false)
|
|
|
|
|
|
func _on_popup_menu_id_pressed(id: int) -> void:
|
|
# 0 = exit
|
|
if id == 0:
|
|
get_tree().quit()
|
|
pass # Replace with function body.
|
|
|
|
|
|
func _on_off_task_button_pressed() -> void:
|
|
if state == State.OffTask:
|
|
state = State.Working
|
|
off_time = 0
|
|
else:
|
|
state = State.OffTask
|
|
off_time = 0
|
|
|
|
|
|
func _on_pause_button_pressed() -> void:
|
|
if state == State.Break:
|
|
state = State.Working
|
|
else:
|
|
state = State.Break
|
|
break_time = 0
|
|
|
|
func get_next_break_name() -> String:
|
|
var currentUnix : int = Time.get_unix_time_from_system()
|
|
var timezone : Dictionary = Time.get_time_zone_from_system()
|
|
var todaysUnix : int = (currentUnix % 86400) + 60 * timezone.bias
|
|
if(todaysUnix > 86400):
|
|
todaysUnix -= 86400
|
|
# lunch at 46800
|
|
# dinner at 64800
|
|
if(todaysUnix < 46800):
|
|
return "Lunch"
|
|
elif(todaysUnix < 64800):
|
|
return "Dinner"
|
|
else:
|
|
return "Midnight"
|
|
|
|
# returns the time reaming until next break int he format H:SS
|
|
func get_next_break_time() -> String:
|
|
# get current unix time
|
|
# use % to get the time since midnight - 86400 seconds in one day
|
|
var currentUnix : int = Time.get_unix_time_from_system()
|
|
var timezone : Dictionary = Time.get_time_zone_from_system()
|
|
var todaysUnix : int = (currentUnix % 86400) + 60 * timezone.bias
|
|
if(todaysUnix > 86400):
|
|
todaysUnix -= 86400
|
|
# lunch at 46800
|
|
# dinner at 64800
|
|
var seconds_to_break : int = 0
|
|
if(todaysUnix < 46800):
|
|
seconds_to_break = 46800 - todaysUnix
|
|
elif(todaysUnix < 64800):
|
|
seconds_to_break = 64800 - todaysUnix
|
|
else:
|
|
seconds_to_break = 86400 - todaysUnix
|
|
|
|
#print("Seconds " + str(seconds_to_break))
|
|
return seconds_to_time(seconds_to_break)
|
|
|
|
func seconds_to_time(seconds : int, has_hours : bool = true) -> String:
|
|
if(has_hours):
|
|
var hours : int = seconds / 3600
|
|
var minutes : int = (seconds / 60) - hours * 60
|
|
return str(hours).pad_zeros(2) + ":" + str(minutes).pad_zeros(2)
|
|
else:
|
|
var minutes : int = (seconds / 60)
|
|
var dSeconds : int = seconds - minutes * 60
|
|
return str(minutes).pad_zeros(2) + ":" + str(dSeconds).pad_zeros(2)
|