Skip to content

Commit 7b4ba01

Browse files
committed
Add volume slider configuration
1 parent 470b47f commit 7b4ba01

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ config_version=5
1212

1313
config/name="RetroHub"
1414
run/main_scene="res://scenes/root/Root.tscn"
15-
config/features=PackedStringArray("4.2")
15+
config/features=PackedStringArray("4.2", "RetroHub")
1616
boot_splash/bg_color=Color(0.188235, 0.235294, 0.290196, 1)
1717
boot_splash/image="res://assets/icons/app/splash.png"
1818
config/icon="res://icon.png"

scenes/config/settings/GeneralSettings.gd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ extends Control
77
@onready var n_language := %Language
88
@onready var n_first_time_wizard_warning := %FirstTimeWizardWarning
99

10+
@onready var n_ui_volume_label := %UIVolumeLabel
11+
@onready var n_ui_volume := %UIVolume
12+
1013
@onready var n_graphics_mode := %GraphicsMode
1114
@onready var n_vsync := %VSync
1215
@onready var n_render_res_label := %RenderResLabel
@@ -72,6 +75,7 @@ func _on_config_ready(config_data: ConfigData):
7275
n_graphics_mode.selected = 1 if config_data.fullscreen else 0
7376
n_vsync.set_pressed_no_signal(config_data.vsync)
7477
n_render_res.value = config_data.render_resolution
78+
n_ui_volume.value = config_data.ui_volume
7579
set_language(config_data.lang)
7680
n_screen_reader.set_pressed_no_signal(config_data.accessibility_screen_reader_enabled)
7781

@@ -144,3 +148,9 @@ func _on_RenderRes_value_changed(value):
144148
func _on_ScreenReader_toggled(button_pressed):
145149
RetroHubConfig.config.accessibility_screen_reader_enabled = button_pressed
146150
RetroHubConfig._save_config()
151+
152+
153+
func _on_ui_volume_value_changed(value):
154+
RetroHubConfig.config.ui_volume = value
155+
n_ui_volume_label.text = str(value) + "%"
156+
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Master"), linear_to_db(value / 100.0))

scenes/config/settings/GeneralSettings.tscn

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,47 @@ layout_mode = 2
125125
size_flags_horizontal = 8
126126
text = "Re-run first time wizard"
127127

128+
[node name="Sound" type="VBoxContainer" parent="ScrollContainer/VBoxContainer"]
129+
layout_mode = 2
130+
131+
[node name="Label" type="Label" parent="ScrollContainer/VBoxContainer/Sound"]
132+
layout_mode = 2
133+
theme_override_fonts/font = ExtResource("2")
134+
text = "Sound"
135+
136+
[node name="AccessibilityFocus" type="Node" parent="ScrollContainer/VBoxContainer/Sound/Label"]
137+
script = ExtResource("5")
138+
139+
[node name="HSeparator" type="HSeparator" parent="ScrollContainer/VBoxContainer/Sound"]
140+
layout_mode = 2
141+
142+
[node name="HBoxContainer" type="HBoxContainer" parent="ScrollContainer/VBoxContainer/Sound"]
143+
layout_mode = 2
144+
size_flags_horizontal = 3
145+
theme_override_constants/separation = 15
146+
147+
[node name="Label" type="Label" parent="ScrollContainer/VBoxContainer/Sound/HBoxContainer"]
148+
layout_mode = 2
149+
size_flags_horizontal = 3
150+
text = "UI volume:"
151+
152+
[node name="AccessibilityFocus" type="Node" parent="ScrollContainer/VBoxContainer/Sound/HBoxContainer/Label"]
153+
script = ExtResource("5")
154+
155+
[node name="UIVolumeLabel" type="Label" parent="ScrollContainer/VBoxContainer/Sound/HBoxContainer"]
156+
unique_name_in_owner = true
157+
layout_mode = 2
158+
text = "100%"
159+
160+
[node name="UIVolume" type="HSlider" parent="ScrollContainer/VBoxContainer/Sound/HBoxContainer"]
161+
unique_name_in_owner = true
162+
custom_minimum_size = Vector2(200, 0)
163+
layout_mode = 2
164+
step = 5.0
165+
value = 1.0
166+
tick_count = 11
167+
ticks_on_borders = true
168+
128169
[node name="Graphics" type="VBoxContainer" parent="ScrollContainer/VBoxContainer"]
129170
layout_mode = 2
130171

