1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-14 21:15:58 +00:00

Added master slider to change all volume

This commit is contained in:
hpham474 2021-11-07 22:43:00 -06:00
parent 737b460991
commit 7bae715ba5
3 changed files with 69 additions and 21 deletions

View File

@ -42,22 +42,23 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="SFX Setting" type="Node2D" parent="Sliders"]
[node name="Master Volume Setting" type="Node2D" parent="Sliders"]
position = Vector2( 0, 8 )
[node name="SFX Label" type="Label" parent="Sliders/SFX Setting"]
[node name="Master Label" type="Label" parent="Sliders/Master Volume Setting"]
margin_left = -0.140289
margin_top = -8.0
margin_right = 64.0
margin_right = 63.8597
margin_bottom = 8.0
custom_colors/font_color = Color( 0, 0, 0, 1 )
text = "SFX:"
text = "Volume:"
align = 2
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SFX Slider" type="HSlider" parent="Sliders/SFX Setting"]
[node name="Master Slider" type="HSlider" parent="Sliders/Master Volume Setting"]
margin_left = 64.0
margin_top = -8.0
margin_right = 208.0
@ -69,27 +70,28 @@ focus_next = NodePath("../../Volume Setting/Volume Slider")
focus_previous = NodePath("../../../Back")
min_value = -25.0
max_value = 0.0
tick_count = 11
tick_count = 10
ticks_on_borders = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Volume Setting" type="Node2D" parent="Sliders"]
[node name="Music Volume Setting" type="Node2D" parent="Sliders"]
position = Vector2( 0, 33 )
[node name="Volume Label" type="Label" parent="Sliders/Volume Setting"]
[node name="Music Label" type="Label" parent="Sliders/Music Volume Setting"]
margin_top = -8.0
margin_right = 64.0
margin_bottom = 8.0
custom_colors/font_color = Color( 0, 0, 0, 1 )
text = "Volume:"
text = "Music:"
align = 2
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Volume Slider" type="HSlider" parent="Sliders/Volume Setting"]
[node name="Music Slider" type="HSlider" parent="Sliders/Music Volume Setting"]
margin_left = 64.0
margin_top = -8.0
margin_right = 208.0
@ -100,7 +102,34 @@ focus_next = NodePath("../../../Buttons/Dark")
focus_previous = NodePath("../../SFX Setting/SFX Slider")
min_value = -50.0
max_value = 0.0
tick_count = 11
tick_count = 10
ticks_on_borders = true
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SFX Volume Setting" type="Node2D" parent="Sliders"]
[node name="SFX Label" type="Label" parent="Sliders/SFX Volume Setting"]
margin_top = 48.0
margin_right = 64.0
margin_bottom = 64.0
custom_colors/font_color = Color( 0, 0, 0, 1 )
text = "SFX:"
align = 2
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SFX Slider" type="HSlider" parent="Sliders/SFX Volume Setting"]
margin_left = 64.0
margin_top = 48.0
margin_right = 208.0
margin_bottom = 64.0
min_value = -50.0
max_value = 0.0
tick_count = 10
ticks_on_borders = true
__meta__ = {
"_edit_use_anchors_": false
@ -108,9 +137,9 @@ __meta__ = {
[node name="Buttons" type="HBoxContainer" parent="."]
margin_left = 216.0
margin_top = 190.0
margin_top = 200.0
margin_right = 424.0
margin_bottom = 214.0
margin_bottom = 224.0
__meta__ = {
"_edit_lock_": true,
"_edit_use_anchors_": false
@ -155,8 +184,9 @@ __meta__ = {
"_edit_use_anchors_": false
}
[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="value_changed" from="Sliders/Master Volume Setting/Master Slider" to="." method="_on_Master_Slider_value_changed"]
[connection signal="value_changed" from="Sliders/Music Volume Setting/Music Slider" to="." method="_on_Music_Slider_value_changed"]
[connection signal="value_changed" from="Sliders/SFX Volume Setting/SFX Slider" to="." method="_on_SFX_Slider_value_changed"]
[connection signal="pressed" from="Buttons/Light" to="." method="_on_Light_pressed"]
[connection signal="pressed" from="Buttons/Dark" to="." method="_on_Dark_pressed"]
[connection signal="pressed" from="Back" to="." method="_on_Button_pressed"]

View File

@ -1,7 +1,8 @@
extends Control
onready var master_slider = find_node("Master Slider", true, true)
onready var music_slider = find_node("Music Slider", true, true)
onready var sound_slider = find_node("SFX Slider", true, true)
onready var music_slider = find_node("Volume Slider", true, true)
onready var theme_buttons = find_node("Buttons", true, true).get_children()
@ -9,23 +10,30 @@ onready var theme_buttons = find_node("Buttons", true, true).get_children()
func _ready():
OptionsController.load_options()
find_next_valid_focus().grab_focus()
sound_slider.value = OptionsController.get_sfx_volume()
master_slider.value = OptionsController.get_mas_volume()
music_slider.value = OptionsController.get_mus_volume()
sound_slider.value = OptionsController.get_sfx_volume()
func _on_Button_pressed():
AudioBus.emit_signal("button_clicked")
queue_free()
#MessageBus.emit_signal("change_scene", "Title")
func _on_Master_Slider_value_changed(value):
AudioBus.emit_signal("button_clicked")
OptionsController.set_mas_vol(value)
OptionsController.save_options()
func _on_Music_Slider_value_changed(value):
AudioBus.emit_signal("button_clicked")
OptionsController.set_mus_vol(value)
OptionsController.save_options()
func _on_SFX_Slider_value_changed(value):
AudioBus.emit_signal("button_clicked")
OptionsController.set_sfx_vol(value)
OptionsController.save_options()
func _on_Volume_Slider_value_changed(value):
OptionsController.set_mus_vol(value)
OptionsController.save_options()
func _on_Light_pressed():
AudioBus.emit_signal("button_clicked")
OptionsController.set_theme("light")

View File

@ -8,6 +8,7 @@ signal change_theme (theme)
var f = File.new()
var options_file = "user://options.save"
var theme = "dark"
var mas_vol = 0
var mus_vol = 0
var sfx_vol = 0
@ -19,7 +20,11 @@ func set_theme(theme_name):
match theme_name:
"dark","light":
theme = String(theme_name)
save_options()
emit_signal("change_theme", theme)
func set_mas_vol(volume):
mas_vol = volume
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mas_vol)
func set_mus_vol(volume):
mus_vol = volume
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("BGM"), mus_vol)
@ -31,6 +36,7 @@ func set_sfx_vol(volume):
func save_options():
f.open(options_file, File.WRITE)
f.store_var(theme)
f.store_var(mas_vol)
f.store_var(mus_vol)
f.store_var(sfx_vol)
f.close()
@ -38,15 +44,19 @@ func load_options():
if f.file_exists(options_file):
f.open(options_file, File.READ)
theme = f.get_var()
mas_vol = f.get_var()
mus_vol = f.get_var()
sfx_vol = f.get_var()
f.close()
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), mus_vol)
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():
return theme
func get_mas_volume():
return mas_vol
func get_mus_volume():
return mus_vol
func get_sfx_volume():