-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from endlessm/push-nmstrnyslszw
Add Settings page with volume controls
- Loading branch information
Showing
16 changed files
with
217 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://d2ay7olsehadk"] | ||
|
||
[ext_resource type="Theme" uid="uid://dqt6eyc0l8kms" path="res://Theme/WorldSelector.tres" id="1_gll88"] | ||
[ext_resource type="Script" path="res://Script/WorldSelector/SettingsPage.gd" id="2_6mi7e"] | ||
|
||
[node name="SettingsPage" type="Control"] | ||
layout_mode = 3 | ||
anchors_preset = 15 | ||
anchor_right = 1.0 | ||
anchor_bottom = 1.0 | ||
grow_horizontal = 2 | ||
grow_vertical = 2 | ||
theme = ExtResource("1_gll88") | ||
script = ExtResource("2_6mi7e") | ||
|
||
[node name="VBoxContainer" type="VBoxContainer" parent="."] | ||
layout_mode = 2 | ||
offset_right = 140.0 | ||
offset_bottom = 144.0 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 3 | ||
|
||
[node name="Title" type="Label" parent="VBoxContainer"] | ||
layout_mode = 2 | ||
theme_type_variation = &"HeaderLarge" | ||
text = "Settings" | ||
horizontal_alignment = 1 | ||
|
||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 3 | ||
size_flags_vertical = 3 | ||
theme_override_constants/margin_left = 5 | ||
theme_override_constants/margin_right = 1 | ||
theme_override_constants/margin_bottom = 5 | ||
|
||
[node name="ExtraWorldsBox" type="VBoxContainer" parent="VBoxContainer/MarginContainer"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
size_flags_vertical = 2 | ||
|
||
[node name="MusicLabel" type="Label" parent="VBoxContainer/MarginContainer/ExtraWorldsBox"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 0 | ||
theme_type_variation = &"HeaderLarge" | ||
theme_override_font_sizes/font_size = 9 | ||
text = "music" | ||
horizontal_alignment = 1 | ||
|
||
[node name="MusicSlider" type="HSlider" parent="VBoxContainer/MarginContainer/ExtraWorldsBox"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
min_value = -30.0 | ||
max_value = 0.0 | ||
|
||
[node name="SfxLabel" type="Label" parent="VBoxContainer/MarginContainer/ExtraWorldsBox"] | ||
layout_mode = 2 | ||
size_flags_horizontal = 0 | ||
theme_type_variation = &"HeaderLarge" | ||
theme_override_font_sizes/font_size = 9 | ||
text = "sfx" | ||
horizontal_alignment = 1 | ||
|
||
[node name="SfxSlider" type="HSlider" parent="VBoxContainer/MarginContainer/ExtraWorldsBox"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
min_value = -30.0 | ||
max_value = 0.0 | ||
|
||
[node name="BackButton" type="Button" parent="VBoxContainer/MarginContainer/ExtraWorldsBox"] | ||
unique_name_in_owner = true | ||
layout_mode = 2 | ||
text = "Go Back" | ||
|
||
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] | ||
[connection signal="pressed" from="VBoxContainer/MarginContainer/ExtraWorldsBox/BackButton" to="." method="_on_back_button_pressed"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
extends Node | ||
|
||
const SETTINGS_PATH := "user://settings.cfg" | ||
|
||
const VOLUME_SECTION := "Volume" | ||
const MIN_VOLUME := -30.0 | ||
|
||
var _settings := ConfigFile.new() | ||
|
||
|
||
func _ready() -> void: | ||
var err := _settings.load(SETTINGS_PATH) | ||
if err != OK and err != ERR_FILE_NOT_FOUND: | ||
print("Failed to load %s: %s" % [SETTINGS_PATH, err]) | ||
|
||
_restore_volumes() | ||
|
||
|
||
func _restore_volumes() -> void: | ||
for bus_idx in AudioServer.bus_count: | ||
var bus := AudioServer.get_bus_name(bus_idx) | ||
var volume_db : float = _settings.get_value(VOLUME_SECTION, bus, 0.0) | ||
print("Restored", [bus_idx, bus, volume_db]) | ||
_set_volume(bus_idx, volume_db) | ||
|
||
|
||
func get_volume(bus: String) -> float: | ||
var bus_idx = AudioServer.get_bus_index(bus) | ||
|
||
return AudioServer.get_bus_volume_db(bus_idx) | ||
|
||
|
||
func set_volume(bus: String, volume_db: float) -> void: | ||
var bus_idx = AudioServer.get_bus_index(bus) | ||
_set_volume(bus_idx, volume_db) | ||
|
||
_settings.set_value(VOLUME_SECTION, bus, volume_db) | ||
_save() | ||
|
||
|
||
func _set_volume(bus_idx: int, volume_db: float) -> void: | ||
AudioServer.set_bus_volume_db(bus_idx, volume_db) | ||
var mute := volume_db <= MIN_VOLUME | ||
AudioServer.set_bus_mute(bus_idx, mute) | ||
|
||
|
||
func _save(): | ||
var err := _settings.save(SETTINGS_PATH) | ||
if err != OK: | ||
print("Failed to save settings to %s: %s" % [SETTINGS_PATH, err]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
extends Control | ||
|
||
signal back | ||
|
||
@onready var music_slider : HSlider = %MusicSlider | ||
@onready var sfx_slider : HSlider = %SfxSlider | ||
|
||
func _ready() -> void: | ||
_initialise_slider(music_slider, "Music") | ||
_initialise_slider(sfx_slider, "Sfx") | ||
|
||
|
||
func _initialise_slider(slider: Slider, bus: String): | ||
slider.value = Settings.get_volume(bus) | ||
slider.value_changed.connect(_on_slider_value_changed.bind(bus)) | ||
|
||
|
||
func _on_slider_value_changed(value: float, bus: String) -> void: | ||
Settings.set_volume(bus, value) | ||
|
||
|
||
func _on_visibility_changed() -> void: | ||
if self.visible and music_slider: | ||
music_slider.grab_focus() | ||
|
||
|
||
func _input(event: InputEvent) -> void: | ||
if self.visible and event.is_action_pressed("ui_cancel"): | ||
back.emit() | ||
|
||
|
||
func _on_back_button_pressed() -> void: | ||
back.emit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[gd_resource type="AudioBusLayout" format=3 uid="uid://dedcyh6mnrxw5"] | ||
|
||
[resource] | ||
bus/1/name = &"Sfx" | ||
bus/1/solo = false | ||
bus/1/mute = false | ||
bus/1/bypass_fx = false | ||
bus/1/volume_db = 0.0 | ||
bus/1/send = &"Master" | ||
bus/2/name = &"Music" | ||
bus/2/solo = false | ||
bus/2/mute = false | ||
bus/2/bypass_fx = false | ||
bus/2/volume_db = 0.0 | ||
bus/2/send = &"Master" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters