stick-the-quick/autoload/HUD/HUD.gd

49 lines
1.2 KiB
GDScript

extends CanvasLayer
const NEGATIVE_TIME_HUE_CYCLE_SPEED: float = 1.0
@onready var _time_label := $MarginContainer/VBoxContainer/Time as Label
@onready var _fps_label := $MarginContainer/VBoxContainer/FPS as Label
var time: float
var _negative_time_hue: float = 0.0
func _ready() -> void:
hide()
func format_time(seconds: float) -> String:
return TimeIntervalFormatting.format_realtime_interval(seconds)
func _should_show() -> bool:
return (
PlayerControl.enabled() and
Storyboard.get_game_mode() != LevelDescriptor.GameMode.HUB
)
func _physics_process(delta: float) -> void:
if _should_show():
show()
if _time_label.visible:
time += delta
if time < 0.0:
_time_label.modulate = (
Color.from_hsv(_negative_time_hue, 1.0, 1.0)
)
_negative_time_hue += delta*NEGATIVE_TIME_HUE_CYCLE_SPEED
else:
_time_label.modulate = Color.WHITE
_time_label.text = format_time(time)
else:
hide()
func _process(delta: float) -> void:
if _fps_label.visible and OS.is_debug_build():
_fps_label.text = "%.1fFPS" % (1.0/delta)
func start_timer(at: float = 0.0) -> void:
_time_label.visible = true
time = at
func stop_timer() -> void:
_time_label.visible = false