diff --git a/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.gd b/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.gd deleted file mode 100644 index b39d4830..00000000 --- a/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.gd +++ /dev/null @@ -1,30 +0,0 @@ -extends Control - -@export var win_scene : PackedScene -@export var lose_scene : PackedScene - -var current_level - -func _ready(): - InGameMenuController.scene_tree = get_tree() - -func _on_level_lost(): - InGameMenuController.open_menu(lose_scene, get_viewport()) - -func _on_level_won(): - $LevelLoader.advance_and_load_level() - -func _on_level_loader_level_loaded(): - current_level = $LevelLoader.current_level - await current_level.ready - if current_level.has_signal("level_won"): - current_level.level_won.connect(_on_level_won) - if current_level.has_signal("level_lost"): - current_level.level_lost.connect(_on_level_lost) - $LevelLoadingScreen.close() - -func _on_level_loader_levels_finished(): - InGameMenuController.open_menu(win_scene, get_viewport()) - -func _on_level_loader_level_load_started(): - $LevelLoadingScreen.reset() diff --git a/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn b/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn index 5d44846a..e950760a 100644 --- a/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn +++ b/addons/maaacks_game_template/examples/scenes/game_scene/game_ui.tscn @@ -1,8 +1,8 @@ -[gd_scene load_steps=11 format=3 uid="uid://bde0cbmryrv5s"] +[gd_scene load_steps=12 format=3 uid="uid://bde0cbmryrv5s"] -[ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/game_scene/game_ui.gd" id="1_lpkm8"] [ext_resource type="PackedScene" uid="uid://ta2xbceba8ec" path="res://addons/maaacks_game_template/examples/scenes/win_screen/win_screen.tscn" id="2_3aw6s"] [ext_resource type="PackedScene" uid="uid://duvowpap0jwaq" path="res://addons/maaacks_game_template/examples/scenes/lose_screen/lose_screen.tscn" id="3_28mfg"] +[ext_resource type="PackedScene" uid="uid://ddxbl58500png" path="res://addons/maaacks_game_template/examples/scenes/level_complete_screen/level_complete_screen.tscn" id="4_gomcd"] [ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/pause_menu_controller.gd" id="5_fc8fx"] [ext_resource type="PackedScene" uid="uid://qeqh1euot2d0" path="res://addons/maaacks_game_template/examples/scenes/menus/pause_menu/pause_menu.tscn" id="5_r56ir"] [ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/level_list_loader.gd" id="6_wd8e4"] @@ -10,6 +10,7 @@ [ext_resource type="PackedScene" uid="uid://bkcsjsk2ciff" path="res://addons/maaacks_game_template/base/scenes/music_players/background_music_player.tscn" id="7_yr75v"] [ext_resource type="PackedScene" uid="uid://dbuv0htkikcv4" path="res://addons/maaacks_game_template/examples/scenes/loading_screen/level_loading_screen.tscn" id="8_0nt60"] [ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/game_scene/configurable_sub_viewport.gd" id="9_u1dsg"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/level_list_manager.gd" id="12_ut0t4"] [node name="GameUI" type="Control"] layout_mode = 3 @@ -18,9 +19,6 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -script = ExtResource("1_lpkm8") -win_scene = ExtResource("2_3aw6s") -lose_scene = ExtResource("3_28mfg") [node name="PauseMenuController" type="Node" parent="."] script = ExtResource("5_fc8fx") @@ -69,6 +67,17 @@ horizontal_alignment = 1 autowrap_mode = 2 script = ExtResource("7_f87ri") +[node name="LevelListManager" type="Node" parent="." node_paths=PackedStringArray("level_list_loader", "level_loading_screen")] +process_mode = 3 +script = ExtResource("12_ut0t4") +level_list_loader = NodePath("../LevelLoader") +main_menu_scene = "res://addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn" +ending_scene = "res://addons/maaacks_game_template/examples/scenes/end_credits/end_credits.tscn" +level_loading_screen = NodePath("../LevelLoadingScreen") +win_screen_scene = ExtResource("2_3aw6s") +lose_screen_scene = ExtResource("3_28mfg") +level_complete_screen_scene = ExtResource("4_gomcd") + [connection signal="level_load_started" from="LevelLoader" to="." method="_on_level_loader_level_load_started"] [connection signal="level_loaded" from="LevelLoader" to="." method="_on_level_loader_level_loaded"] [connection signal="levels_finished" from="LevelLoader" to="." method="_on_level_loader_levels_finished"] diff --git a/addons/maaacks_game_template/examples/scenes/level_complete_screen/level_complete_screen.gd b/addons/maaacks_game_template/examples/scenes/level_complete_screen/level_complete_screen.gd new file mode 100644 index 00000000..bdd91432 --- /dev/null +++ b/addons/maaacks_game_template/examples/scenes/level_complete_screen/level_complete_screen.gd @@ -0,0 +1 @@ +extends "res://addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.gd" diff --git a/addons/maaacks_game_template/examples/scenes/level_complete_screen/level_complete_screen.tscn b/addons/maaacks_game_template/examples/scenes/level_complete_screen/level_complete_screen.tscn new file mode 100644 index 00000000..e6b790bf --- /dev/null +++ b/addons/maaacks_game_template/examples/scenes/level_complete_screen/level_complete_screen.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=3 format=3 uid="uid://ddxbl58500png"] + +[ext_resource type="PackedScene" uid="uid://cpa0hksdk0vjv" path="res://addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.tscn" id="1_67ooa"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/examples/scenes/level_complete_screen/level_complete_screen.gd" id="1_fgelo"] + +[node name="LevelCompleteScreen" instance=ExtResource("1_67ooa")] +script = ExtResource("1_fgelo") diff --git a/addons/maaacks_game_template/examples/scenes/lose_screen/lose_screen.tscn b/addons/maaacks_game_template/examples/scenes/lose_screen/lose_screen.tscn index dab43647..0ea4b0aa 100644 --- a/addons/maaacks_game_template/examples/scenes/lose_screen/lose_screen.tscn +++ b/addons/maaacks_game_template/examples/scenes/lose_screen/lose_screen.tscn @@ -5,4 +5,3 @@ [node name="LoseScreen" instance=ExtResource("1_exl4x")] script = ExtResource("2_ay3xf") -main_menu_scene = "res://addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn" diff --git a/addons/maaacks_game_template/examples/scenes/win_screen/win_screen.tscn b/addons/maaacks_game_template/examples/scenes/win_screen/win_screen.tscn index ea9087ce..07d6826b 100644 --- a/addons/maaacks_game_template/examples/scenes/win_screen/win_screen.tscn +++ b/addons/maaacks_game_template/examples/scenes/win_screen/win_screen.tscn @@ -5,5 +5,3 @@ [node name="WinScreen" instance=ExtResource("1_n1ig8")] script = ExtResource("2_hckpo") -next_scene = "res://addons/maaacks_game_template/examples/scenes/end_credits/end_credits.tscn" -main_menu_scene = "res://addons/maaacks_game_template/examples/scenes/menus/main_menu/main_menu_with_animations.tscn" diff --git a/addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.gd b/addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.gd new file mode 100644 index 00000000..c5ad9d80 --- /dev/null +++ b/addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.gd @@ -0,0 +1,23 @@ +extends CanvasLayer + +signal continue_pressed +signal restart_pressed +signal main_menu_pressed + +func _input(event): + if event.is_action_pressed("ui_cancel"): + if $ConfirmMainMenu.visible: + $ConfirmMainMenu.hide() + get_viewport().set_input_as_handled() + +func _on_main_menu_button_pressed(): + $ConfirmMainMenu.popup_centered() + +func _on_continue_button_pressed(): + continue_pressed.emit() + +func _on_confirm_main_menu_confirmed(): + main_menu_pressed.emit() + +func _on_restart_button_pressed(): + restart_pressed.emit() diff --git a/addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.tscn b/addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.tscn new file mode 100644 index 00000000..9aa8f112 --- /dev/null +++ b/addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.tscn @@ -0,0 +1,96 @@ +[gd_scene load_steps=4 format=3 uid="uid://cpa0hksdk0vjv"] + +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.gd" id="1_fgelo"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/ui_sound_controller.gd" id="2_p87ka"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/base/scripts/capture_focus.gd" id="3_h5el0"] + +[node name="LevelCompleteScreen" type="CanvasLayer"] +process_mode = 3 +layer = 10 +script = ExtResource("1_fgelo") + +[node name="UISoundController" type="Node" parent="."] +script = ExtResource("2_p87ka") + +[node name="BackgroundColor" type="ColorRect" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0, 0, 0, 0.501961) + +[node name="BackgroundTextureRect" type="TextureRect" parent="."] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +expand_mode = 1 +stretch_mode = 5 + +[node name="PanelContainer" type="PanelContainer" parent="."] +custom_minimum_size = Vector2(410, 240) +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -205.0 +offset_top = -120.0 +offset_right = 205.0 +offset_bottom = 120.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 16 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 16 + +[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"] +layout_mode = 2 +alignment = 1 + +[node name="LevelCompleteMessage" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_vertical = 3 +text = "Level complete!" +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="ButtonsContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_constants/separation = 16 +alignment = 1 +script = ExtResource("3_h5el0") + +[node name="MainMenuButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/ButtonsContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(128, 40) +layout_mode = 2 +text = "Main Menu" + +[node name="RestartButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/ButtonsContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(128, 40) +layout_mode = 2 +text = "Restart" + +[node name="ContinueButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/ButtonsContainer"] +unique_name_in_owner = true +custom_minimum_size = Vector2(128, 40) +layout_mode = 2 +text = "Continue" + +[node name="ConfirmMainMenu" type="ConfirmationDialog" parent="."] +initial_position = 2 +dialog_text = "Go back to main menu?" + +[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/ButtonsContainer/MainMenuButton" to="." method="_on_main_menu_button_pressed"] +[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/ButtonsContainer/RestartButton" to="." method="_on_restart_button_pressed"] +[connection signal="pressed" from="PanelContainer/MarginContainer/VBoxContainer/ButtonsContainer/ContinueButton" to="." method="_on_continue_button_pressed"] +[connection signal="confirmed" from="ConfirmMainMenu" to="." method="_on_confirm_main_menu_confirmed"] diff --git a/addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.gd b/addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.gd index 6be82f56..46b6466c 100644 --- a/addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.gd +++ b/addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.gd @@ -1,6 +1,7 @@ extends CanvasLayer -@export_file("*.tscn") var main_menu_scene : String +signal restart_pressed +signal main_menu_pressed func _input(event): if event.is_action_pressed("ui_cancel"): @@ -10,15 +11,9 @@ func _input(event): $ConfirmMainMenu.hide() get_viewport().set_input_as_handled() -func _setup_main_menu(): - if main_menu_scene.is_empty(): - %MainMenuButton.hide() - func _ready(): if OS.has_feature("web"): %ExitButton.hide() - _setup_main_menu() - InGameMenuController.scene_tree = get_tree() func _on_exit_button_pressed(): $ConfirmExit.popup_centered() @@ -27,13 +22,10 @@ func _on_main_menu_button_pressed(): $ConfirmMainMenu.popup_centered() func _on_restart_button_pressed(): - SceneLoader.reload_current_scene() - InGameMenuController.close_menu() + restart_pressed.emit() func _on_confirm_main_menu_confirmed(): - SceneLoader.load_scene(main_menu_scene) - InGameMenuController.close_menu() - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + main_menu_pressed.emit() func _on_confirm_exit_confirmed(): get_tree().quit() diff --git a/addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.tscn b/addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.tscn index 0729609b..d8c692eb 100644 --- a/addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.tscn +++ b/addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.tscn @@ -8,7 +8,6 @@ process_mode = 3 layer = 10 script = ExtResource("1_vd50a") -main_menu_scene = "res://addons/maaacks_game_template/base/scenes/menus/main_menu/main_menu.tscn" [node name="UISoundController" type="Node" parent="."] script = ExtResource("2_haoyh") @@ -46,10 +45,10 @@ grow_vertical = 2 [node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] layout_mode = 2 -theme_override_constants/margin_left = 8 -theme_override_constants/margin_top = 8 -theme_override_constants/margin_right = 8 -theme_override_constants/margin_bottom = 8 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 16 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 16 [node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"] layout_mode = 2 @@ -59,12 +58,13 @@ alignment = 1 unique_name_in_owner = true layout_mode = 2 size_flags_vertical = 3 -text = "You lose." +text = "You lost..." horizontal_alignment = 1 vertical_alignment = 1 [node name="ButtonsContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"] layout_mode = 2 +theme_override_constants/separation = 16 alignment = 1 script = ExtResource("3_mqffv") diff --git a/addons/maaacks_game_template/extras/scenes/win_screen/win_screen.gd b/addons/maaacks_game_template/extras/scenes/win_screen/win_screen.gd index 1aa8213d..7db63792 100644 --- a/addons/maaacks_game_template/extras/scenes/win_screen/win_screen.gd +++ b/addons/maaacks_game_template/extras/scenes/win_screen/win_screen.gd @@ -1,7 +1,7 @@ extends CanvasLayer -@export_file("*.tscn") var next_scene : String -@export_file("*.tscn") var main_menu_scene : String +signal continue_pressed +signal main_menu_pressed func _input(event): if event.is_action_pressed("ui_cancel"): @@ -11,20 +11,9 @@ func _input(event): $ConfirmMainMenu.hide() get_viewport().set_input_as_handled() -func _setup_continue(): - if next_scene.is_empty(): - %ContinueButton.hide() - -func _setup_main_menu(): - if main_menu_scene.is_empty(): - %MainMenuButton.hide() - func _ready(): if OS.has_feature("web"): %ExitButton.hide() - _setup_continue() - _setup_main_menu() - InGameMenuController.scene_tree = get_tree() func _on_exit_button_pressed(): $ConfirmExit.popup_centered() @@ -33,13 +22,10 @@ func _on_main_menu_button_pressed(): $ConfirmMainMenu.popup_centered() func _on_continue_button_pressed(): - SceneLoader.load_scene(next_scene) - InGameMenuController.close_menu() + continue_pressed.emit() func _on_confirm_main_menu_confirmed(): - SceneLoader.load_scene(main_menu_scene) - InGameMenuController.close_menu() - Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + main_menu_pressed.emit() func _on_confirm_exit_confirmed(): get_tree().quit() diff --git a/addons/maaacks_game_template/extras/scenes/win_screen/win_screen.tscn b/addons/maaacks_game_template/extras/scenes/win_screen/win_screen.tscn index 9413d20c..bd3638cc 100644 --- a/addons/maaacks_game_template/extras/scenes/win_screen/win_screen.tscn +++ b/addons/maaacks_game_template/extras/scenes/win_screen/win_screen.tscn @@ -8,7 +8,6 @@ process_mode = 3 layer = 10 script = ExtResource("1_elvr7") -main_menu_scene = "res://addons/maaacks_game_template/base/scenes/Menus/MainMenu/MainMenu.tscn" [node name="UISoundController" type="Node" parent="."] script = ExtResource("2_g47g8") @@ -46,10 +45,10 @@ grow_vertical = 2 [node name="MarginContainer" type="MarginContainer" parent="PanelContainer"] layout_mode = 2 -theme_override_constants/margin_left = 8 -theme_override_constants/margin_top = 8 -theme_override_constants/margin_right = 8 -theme_override_constants/margin_bottom = 8 +theme_override_constants/margin_left = 16 +theme_override_constants/margin_top = 16 +theme_override_constants/margin_right = 16 +theme_override_constants/margin_bottom = 16 [node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"] layout_mode = 2 @@ -65,17 +64,20 @@ vertical_alignment = 1 [node name="ButtonsContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"] layout_mode = 2 +theme_override_constants/separation = 16 alignment = 1 script = ExtResource("3_am347") [node name="ExitButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/ButtonsContainer"] unique_name_in_owner = true +visible = false custom_minimum_size = Vector2(128, 40) layout_mode = 2 text = "Exit" [node name="MainMenuButton" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer/ButtonsContainer"] unique_name_in_owner = true +visible = false custom_minimum_size = Vector2(128, 40) layout_mode = 2 text = "Main Menu" diff --git a/addons/maaacks_game_template/extras/scripts/level_list_loader.gd b/addons/maaacks_game_template/extras/scripts/level_list_loader.gd index 765ab31d..539d5236 100644 --- a/addons/maaacks_game_template/extras/scripts/level_list_loader.gd +++ b/addons/maaacks_game_template/extras/scripts/level_list_loader.gd @@ -28,6 +28,9 @@ func get_level_file(level_id : int = get_current_level_id()): level_id = files.size() - 1 return files[level_id] +func is_on_last_level(): + return get_current_level_id() + 1 >= files.size() + func advance_level() -> bool: var level_id : int = get_current_level_id() level_id += 1 @@ -45,6 +48,7 @@ func _attach_level(level_resource : Resource): return instance func load_level(level_id : int = get_current_level_id()): + GameLevelLog.set_current_level(level_id) if is_instance_valid(current_level): current_level.queue_free() await current_level.tree_exited @@ -59,6 +63,9 @@ func load_level(level_id : int = get_current_level_id()): current_level = _attach_level(SceneLoader.get_resource()) level_loaded.emit() +func reload_level(): + load_level() + func advance_and_load_level(): if advance_level(): load_level() diff --git a/addons/maaacks_game_template/extras/scripts/level_list_manager.gd b/addons/maaacks_game_template/extras/scripts/level_list_manager.gd new file mode 100644 index 00000000..2a4a7fee --- /dev/null +++ b/addons/maaacks_game_template/extras/scripts/level_list_manager.gd @@ -0,0 +1,126 @@ +class_name LevelListManager +extends Node +## Manager of level progress and the result screens between them. +## +## A helper script to assign to a node in a scene. +## It works with a level list loader and a loading screen +## to advance levels and open menus when players win or lose. +## The process mode on the node should be set to `Always`, as +## InGameMenuController will pause the game, while menus will +## try to emit signals connected back to this node. + +## Required reference to a level list loader in the scene. +@export var level_list_loader : LevelListLoader +## Required path to a main menu scene. +@export_file("*.tscn") var main_menu_scene : String +## Optional path to an ending scene. +@export_file("*.tscn") var ending_scene : String +@export_group("Screens") +## Optional reference to a loading screen in the scene. +@export var level_loading_screen : LoadingScreen +## Optional win screen to be shown after the last level is won. +@export var win_screen_scene : PackedScene +## Optional lose screen to be shown after the level is lost. +@export var lose_screen_scene : PackedScene +## Optional level compete screen to be shown after the level is won. +@export var level_complete_screen_scene : PackedScene + +## Reference to the current level node. +var current_level + +func _try_connecting_signal_to_node(node : Node, signal_name : String, callable : Callable): + if node.has_signal(signal_name) and not node.is_connected(signal_name, callable): + node.connect(signal_name, callable) + +func _try_connecting_signal_to_level(signal_name : String, callable : Callable): + _try_connecting_signal_to_node(current_level, signal_name, callable) + +func _try_connecting_signal_to_current_menu(signal_name : String, callable : Callable): + _try_connecting_signal_to_node(InGameMenuController.current_menu, signal_name, callable) + +func _load_main_menu(): + InGameMenuController.close_menu() + SceneLoader.load_scene(main_menu_scene) + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + +func _advance_and_load_main_menu(): + level_list_loader.advance_level() + _load_main_menu() + +func _load_ending(): + InGameMenuController.close_menu() + if ending_scene: + SceneLoader.load_scene(ending_scene) + else: + _load_main_menu() + +func _on_level_lost(): + if lose_screen_scene: + InGameMenuController.open_menu(lose_screen_scene, get_viewport()) + _try_connecting_signal_to_current_menu(&"restart_pressed", _reload_level) + _try_connecting_signal_to_current_menu(&"main_menu_pressed", _load_main_menu) + else: + _reload_level() + +func _advance_and_reload(): + InGameMenuController.close_menu() + var _current_level_id = level_list_loader.get_current_level_id() + level_list_loader.advance_level() + level_list_loader.load_level(_current_level_id) + +func _load_next_level(): + InGameMenuController.close_menu() + level_list_loader.advance_and_load_level() + +func _reload_level(): + InGameMenuController.close_menu() + level_list_loader.reload_level() + +func _load_win_screen_or_ending(): + if win_screen_scene: + InGameMenuController.open_menu(win_screen_scene, get_viewport()) + _try_connecting_signal_to_current_menu(&"continue_pressed", _load_ending) + _try_connecting_signal_to_current_menu(&"restart_pressed", _reload_level) + _try_connecting_signal_to_current_menu(&"main_menu_pressed", _load_main_menu) + else: + _load_ending() + +func _load_level_complete_screen_or_next_level(): + if level_complete_screen_scene: + InGameMenuController.open_menu(level_complete_screen_scene, get_viewport()) + _try_connecting_signal_to_current_menu(&"continue_pressed", _load_next_level) + _try_connecting_signal_to_current_menu(&"restart_pressed", _advance_and_reload) + _try_connecting_signal_to_current_menu(&"main_menu_pressed", _advance_and_load_main_menu) + else: + _load_next_level() + +func _on_level_won(): + if level_list_loader.is_on_last_level(): + _load_win_screen_or_ending() + else: + _load_level_complete_screen_or_next_level() + +func _connect_level_signals(): + _try_connecting_signal_to_level(&"level_won", _on_level_won) + _try_connecting_signal_to_level(&"level_lost", _on_level_lost) + _try_connecting_signal_to_level(&"level_skipped", _load_next_level) + +func _on_level_loader_level_loaded(): + current_level = level_list_loader.current_level + await current_level.ready + _connect_level_signals() + if level_loading_screen: + level_loading_screen.close() + +func _on_level_loader_levels_finished(): + _load_win_screen_or_ending() + +func _on_level_loader_level_load_started(): + if level_loading_screen: + level_loading_screen.reset() + +func _ready(): + InGameMenuController.scene_tree = get_tree() + level_list_loader.level_loaded.connect(_on_level_loader_level_loaded) + level_list_loader.levels_finished.connect(_on_level_loader_levels_finished) + level_list_loader.level_load_started.connect(_on_level_loader_level_load_started) diff --git a/addons/maaacks_game_template/extras/scripts/level_loader.gd b/addons/maaacks_game_template/extras/scripts/level_loader.gd index 62cda3b2..c0d6a3d4 100644 --- a/addons/maaacks_game_template/extras/scripts/level_loader.gd +++ b/addons/maaacks_game_template/extras/scripts/level_loader.gd @@ -41,6 +41,9 @@ func load_level(level_path : String = get_current_level_path()): current_level = _attach_level(SceneLoader.get_resource()) level_loaded.emit() +func reload_level(): + load_level() + func _ready(): if auto_load: load_level() diff --git a/scenes/game_scene/game_ui.gd b/scenes/game_scene/game_ui.gd deleted file mode 100644 index b39d4830..00000000 --- a/scenes/game_scene/game_ui.gd +++ /dev/null @@ -1,30 +0,0 @@ -extends Control - -@export var win_scene : PackedScene -@export var lose_scene : PackedScene - -var current_level - -func _ready(): - InGameMenuController.scene_tree = get_tree() - -func _on_level_lost(): - InGameMenuController.open_menu(lose_scene, get_viewport()) - -func _on_level_won(): - $LevelLoader.advance_and_load_level() - -func _on_level_loader_level_loaded(): - current_level = $LevelLoader.current_level - await current_level.ready - if current_level.has_signal("level_won"): - current_level.level_won.connect(_on_level_won) - if current_level.has_signal("level_lost"): - current_level.level_lost.connect(_on_level_lost) - $LevelLoadingScreen.close() - -func _on_level_loader_levels_finished(): - InGameMenuController.open_menu(win_scene, get_viewport()) - -func _on_level_loader_level_load_started(): - $LevelLoadingScreen.reset() diff --git a/scenes/game_scene/game_ui.tscn b/scenes/game_scene/game_ui.tscn index 0c8a38c6..2565c782 100644 --- a/scenes/game_scene/game_ui.tscn +++ b/scenes/game_scene/game_ui.tscn @@ -1,15 +1,16 @@ -[gd_scene load_steps=11 format=3 uid="uid://dqdwmllvu2lv5"] +[gd_scene load_steps=12 format=3 uid="uid://drimutrn1jfv1"] -[ext_resource type="Script" path="res://scenes/game_scene/game_ui.gd" id="1_solt8"] -[ext_resource type="PackedScene" path="res://scenes/win_screen/win_screen.tscn" id="2_nfgj1"] -[ext_resource type="PackedScene" path="res://scenes/lose_screen/lose_screen.tscn" id="3_cwxig"] -[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/pause_menu_controller.gd" id="4_6b6cy"] -[ext_resource type="PackedScene" path="res://scenes/menus/pause_menu/pause_menu.tscn" id="5_lfufl"] -[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/level_list_loader.gd" id="6_b43ns"] -[ext_resource type="PackedScene" path="res://addons/maaacks_game_template/base/scenes/music_players/background_music_player.tscn" id="7_np5mq"] -[ext_resource type="PackedScene" path="res://scenes/loading_screen/level_loading_screen.tscn" id="8_gkk0v"] -[ext_resource type="Script" path="res://scenes/game_scene/configurable_sub_viewport.gd" id="9_vodd8"] -[ext_resource type="Script" path="res://scenes/game_scene/input_display_label.gd" id="10_lmnoo"] +[ext_resource type="PackedScene" path="res://scenes/menus/pause_menu/pause_menu.tscn" id="2_aajmq"] +[ext_resource type="PackedScene" path="res://scenes/loading_screen/level_loading_screen.tscn" id="5_26pe0"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/pause_menu_controller.gd" id="5_qyvaq"] +[ext_resource type="Script" path="res://scenes/game_scene/configurable_sub_viewport.gd" id="6_uku7d"] +[ext_resource type="Script" path="res://scenes/game_scene/input_display_label.gd" id="7_13r7m"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/level_list_loader.gd" id="7_nehdg"] +[ext_resource type="PackedScene" path="res://addons/maaacks_game_template/base/scenes/music_players/background_music_player.tscn" id="8_ga7qu"] +[ext_resource type="Script" path="res://addons/maaacks_game_template/extras/scripts/level_list_manager.gd" id="8_xo65h"] +[ext_resource type="PackedScene" path="res://scenes/win_screen/win_screen.tscn" id="9_14f5u"] +[ext_resource type="PackedScene" path="res://scenes/lose_screen/lose_screen.tscn" id="10_4r32w"] +[ext_resource type="PackedScene" path="res://scenes/level_complete_screen/level_complete_screen.tscn" id="11_qq1cf"] [node name="GameUI" type="Control"] layout_mode = 3 @@ -18,23 +19,20 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -script = ExtResource("1_solt8") -win_scene = ExtResource("2_nfgj1") -lose_scene = ExtResource("3_cwxig") [node name="PauseMenuController" type="Node" parent="."] -script = ExtResource("4_6b6cy") -pause_menu_packed = ExtResource("5_lfufl") +script = ExtResource("5_qyvaq") +pause_menu_packed = ExtResource("2_aajmq") [node name="LevelLoader" type="Node" parent="." node_paths=PackedStringArray("level_container")] -script = ExtResource("6_b43ns") +script = ExtResource("7_nehdg") level_container = NodePath("../ViewportContainer/ConfigurableSubViewport") files = Array[String](["res://scenes/game_scene/levels/level_1.tscn", "res://scenes/game_scene/levels/level_2.tscn", "res://scenes/game_scene/levels/level_3.tscn"]) directory = "res://scenes/game_scene/levels" -[node name="BackgroundMusicPlayer" parent="." instance=ExtResource("7_np5mq")] +[node name="BackgroundMusicPlayer" parent="." instance=ExtResource("8_ga7qu")] -[node name="LevelLoadingScreen" parent="." instance=ExtResource("8_gkk0v")] +[node name="LevelLoadingScreen" parent="." instance=ExtResource("5_26pe0")] visible = false [node name="ViewportContainer" type="SubViewportContainer" parent="."] @@ -52,7 +50,7 @@ audio_listener_enable_2d = true audio_listener_enable_3d = true size = Vector2i(1280, 720) render_target_update_mode = 4 -script = ExtResource("9_vodd8") +script = ExtResource("6_uku7d") [node name="InputDisplayLabel" type="Label" parent="."] layout_mode = 1 @@ -67,7 +65,18 @@ grow_vertical = 2 theme_override_font_sizes/font_size = 64 horizontal_alignment = 1 autowrap_mode = 2 -script = ExtResource("10_lmnoo") +script = ExtResource("7_13r7m") + +[node name="LevelListManager" type="Node" parent="." node_paths=PackedStringArray("level_list_loader", "level_loading_screen")] +process_mode = 3 +script = ExtResource("8_xo65h") +level_list_loader = NodePath("../LevelLoader") +main_menu_scene = "res://scenes/menus/main_menu/main_menu_with_animations.tscn" +ending_scene = "res://scenes/end_credits/end_credits.tscn" +level_loading_screen = NodePath("../LevelLoadingScreen") +win_screen_scene = ExtResource("9_14f5u") +lose_screen_scene = ExtResource("10_4r32w") +level_complete_screen_scene = ExtResource("11_qq1cf") [connection signal="level_load_started" from="LevelLoader" to="." method="_on_level_loader_level_load_started"] [connection signal="level_loaded" from="LevelLoader" to="." method="_on_level_loader_level_loaded"] diff --git a/scenes/level_complete_screen/level_complete_screen.gd b/scenes/level_complete_screen/level_complete_screen.gd new file mode 100644 index 00000000..bdd91432 --- /dev/null +++ b/scenes/level_complete_screen/level_complete_screen.gd @@ -0,0 +1 @@ +extends "res://addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.gd" diff --git a/scenes/level_complete_screen/level_complete_screen.tscn b/scenes/level_complete_screen/level_complete_screen.tscn new file mode 100644 index 00000000..ff80de7a --- /dev/null +++ b/scenes/level_complete_screen/level_complete_screen.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=3 format=3 uid="uid://ct0ou4d0sdvem"] + +[ext_resource type="PackedScene" path="res://addons/maaacks_game_template/extras/scenes/level_complete_screen/level_complete_screen.tscn" id="1_25p8s"] +[ext_resource type="Script" path="res://scenes/level_complete_screen/level_complete_screen.gd" id="2_m6qbr"] + +[node name="LevelCompleteScreen" instance=ExtResource("1_25p8s")] +script = ExtResource("2_m6qbr") diff --git a/scenes/lose_screen/lose_screen.tscn b/scenes/lose_screen/lose_screen.tscn index ce3936e4..d63ada2d 100644 --- a/scenes/lose_screen/lose_screen.tscn +++ b/scenes/lose_screen/lose_screen.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://bo6nuosxyy70d"] +[gd_scene load_steps=3 format=3 uid="uid://utapfiirju3q"] [ext_resource type="PackedScene" path="res://addons/maaacks_game_template/extras/scenes/lose_screen/lose_screen.tscn" id="1_x7wpf"] -[ext_resource type="Script" path="res://scenes/lose_screen/lose_screen.gd" id="2_7w5uq"] +[ext_resource type="Script" path="res://scenes/lose_screen/lose_screen.gd" id="2_4ndbb"] [node name="LoseScreen" instance=ExtResource("1_x7wpf")] -script = ExtResource("2_7w5uq") -main_menu_scene = "res://scenes/menus/main_menu/main_menu_with_animations.tscn" +script = ExtResource("2_4ndbb") diff --git a/scenes/win_screen/win_screen.tscn b/scenes/win_screen/win_screen.tscn index 98bd582f..0993be8e 100644 --- a/scenes/win_screen/win_screen.tscn +++ b/scenes/win_screen/win_screen.tscn @@ -1,9 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://epsnjw0ujl7u"] +[gd_scene load_steps=3 format=3 uid="uid://d1r2vpctegn45"] [ext_resource type="PackedScene" path="res://addons/maaacks_game_template/extras/scenes/win_screen/win_screen.tscn" id="1_a22q4"] -[ext_resource type="Script" path="res://scenes/win_screen/win_screen.gd" id="2_rlg38"] +[ext_resource type="Script" path="res://scenes/win_screen/win_screen.gd" id="2_eiyje"] [node name="WinScreen" instance=ExtResource("1_a22q4")] -script = ExtResource("2_rlg38") -next_scene = "res://scenes/end_credits/end_credits.tscn" -main_menu_scene = "res://scenes/menus/main_menu/main_menu_with_animations.tscn" +script = ExtResource("2_eiyje")