Skip to content

Commit 247d2ba

Browse files
authored
Merge pull request #67 from Maaack/updates-from-game-template
Updates from game template
2 parents da64c6f + 544be9b commit 247d2ba

File tree

9 files changed

+93
-28
lines changed

9 files changed

+93
-28
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Godot Menus Template
2-
For Godot 4.4 (4.3+ compatible)
2+
For Godot 4.5 (4.3+ compatible)
33

44
This template has a main menu, options menus, credits, and a scene loader.
55

@@ -132,6 +132,7 @@ These instructions assume starting with just the contents of `addons/`. This wil
132132
[Loading Scenes](/addons/maaacks_menus_template/docs/LoadingScenes.md)
133133
[Input Icon Mapping](/addons/maaacks_menus_template/docs/InputIconMapping.md)
134134
[Joypad Inputs](/addons/maaacks_menus_template/docs/JoypadInputs.md)
135+
[Blending Music](/addons/maaacks_menus_template/docs/BlendingMusic.md)
135136
[Add Custom Options](/addons/maaacks_menus_template/docs/AddingCustomOptions.md)
136137
[How Parts Work](/addons/maaacks_menus_template/docs/HowPartsWork.md)
137138
[Automatic Updating](/addons/maaacks_menus_template/docs/AutomaticUpdating.md)

addons/maaacks_menus_template/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Godot Menus Template
2-
For Godot 4.4 (4.3+ compatible)
2+
For Godot 4.5 (4.3+ compatible)
33

44
This template has a main menu, options menus, credits, and a scene loader.
55

@@ -132,6 +132,7 @@ These instructions assume starting with just the contents of `addons/`. This wil
132132
[Loading Scenes](/addons/maaacks_menus_template/docs/LoadingScenes.md)
133133
[Input Icon Mapping](/addons/maaacks_menus_template/docs/InputIconMapping.md)
134134
[Joypad Inputs](/addons/maaacks_menus_template/docs/JoypadInputs.md)
135+
[Blending Music](/addons/maaacks_menus_template/docs/BlendingMusic.md)
135136
[Add Custom Options](/addons/maaacks_menus_template/docs/AddingCustomOptions.md)
136137
[How Parts Work](/addons/maaacks_menus_template/docs/HowPartsWork.md)
137138
[Automatic Updating](/addons/maaacks_menus_template/docs/AutomaticUpdating.md)

addons/maaacks_menus_template/base/scripts/player_config.gd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ const CONFIG_FILE_LOCATION := "user://player_config.cfg"
77

88
static var config_file : ConfigFile
99

10-
static func _init() -> void:
11-
load_config_file()
12-
1310
static func _save_config_file() -> void:
1411
var save_error : int = config_file.save(CONFIG_FILE_LOCATION)
1512
if save_error:
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Blending Music Between Scenes
2+
3+
This page covers the `ProjectMusicController`, which is used to blend music in between scenes, that would otherwise abruptly stop the music when they get unloaded.
4+
5+
## Setup
6+
7+
1. Verify the `Music` audio bus.
8+
9+
1. Open the Audio bus editor.
10+
2. Confirm that `Music` audio bus is available.
11+
1. If the last bus is `New Bus`, try restarting the editor and checking again.
12+
3. If the audio bus doesn't exist, add it and save the project.
13+
14+
2. Verify the `ProjectMusicController` autoload.
15+
16+
1. Open the Project Settings.
17+
2. Open the `Globals` tab.
18+
3. Confirm that the `ProjectMusicController` is listed as an autoload.
19+
20+
3. Setup music blending between scenes.
21+
22+
1. Open up the `project_music_controller.tscn` scene.
23+
2. Inspect the root node of the scene tree (`ProjectMusicController`).
24+
3. Confirm that the `audio_bus` is set to `Music`.
25+
4. Expand the `Blending` variable group.
26+
5. Set a `fade_out_duration` or `fade_in_duration`, in seconds.
27+
28+
4. Add background music to your scenes.
29+
30+
1. Import the music asset into the project.
31+
2. Add a `BackgroundMusicPlayer`.
32+
3. Assign the music asset to the `stream` property.
33+
4. Make sure that the `bus` property is set to `Music` and `autoplay` is `true`.
34+
5. Save the scene.
35+
36+
## Internal Details
37+
38+
When a background music player is about to exit the scene tree, it gets reparented to the autoload node. This allows it to continue playing until the next scene is ready and a new background music player is detected. If the audio stream players share the same stream, then the controller will seek the next player to the same position on the stream, before removing the previous one. If a different stream is detected and a fade out duration is set, then the previous player will blend into the next one, by having its volume lowered to zero over the fade out duration.
39+
40+
The autload adds the "BlendMusic" audio bus is added at runtime. If a fade in duration is set, then the temporary bus is used to combine the increasing volume of the player with any other animations local to the scene.
41+
42+
The autoload will work with any `AudioStreamPlayer` with `bus` set to `Music` and `autoplay` set to `true`. These are detected up as they enter the scene tree. To dynamically add an `AudioStreamPlayer` to the background music, call `ProjectMusicController.play_stream(background_music_player)`.

