aboutsummaryrefslogtreecommitdiff
path: root/client/menu/rating/rating.gd
blob: 023c133309a404e40caf04b9ea6473d78b2e4b1b (plain)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Hurry Curry! - a game about cooking
# Copyright (C) 2025 Hurry Curry! contributors
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
#
extends Menu

const PARTICLE_AMOUNTS = [1, 6, 32, 128]

@onready var game: Game = $"../Game"
@onready var title: Label = $MarginContainer/PanelContainer/VBoxContainer/Text/Title
@onready var subtitle: Label = $MarginContainer/PanelContainer/VBoxContainer/Text/Subtitle
@onready var stars = $MarginContainer/PanelContainer/VBoxContainer/Stars.get_children()
@onready var star_timer = $StarTimer
@onready var particles = $Control/Particles
@onready var close_button: Button = $MarginContainer/PanelContainer/VBoxContainer/HBoxContainer/Close

func _ready():
	super()
	show_rating(data[0], data[1])
	close_button.disabled = true # Disable for short time period to prevent accidental button press

func _process(_delta):
	particles.emission_rect_extents = get_viewport_rect().size * Vector2(0.5, 0.5)

func show_rating(stars_: int, points: int):
	match stars_:
		0: title.text = tr("c.score.poor")
		1: title.text = tr("c.score.acceptable")
		2: title.text = tr("c.score.good")
		3: title.text = tr("c.score.excellent")
	
	subtitle.text = tr("c.score.points_par").format([points])
	
	for i in range(0, stars_):
		var star: TextureRect = stars[i]
		star_timer.start()
		await star_timer.timeout
		star.material.set_shader_parameter("t", 1)
		star.get_node("Sound").play()
	
	particles.amount = PARTICLE_AMOUNTS[stars_]
	
	if stars_ > 1:
		particles.emitting = true

func _on_close_pressed():
	exit()

func _on_button_timer_timeout() -> void:
	close_button.disabled = false

func _on_scoreboard_pressed() -> void:
	exit()
	game.mp.send_chat(game.my_player_id, "/scoreboard %s" % Global.last_map_name)