From 28df2fc7dd2f23bbf62655a4f3d99134534f1b6e Mon Sep 17 00:00:00 2001 From: Satharis Date: Sat, 12 Sep 2020 01:38:20 -0700 Subject: [PATCH] Added more audio busses and options menu settings for them. (#1603) * Added field and method changes to allow playing jukebox track lists on a specific audio bus. * Changed audio stream players to play SFX and GUI sounds on their respective busses. * Added volume sliders and mute checkboxes for ambiance, sfx and gui to the options menu. --- default_bus_layout.tres | 12 ++ .../common/music_tracks.json | 1 + src/engine/Settings.cs | 45 +++++++ src/general/Jukebox.cs | 15 ++- src/general/MusicCategory.cs | 2 + src/general/OptionsMenu.cs | 92 ++++++++++++- src/general/OptionsMenu.tscn | 127 +++++++++++++++++- src/gui_common/GUICommon.cs | 1 + src/microbe_stage/Microbe.tscn | 4 + 9 files changed, 287 insertions(+), 12 deletions(-) diff --git a/default_bus_layout.tres b/default_bus_layout.tres index dc8676e2a62..364f82659af 100644 --- a/default_bus_layout.tres +++ b/default_bus_layout.tres @@ -13,3 +13,15 @@ bus/2/mute = false bus/2/bypass_fx = false bus/2/volume_db = 0.0 bus/2/send = "Master" +bus/3/name = "SFX" +bus/3/solo = false +bus/3/mute = false +bus/3/bypass_fx = false +bus/3/volume_db = 0.0 +bus/3/send = "Master" +bus/4/name = "GUI" +bus/4/solo = false +bus/4/mute = false +bus/4/bypass_fx = false +bus/4/volume_db = 0.0 +bus/4/send = "Master" diff --git a/simulation_parameters/common/music_tracks.json b/simulation_parameters/common/music_tracks.json index 5ad524cdaca..6dbac1ef6dd 100644 --- a/simulation_parameters/common/music_tracks.json +++ b/simulation_parameters/common/music_tracks.json @@ -39,6 +39,7 @@ ] }, { + "TrackBus": "Ambiance", "Tracks": [ { "ResourcePath": "res://assets/sounds/soundeffects/microbe-ambience.ogg" diff --git a/src/engine/Settings.cs b/src/engine/Settings.cs index 52c68111aee..c7e273435db 100644 --- a/src/engine/Settings.cs +++ b/src/engine/Settings.cs @@ -76,6 +76,36 @@ private Settings() /// public bool VolumeMusicMuted { get; set; } = false; + /// + /// The Db value to be added to the ambiance audio bus + /// + public float VolumeAmbiance { get; set; } = 0.0f; + + /// + /// If true ambiance is muted + /// + public bool VolumeAmbianceMuted { get; set; } = false; + + /// + /// The Db value to be added to the sfx audio bus + /// + public float VolumeSFX { get; set; } = 0.0f; + + /// + /// If true sfx is muted + /// + public bool VolumeSFXMuted { get; set; } = false; + + /// + /// The Db value to be added to the gui audio bus + /// + public float VolumeGUI { get; set; } = 0.0f; + + /// + /// If true gui audio bus is muted + /// + public bool VolumeGUIMuted { get; set; } = false; + // Performance Properties /// @@ -283,6 +313,21 @@ public void ApplySoundSettings() AudioServer.SetBusVolumeDb(music, VolumeMusic); AudioServer.SetBusMute(music, VolumeMusicMuted); + + var ambiance = AudioServer.GetBusIndex("Ambiance"); + + AudioServer.SetBusVolumeDb(ambiance, VolumeAmbiance); + AudioServer.SetBusMute(ambiance, VolumeAmbianceMuted); + + var sfx = AudioServer.GetBusIndex("SFX"); + + AudioServer.SetBusVolumeDb(sfx, VolumeSFX); + AudioServer.SetBusMute(sfx, VolumeSFXMuted); + + var gui = AudioServer.GetBusIndex("GUI"); + + AudioServer.SetBusVolumeDb(gui, VolumeGUI); + AudioServer.SetBusMute(gui, VolumeGUIMuted); } /// diff --git a/src/general/Jukebox.cs b/src/general/Jukebox.cs index 2c4a05cb8ba..a734a4ee916 100644 --- a/src/general/Jukebox.cs +++ b/src/general/Jukebox.cs @@ -191,7 +191,7 @@ private AudioPlayer GetNextPlayer(int index) return audioPlayers[index]; } - private void PlayTrack(AudioPlayer player, TrackList.Track track, float fromPosition = 0) + private void PlayTrack(AudioPlayer player, TrackList.Track track, string trackBus, float fromPosition = 0) { if (player.CurrentTrack != track.ResourcePath) { @@ -199,6 +199,7 @@ private void PlayTrack(AudioPlayer player, TrackList.Track track, float fromPosi player.Player.Stream = stream; player.CurrentTrack = track.ResourcePath; + player.Bus = trackBus; player.Player.Play(fromPosition); @@ -345,7 +346,7 @@ private void SetupStreamsFromCategory() // Resume track (but only one per list) if (track.WasPlaying) { - PlayTrack(GetNextPlayer(nextPlayerToUse++), track, track.PreviousPlayedPosition); + PlayTrack(GetNextPlayer(nextPlayerToUse++), track, list.TrackBus, track.PreviousPlayedPosition); break; } } @@ -399,7 +400,7 @@ private void PlayNextTrackFromList(TrackList list, Func getPla { list.LastPlayedIndex = (list.LastPlayedIndex + 1) % list.Tracks.Count; - PlayTrack(getPlayer(playerToUse), list.Tracks[list.LastPlayedIndex]); + PlayTrack(getPlayer(playerToUse), list.Tracks[list.LastPlayedIndex], list.TrackBus); } else { @@ -414,7 +415,7 @@ private void PlayNextTrackFromList(TrackList list, Func getPla } while (nextIndex == list.LastPlayedIndex && list.Tracks.Count > 1); - PlayTrack(getPlayer(playerToUse), list.Tracks[nextIndex]); + PlayTrack(getPlayer(playerToUse), list.Tracks[nextIndex], list.TrackBus); list.LastPlayedIndex = nextIndex; } } @@ -470,6 +471,12 @@ public bool StreamPaused public bool Playing => Player.Playing; + public string Bus + { + get => Player.Bus; + set => Player.Bus = value; + } + public void Stop() { CurrentTrack = null; diff --git a/src/general/MusicCategory.cs b/src/general/MusicCategory.cs index fb2f5d2cbc2..b59e20d154a 100644 --- a/src/general/MusicCategory.cs +++ b/src/general/MusicCategory.cs @@ -90,6 +90,8 @@ public enum Order public Order TrackOrder { get; set; } = Order.Random; + public string TrackBus { get; set; } = "Music"; + public List Tracks { get; set; } [JsonIgnore] diff --git a/src/general/OptionsMenu.cs b/src/general/OptionsMenu.cs index dbfbcd8e1ed..d48426bc700 100644 --- a/src/general/OptionsMenu.cs +++ b/src/general/OptionsMenu.cs @@ -69,6 +69,24 @@ GUI Control Paths [Export] public NodePath MusicMutedPath; + [Export] + public NodePath AmbianceVolumePath; + + [Export] + public NodePath AmbianceMutedPath; + + [Export] + public NodePath SFXVolumePath; + + [Export] + public NodePath SFXMutedPath; + + [Export] + public NodePath GUIVolumePath; + + [Export] + public NodePath GUIMutedPath; + // Performance tab. [Export] public NodePath PerformanceTabPath; @@ -135,6 +153,12 @@ GUI Control Paths private CheckBox masterMuted; private Slider musicVolume; private CheckBox musicMuted; + private Slider ambianceVolume; + private CheckBox ambianceMuted; + private Slider sfxVolume; + private CheckBox sfxMuted; + private Slider guiVolume; + private CheckBox guiMuted; // Performance tab private Control performanceTab; @@ -214,6 +238,12 @@ public override void _Ready() masterMuted = GetNode(MasterMutedPath); musicVolume = GetNode(MusicVolumePath); musicMuted = GetNode(MusicMutedPath); + ambianceVolume = GetNode(AmbianceVolumePath); + ambianceMuted = GetNode(AmbianceMutedPath); + sfxVolume = GetNode(SFXVolumePath); + sfxMuted = GetNode(SFXMutedPath); + guiVolume = GetNode(GUIVolumePath); + guiMuted = GetNode(GUIMutedPath); // Performance performanceTab = GetNode(PerformanceTabPath); @@ -265,6 +295,12 @@ public void ApplySettingsToControls(Settings settings) masterMuted.Pressed = settings.VolumeMasterMuted; musicVolume.Value = ConvertDBToSoundBar(settings.VolumeMusic); musicMuted.Pressed = settings.VolumeMusicMuted; + ambianceVolume.Value = ConvertDBToSoundBar(settings.VolumeAmbiance); + ambianceMuted.Pressed = settings.VolumeAmbianceMuted; + sfxVolume.Value = ConvertDBToSoundBar(settings.VolumeSFX); + sfxMuted.Pressed = settings.VolumeSFXMuted; + guiVolume.Value = ConvertDBToSoundBar(settings.VolumeGUI); + guiMuted.Pressed = settings.VolumeGUIMuted; // Performance cloudInterval.Selected = CloudIntervalToIndex(settings.CloudUpdateInterval); @@ -617,6 +653,14 @@ private void OnChromaticAberrationValueChanged(float amount) } // Sound Button Callbacks + private void OnMasterVolumeChanged(float value) + { + Settings.Instance.VolumeMaster = ConvertSoundBarToDb(value); + Settings.ApplySoundSettings(); + + CompareSettings(); + } + private void OnMasterMutedToggled(bool pressed) { Settings.Instance.VolumeMasterMuted = pressed; @@ -625,6 +669,14 @@ private void OnMasterMutedToggled(bool pressed) CompareSettings(); } + private void OnMusicVolumeChanged(float value) + { + Settings.Instance.VolumeMusic = ConvertSoundBarToDb(value); + Settings.ApplySoundSettings(); + + CompareSettings(); + } + private void OnMusicMutedToggled(bool pressed) { Settings.Instance.VolumeMusicMuted = pressed; @@ -633,17 +685,49 @@ private void OnMusicMutedToggled(bool pressed) CompareSettings(); } - private void OnMasterVolumeChanged(float value) + private void OnAmbianceVolumeChanged(float value) { - Settings.Instance.VolumeMaster = ConvertSoundBarToDb(value); + Settings.Instance.VolumeAmbiance = ConvertSoundBarToDb(value); Settings.ApplySoundSettings(); CompareSettings(); } - private void OnMusicVolumeChanged(float value) + private void OnAmbianceMutedToggled(bool pressed) { - Settings.Instance.VolumeMusic = ConvertSoundBarToDb(value); + Settings.Instance.VolumeAmbianceMuted = pressed; + Settings.ApplySoundSettings(); + + CompareSettings(); + } + + private void OnSFXVolumeChanged(float value) + { + Settings.Instance.VolumeSFX = ConvertSoundBarToDb(value); + Settings.ApplySoundSettings(); + + CompareSettings(); + } + + private void OnSFXMutedToggled(bool pressed) + { + Settings.Instance.VolumeSFXMuted = pressed; + Settings.ApplySoundSettings(); + + CompareSettings(); + } + + private void OnGUIVolumeChanged(float value) + { + Settings.Instance.VolumeGUI = ConvertSoundBarToDb(value); + Settings.ApplySoundSettings(); + + CompareSettings(); + } + + private void OnGUIMutedToggled(bool pressed) + { + Settings.Instance.VolumeGUIMuted = pressed; Settings.ApplySoundSettings(); CompareSettings(); diff --git a/src/general/OptionsMenu.tscn b/src/general/OptionsMenu.tscn index 20f26da6923..83e9a876c6c 100644 --- a/src/general/OptionsMenu.tscn +++ b/src/general/OptionsMenu.tscn @@ -58,6 +58,12 @@ MasterVolumePath = NodePath("CenterContainer/VBoxContainer/PanelContainer/Margin MasterMutedPath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer/MasterMuted") MusicVolumePath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer2/MusicVolume") MusicMutedPath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer2/MusicMuted") +AmbianceVolumePath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer3/AmbianceVolume") +AmbianceMutedPath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer3/AmbianceMuted") +SFXVolumePath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer4/SFXVolume") +SFXMutedPath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer4/SFXMuted") +GUIVolumePath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer5/GUIVolume") +GUIMutedPath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer5/GUIMuted") PerformanceTabPath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Performance") CloudIntervalPath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Performance/VBoxContainer/HBoxContainer/CloudInterval") CloudResolutionPath = NodePath("CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Performance/VBoxContainer/HBoxContainer2/CloudResolution") @@ -390,17 +396,25 @@ size_flags_horizontal = 0 custom_styles/hover_pressed = SubResource( 2 ) text = "Mute" -[node name="Label2" type="Label" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] +[node name="HSeparator" type="HSeparator" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] margin_top = 68.0 margin_right = 517.0 -margin_bottom = 91.0 +margin_bottom = 72.0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Label2" type="Label" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] +margin_top = 82.0 +margin_right = 517.0 +margin_bottom = 105.0 text = "Music volume" align = 1 [node name="HBoxContainer2" type="HBoxContainer" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] -margin_top = 101.0 +margin_top = 115.0 margin_right = 517.0 -margin_bottom = 126.0 +margin_bottom = 140.0 [node name="MusicVolume" type="HSlider" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer2"] margin_right = 435.0 @@ -423,6 +437,105 @@ size_flags_horizontal = 0 custom_styles/hover_pressed = SubResource( 2 ) text = "Mute" +[node name="Label3" type="Label" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] +margin_top = 150.0 +margin_right = 517.0 +margin_bottom = 173.0 +text = "Ambiance Volume" +align = 1 + +[node name="HBoxContainer3" type="HBoxContainer" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] +margin_top = 183.0 +margin_right = 517.0 +margin_bottom = 208.0 + +[node name="AmbianceVolume" type="HSlider" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer3"] +margin_right = 435.0 +margin_bottom = 25.0 +size_flags_horizontal = 3 +size_flags_vertical = 1 +value = 80.0 + +[node name="HSeparator" type="HSeparator" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer3"] +margin_left = 439.0 +margin_right = 442.0 +margin_bottom = 25.0 +custom_styles/separator = SubResource( 5 ) + +[node name="AmbianceMuted" type="CheckBox" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer3"] +margin_left = 446.0 +margin_right = 517.0 +margin_bottom = 25.0 +size_flags_horizontal = 0 +custom_styles/hover_pressed = SubResource( 2 ) +text = "Mute" + +[node name="Label4" type="Label" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] +margin_top = 218.0 +margin_right = 517.0 +margin_bottom = 241.0 +text = "SFX Volume" +align = 1 + +[node name="HBoxContainer4" type="HBoxContainer" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] +margin_top = 251.0 +margin_right = 517.0 +margin_bottom = 276.0 + +[node name="SFXVolume" type="HSlider" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer4"] +margin_right = 435.0 +margin_bottom = 25.0 +size_flags_horizontal = 3 +size_flags_vertical = 1 +value = 80.0 + +[node name="HSeparator" type="HSeparator" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer4"] +margin_left = 439.0 +margin_right = 442.0 +margin_bottom = 25.0 +custom_styles/separator = SubResource( 5 ) + +[node name="SFXMuted" type="CheckBox" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer4"] +margin_left = 446.0 +margin_right = 517.0 +margin_bottom = 25.0 +size_flags_horizontal = 0 +custom_styles/hover_pressed = SubResource( 2 ) +text = "Mute" + +[node name="Label5" type="Label" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] +margin_top = 286.0 +margin_right = 517.0 +margin_bottom = 309.0 +text = "GUI Volume" +align = 1 + +[node name="HBoxContainer5" type="HBoxContainer" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer"] +margin_top = 319.0 +margin_right = 517.0 +margin_bottom = 344.0 + +[node name="GUIVolume" type="HSlider" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer5"] +margin_right = 435.0 +margin_bottom = 25.0 +size_flags_horizontal = 3 +size_flags_vertical = 1 +value = 80.0 + +[node name="HSeparator" type="HSeparator" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer5"] +margin_left = 439.0 +margin_right = 442.0 +margin_bottom = 25.0 +custom_styles/separator = SubResource( 5 ) + +[node name="GUIMuted" type="CheckBox" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer5"] +margin_left = 446.0 +margin_right = 517.0 +margin_bottom = 25.0 +size_flags_horizontal = 0 +custom_styles/hover_pressed = SubResource( 2 ) +text = "Mute" + [node name="Performance" type="Control" parent="CenterContainer/VBoxContainer/PanelContainer/MarginContainer"] visible = false margin_left = 15.0 @@ -818,6 +931,12 @@ dialog_text = "Error: Failed to save new settings to configuration file." [connection signal="toggled" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer/MasterMuted" to="." method="OnMasterMutedToggled"] [connection signal="value_changed" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer2/MusicVolume" to="." method="OnMusicVolumeChanged"] [connection signal="toggled" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer2/MusicMuted" to="." method="OnMusicMutedToggled"] +[connection signal="value_changed" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer3/AmbianceVolume" to="." method="OnAmbianceVolumeChanged"] +[connection signal="toggled" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer3/AmbianceMuted" to="." method="OnAmbianceMutedToggled"] +[connection signal="value_changed" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer4/SFXVolume" to="." method="OnSFXVolumeChanged"] +[connection signal="toggled" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer4/SFXMuted" to="." method="OnSFXMutedToggled"] +[connection signal="value_changed" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer5/GUIVolume" to="." method="OnGUIVolumeChanged"] +[connection signal="toggled" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Sound/VBoxContainer/HBoxContainer5/GUIMuted" to="." method="OnGUIMutedToggled"] [connection signal="item_selected" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Performance/VBoxContainer/HBoxContainer/CloudInterval" to="." method="OnCloudIntervalSelected"] [connection signal="item_selected" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Performance/VBoxContainer/HBoxContainer2/CloudResolution" to="." method="OnCloudResolutionSelected"] [connection signal="toggled" from="CenterContainer/VBoxContainer/PanelContainer/MarginContainer/Misc/VBoxContainer/Intro" to="." method="OnIntroToggled"] diff --git a/src/gui_common/GUICommon.cs b/src/gui_common/GUICommon.cs index 5b6b48652b5..89d22b970b9 100644 --- a/src/gui_common/GUICommon.cs +++ b/src/gui_common/GUICommon.cs @@ -16,6 +16,7 @@ private GUICommon() instance = this; AudioSource = new AudioStreamPlayer(); + AudioSource.Bus = "GUI"; tween = new Tween(); AddChild(AudioSource); diff --git a/src/microbe_stage/Microbe.tscn b/src/microbe_stage/Microbe.tscn index 8a6841c7f63..8b2045cab86 100644 --- a/src/microbe_stage/Microbe.tscn +++ b/src/microbe_stage/Microbe.tscn @@ -14,6 +14,7 @@ render_priority = 1 shader = ExtResource( 4 ) shader_param/wigglyNess = 1.0 shader_param/movementWigglyNess = 1.0 +shader_param/dissolveValue = null shader_param/healthFraction = 0.25 shader_param/tint = Plane( 1, 1, 1, 1 ) shader_param/albedoTexture = ExtResource( 2 ) @@ -45,12 +46,15 @@ MaterialToEdit = SubResource( 1 ) [node name="EngulfAudio" type="AudioStreamPlayer3D" parent="."] stream = ExtResource( 6 ) +bus = "SFX" [node name="OtherAudio" type="AudioStreamPlayer3D" parent="."] +bus = "SFX" [node name="MovementAudio" type="AudioStreamPlayer3D" parent="."] stream = ExtResource( 7 ) autoplay = true +bus = "SFX" [node name="EngulfDetector" type="Area" parent="."] input_ray_pickable = false