aboutsummaryrefslogtreecommitdiff
path: root/client/menu/scene_transition.gd
blob: 66b6c4e455ace0173e8f0d14d8ead8c43350ffcd (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
66
67
68
# Undercooked - a game about cooking
# Copyright 2024 metamuffin
# 
# 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/>.
# 
class_name SceneTransition
extends ColorRect

@onready var anim: AnimationPlayer = $animation
@export var ingame = false

@export var auto_fade_in := true

var black = true
var fading = false

func _ready():
	visible = true
	if auto_fade_in: fade_in()

func fade_in():
	if black: anim.play("fade_in"); fading = true
	black = false
	if fading: await anim.animation_finished
	fading = false

func fade_out():
	if not black: anim.play("fade_out"); fading = true
	black = true
	if fading: await anim.animation_finished
	fading = false

func transition_to(path: String):
	await out()
	get_tree().change_scene_to_file(path)

func instant_to(path: String):
	get_tree().change_scene_to_file(path)

func quit():
	await out()
	get_tree().quit()

func out():
	visible = true
	if menu.visible:
		menu.anim.play_backwards("activate")
		await menu.anim.animation_finished
	anim.play("fade_out")
	await anim.animation_finished

@onready var menu = $IngameMenu
func _process(_delta):
	if ingame:
		if not menu.visible and Input.is_action_just_pressed("pause"):
			menu.act()
		elif menu.visible and Input.is_action_just_pressed("pause"):
			menu.deact()