diff --git a/godot/gui/GameWon.tscn b/godot/gui/GameWon.tscn index 49889fc..f91c385 100644 --- a/godot/gui/GameWon.tscn +++ b/godot/gui/GameWon.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://assets/fonts/ttf/PixelOperator8.ttf" type="DynamicFontData" id=1] [ext_resource path="res://assets/fonts/ttf/PixelOperatorHB8.ttf" type="DynamicFontData" id=2] [ext_resource path="res://gui/GameWonScreen.gdns" type="Script" id=3] +[ext_resource path="res://assets/sounds/victory.wav" type="AudioStream" id=4] [sub_resource type="DynamicFont" id=1] size = 50 @@ -45,4 +46,9 @@ custom_fonts/font = SubResource( 2 ) custom_styles/hover = SubResource( 3 ) text = "SALIR" +[node name="VictorySound" type="AudioStreamPlayer" parent="."] +stream = ExtResource( 4 ) +volume_db = -18.0 + +[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"] [connection signal="pressed" from="Control/QuitButton" to="." method="_on_quit_button_pressed"] diff --git a/src/gui/game_won/GameWonScreen.cpp b/src/gui/game_won/GameWonScreen.cpp index f51822e..81ddc6d 100644 --- a/src/gui/game_won/GameWonScreen.cpp +++ b/src/gui/game_won/GameWonScreen.cpp @@ -2,6 +2,7 @@ #include "Event.h" +#include #include #include @@ -11,6 +12,7 @@ void alai::GameWonScreen::_register_methods() godot::register_method("connect_signal", &GameWonScreen::connect_signal); godot::register_method("_on_player_won", &GameWonScreen::_on_player_won); godot::register_method("_on_quit_button_pressed", &GameWonScreen::_on_quit_button_pressed); + godot::register_method("_on_visibility_changed", &GameWonScreen::_on_visibility_changed); } alai::GameWonScreen::GameWonScreen() @@ -64,3 +66,16 @@ void alai::GameWonScreen::connect_signal() auto event = get_node("/root/Event"); event->connect("player_won", this, "_on_player_won"); } + +void alai::GameWonScreen::_on_visibility_changed() +{ + auto victorysound = get_node("VictorySound"); + if (is_visible()) + { + victorysound->play(); + } + else + { + victorysound->stop(); + } +} diff --git a/src/gui/game_won/GameWonScreen.h b/src/gui/game_won/GameWonScreen.h index 987b7a1..683e554 100644 --- a/src/gui/game_won/GameWonScreen.h +++ b/src/gui/game_won/GameWonScreen.h @@ -45,6 +45,7 @@ namespace alai void _on_player_won(); void _on_quit_button_pressed(); void connect_signal(); + void _on_visibility_changed(); }; }