aboutsummaryrefslogtreecommitdiff
path: root/client/menu/scene_transition.gd
blob: b6479a7fc0547faf055565c6a0a387a2552538e8 (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
# Hurry Curry! - a game about cooking
# Copyright 2024 metamuffin
# Copyright 2024 tpart
#
# 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 Control

@onready var black_anim: AnimationPlayer = $black_fader
@onready var text_anim: AnimationPlayer = $text_fader
@onready var text: Label = $text_margin/text

var s_current = false
var s_target = false
var fading = false

func _ready():
	$black.visible = true
	text.visible = true
	text.text = ""

func set_loading_text(s: String):
	text.text = s
	text_anim.play("fade")

func next():
	while fading: await black_anim.animation_finished
	if s_target == s_current: return
	fading = true
	if s_target:
		if text.text != "":
			text_anim.play_backwards("fade")
			await text_anim.animation_finished
		black_anim.play_backwards("fade")
		await black_anim.animation_finished
		self.mouse_filter = Control.MOUSE_FILTER_IGNORE
		set_loading_text("")
		s_current = true
	else:
		self.mouse_filter = Control.MOUSE_FILTER_STOP
		black_anim.play("fade")
		await black_anim.animation_finished
		await get_tree().process_frame # animation finishes one frame early
		s_current = false
	fading = false
	await next()

func fade_in():
	s_target = true
	await next()
func fade_out():
	s_target = false
	await next()

func _exit_tree():
	if fading: push_error("SceneTransition destroyed while fading")