Code reorganizing
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
extends CanvasLayer
|
||||
|
||||
signal fading_finished
|
||||
signal transition_finished
|
||||
|
||||
@onready var big_fading = $BigFading
|
||||
@onready var small_fading = $SmallFading
|
||||
@onready var big_animation = $BigFading/BigFadingAnimation
|
||||
@onready var small_animation = $SmallFading/SmallFadingAnimation
|
||||
@onready var mask = $Mask
|
||||
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
||||
#Hiding masks
|
||||
big_fading.visible = false
|
||||
small_fading.visible = false
|
||||
mask.visible = false
|
||||
|
||||
#Connecting signals
|
||||
big_animation.connect("animation_finished", _on_animation_finished)
|
||||
small_animation.connect("animation_finished", _on_animation_finished)
|
||||
|
||||
|
||||
|
||||
func _on_animation_finished(anim_name):
|
||||
|
||||
#Fades back to normal when fade_to_black is done
|
||||
if anim_name == "fade_to_black":
|
||||
fading_finished.emit()
|
||||
big_animation.play("fade_to_normal")
|
||||
small_animation.play("fade_to_normal")
|
||||
|
||||
#Resets everything when fading_to_normal is done
|
||||
elif anim_name == "fade_to_normal":
|
||||
transition_finished.emit()
|
||||
Globals.is_transitioning = false
|
||||
big_fading.visible = false
|
||||
small_fading.visible = false
|
||||
|
||||
|
||||
|
||||
#Handles fading transitions
|
||||
func fading(size):
|
||||
|
||||
Globals.is_transitioning = true
|
||||
|
||||
if size == "big":
|
||||
big_fading.visible = true
|
||||
big_animation.play("fade_to_black")
|
||||
elif size == "small":
|
||||
small_fading.visible = true
|
||||
small_animation.play("fade_to_black")
|
||||
|
||||
|
||||
|
||||
#Transitions the scenes
|
||||
func transition(fading_screen_size, scenes_to_hide, scenes_to_show):
|
||||
|
||||
#Fade in and out
|
||||
fading(fading_screen_size)
|
||||
await self.fading_finished
|
||||
|
||||
#When the screen is black from fading, change the shown scenes before it fades back to normal
|
||||
for scene in scenes_to_hide:
|
||||
scene.hide()
|
||||
for scene in scenes_to_show:
|
||||
scene.show()
|
||||
|
||||
Reference in New Issue
Block a user