Compare commits
5 commits
5e89c73c31
...
fbabe444c7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fbabe444c7 | ||
|
|
ae885259ec | ||
|
|
e0508b2edc | ||
|
|
c1415f3e43 | ||
|
|
53e5ca8f7b |
|
|
@ -5,6 +5,12 @@ signal selected_pokemon_changed
|
|||
signal battle_requested(sent : SentPokemon, target : Node) #emis par ThrowState : BattleLauncher s'y branche
|
||||
signal battle_finished(outcome : int, target : Node) #emis par BattleLauncher (outcome = valeur de Battle.Outcome)
|
||||
|
||||
signal save_started
|
||||
signal save_finished(success : bool)
|
||||
|
||||
signal load_started
|
||||
signal load_finished(success : bool)
|
||||
|
||||
var story_progress : int = 0 # 0 = début, 1 = après 1er badge, 2 = après 2e badge, etc.
|
||||
var player_team : PokemonTeam = PokemonTeam.new()
|
||||
var player_storage : PokemonStorage = PokemonStorage.new()
|
||||
|
|
@ -49,18 +55,39 @@ func _set_selected(index : int) -> void:
|
|||
selected_index = index
|
||||
selected_pokemon_changed.emit()
|
||||
|
||||
#---------- Système de Save ----------
|
||||
|
||||
func save() -> void:
|
||||
save_started.emit()
|
||||
await get_tree().process_frame
|
||||
var config := ConfigFile.new()
|
||||
config.set_value("progress", "story_progress", story_progress)
|
||||
config.set_value("team", "data", player_team.to_dict())
|
||||
config.set_value("storage", "data", player_storage.to_dict())
|
||||
config.save("user://save.cfg")
|
||||
|
||||
var err := config.save("user://save.cfg")
|
||||
save_finished.emit(err == OK)
|
||||
|
||||
func has_save() -> bool:
|
||||
return FileAccess.file_exists("user://save.cfg")
|
||||
|
||||
func load_data() -> void:
|
||||
if not has_save():
|
||||
load_finished.emit(false)
|
||||
return
|
||||
|
||||
load_started.emit()
|
||||
await get_tree().process_frame
|
||||
|
||||
var config := ConfigFile.new()
|
||||
if config.load("user://save.cfg") == OK:
|
||||
var err : Error = config.load("user://save.cfg")
|
||||
var success := err == OK
|
||||
|
||||
if success:
|
||||
story_progress = config.get_value("progress", "story_progress", 0)
|
||||
var team_data : Variant = config.get_value("team", "data", {})
|
||||
player_team = PokemonTeam.from_dict(team_data) if team_data is Dictionary else PokemonTeam.new()
|
||||
var storage_data : Variant = config.get_value("storage", "data", {})
|
||||
player_storage = PokemonStorage.from_dict(storage_data) if storage_data is Dictionary else PokemonStorage.new()
|
||||
|
||||
load_finished.emit(success)
|
||||
|
|
|
|||
29
game/ui/hud/save_hud.gd
Normal file
29
game/ui/hud/save_hud.gd
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
extends CanvasLayer
|
||||
|
||||
@onready var panel : PanelContainer = $Panel
|
||||
@onready var label : Label = $Panel/Label
|
||||
|
||||
func _ready() -> void:
|
||||
panel.visible = false
|
||||
GameData.save_started.connect(_on_save_started)
|
||||
GameData.save_finished.connect(_on_save_finished)
|
||||
|
||||
func _on_save_started() -> void:
|
||||
label.text = "Sauvegarde en cours..."
|
||||
panel.visible = true
|
||||
panel.modulate.a = 1.0
|
||||
|
||||
func _on_save_finished(success : bool) -> void:
|
||||
label.text = "Sauvegardé !" if success else "Échec de la sauvegarde"
|
||||
_fade_out()
|
||||
|
||||
func _on_load_finished(success : bool) -> void:
|
||||
label.text = "Chargé !" if success else "Aucune sauvegarde"
|
||||
_fade_out()
|
||||
|
||||
func _fade_out() -> void:
|
||||
# petit fade out après un court délai
|
||||
var tween := create_tween()
|
||||
tween.tween_interval(0.8)
|
||||
tween.tween_property(panel, "modulate:a", 0.0, 0.3)
|
||||
tween.tween_callback(func() -> void: panel.visible = false)
|
||||
1
game/ui/hud/save_hud.gd.uid
Normal file
1
game/ui/hud/save_hud.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://rgm6aitwyxdv
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene format=3 uid="uid://di22cs2qposdm"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://7hglx6nfu063" path="res://addons/controller_icons/objects/ControllerIconTexture.gd" id="1_4xhdt"]
|
||||
[ext_resource type="Script" uid="uid://rgm6aitwyxdv" path="res://game/ui/hud/save_hud.gd" id="1_euh0j"]
|
||||
[ext_resource type="Script" uid="uid://b3ddqgiawrh5c" path="res://game/ui/hud/team_hud.gd" id="2_lkjh2"]
|
||||
|
||||
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_uyiaf"]
|
||||
|
|
@ -25,6 +26,16 @@ metadata/_custom_type_script = "uid://7hglx6nfu063"
|
|||
|
||||
[node name="Ui" type="CanvasLayer" unique_id=1492671226]
|
||||
|
||||
[node name="SaveHUD" type="CanvasLayer" parent="." unique_id=319200051]
|
||||
script = ExtResource("1_euh0j")
|
||||
|
||||
[node name="Panel" type="PanelContainer" parent="SaveHUD" unique_id=243494129]
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="Label" type="Label" parent="SaveHUD/Panel" unique_id=42675420]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="." unique_id=38584238]
|
||||
anchors_preset = 3
|
||||
anchor_left = 1.0
|
||||
|
|
|
|||
73
game/ui/loading_screen/loading_screen.gd
Normal file
73
game/ui/loading_screen/loading_screen.gd
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
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
|
||||
1
game/ui/loading_screen/loading_screen.gd.uid
Normal file
1
game/ui/loading_screen/loading_screen.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://nl7jg02c6wwm
|
||||
42
game/ui/loading_screen/loading_screen.tscn
Normal file
42
game/ui/loading_screen/loading_screen.tscn
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
[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
|
||||
|
|
@ -4,7 +4,6 @@ extends Node
|
|||
@onready var Quit: Button = %Quit
|
||||
@onready var background: TextureRect = %Background
|
||||
@onready var music_player: AudioStreamPlayer = %MusicPlayer
|
||||
@onready var transition_rect: ColorRect = %TransitionRect
|
||||
@onready var version_label: Label = %VersionLabel
|
||||
@onready var game_infos: Control = %GameInfos
|
||||
|
||||
|
|
@ -14,11 +13,12 @@ extends Node
|
|||
|
||||
const GAME_SCENE_PATH := "res://game/world/main.tscn"
|
||||
const MUSIC_FADE_DURATION := 0.8
|
||||
const SCREEN_FADE_DURATION := 0.6
|
||||
|
||||
var is_transitioning : bool = false
|
||||
|
||||
func _ready() -> void:
|
||||
GameData.load_data()
|
||||
|
||||
update_background()
|
||||
setup_version_label()
|
||||
play_menu_music()
|
||||
|
|
@ -52,27 +52,18 @@ func fade_in_game_infos() -> void:
|
|||
tween.tween_property(game_infos, "modulate:a", 1.0, 1.0)
|
||||
|
||||
func _on_start_pressed() -> void:
|
||||
GameData.load_data()
|
||||
if is_transitioning: return
|
||||
is_transitioning = true
|
||||
play_click_sound()
|
||||
start_transition_to(GAME_SCENE_PATH)
|
||||
LoadingScreen.change_scene(GAME_SCENE_PATH, "Préparation de l'aventure...")
|
||||
|
||||
func play_click_sound() -> void:
|
||||
UiAudio.play(start_click_sound)
|
||||
|
||||
func fade_out_music() -> void:
|
||||
if !music_player.playing: return
|
||||
var tween := create_tween()
|
||||
tween.tween_property(music_player, "volume_db", -80.0, MUSIC_FADE_DURATION)
|
||||
|
||||
func _on_quit_pressed() -> void:
|
||||
get_tree().quit()
|
||||
|
||||
func start_transition_to(scene_path : String) -> void:
|
||||
if music_player.playing:
|
||||
var music_tween := create_tween()
|
||||
music_tween.tween_property(music_player, "volume_db", -80.0, MUSIC_FADE_DURATION)
|
||||
|
||||
transition_rect.visible = true
|
||||
transition_rect.modulate.a = 0.0
|
||||
var screen_tween := create_tween()
|
||||
screen_tween.tween_property(transition_rect, "modulate:a", 1.0, SCREEN_FADE_DURATION)
|
||||
await screen_tween.finished
|
||||
|
||||
get_tree().change_scene_to_file(scene_path)
|
||||
|
|
|
|||
|
|
@ -167,16 +167,5 @@ grow_vertical = 0
|
|||
[node name="MusicPlayer" type="AudioStreamPlayer" parent="." unique_id=1279071971]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="TransitionRect" type="ColorRect" parent="." unique_id=389028330]
|
||||
unique_name_in_owner = true
|
||||
modulate = Color(1, 1, 1, 0)
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 1)
|
||||
|
||||
[connection signal="pressed" from="GameInfos/Buttons/VBoxContainer/StartContainer/HBoxContainer/Start" to="." method="_on_start_pressed"]
|
||||
[connection signal="pressed" from="GameInfos/Buttons/VBoxContainer/QuitContainer/HBoxContainer/Quit" to="." method="_on_quit_pressed"]
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ buses/default_bus_layout="res://game/core/default_bus_layout.tres"
|
|||
ControllerIcons="*uid://b7ho1rjcpht1d"
|
||||
GameData="*uid://d4beiel88cwc7"
|
||||
UiAudio="*uid://7e7fe2xk3aue"
|
||||
LoadingScreen="*uid://ckyjxhrfhaqlc"
|
||||
Pokedex="*uid://dijnkrewbwgmx"
|
||||
MountRegistry="*uid://u4gskwbwm0b0"
|
||||
DebugPokemonPanel="*uid://b3058rssf6ud5"
|
||||
|
|
|
|||
Loading…
Reference in a new issue