From fa2e3cfc9ad5a668f0b883705992e80bfb1bff31 Mon Sep 17 00:00:00 2001 From: 2212733 <2212733@stud.hs-mannheim.de> Date: Wed, 15 Apr 2026 10:46:27 +0200 Subject: [PATCH] implemented pause menu, fixed bug of music not looping --- scenes/game.tscn | 154 +++++++++++++++++++++++++++++ scripts/music_manager.gd | 7 +- scripts/options_menu_ingame.gd | 53 ++++++++++ scripts/options_menu_ingame.gd.uid | 1 + scripts/pause_menu.gd | 26 +++++ scripts/pause_menu.gd.uid | 1 + 6 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 scripts/options_menu_ingame.gd create mode 100644 scripts/options_menu_ingame.gd.uid create mode 100644 scripts/pause_menu.gd create mode 100644 scripts/pause_menu.gd.uid diff --git a/scenes/game.tscn b/scenes/game.tscn index 8086475..bd0326f 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -17,6 +17,9 @@ [ext_resource type="Script" uid="uid://ckv6prbe1o7s1" path="res://scripts/drop_manager.gd" id="10_vtaks"] [ext_resource type="Script" uid="uid://pmmc7tivuuo4" path="res://scripts/perk_effects.gd" id="16_ca42v"] [ext_resource type="Script" uid="uid://dm1sntwjrv3vl" path="res://scripts/level_up_manager.gd" id="16_rysoc"] +[ext_resource type="Script" uid="uid://duauc778wc3hd" path="res://scripts/pause_menu.gd" id="18_264po"] +[ext_resource type="FontFile" uid="uid://8v71dcws4q6o" path="res://assets/fonts/slkscre.ttf" id="19_1kice"] +[ext_resource type="Script" uid="uid://586y330mhx8" path="res://scripts/options_menu_ingame.gd" id="20_1kice"] [sub_resource type="Resource" id="Resource_ssvqc"] script = ExtResource("6_ir15t") @@ -2428,4 +2431,155 @@ offset_bottom = 40.0 [node name="PerkEffects" type="Node2D" parent="." unique_id=2027136639] script = ExtResource("16_ca42v") +[node name="PauseMenu" type="CanvasLayer" parent="." unique_id=551813974] +process_mode = 3 +script = ExtResource("18_264po") + +[node name="BackgroundRect" type="ColorRect" parent="PauseMenu" unique_id=2031198327] +z_index = -1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0, 0, 0, 0.47058824) + +[node name="VBoxContainer" type="VBoxContainer" parent="PauseMenu" unique_id=1987220146] +z_index = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -308.5 +offset_top = -106.0 +offset_right = 308.5 +offset_bottom = 106.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/separation = 50 +alignment = 1 + +[node name="Label" type="Label" parent="PauseMenu/VBoxContainer" unique_id=1321477768] +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 64 +text = "Pause" +horizontal_alignment = 1 + +[node name="ContinueButton" type="Button" parent="PauseMenu/VBoxContainer" unique_id=760316781] +custom_minimum_size = Vector2(200, 45) +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 32 +text = "Continue" + +[node name="OptionsButton" type="Button" parent="PauseMenu/VBoxContainer" unique_id=857989621] +custom_minimum_size = Vector2(200, 45) +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 32 +text = "Options" + +[node name="QuitButton" type="Button" parent="PauseMenu/VBoxContainer" unique_id=1745540926] +custom_minimum_size = Vector2(200, 45) +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 32 +text = "Quit" + +[node name="OptionsMenu" type="Control" parent="PauseMenu" unique_id=1962611001] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("20_1kice") + +[node name="VBoxContainer" type="VBoxContainer" parent="PauseMenu/OptionsMenu" unique_id=494075248] +z_index = 2 +layout_mode = 1 +anchors_preset = 8 +anchor_left = 0.5 +anchor_top = 0.5 +anchor_right = 0.5 +anchor_bottom = 0.5 +offset_left = -308.5 +offset_top = -106.0 +offset_right = 308.5 +offset_bottom = 106.0 +grow_horizontal = 2 +grow_vertical = 2 +theme_override_constants/separation = 50 +alignment = 1 + +[node name="Label" type="Label" parent="PauseMenu/OptionsMenu/VBoxContainer" unique_id=2020901742] +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 64 +text = "Options" +horizontal_alignment = 1 + +[node name="HBoxContainer" type="HBoxContainer" parent="PauseMenu/OptionsMenu/VBoxContainer" unique_id=1131620527] +custom_minimum_size = Vector2(300, 0) +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer" unique_id=1154725043] +custom_minimum_size = Vector2(150, 0) +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 32 +text = "Music Volume" + +[node name="HSlider" type="HSlider" parent="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer" unique_id=880316772] +custom_minimum_size = Vector2(300, 30) +layout_mode = 2 + +[node name="HBoxContainer3" type="HBoxContainer" parent="PauseMenu/OptionsMenu/VBoxContainer" unique_id=240142399] +custom_minimum_size = Vector2(300, 0) +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer3" unique_id=154714416] +custom_minimum_size = Vector2(150, 0) +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 32 +text = "SFX Volume" + +[node name="HSlider" type="HSlider" parent="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer3" unique_id=173892539] +custom_minimum_size = Vector2(300, 30) +layout_mode = 2 + +[node name="HBoxContainer2" type="HBoxContainer" parent="PauseMenu/OptionsMenu/VBoxContainer" unique_id=1323966021] +custom_minimum_size = Vector2(300, 0) +layout_mode = 2 +alignment = 1 + +[node name="Label" type="Label" parent="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer2" unique_id=1472770579] +custom_minimum_size = Vector2(150, 0) +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 32 +text = "Fullscreen" + +[node name="CheckBox" type="CheckBox" parent="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer2" unique_id=2108676279] +layout_mode = 2 + +[node name="BackButton" type="Button" parent="PauseMenu/OptionsMenu/VBoxContainer" unique_id=141581932] +custom_minimum_size = Vector2(200, 45) +layout_mode = 2 +theme_override_fonts/font = ExtResource("19_1kice") +theme_override_font_sizes/font_size = 32 +text = "Back" + [connection signal="timeout" from="SpawnTimer" to="SpawnControl" method="_on_spawn_timer_timeout"] +[connection signal="pressed" from="PauseMenu/VBoxContainer/ContinueButton" to="PauseMenu" method="_on_continue_button_pressed"] +[connection signal="pressed" from="PauseMenu/VBoxContainer/OptionsButton" to="PauseMenu" method="_on_options_button_pressed"] +[connection signal="pressed" from="PauseMenu/VBoxContainer/QuitButton" to="PauseMenu" method="_on_quit_button_pressed"] +[connection signal="value_changed" from="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer/HSlider" to="PauseMenu/OptionsMenu" method="_on_h_slider_value_changed"] +[connection signal="value_changed" from="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer3/HSlider" to="PauseMenu/OptionsMenu" method="_on_h2_slider_value_changed"] +[connection signal="toggled" from="PauseMenu/OptionsMenu/VBoxContainer/HBoxContainer2/CheckBox" to="PauseMenu/OptionsMenu" method="_on_check_box_toggled"] +[connection signal="pressed" from="PauseMenu/OptionsMenu/VBoxContainer/BackButton" to="PauseMenu/OptionsMenu" method="_on_back_button_pressed"] diff --git a/scripts/music_manager.gd b/scripts/music_manager.gd index cf01ec8..e8e3493 100644 --- a/scripts/music_manager.gd +++ b/scripts/music_manager.gd @@ -6,12 +6,17 @@ func _ready(): music_player = AudioStreamPlayer.new() music_player.bus = "Music" add_child(music_player) + music_player.process_mode = Node.PROCESS_MODE_ALWAYS + music_player.finished.connect(_on_music_finished) func play(stream: AudioStream): if music_player.stream == stream and music_player.playing: - return # läuft schon, nichts tun + return music_player.stream = stream music_player.play() func stop(): music_player.stop() + +func _on_music_finished(): + music_player.play() diff --git a/scripts/options_menu_ingame.gd b/scripts/options_menu_ingame.gd new file mode 100644 index 0000000..016e2b6 --- /dev/null +++ b/scripts/options_menu_ingame.gd @@ -0,0 +1,53 @@ +extends Control + +var sfx_preview = preload("res://assets/music&sfx/sfx/hit2.wav") + +func _ready(): + hide() + # Music Slider + $VBoxContainer/HBoxContainer/HSlider.min_value = 0.0 + $VBoxContainer/HBoxContainer/HSlider.max_value = 1.0 + $VBoxContainer/HBoxContainer/HSlider.step = 0.01 + # Aktuellen Bus-Wert als Startwert setzen + var bus_idx = AudioServer.get_bus_index("Music") + $VBoxContainer/HBoxContainer/HSlider.value = db_to_linear(AudioServer.get_bus_volume_db(bus_idx)) + + # SFX Slider + $VBoxContainer/HBoxContainer3/HSlider.min_value = 0.0 + $VBoxContainer/HBoxContainer3/HSlider.max_value = 1.0 + $VBoxContainer/HBoxContainer3/HSlider.step = 0.01 + # Aktuellen Bus-Wert als Startwert setzen + var sfx_idx = AudioServer.get_bus_index("SFX") + $VBoxContainer/HBoxContainer3/HSlider.value = db_to_linear(AudioServer.get_bus_volume_db(sfx_idx)) + +func _on_back_button_pressed() -> void: + hide() + get_parent().get_node("VBoxContainer").show() + +func _on_check_box_toggled(toggled_on: bool) -> void: + if toggled_on: + DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) + else: + DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) + +func _on_h_slider_value_changed(value: float) -> void: + var bus_idx = AudioServer.get_bus_index("Music") + AudioServer.set_bus_volume_db(bus_idx, linear_to_db(value)) + + +func _on_h2_slider_value_changed(value: float) -> void: + var bus_idx = AudioServer.get_bus_index("SFX") + AudioServer.set_bus_volume_db(bus_idx, linear_to_db(value)) + + # Vorschau-Sound abspielen + var preview = AudioStreamPlayer.new() + add_child(preview) + preview.stream = sfx_preview + preview.bus = "SFX" + preview.play() + await preview.finished + preview.queue_free() + +func _unhandled_input(event): + if event.is_action_pressed("ui_cancel") and visible: + _on_back_button_pressed() diff --git a/scripts/options_menu_ingame.gd.uid b/scripts/options_menu_ingame.gd.uid new file mode 100644 index 0000000..0b744d8 --- /dev/null +++ b/scripts/options_menu_ingame.gd.uid @@ -0,0 +1 @@ +uid://586y330mhx8 diff --git a/scripts/pause_menu.gd b/scripts/pause_menu.gd new file mode 100644 index 0000000..4cf3e42 --- /dev/null +++ b/scripts/pause_menu.gd @@ -0,0 +1,26 @@ +extends CanvasLayer + +func _ready(): + hide() + +func _unhandled_input(event): + if event.is_action_pressed("ui_cancel"): + if $OptionsMenu.visible: + return + toggle_pause() + +func toggle_pause(): + var paused = not get_tree().paused + get_tree().paused = paused + visible = paused + +func _on_continue_button_pressed() -> void: + toggle_pause() + +func _on_quit_button_pressed() -> void: + get_tree().quit() + + +func _on_options_button_pressed() -> void: + $VBoxContainer.hide() + $OptionsMenu.show() diff --git a/scripts/pause_menu.gd.uid b/scripts/pause_menu.gd.uid new file mode 100644 index 0000000..f71afa3 --- /dev/null +++ b/scripts/pause_menu.gd.uid @@ -0,0 +1 @@ +uid://duauc778wc3hd