addons/maaacks_menus_template/examples/scenes/end_credits/end_credits.gd

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,49 @@ extends ScrollingCredits
44
## This option forces the mouse to be visible when the menu shows up.
55
## Useful for games that capture the mouse, and don't automatically return it.
66
@export var force_mouse_mode_visible : bool = false
7+
8+
@onready var end_message_panel = %EndMessagePanel
9+
@onready var exit_button = %ExitButton
10+
@onready var menu_button = %MenuButton
711
@onready var init_mouse_filter : MouseFilter = mouse_filter
812

913
func _on_scroll_container_end_reached() -> void:
10-
%EndMessagePanel.show()
14+
end_message_panel.show()
1115
mouse_filter = Control.MOUSE_FILTER_STOP
1216
if force_mouse_mode_visible:
1317
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
1418
super._on_scroll_container_end_reached()
1519

16-
func _on_MenuButton_pressed() -> void:
20+
func load_main_menu() -> void:
1721
SceneLoader.load_scene(main_menu_scene)
1822

19-
func _on_ExitButton_pressed() -> void:
23+
func exit_game() -> void:
24+
if OS.has_feature("web"):
25+
load_main_menu()
2026
get_tree().quit()
2127

2228
func _on_visibility_changed() -> void:
2329
if visible:
24-
%EndMessagePanel.hide()
30+
end_message_panel.hide()
2531
mouse_filter = init_mouse_filter
2632

2733
func _ready() -> void:
2834
visibility_changed.connect(_on_visibility_changed)
2935
if main_menu_scene.is_empty():
30-
%MenuButton.hide()
36+
menu_button.hide()
3137
if OS.has_feature("web"):
32-
%ExitButton.hide()
38+
exit_button.hide()
3339
super._ready()
3440

3541
func _unhandled_input(event : InputEvent) -> void:
36-
if event.is_action_pressed("ui_cancel"):
37-
if not %EndMessagePanel.visible:
42+
if event.is_action_released("ui_cancel"):
43+
if not end_message_panel.visible:
3844
_on_scroll_container_end_reached()
3945
else:
40-
get_tree().quit()
46+
exit_game()
47+
48+
func _on_exit_button_pressed():
49+
exit_game()
50+
51+
func _on_menu_button_pressed():
52+
load_main_menu()

addons/maaacks_menus_template/examples/scenes/end_credits/end_credits.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ size_flags_horizontal = 3
8787
size_flags_vertical = 3
8888
text = "Menu"
8989

