From 388fcb948365d4ce364609ac5a31c47360aa51fc Mon Sep 17 00:00:00 2001 From: hpham474 Date: Sun, 7 Nov 2021 20:33:07 -0600 Subject: [PATCH] Added AudioBus. SFX Vol slider now works --- godot_ship/default_bus_layout.tres | 6 +++++ godot_ship/project.godot | 3 ++- godot_ship/scenes/AudioController.tscn | 22 +++++++++++++++++++ godot_ship/scenes/BackgroundMusic.tscn | 15 ------------- godot_ship/scenes/Options.tscn | 8 ++----- godot_ship/scenes/Title Screen.tscn | 6 +---- .../audio controller/AudioController.gd | 17 ++++++++++++++ godot_ship/script/game/Audio Bus.gd | 8 +++++++ godot_ship/script/options/Options.gd | 9 ++++---- .../script/options/OptionsController.gd | 2 ++ .../script/title screen/Title Screen.gd | 4 ---- 11 files changed, 65 insertions(+), 35 deletions(-) create mode 100644 godot_ship/scenes/AudioController.tscn delete mode 100644 godot_ship/scenes/BackgroundMusic.tscn create mode 100644 godot_ship/script/audio controller/AudioController.gd create mode 100644 godot_ship/script/game/Audio Bus.gd diff --git a/godot_ship/default_bus_layout.tres b/godot_ship/default_bus_layout.tres index ae28e38..60797cc 100644 --- a/godot_ship/default_bus_layout.tres +++ b/godot_ship/default_bus_layout.tres @@ -7,3 +7,9 @@ bus/1/mute = false bus/1/bypass_fx = false bus/1/volume_db = 0.0 bus/1/send = "Master" +bus/2/name = "SFX" +bus/2/solo = false +bus/2/mute = false +bus/2/bypass_fx = false +bus/2/volume_db = 0.0 +bus/2/send = "Master" diff --git a/godot_ship/project.godot b/godot_ship/project.godot index 200002f..826454e 100644 --- a/godot_ship/project.godot +++ b/godot_ship/project.godot @@ -17,8 +17,9 @@ config/icon="res://icon.png" [autoload] MessageBus="*res://script/game/Message Bus.gd" +AudioBus="*res://script/game/Audio Bus.gd" OptionsController="*res://script/options/OptionsController.gd" -AudioController="*res://scenes/BackgroundMusic.tscn" +AudioController="*res://scenes/AudioController.tscn" [display] diff --git a/godot_ship/scenes/AudioController.tscn b/godot_ship/scenes/AudioController.tscn new file mode 100644 index 0000000..5de3d12 --- /dev/null +++ b/godot_ship/scenes/AudioController.tscn @@ -0,0 +1,22 @@ +[gd_scene load_steps=4 format=2] + +[ext_resource path="res://assets/audio/BGM - Captain Scurvy.ogg" type="AudioStream" id=1] +[ext_resource path="res://script/audio controller/AudioController.gd" type="Script" id=2] +[ext_resource path="res://assets/audio/ButtonSFX.ogg" type="AudioStream" id=3] + +[node name="Control" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 2 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="BGM" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 1 ) +autoplay = true +bus = "BGM" + +[node name="buttonSFX" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 3 ) +bus = "SFX" diff --git a/godot_ship/scenes/BackgroundMusic.tscn b/godot_ship/scenes/BackgroundMusic.tscn deleted file mode 100644 index 0ebc2a0..0000000 --- a/godot_ship/scenes/BackgroundMusic.tscn +++ /dev/null @@ -1,15 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://assets/audio/BGM - Captain Scurvy.ogg" type="AudioStream" id=1] - -[node name="Control" type="Control"] -anchor_right = 1.0 -anchor_bottom = 1.0 -__meta__ = { -"_edit_use_anchors_": false -} - -[node name="BGM" type="AudioStreamPlayer" parent="."] -stream = ExtResource( 1 ) -autoplay = true -bus = "BGM" diff --git a/godot_ship/scenes/Options.tscn b/godot_ship/scenes/Options.tscn index 1f4ed81..c8ddd62 100644 --- a/godot_ship/scenes/Options.tscn +++ b/godot_ship/scenes/Options.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://script/options/Option-Background.png" type="Texture" id=1] [ext_resource path="res://script/options/Options.gd" type="Script" id=2] -[ext_resource path="res://assets/audio/ButtonSFX.ogg" type="AudioStream" id=3] [node name="Options" type="Control"] anchor_right = 1.0 @@ -68,7 +67,7 @@ focus_neighbour_top = NodePath("../../../Back") focus_neighbour_bottom = NodePath("../../Volume Setting/Volume Slider") focus_next = NodePath("../../Volume Setting/Volume Slider") focus_previous = NodePath("../../../Back") -min_value = -30.0 +min_value = -25.0 max_value = 0.0 tick_count = 11 __meta__ = { @@ -156,9 +155,6 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="ButtonSFX" type="AudioStreamPlayer" parent="."] -stream = ExtResource( 3 ) - [connection signal="value_changed" from="Sliders/SFX Setting/SFX Slider" to="." method="_on_SFX_Slider_value_changed"] [connection signal="value_changed" from="Sliders/Volume Setting/Volume Slider" to="." method="_on_Volume_Slider_value_changed"] [connection signal="pressed" from="Buttons/Light" to="." method="_on_Light_pressed"] diff --git a/godot_ship/scenes/Title Screen.tscn b/godot_ship/scenes/Title Screen.tscn index 37598e5..a309212 100644 --- a/godot_ship/scenes/Title Screen.tscn +++ b/godot_ship/scenes/Title Screen.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=3 format=2] [ext_resource path="res://script/title screen/Title-Screen-Background.png" type="Texture" id=1] [ext_resource path="res://script/title screen/Title Screen.gd" type="Script" id=2] -[ext_resource path="res://assets/audio/ButtonSFX.ogg" type="AudioStream" id=3] [node name="Title Node" type="Control"] anchor_right = 1.0 @@ -16,9 +15,6 @@ __meta__ = { position = Vector2( 320, 180 ) texture = ExtResource( 1 ) -[node name="ButtonSFX" type="AudioStreamPlayer" parent="."] -stream = ExtResource( 3 ) - [node name="VBoxContainer" type="VBoxContainer" parent="."] anchor_left = 0.5 anchor_top = 0.5 diff --git a/godot_ship/script/audio controller/AudioController.gd b/godot_ship/script/audio controller/AudioController.gd new file mode 100644 index 0000000..a128649 --- /dev/null +++ b/godot_ship/script/audio controller/AudioController.gd @@ -0,0 +1,17 @@ +extends Control + +# Declare member variables here. Examples: +# var a = 2 +# var b = "text" + + +# Called when the node enters the scene tree for the first time. +func _ready(): + var _errno = 0 + _errno += AudioBus.connect("button_clicked", self, "_button_clicked") + +func _button_clicked(): + $buttonSFX.play() +# Called every frame. 'delta' is the elapsed time since the previous frame. +#func _process(delta): +# pass diff --git a/godot_ship/script/game/Audio Bus.gd b/godot_ship/script/game/Audio Bus.gd new file mode 100644 index 0000000..4fbe1d1 --- /dev/null +++ b/godot_ship/script/game/Audio Bus.gd @@ -0,0 +1,8 @@ +extends Node + + +# Ignore "unused signal" warnings in this class +# warning-ignore-all:unused_signal + +# Ask for a scene change +signal button_clicked diff --git a/godot_ship/script/options/Options.gd b/godot_ship/script/options/Options.gd index 061b44e..f61cddb 100644 --- a/godot_ship/script/options/Options.gd +++ b/godot_ship/script/options/Options.gd @@ -13,11 +13,12 @@ func _ready(): music_slider.value = OptionsController.get_mus_volume() func _on_Button_pressed(): - $ButtonSFX.play() + AudioBus.emit_signal("button_clicked") queue_free() -# MessageBus.emit_signal("change_scene", "Title") + #MessageBus.emit_signal("change_scene", "Title") func _on_SFX_Slider_value_changed(value): + AudioBus.emit_signal("button_clicked") OptionsController.set_sfx_vol(value) OptionsController.save_options() @@ -26,11 +27,11 @@ func _on_Volume_Slider_value_changed(value): OptionsController.save_options() func _on_Light_pressed(): + AudioBus.emit_signal("button_clicked") OptionsController.set_theme("light") OptionsController.save_options() - $ButtonSFX.play() func _on_Dark_pressed(): + AudioBus.emit_signal("button_clicked") OptionsController.set_theme("dark") OptionsController.save_options() - $ButtonSFX.play() diff --git a/godot_ship/script/options/OptionsController.gd b/godot_ship/script/options/OptionsController.gd index b031864..ce5cc99 100644 --- a/godot_ship/script/options/OptionsController.gd +++ b/godot_ship/script/options/OptionsController.gd @@ -28,6 +28,7 @@ func set_mus_vol(volume): emit_signal("change_mus_volume", mus_vol) func set_sfx_vol(volume): sfx_vol = volume + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol) emit_signal("change_sfx_volume", sfx_vol) #Option Save File @@ -45,6 +46,7 @@ func load_options(): sfx_vol = f.get_var() f.close() AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol) + AudioServer.set_bus_volume_db(AudioServer.get_bus_index("SFX"), sfx_vol) # Getters func get_theme(): diff --git a/godot_ship/script/title screen/Title Screen.gd b/godot_ship/script/title screen/Title Screen.gd index b1a2682..e1e92ea 100644 --- a/godot_ship/script/title screen/Title Screen.gd +++ b/godot_ship/script/title screen/Title Screen.gd @@ -5,21 +5,17 @@ func _ready(): $VBoxContainer/Singleplayer.grab_focus() func _on_Singleplayer_pressed(): - $ButtonSFX.play() MessageBus.emit_signal("change_scene", "Singleplayer") queue_free() func _on_Multiplayer_pressed(): - $ButtonSFX.play() MessageBus.emit_signal("change_scene", "Multiplayer") queue_free() func _on_Options_pressed(): - $ButtonSFX.play() MessageBus.emit_signal("change_scene", "Options") queue_free() func _on_Quit_pressed(): - $ButtonSFX.play() MessageBus.emit_signal("quit") queue_free()