aboutsummaryrefslogtreecommitdiffstats
path: root/Scripts/UI_Control.gd
blob: a45503aa7911e7449e0ef82f9aa0671d40905f78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
extends Control

@onready var in_game_ui = $InGameUI
@onready var post_game_ui = $PostGameUI

@onready var time_label = $InGameUI/CurrentTime

@onready var gold_sprite: AnimatedSprite2D = $PostGameUI/Gold
@onready var silver_sprite: AnimatedSprite2D = $PostGameUI/Silver
@onready var bronze_sprite: AnimatedSprite2D = $PostGameUI/Bronze


func update_timer_label(new_time: float):
	if(new_time < 0):
		time_label.text = "Waiting for player to start driving..."
		return
	time_label.text = str(new_time).pad_decimals(3)

func switch_to_post_game_UI(medal: int):
	in_game_ui.visible = false
	post_game_ui.visible = true
	$PostGameUI/FinalTime.text = time_label.text
	
	if medal == 0:
		gold_sprite.visible = true
		gold_sprite.play("default")
	elif medal == 1:
		silver_sprite.visible = true
		silver_sprite.play("default")
	elif medal == 2:
		bronze_sprite.visible = true
		bronze_sprite.play("default")

func switch_to_in_game_UI():
	in_game_ui.visible = true
	post_game_ui.visible = false
	
	gold_sprite.visible = false
	silver_sprite.visible = false
	bronze_sprite.visible = false

func _on_start_button_pressed():
	var root = owner.owner
	if root and root.has_method("start_driving"):
		root.start_driving()