Volume sliders in options menu immediately affect bus volumes.

However, the values aren't saved unless the player clicks the apply
button. This, as well as how the options menu works in general (in
terms of how applying/saving changes works) will probably be changed
in the future.
This commit is contained in:
drwhut 2021-03-01 13:01:28 +00:00
parent 0405e80e45
commit 5eb710f3c2
2 changed files with 28 additions and 9 deletions

View File

@ -878,6 +878,9 @@ __meta__ = {
"_edit_use_anchors_": false
}
[connection signal="value_changed" from="MarginContainer/VBoxContainer/TabContainer/Audio/GridContainer/MasterVolumeSlider" to="." method="_on_MasterVolumeSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/TabContainer/Audio/GridContainer/MusicVolumeSlider" to="." method="_on_MusicVolumeSlider_value_changed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/TabContainer/Audio/GridContainer/SoundsVolumeSlider" to="." method="_on_SoundsVolumeSlider_value_changed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/TabContainer/General/GridContainer/OpenAssetsButton" to="." method="_on_OpenAssetsButton_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/TabContainer/General/GridContainer/ReimportButton" to="." method="_on_ReimportButton_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/TabContainer/General/GridContainer/ViewLicenseButton" to="." method="_on_ViewLicenseButton_pressed"]

View File

@ -70,15 +70,7 @@ func _apply_config(config: ConfigFile) -> void:
# AUDIO #
#########
for volume_key in config.get_section_keys("audio"):
var bus_name = volume_key.split("_")[0].capitalize()
var bus_index = AudioServer.get_bus_index(bus_name)
var bus_volume = config.get_value("audio", volume_key)
AudioServer.set_bus_mute(bus_index, bus_volume == 0)
if bus_volume > 0:
var bus_db = _volume_to_db(bus_volume)
AudioServer.set_bus_volume_db(bus_index, bus_db)
_apply_audio_config(config)
################
# KEY BINDINGS #
@ -126,6 +118,21 @@ func _apply_config(config: ConfigFile) -> void:
get_viewport().msaa = msaa
# Apply the audio options in the given config. We need to be able to do this
# separately to the rest of the options, as the volume sliders should affect
# the audio levels immediately.
# config: The options to apply.
func _apply_audio_config(config: ConfigFile) -> void:
for volume_key in config.get_section_keys("audio"):
var bus_name = volume_key.split("_")[0].capitalize()
var bus_index = AudioServer.get_bus_index(bus_name)
var bus_volume = config.get_value("audio", volume_key)
AudioServer.set_bus_mute(bus_index, bus_volume == 0)
if bus_volume > 0:
var bus_db = _volume_to_db(bus_volume)
AudioServer.set_bus_volume_db(bus_index, bus_db)
# Create a config file from the current options.
# Returns: A config file whose values are based on the current options.
func _create_config_from_current() -> ConfigFile:
@ -323,6 +330,12 @@ func _on_BindingBackground_unhandled_input(event: InputEvent):
func _on_CancelBindButton_pressed():
_binding_background.visible = false
func _on_MasterVolumeSlider_value_changed(_value: float):
_apply_audio_config(_create_config_from_current())
func _on_MusicVolumeSlider_value_changed(_value: float):
_apply_audio_config(_create_config_from_current())
func _on_OpenAssetsButton_pressed():
var asset_paths = AssetDB.get_asset_paths()
if asset_paths.empty():
@ -430,5 +443,8 @@ func _on_ResetBindingsConfirm_confirmed():
node.input_event = event
node.update_text()
func _on_SoundsVolumeSlider_value_changed(_value: float):
_apply_audio_config(_create_config_from_current())
func _on_ViewLicenseButton_pressed():
_license_dialog.popup_centered()