90-
[connection signal="pressed" from="CenterContainer/EndMessagePanel/VBoxContainer/CenterContainer/HBoxContainer/ExitButton" to="." method="_on_ExitButton_pressed"]
91-
[connection signal="pressed" from="CenterContainer/EndMessagePanel/VBoxContainer/CenterContainer/HBoxContainer/MenuButton" to="." method="_on_MenuButton_pressed"]
90+
[connection signal="pressed" from="CenterContainer/EndMessagePanel/VBoxContainer/CenterContainer/HBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"]
91+
[connection signal="pressed" from="CenterContainer/EndMessagePanel/VBoxContainer/CenterContainer/HBoxContainer/MenuButton" to="." method="_on_menu_button_pressed"]

addons/maaacks_menus_template/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ description="Template with main menu, options menu, credits, and a scene loader.
55
66
Created in collaboration with members of the Godot Wild Jam community."
77
author="Marek Belski"
8-
version="1.2.0"
8+
version="1.2.1"
99
script="maaacks_menus_template.gd"

scenes/end_credits/end_credits.gd

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,49 @@ extends ScrollingCredits
44
## This option forces the mouse to be visible when the menu shows up.
55
## Useful for games that capture the mouse, and don't automatically return it.
66
@export var force_mouse_mode_visible : bool = false
7+
8+
@onready var end_message_panel = %EndMessagePanel
9+
@onready var exit_button = %ExitButton
10+
@onready var menu_button = %MenuButton
711
@onready var init_mouse_filter : MouseFilter = mouse_filter
812

913
func _on_scroll_container_end_reached() -> void:
10-
%EndMessagePanel.show()
14+
end_message_panel.show()
1115
mouse_filter = Control.MOUSE_FILTER_STOP
1216
if force_mouse_mode_visible:
1317
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
1418
super._on_scroll_container_end_reached()
1519

16-
func _on_MenuButton_pressed() -> void:
20+
func load_main_menu() -> void:
1721
SceneLoader.load_scene(main_menu_scene)
1822

19-
func _on_ExitButton_pressed() -> void:
23+
func exit_game() -> void:
24+
if OS.has_feature("web"):
25+
load_main_menu()
2026
get_tree().quit()
2127

2228
func _on_visibility_changed() -> void:
2329
if visible:
24-
%EndMessagePanel.hide()
30+
end_message_panel.hide()
2531
mouse_filter = init_mouse_filter
2632

2733
func _ready() -> void:
2834
visibility_changed.connect(_on_visibility_changed)
2935
if main_menu_scene.is_empty():
30-
%MenuButton.hide()
36+
menu_button.hide()
3137
if OS.has_feature("web"):
32-
%ExitButton.hide()
38+
exit_button.hide()
3339
super._ready()
3440

3541
func _unhandled_input(event : InputEvent) -> void:
36-
if event.is_action_pressed("ui_cancel"):
37-
if not %EndMessagePanel.visible:
42+
if event.is_action_released("ui_cancel"):
43+
if not end_message_panel.visible:
3844
_on_scroll_container_end_reached()
3945
else:
40-
get_tree().quit()
46+
exit_game()
47+
48+
func _on_exit_button_pressed():
49+
exit_game()
50+
51+
func _on_menu_button_pressed():
52+
load_main_menu()

scenes/end_credits/end_credits.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ size_flags_horizontal = 3
8787
size_flags_vertical = 3
8888
text = "Menu"
8989

90-
[connection signal="pressed" from="CenterContainer/EndMessagePanel/VBoxContainer/CenterContainer/HBoxContainer/ExitButton" to="." method="_on_ExitButton_pressed"]
91-
[connection signal="pressed" from="CenterContainer/EndMessagePanel/VBoxContainer/CenterContainer/HBoxContainer/MenuButton" to="." method="_on_MenuButton_pressed"]
90+
[connection signal="pressed" from="CenterContainer/EndMessagePanel/VBoxContainer/CenterContainer/HBoxContainer/ExitButton" to="." method="_on_exit_button_pressed"]
91+
[connection signal="pressed" from="CenterContainer/EndMessagePanel/VBoxContainer/CenterContainer/HBoxContainer/MenuButton" to="." method="_on_menu_button_pressed"]

0 commit comments

Comments
 (0)