From dbe3441c1bcb6decb417e4b2db3efe12b21389b7 Mon Sep 17 00:00:00 2001 From: betalars Date: Sat, 28 Sep 2024 01:49:44 +0200 Subject: [PATCH] move audio settings into own panel --- src/logic-scenes/main menu/audio_settings.gd | 71 ++++++ .../main menu/audio_settings.tscn | 192 ++++++++++++++++ src/logic-scenes/startup/startup.tscn | 216 +++--------------- 3 files changed, 301 insertions(+), 178 deletions(-) create mode 100644 src/logic-scenes/main menu/audio_settings.gd create mode 100644 src/logic-scenes/main menu/audio_settings.tscn diff --git a/src/logic-scenes/main menu/audio_settings.gd b/src/logic-scenes/main menu/audio_settings.gd new file mode 100644 index 0000000..bf44a42 --- /dev/null +++ b/src/logic-scenes/main menu/audio_settings.gd @@ -0,0 +1,71 @@ +extends TabBar + +signal changed + +var has_stage:bool = false: + set(stage): + has_stage = stage + visible = has_stage + %MusicPreview.playing = has_stage + +var current_music_decay:float = 0 + +@onready var music_mute_switch: CheckBox = %MuteSoundtrack +@onready var sfx_mute_switch: CheckBox = %MuteSFX +@onready var music_slider: Range = %MusicSlider +@onready var sfx_slider: Range = %SoundSlider +@onready var speech_slider: Range = %SpeechSlider +@onready var sum_slider: Range = %SumSlider + +func _process(delta: float) -> void: + if current_music_decay > 0: + current_music_decay -= delta + if current_music_decay < 0: + %MusicMixer.play("blend_out") + + +var has_changed: bool = false: + set(value): + has_changed = value + +func _ready() -> void: + update_ui_from_state() + + music_mute_switch.pressed.connect(func(value): State.music_muted = value) + sfx_mute_switch.pressed.connect(func(value): State.music_muted = value) + + music_slider.value_changed.connect( + func(value): + State.music_volume = value + current_music_decay = 2 + %MusicMixer.play("blend_in") + ) + sfx_slider.value_changed.connect(func(value): State.sfx_volume = value) + speech_slider.value_changed.connect(func(value): State.speech_volume = value) + sum_slider.value_changed.connect(func(value): State.main_volume = value) + + changed.connect(func():has_changed = true) + + %ResetButton.pressed.connect(_on_reset_button_pressed) + %SaveButton.pressed.connect(_on_exit_button_pressed) + + +func _on_reset_button_pressed(): + music_mute_switch.button_pressed = false + sfx_mute_switch.button_pressed = false + music_slider.value = 1 + sfx_slider.value = 1 + speech_slider.value = 1 + sum_slider.value = 1 + +func update_ui_from_state(): + music_mute_switch.button_pressed = State.sfx_muted + sfx_mute_switch.button_pressed = State.music_muted + music_slider.value = State.music_volume + sfx_slider.value = State.sfx_volume + speech_slider.value = State.speech_volume + sum_slider.value = State.main_volume + +func _on_exit_button_pressed() -> void: + State.save_settings() + State.leave_stage(self) diff --git a/src/logic-scenes/main menu/audio_settings.tscn b/src/logic-scenes/main menu/audio_settings.tscn new file mode 100644 index 0000000..a97dc82 --- /dev/null +++ b/src/logic-scenes/main menu/audio_settings.tscn @@ -0,0 +1,192 @@ +[gd_scene load_steps=9 format=3 uid="uid://dfhkfocy8axb8"] + +[ext_resource type="Script" path="res://logic-scenes/main menu/audio_settings.gd" id="1_0lla1"] +[ext_resource type="AudioStream" uid="uid://cl74a68tjwinh" path="res://base-environments/youth_room/audio/Youth Loop.wav" id="2_01rsa"] + +[sub_resource type="Animation" id="Animation_lax27"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("../MusicSlider/MusicPreview:volume_db") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [-80.0] +} + +[sub_resource type="Animation" id="Animation_yggd5"] +resource_name = "blend_in" +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("../MusicSlider/MusicPreview:volume_db") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 0.9), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [-80.0, 0.0] +} + +[sub_resource type="Animation" id="Animation_jjj7g"] +resource_name = "blend_out" +length = 3.0 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("../MusicSlider/MusicPreview:volume_db") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 3), +"transitions": PackedFloat32Array(1, 1), +"update": 0, +"values": [0.0, -80.0] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_sfx55"] +_data = { +"RESET": SubResource("Animation_lax27"), +"blend_in": SubResource("Animation_yggd5"), +"blend_out": SubResource("Animation_jjj7g") +} + +[sub_resource type="InputEventAction" id="InputEventAction_gy6yb"] +action = &"ui_cancel" +pressed = true + +[sub_resource type="Shortcut" id="Shortcut_0peu0"] +events = [SubResource("InputEventAction_gy6yb")] + +[node name="Audio Settings" type="VBoxContainer"] +script = ExtResource("1_0lla1") +metadata/_tab_index = 1 + +[node name="Label" type="Label" parent="."] +layout_mode = 2 +theme_type_variation = &"HeaderLarge" +text = "Audio Settings" + +[node name="VBoxContainer" type="VBoxContainer" parent="."] +layout_mode = 2 + +[node name="MuteSoundtrack" type="CheckBox" parent="VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +tooltip_text = "All Game Music is safe to stream." +text = "mute Soundtrack" + +[node name="MuteSFX" type="CheckBox" parent="VBoxContainer"] +unique_name_in_owner = true +layout_mode = 2 +text = "mute Sound-Effects" + +[node name="AdjustmentLabel" type="Label" parent="VBoxContainer"] +layout_mode = 2 +text = "Volume Adjustment" + +[node name="GridContainer" type="GridContainer" parent="VBoxContainer"] +layout_mode = 2 +columns = 2 + +[node name="Label" type="Label" parent="VBoxContainer/GridContainer"] +layout_mode = 2 +text = "Music" + +[node name="MusicSlider" type="HSlider" parent="VBoxContainer/GridContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 4 +max_value = 1.0 +step = 0.05 +value = 0.5 +ticks_on_borders = true + +[node name="MusicPreview" type="AudioStreamPlayer" parent="VBoxContainer/GridContainer/MusicSlider"] +unique_name_in_owner = true +stream = ExtResource("2_01rsa") +volume_db = -80.0 +bus = &"music" + +[node name="MusicMixer" type="AnimationPlayer" parent="VBoxContainer/GridContainer/MusicSlider"] +unique_name_in_owner = true +root_node = NodePath("../../SumSlider") +libraries = { +"": SubResource("AnimationLibrary_sfx55") +} + +[node name="Label3" type="Label" parent="VBoxContainer/GridContainer"] +layout_mode = 2 +text = "Sounds" + +[node name="SoundSlider" type="HSlider" parent="VBoxContainer/GridContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 4 +max_value = 1.0 +step = 0.05 +value = 0.5 + +[node name="Label4" type="Label" parent="VBoxContainer/GridContainer"] +layout_mode = 2 +text = "Speech" + +[node name="SpeechSlider" type="HSlider" parent="VBoxContainer/GridContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 4 +max_value = 1.0 +step = 0.05 +value = 0.5 + +[node name="Label5" type="Label" parent="VBoxContainer/GridContainer"] +layout_mode = 2 +text = "Sum" + +[node name="SumSlider" type="HSlider" parent="VBoxContainer/GridContainer"] +unique_name_in_owner = true +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 4 +max_value = 1.0 +step = 0.05 +value = 0.5 + +[node name="Audio Sliders" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="Labels" type="VBoxContainer" parent="VBoxContainer/Audio Sliders"] +layout_mode = 2 + +[node name="Sliders" type="VBoxContainer" parent="VBoxContainer/Audio Sliders"] +layout_mode = 2 + +[node name="Sounds" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="Speech" type="HBoxContainer" parent="VBoxContainer"] +layout_mode = 2 + +[node name="confirm_buttons" type="HSplitContainer" parent="."] +layout_mode = 2 +size_flags_horizontal = 4 +size_flags_vertical = 10 + +[node name="ResetButton" type="Button" parent="confirm_buttons"] +unique_name_in_owner = true +layout_mode = 2 +text = "reset" + +[node name="SaveButton" type="Button" parent="confirm_buttons"] +unique_name_in_owner = true +layout_mode = 2 +shortcut = SubResource("Shortcut_0peu0") +text = "save and exit" diff --git a/src/logic-scenes/startup/startup.tscn b/src/logic-scenes/startup/startup.tscn index f9afb99..7057f66 100644 --- a/src/logic-scenes/startup/startup.tscn +++ b/src/logic-scenes/startup/startup.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=11 format=3 uid="uid://gldtxysavetf"] +[gd_scene load_steps=10 format=3 uid="uid://gldtxysavetf"] [ext_resource type="Texture2D" uid="uid://d0ucjqi8tx6vt" path="res://import/interface-elements/frame.png" id="1_8giso"] [ext_resource type="Theme" uid="uid://dla4kae5kbwdh" path="res://logic-scenes/themes/system.theme" id="1_ot7jp"] -[ext_resource type="Script" path="res://logic-scenes/startup/volume_sliders.gd" id="3_q2gbh"] [ext_resource type="Texture2D" uid="uid://bwicl5q0lw06q" path="res://import/interface-elements/bottom.png" id="3_s5ssh"] [ext_resource type="PackedScene" uid="uid://dy5rd437h5hsw" path="res://logic-scenes/board/card.tscn" id="5_7c77g"] @@ -81,29 +80,6 @@ func _on_subtitle_option_selected(index): # Volume Settings -func _on_mute_soundtrack_toggled(button_pressed): - AudioServer.set_bus_mute(AudioServer.get_bus_index(\"music\"),button_pressed) - - -func _on_mute_sfx_toggled(button_pressed): - AudioServer.set_bus_mute(AudioServer.get_bus_index(\"sfx\"),button_pressed) - - -func _on_music_volume_changed(value): - AudioServer.set_bus_volume_db(AudioServer.get_bus_index(\"music\"), linear_to_db(value/2)) - - -func _on_sfx_volume_changed(value): - AudioServer.set_bus_volume_db(AudioServer.get_bus_index(\"sfx\"), linear_to_db(value/2)) - - -func _on_text_volume_changed(value): - AudioServer.set_bus_volume_db(AudioServer.get_bus_index(\"text\"), linear_to_db(value)) - - -func _on_master_volume_changed(value): - AudioServer.set_bus_volume_db(AudioServer.get_bus_index(\"Master\"), linear_to_db(value)) - # Final Page @@ -138,53 +114,52 @@ var focus_list: Array @onready var simplified_controls = $\"physical Accessibility/Container2/simplified controls\" func _ready(): - for child in get_children(): - focus_list.append(_find_selectable_in(child)) + for child in get_children(): + focus_list.append(_find_selectable_in(child)) func _find_selectable_in(parent:Control): - if parent.focus_mode != FOCUS_NONE: - return parent - if parent.get_child_count() == 0: - return self - else: - for child in parent.get_children(): - var ret = _find_selectable_in(child) - if not ret == self: - return ret + if parent.focus_mode != FOCUS_NONE: + return parent + if parent.get_child_count() == 0: + return self + else: + for child in parent.get_children(): + var ret = _find_selectable_in(child) + if not ret == self: + return ret func _unhandled_input(event): - if event.is_action_type(): - if event.is_action_pressed(\"ui_left\"): previous() - elif event.is_action_pressed(\"ui_right\"): next() + if event.is_action_type(): + if event.is_action_pressed(\"ui_left\"): previous() + elif event.is_action_pressed(\"ui_right\"): next() func next(): - if current_tab < get_tab_count()-1: - if !Input.is_action_just_released(\"mouse_left\"): - if not get_viewport().gui_get_focus_owner() == null: - focus_list[current_tab] = get_viewport().gui_get_focus_owner() - current_tab += 1 - focus_list[current_tab].grab_focus() - else: - current_tab += 1 + if current_tab < get_tab_count()-1: + if !Input.is_action_just_released(\"mouse_left\"): + if not get_viewport().gui_get_focus_owner() == null: + focus_list[current_tab] = get_viewport().gui_get_focus_owner() + current_tab += 1 + focus_list[current_tab].grab_focus() + else: + current_tab += 1 func previous(): - if current_tab > 0: - if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT): - if not get_viewport().gui_get_focus_owner() == null: - focus_list[current_tab] = get_viewport().gui_get_focus_owner() - current_tab -= 1 - focus_list[current_tab].grab_focus() - else: - current_tab -= 1 + if current_tab > 0: + if !Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT): + if not get_viewport().gui_get_focus_owner() == null: + focus_list[current_tab] = get_viewport().gui_get_focus_owner() + current_tab -= 1 + focus_list[current_tab].grab_focus() + else: + current_tab -= 1 func _on_screenreader_toggled(button_pressed): - State.screen_reader = button_pressed # this is how you reach the global state - disable_rendering.disabled = not button_pressed # if screenreader was toggled - disabled = false - simplified_controls.button_pressed = button_pressed - State.simplified_navigation = button_pressed - - + State.screen_reader = button_pressed # this is how you reach the global state + disable_rendering.disabled = not button_pressed # if screenreader was toggled - disabled = false + simplified_controls.button_pressed = button_pressed + State.simplified_navigation = button_pressed + " [sub_resource type="GDScript" id="GDScript_v567h"] @@ -394,118 +369,11 @@ layout_mode = 2 disabled = true text = "go back" -[node name="Audio Settings" type="VBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer"] -visible = false -layout_mode = 2 -metadata/_tab_index = 1 - -[node name="Label" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings"] -layout_mode = 2 -theme_type_variation = &"HeaderLarge" -text = "Audio Settings" - -[node name="VBoxContainer" type="VBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings"] -layout_mode = 2 - -[node name="CheckBox" type="CheckBox" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer"] -layout_mode = 2 -text = "mute Soundtrack" - -[node name="CheckBox2" type="CheckBox" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer"] -layout_mode = 2 -text = "mute Sound-Effects" - -[node name="Label2" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer"] -layout_mode = 2 -text = "Volume Sliders" - -[node name="GridContainer" type="GridContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer"] -layout_mode = 2 -columns = 2 - -[node name="Label" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer"] -layout_mode = 2 -text = "Music" - -[node name="Music" type="HSlider" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 4 -max_value = 1.0 -step = 0.05 -value = 0.5 -ticks_on_borders = true -script = ExtResource("3_q2gbh") - -[node name="Label3" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer"] -layout_mode = 2 -text = "Sounds" - -[node name="Sounds" type="HSlider" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 4 -max_value = 1.0 -step = 0.05 -value = 0.5 - -[node name="Label4" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer"] -layout_mode = 2 -text = "Speech" - -[node name="Speech" type="HSlider" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 4 -max_value = 1.0 -step = 0.05 -value = 0.5 - -[node name="Label5" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer"] -layout_mode = 2 -text = "Sum" - -[node name="Sum" type="HSlider" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer"] -layout_mode = 2 -size_flags_horizontal = 3 -size_flags_vertical = 4 -max_value = 1.0 -step = 0.05 -value = 0.5 - -[node name="Audio Sliders" type="HBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer"] -layout_mode = 2 - -[node name="Labels" type="VBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/Audio Sliders"] -layout_mode = 2 - -[node name="Sliders" type="VBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/Audio Sliders"] -layout_mode = 2 - -[node name="Sounds" type="HBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer"] -layout_mode = 2 - -[node name="Speech" type="HBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer"] -layout_mode = 2 - -[node name="navbuttons" type="VSplitContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings"] -layout_mode = 2 -size_flags_horizontal = 4 -size_flags_vertical = 10 - -[node name="Next" type="Button" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/navbuttons"] -layout_mode = 2 -text = "okay" - -[node name="previous" type="Button" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/navbuttons"] -layout_mode = 2 -text = "go back" - [node name="Content Notes" type="VBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer"] visible = false custom_minimum_size = Vector2(512, 0) layout_mode = 2 -metadata/_tab_index = 2 +metadata/_tab_index = 1 [node name="Label" type="Label" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Content Notes"] layout_mode = 2 @@ -637,7 +505,7 @@ text = "go back" [node name="Managing Expectations" type="VBoxContainer" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer"] visible = false layout_mode = 2 -metadata/_tab_index = 3 +metadata/_tab_index = 2 [node name="VSeparator" type="VSeparator" parent="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Managing Expectations"] custom_minimum_size = Vector2(0, 50) @@ -720,14 +588,6 @@ text = "I never put in much effort for Homework" [connection signal="item_selected" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/physical Accessibility/Container2/GridContainer/ItemList2" to="." method="_on_subtitle_option_selected"] [connection signal="pressed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/physical Accessibility/navbuttons/Next" to="CenterContainer/PanelContainer/VBoxContainer/TabContainer" method="next"] [connection signal="pressed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/physical Accessibility/navbuttons/previous" to="CenterContainer/PanelContainer/VBoxContainer/TabContainer" method="previous"] -[connection signal="toggled" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/CheckBox" to="." method="_on_mute_soundtrack_toggled"] -[connection signal="toggled" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/CheckBox2" to="." method="_on_mute_sfx_toggled"] -[connection signal="value_changed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer/Music" to="." method="_on_music_volume_changed"] -[connection signal="value_changed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer/Sounds" to="." method="_on_sfx_volume_changed"] -[connection signal="value_changed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer/Speech" to="." method="_on_text_volume_changed"] -[connection signal="value_changed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/VBoxContainer/GridContainer/Sum" to="." method="_on_master_volume_changed"] -[connection signal="pressed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/navbuttons/Next" to="CenterContainer/PanelContainer/VBoxContainer/TabContainer" method="next"] -[connection signal="pressed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Audio Settings/navbuttons/previous" to="CenterContainer/PanelContainer/VBoxContainer/TabContainer" method="previous"] [connection signal="pressed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Content Notes/show content Notes" to="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Content Notes/ScrollContainer/Content Notes" method="show"] [connection signal="pressed" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Content Notes/show content Notes" to="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Content Notes/show content Notes" method="set_disabled" binds= [true]] [connection signal="toggled" from="CenterContainer/PanelContainer/VBoxContainer/TabContainer/Content Notes/ScrollContainer/Content Notes/VBoxContainer5/VBoxContainer/content_notes" to="." method="_on_content_notes_toggled"]