@@ -279,6 +320,7 @@ vertical_alignment = 1
279320
[connection signal="pressed" from="ScrollContainer/VBoxContainer/User/HBoxContainer2/SetThemePath" to="." method="_on_SetThemePath_pressed"]
280321
[connection signal="item_selected" from="ScrollContainer/VBoxContainer/User/HBoxContainer3/Language" to="." method="_on_Language_item_selected"]
281322
[connection signal="pressed" from="ScrollContainer/VBoxContainer/User/SetupWizardButton" to="." method="_on_SetupWizardButton_pressed"]
323+
[connection signal="value_changed" from="ScrollContainer/VBoxContainer/Sound/HBoxContainer/UIVolume" to="." method="_on_ui_volume_value_changed"]
282324
[connection signal="item_selected" from="ScrollContainer/VBoxContainer/Graphics/HBoxContainer/GraphicsMode" to="." method="_on_GraphicsMode_item_selected"]
283325
[connection signal="toggled" from="ScrollContainer/VBoxContainer/Graphics/HBoxContainer2/VSync" to="." method="_on_VSync_toggled"]
284326
[connection signal="value_changed" from="ScrollContainer/VBoxContainer/Graphics/HBoxContainer3/RenderRes" to="." method="_on_RenderRes_value_changed"]

source/data/ConfigData.gd

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var virtual_keyboard_show_on_controller : bool = true: set = _set_virtual_keyboa
3636
var virtual_keyboard_show_on_mouse : bool = false: set = _set_virtual_keyboard_show_on_mouse
3737
var accessibility_screen_reader_enabled : bool = true: set = _set_accessibility_screen_reader_enabled
3838
var custom_gamemedia_dir : String = "": set = _set_custom_gamemedia_dir
39+
var ui_volume : int = 100: set = _set_ui_volume
3940

4041
const KEY_CONFIG_VERSION = "config_version"
4142
const KEY_IS_FIRST_TIME = "is_first_time"
@@ -66,6 +67,7 @@ const KEY_VIRTUAL_KEYBOARD_SHOW_ON_CONTROLLER = "virtual_keyboard_show_on_contro
6667
const KEY_VIRTUAL_KEYBOARD_SHOW_ON_MOUSE = "virtual_keyboard_show_on_mouse"
6768
const KEY_ACCESSIBILITY_SCREEN_READER_ENABLED = "accessibility_screen_reader_enabled"
6869
const KEY_CUSTOM_GAMEMEDIA_DIR = "custom_gamemedia_dir"
70+
const KEY_UI_VOLUME = "ui_volume"
6971

7072

7173
const _keys = [
@@ -97,7 +99,8 @@ const _keys = [
9799
KEY_VIRTUAL_KEYBOARD_SHOW_ON_CONTROLLER,
98100
KEY_VIRTUAL_KEYBOARD_SHOW_ON_MOUSE,
99101
KEY_ACCESSIBILITY_SCREEN_READER_ENABLED,
100-
KEY_CUSTOM_GAMEMEDIA_DIR
102+
KEY_CUSTOM_GAMEMEDIA_DIR,
103+
KEY_UI_VOLUME
101104
]
102105

103106
var _should_save : bool = true
@@ -303,6 +306,10 @@ func _set_custom_gamemedia_dir(_custom_gamemedia_dir):
303306
mark_for_saving()
304307
custom_gamemedia_dir = _custom_gamemedia_dir
305308

309+
func _set_ui_volume(_ui_volume):
310+
mark_for_saving()
311+
ui_volume = _ui_volume
312+
306313
func mark_for_saving():
307314
if _should_save:
308315
_config_changed = true

0 commit comments

Comments
 (0)