diff --git a/game/ui/loading_screen/loading_screen.gd b/game/ui/loading_screen/loading_screen.gd deleted file mode 100644 index af8f994..0000000 --- a/game/ui/loading_screen/loading_screen.gd +++ /dev/null @@ -1,73 +0,0 @@ -extends CanvasLayer - -@onready var transition_rect : ColorRect = $TransitionRect -@onready var status_label : Label = %StatusLabel -@onready var progress_bar : ProgressBar = %ProgressBar - -const FADE_DURATION := 0.6 -const MIN_DISPLAY_TIME := 0.4 # évite le flash sur les chargements instantanés - -func _ready() -> void: - transition_rect.visible = false - process_mode = Node.PROCESS_MODE_ALWAYS - -func change_scene(scene_path : String, message : String = "Chargement...") -> void: - var start_ms := Time.get_ticks_msec() - - # --- 1. Afficher l'écran de chargement (fade in) --- - status_label.text = message - progress_bar.value = 0 - transition_rect.modulate.a = 0.0 - transition_rect.visible = true - - var fade_in := create_tween() - fade_in.tween_property(transition_rect, "modulate:a", 1.0, FADE_DURATION) - await fade_in.finished - - # --- 2. Lancer le chargement en arrière-plan --- - var err := ResourceLoader.load_threaded_request(scene_path) - if err != OK: - push_error("Échec du lancement du chargement : %s (err %d)" % [scene_path, err]) - await _fade_out() - return - - # --- 3. Boucle jusqu'à ce que la scène soit prête --- - var prog : Array = [] - while true: - var status := ResourceLoader.load_threaded_get_status(scene_path, prog) - match status: - ResourceLoader.THREAD_LOAD_IN_PROGRESS: - if prog.size() > 0: - progress_bar.value = prog[0] * 100.0 - await get_tree().process_frame - ResourceLoader.THREAD_LOAD_LOADED: - break - _: - push_error("Échec du chargement de %s" % scene_path) - await _fade_out() - return - - var packed : PackedScene = ResourceLoader.load_threaded_get(scene_path) - if packed == null: - push_error("PackedScene nulle pour %s" % scene_path) - await _fade_out() - return - - # --- 4. Durée minimale visible (anti-flash) --- - var elapsed := (Time.get_ticks_msec() - start_ms) / 1000.0 - if elapsed < MIN_DISPLAY_TIME: - await get_tree().create_timer(MIN_DISPLAY_TIME - elapsed).timeout - - # --- 5. Changer de scène --- - get_tree().change_scene_to_packed(packed) - - # --- 6. Laisser la nouvelle scène s'initialiser, puis fade out --- - await get_tree().process_frame - await get_tree().process_frame - await _fade_out() - -func _fade_out() -> void: - var tween := create_tween() - tween.tween_property(transition_rect, "modulate:a", 0.0, FADE_DURATION) - await tween.finished - transition_rect.visible = false diff --git a/game/ui/loading_screen/loading_screen.gd.uid b/game/ui/loading_screen/loading_screen.gd.uid deleted file mode 100644 index 1e63238..0000000 --- a/game/ui/loading_screen/loading_screen.gd.uid +++ /dev/null @@ -1 +0,0 @@ -uid://nl7jg02c6wwm diff --git a/game/ui/loading_screen/loading_screen.tscn b/game/ui/loading_screen/loading_screen.tscn deleted file mode 100644 index e910bf9..0000000 --- a/game/ui/loading_screen/loading_screen.tscn +++ /dev/null @@ -1,42 +0,0 @@ -[gd_scene format=3 uid="uid://ckyjxhrfhaqlc"] - -[ext_resource type="Script" uid="uid://nl7jg02c6wwm" path="res://game/ui/loading_screen/loading_screen.gd" id="1_v6dnv"] - -[node name="LoadingScreen" type="CanvasLayer" unique_id=255554158] -layer = 128 -script = ExtResource("1_v6dnv") - -[node name="TransitionRect" type="ColorRect" parent="." unique_id=2119321044] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -color = Color(0, 0, 0, 1) - -[node name="MarginContainer" type="MarginContainer" parent="TransitionRect" unique_id=1396198220] -layout_mode = 1 -anchors_preset = 3 -anchor_left = 1.0 -anchor_top = 1.0 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_left = -1152.0 -offset_top = -54.0 -grow_horizontal = 0 -grow_vertical = 0 -theme_override_constants/margin_right = 15 -theme_override_constants/margin_bottom = 15 - -[node name="VBoxContainer" type="VBoxContainer" parent="TransitionRect/MarginContainer" unique_id=550870747] -layout_mode = 2 -size_flags_horizontal = 8 -size_flags_vertical = 8 - -[node name="StatusLabel" type="Label" parent="TransitionRect/MarginContainer/VBoxContainer" unique_id=782325402] -unique_name_in_owner = true -layout_mode = 2 - -[node name="ProgressBar" type="ProgressBar" parent="TransitionRect/MarginContainer/VBoxContainer" unique_id=1836299440] -unique_name_in_owner = true -layout_mode = 2 diff --git a/game/ui/main_menu/main_menu.gd b/game/ui/main_menu/main_menu.gd index 829c5b7..6465087 100644 --- a/game/ui/main_menu/main_menu.gd +++ b/game/ui/main_menu/main_menu.gd @@ -8,11 +8,11 @@ extends Node @onready var game_infos: Control = %GameInfos @onready var options_menu : OptionsMenu = %OptionsMenu +@export var game_scene: PackedScene @export var progression_backgrounds: Array[Texture2D] = [] @export var menu_music: AudioStream @export var start_click_sound: AudioStream -const GAME_SCENE_PATH := "res://game/world/main.tscn" const MUSIC_FADE_DURATION := 0.8 var is_transitioning : bool = false @@ -54,8 +54,8 @@ func _on_start_pressed() -> void: if is_transitioning: return is_transitioning = true play_click_sound() - LoadingScreen.change_scene(GAME_SCENE_PATH, "Préparation de l'aventure...") - + SceneTransition.change_scene(game_scene) + func play_click_sound() -> void: UiAudio.play(start_click_sound) diff --git a/game/ui/main_menu/main_menu.tscn b/game/ui/main_menu/main_menu.tscn index ebb3ecd..39dde4d 100644 --- a/game/ui/main_menu/main_menu.tscn +++ b/game/ui/main_menu/main_menu.tscn @@ -1,6 +1,7 @@ [gd_scene format=3 uid="uid://bluq6da7tku3d"] [ext_resource type="Script" uid="uid://cj37ns1ahfvhr" path="res://game/ui/main_menu/main_menu.gd" id="1_ekxnf"] +[ext_resource type="PackedScene" uid="uid://bicg07c42wm1t" path="res://game/world/main.tscn" id="2_0p1rw"] [ext_resource type="Script" uid="uid://7hglx6nfu063" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="2_bqqt6"] [ext_resource type="Texture2D" uid="uid://d23fefvrd41re" path="res://assets/textures/background/0.png" id="2_wu84c"] [ext_resource type="PackedScene" uid="uid://bguem4nrp55gu" path="res://game/ui/options_menu/options_menu.tscn" id="4_1x88f"] @@ -27,6 +28,7 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_ekxnf") +game_scene = ExtResource("2_0p1rw") progression_backgrounds = Array[Texture2D]([ExtResource("2_wu84c")]) [node name="Background" type="TextureRect" parent="." unique_id=545049912] diff --git a/game/ui/scene_transition.gd b/game/ui/scene_transition.gd new file mode 100644 index 0000000..fd77592 --- /dev/null +++ b/game/ui/scene_transition.gd @@ -0,0 +1,68 @@ +# res://autoload/scene_transition.gd +extends CanvasLayer + +signal transition_finished + +@export var fade_duration: float = 0.4 +@export var color: Color = Color.BLACK + +var _rect: ColorRect +var _is_transitioning := false + +func _ready() -> void: + # Couche au-dessus de tout + layer = 128 + # Ne bloque pas les inputs quand invisible + process_mode = Node.PROCESS_MODE_ALWAYS + + _rect = ColorRect.new() + _rect.color = color + _rect.modulate.a = 0.0 + _rect.visible = false + _rect.mouse_filter = Control.MOUSE_FILTER_IGNORE + _rect.set_anchors_preset(Control.PRESET_FULL_RECT) + add_child(_rect) + +func change_scene(scene: PackedScene, duration: float = -1.0) -> void: + var prev := fade_duration + if duration > 0.0: + fade_duration = duration + await change_scene_path(scene.resource_path) + fade_duration = prev + +func change_scene_path(path: String) -> void: + if _is_transitioning: + return + _is_transitioning = true + + # 1. Fade vers le noir + await _fade(1.0) + + # 2. Changement effectif + var err := get_tree().change_scene_to_file(path) + if err != OK: + push_error("Erreur changement de scène: %s" % err) + await _fade(0.0) + _is_transitioning = false + return + + # 3. Attendre que la nouvelle scène soit prête + await get_tree().process_frame + await get_tree().process_frame + + # 4. Fade depuis le noir + await _fade(0.0) + + _is_transitioning = false + transition_finished.emit() + + +func _fade(target_alpha: float) -> void: + _rect.visible = true + var tween := create_tween() + tween.set_ease(Tween.EASE_IN_OUT) + tween.set_trans(Tween.TRANS_SINE) + tween.tween_property(_rect, "modulate:a", target_alpha, fade_duration) + await tween.finished + if is_zero_approx(target_alpha): + _rect.visible = false diff --git a/game/ui/scene_transition.gd.uid b/game/ui/scene_transition.gd.uid new file mode 100644 index 0000000..e3dda34 --- /dev/null +++ b/game/ui/scene_transition.gd.uid @@ -0,0 +1 @@ +uid://b5th8pkqmblsd diff --git a/project.godot b/project.godot index ad73569..2ce481b 100644 --- a/project.godot +++ b/project.godot @@ -27,7 +27,7 @@ ControllerIcons="*uid://b7ho1rjcpht1d" GameData="*uid://d4beiel88cwc7" UiAudio="*uid://7e7fe2xk3aue" Settings="*uid://dyqiytgbiuuk5" -LoadingScreen="*uid://ckyjxhrfhaqlc" +SceneTransition="*uid://b5th8pkqmblsd" Hints="*uid://bqapxkrub0fcs" Pokedex="*uid://dijnkrewbwgmx" MountRegistry="*uid://u4gskwbwm0b0"