From cdb57f90e6090afb54145a297f2c82ba29e8b51b Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 4 Apr 2022 15:02:36 +0200 Subject: [PATCH] :wrench: Add functionality to the mute button --- src/levels/Game.tscn | 15 +++------------ src/levels/PhaseOneMusic.gd | 18 +++++++++++++++--- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/levels/Game.tscn b/src/levels/Game.tscn index 24c9f32..3582e15 100644 --- a/src/levels/Game.tscn +++ b/src/levels/Game.tscn @@ -109,16 +109,6 @@ align = 2 valign = 1 script = SubResource( 1 ) -[node name="HealthBar" type="ProgressBar" parent="UserInterface/TheDarkNightUI/Panel"] -visible = false -anchor_bottom = 1.0 -margin_left = 14.0 -margin_top = 14.0 -margin_right = 320.0 -margin_bottom = -14.0 -grow_vertical = 2 -value = 50.0 - [node name="TextureProgress" type="TextureProgress" parent="UserInterface/TheDarkNightUI/Panel"] margin_left = 15.0 margin_top = 15.0 @@ -129,7 +119,7 @@ texture_under = ExtResource( 10 ) texture_progress = ExtResource( 9 ) texture_progress_offset = Vector2( 10, 5 ) -[node name="Button" type="Button" parent="UserInterface/TheDarkNightUI/Panel"] +[node name="MuteButton" type="Button" parent="UserInterface/TheDarkNightUI/Panel"] anchor_left = 1.0 anchor_right = 1.0 anchor_bottom = 1.0 @@ -139,8 +129,9 @@ margin_right = -50.0 margin_bottom = -10.0 flat = true -[node name="Sprite" type="Sprite" parent="UserInterface/TheDarkNightUI/Panel/Button"] +[node name="Sprite" type="Sprite" parent="UserInterface/TheDarkNightUI/Panel/MuteButton"] position = Vector2( 25, 30 ) texture = ExtResource( 12 ) [connection signal="intensity_changed" from="PhaseOne/Entities/Fire" to="PhaseOne/Music" method="_on_Fire_intensity_changed"] +[connection signal="pressed" from="UserInterface/TheDarkNightUI/Panel/MuteButton" to="PhaseOne/Music" method="_on_MuteButton_pressed"] diff --git a/src/levels/PhaseOneMusic.gd b/src/levels/PhaseOneMusic.gd index 9a771ac..10d8f4d 100644 --- a/src/levels/PhaseOneMusic.gd +++ b/src/levels/PhaseOneMusic.gd @@ -7,14 +7,26 @@ export var bell_min: float = 0.20 export var bell_max: float = 0.60 export var drum_min: float = 0.40 export var drum_max: float = 0.80 +export var muted: bool = false setget set_mute func _on_Fire_intensity_changed(value): $Choir.volume_db = (smoothstep(choir_min, choir_max, value) - 1) * 60 - $Choir.bus = "Master" if $Choir.volume_db > -60 else "Mute" + $Choir.bus = "Master" if not muted and $Choir.volume_db > -60 else "Mute" $Bell.volume_db = (smoothstep(bell_min, bell_max, value) - 1) * 60 - $Bell.bus = "Master" if $Choir.volume_db > -60 else "Mute" + $Bell.bus = "Master" if not muted and $Bell.volume_db > -60 else "Mute" $Drum.volume_db = (smoothstep(drum_min, drum_max, value) - 1) * 60 - $Drum.bus = "Master" if $Choir.volume_db > -60 else "Mute" + $Drum.bus = "Master" if not muted and $Drum.volume_db > -60 else "Mute" + + +func set_mute(value): + muted = value + $Choir.bus = "Master" if not muted and $Choir.volume_db > -60 else "Mute" + $Bell.bus = "Master" if not muted and $Bell.volume_db > -60 else "Mute" + $Drum.bus = "Master" if not muted and $Drum.volume_db > -60 else "Mute" + + +func _on_MuteButton_pressed(): + set_mute(not muted)