Files
tgcc/core/scene_manager/scene_manager.gd

44 lines
1.2 KiB
GDScript

extends CanvasLayer
@export var config: SceneConfig
@onready var color_rect = $ColorRect
@onready var loading_screen = $LoadingScreen
@export var transition_duration: float = 1
func _ready() -> void:
color_rect.color.a = 0.0
color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
loading_screen.hide()
func change_scene(scene_enum: SceneConfig.SceneName) -> void:
if not config or not config.scenes.has(scene_enum):
return
var target_scene: PackedScene = config.scenes[scene_enum]
color_rect.mouse_filter = Control.MOUSE_FILTER_STOP
var tween_in = create_tween()
tween_in.tween_property(color_rect, "color:a", 1.0, transition_duration)
await tween_in.finished
loading_screen.show()
await get_tree().process_frame
get_tree().change_scene_to_packed(target_scene)
loading_screen.hide()
var tween_out = create_tween()
tween_out.tween_property(color_rect, "color:a", 0.0, transition_duration)
await tween_out.finished
color_rect.mouse_filter = Control.MOUSE_FILTER_IGNORE
func quit_game() -> void:
color_rect.mouse_filter = Control.MOUSE_FILTER_STOP
var tween = create_tween()
tween.tween_property(color_rect, "color:a", 1.0, transition_duration)
await tween.finished
get_tree().quit()