Reminder.gd 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. @tool
  2. extends PanelContainer
  3. var timer_active := false
  4. func _process(_delta: float) -> void:
  5. if timer_active:
  6. var time_left = $Timer.time_left
  7. $VBoxContainer/TimerCountdown.text = gen_time_string(format_time(time_left)) + " Left..."
  8. func format_time(time_time := 0.0) -> Dictionary:
  9. var mils = abs(fmod(time_time, 1) * 100)
  10. var secs = abs(fmod(time_time, 60))
  11. var mins = abs(time_time / 60)
  12. return {"mils": int(mils), "secs": int(secs), "mins": int(mins)}
  13. func gen_time_string(timer_dict := {}) -> String:
  14. return str(int(timer_dict["mins"])).pad_zeros(2) + ":" + str(int(timer_dict["secs"])).pad_zeros(2) + ":" + str(int(timer_dict["mils"])).pad_zeros(2)
  15. func timer_finished() -> void:
  16. for i in 3:
  17. $AudioStreamPlayer.play()
  18. await get_tree().create_timer(1).timeout
  19. start_timer()
  20. func start_timer() -> void:
  21. print("ahh")
  22. if not timer_active:
  23. $Timer.wait_time = $VBoxContainer/HBoxContainer/SpinBox.value * 60
  24. $Timer.start()
  25. $VBoxContainer/Inactive.hide()
  26. $VBoxContainer/TimerCountdown.show()
  27. timer_active = true
  28. else:
  29. timer_active = false
  30. $Timer.stop()
  31. $VBoxContainer/Inactive.show()
  32. $VBoxContainer/TimerCountdown.hide()
  33. $VBoxContainer/HBoxContainer/Start.text = "Start" if not timer_active else "Stop"
  34. func on_pressed() -> void:
  35. print("FUCK")