From e8895f81371c9ff3c98e00c5e82ffa46fd2748bd Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Thu, 11 Feb 2021 10:46:08 +0100 Subject: [PATCH] toggle music button to scene --- scenes/game.gd | 7 +++++++ scenes/level_select.gd | 7 +------ scenes/level_select.tscn | 16 +++------------- scenes/music_button.gd | 9 +++++++++ scenes/music_button.tscn | 17 +++++++++++++++++ 5 files changed, 37 insertions(+), 19 deletions(-) create mode 100644 scenes/music_button.gd create mode 100644 scenes/music_button.tscn diff --git a/scenes/game.gd b/scenes/game.gd index 2cb162f..c53f9ca 100644 --- a/scenes/game.gd +++ b/scenes/game.gd @@ -86,3 +86,10 @@ func notify(text, target=null, hint_slug=null): func open_survey(): OS.shell_open("https://docs.google.com/forms/d/e/1FAIpQLSehHVcYfELT59h6plcn2ilbuqBcmDX3TH0qzB4jCgFIFOy_qg/viewform") + +func toggle_music(): + var music = game.find_node("Music") + if music.volume_db > -20: + music.volume_db -= 100 + else: + music.volume_db += 100 diff --git a/scenes/level_select.gd b/scenes/level_select.gd index 9561796..acd0866 100644 --- a/scenes/level_select.gd +++ b/scenes/level_select.gd @@ -65,10 +65,5 @@ func reload(): -func toggle_music(): - var music = game.find_node("Music") - if music.volume_db > -20: - music.volume_db -= 100 - else: - music.volume_db += 100 + diff --git a/scenes/level_select.tscn b/scenes/level_select.tscn index c3b25ab..2f8e4f3 100644 --- a/scenes/level_select.tscn +++ b/scenes/level_select.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://styles/theme.tres" type="Theme" id=1] [ext_resource path="res://scenes/level_select.gd" type="Script" id=2] [ext_resource path="res://styles/alert_button.tres" type="StyleBox" id=3] +[ext_resource path="res://scenes/music_button.tscn" type="PackedScene" id=4] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.54902, 0.0392157, 0.0392157, 1 ) @@ -63,17 +64,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Button3" type="Button" parent="."] -margin_left = 241.005 -margin_top = 58.856 -margin_right = 387.005 -margin_bottom = 97.856 -focus_mode = 0 -enabled_focus_mode = 0 -text = "Toggle music" -__meta__ = { -"_edit_use_anchors_": false -} +[node name="Button3" parent="." instance=ExtResource( 4 )] [node name="HelpLabel" type="Label" parent="."] visible = false @@ -101,5 +92,4 @@ __meta__ = { } [connection signal="pressed" from="Button" to="." method="back"] [connection signal="pressed" from="Button2" to="." method="reload"] -[connection signal="pressed" from="Button3" to="." method="toggle_music"] [connection signal="pressed" from="HelpLabel/Button3" to="." method="onSurveyPressed"] diff --git a/scenes/music_button.gd b/scenes/music_button.gd new file mode 100644 index 0000000..6cc4e03 --- /dev/null +++ b/scenes/music_button.gd @@ -0,0 +1,9 @@ +extends Button + + +func _ready(): + pass + + +func toggle_music(): + game.toggle_music() diff --git a/scenes/music_button.tscn b/scenes/music_button.tscn new file mode 100644 index 0000000..70f47b0 --- /dev/null +++ b/scenes/music_button.tscn @@ -0,0 +1,17 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://scenes/music_button.gd" type="Script" id=1] + +[node name="Button3" type="Button"] +margin_left = 241.005 +margin_top = 58.856 +margin_right = 387.005 +margin_bottom = 97.856 +focus_mode = 0 +enabled_focus_mode = 0 +text = "Toggle music" +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} +[connection signal="pressed" from="." to="." method="toggle_music"]