From 2cbb6d141451b7ebd197fdb48c455924647c4803 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sun, 25 Apr 2021 00:30:26 +0200 Subject: [PATCH] added even more fades --- scenes/ExitScene.gd | 4 ++++ scenes/ExitScene.tscn | 12 +++++++++++ scenes/MainMenu.gd | 2 +- scenes/PauseMenu.gd | 32 ++++++++++++++++++++++++---- scenes/PauseMenu.tscn | 49 ++++++++++++++++++++++++++++++------------- 5 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 scenes/ExitScene.gd create mode 100644 scenes/ExitScene.tscn diff --git a/scenes/ExitScene.gd b/scenes/ExitScene.gd new file mode 100644 index 0000000..9d4bc42 --- /dev/null +++ b/scenes/ExitScene.gd @@ -0,0 +1,4 @@ +extends ColorRect + +func _ready(): + get_tree().quit(0) diff --git a/scenes/ExitScene.tscn b/scenes/ExitScene.tscn new file mode 100644 index 0000000..9e22a7c --- /dev/null +++ b/scenes/ExitScene.tscn @@ -0,0 +1,12 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://scenes/ExitScene.gd" type="Script" id=1] + +[node name="ExitScene" type="ColorRect"] +anchor_right = 1.0 +anchor_bottom = 1.0 +color = Color( 0, 0, 0, 1 ) +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/scenes/MainMenu.gd b/scenes/MainMenu.gd index ebe26a9..c6da072 100644 --- a/scenes/MainMenu.gd +++ b/scenes/MainMenu.gd @@ -29,7 +29,7 @@ func _on_ContinueButton_pressed(): func _on_ExitButton_pressed(): - get_tree().quit(0) + Transit.change_scene("res://scenes/ExitScene.tscn", 0.2) func _on_CreditsButton_pressed(): diff --git a/scenes/PauseMenu.gd b/scenes/PauseMenu.gd index f939bbf..34c6186 100644 --- a/scenes/PauseMenu.gd +++ b/scenes/PauseMenu.gd @@ -1,21 +1,40 @@ extends Control +onready var panel := $MarginContainer/Panel +onready var background := $Background +onready var tween := $Tween + +var animation_speed = 0.4 + func load_main_menu(): Transit.change_scene("res://scenes/MainMenu.tscn", 0.5) func pause(): - get_tree().paused = true - show() + if not get_tree().paused: + get_tree().paused = true + show() + tween.stop_all() + tween.interpolate_property(background, "modulate", null, Color(1, 1, 1, 1), 2*animation_speed/3, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) + tween.interpolate_property(panel, "modulate", null, Color(1, 1, 1, 1), animation_speed, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) + tween.start() func unpause(): - get_tree().paused = false - hide() + if get_tree().paused: + get_tree().paused = false + tween.stop_all() + tween.interpolate_property(background, "modulate", null, Color(1, 1, 1, 0), animation_speed/2, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) + tween.interpolate_property(panel, "modulate", null, Color(1, 1, 1, 0), animation_speed/2, Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) + tween.start() func _ready(): + panel.modulate = Color(1, 1, 1, 0) + background.modulate = Color(1, 1, 1, 0) connect("gui_input", self, '_on_gui_input') + tween.connect("tween_all_completed", self, "_on_Tween_tween_all_completed") + func _input(event: InputEvent): if event.is_action_pressed("ui_cancel") and visible: @@ -37,3 +56,8 @@ func _on_ContinueButton_pressed(): func _on_MenuButton_pressed(): unpause() load_main_menu() + + +func _on_Tween_tween_all_completed(): + if panel.modulate == Color(1, 1, 1, 0): + hide() diff --git a/scenes/PauseMenu.tscn b/scenes/PauseMenu.tscn index 962b4ee..33e0cb0 100644 --- a/scenes/PauseMenu.tscn +++ b/scenes/PauseMenu.tscn @@ -1,10 +1,28 @@ -[gd_scene load_steps=6 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://scenes/PauseMenu.gd" type="Script" id=1] [ext_resource path="res://images/pause.png" type="Texture" id=2] [ext_resource path="res://scenes/typo/Button.tscn" type="PackedScene" id=3] [ext_resource path="res://fonts/open-sans/OpenSans-Light.ttf" type="DynamicFontData" id=4] +[sub_resource type="StyleBoxFlat" id=3] +content_margin_left = 0.0 +content_margin_right = 0.0 +content_margin_top = 0.0 +content_margin_bottom = 0.0 +bg_color = Color( 0.160784, 0.152941, 0.180392, 1 ) +border_width_left = 4 +border_width_top = 4 +border_width_right = 4 +border_width_bottom = 4 +corner_radius_top_left = 10 +corner_radius_top_right = 10 +corner_radius_bottom_right = 10 +corner_radius_bottom_left = 10 +shadow_color = Color( 0, 0, 0, 0.392157 ) +shadow_size = 40 +shadow_offset = Vector2( 10, 10 ) + [sub_resource type="DynamicFont" id=1] size = 50 font_data = ExtResource( 4 ) @@ -22,7 +40,7 @@ __meta__ = { [node name="Background" type="ColorRect" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 -color = Color( 0, 0, 0, 0.196078 ) +color = Color( 0, 0, 0, 0.27451 ) __meta__ = { "_edit_use_anchors_": false } @@ -30,6 +48,7 @@ __meta__ = { [node name="BackgroundButton" type="TextureButton" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 +mouse_default_cursor_shape = 2 expand = true __meta__ = { "_edit_use_anchors_": false @@ -47,14 +66,14 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="ColorRect" type="ColorRect" parent="MarginContainer"] +[node name="Panel" type="Panel" parent="MarginContainer"] margin_left = 400.0 margin_top = 100.0 margin_right = 1520.0 margin_bottom = 980.0 -color = Color( 0.164706, 0.180392, 0.196078, 1 ) +custom_styles/panel = SubResource( 3 ) -[node name="MarginContainer2" type="MarginContainer" parent="MarginContainer/ColorRect"] +[node name="MarginContainer2" type="MarginContainer" parent="MarginContainer/Panel"] anchor_right = 1.0 anchor_bottom = 1.0 custom_constants/margin_right = 50 @@ -65,7 +84,7 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/ColorRect/MarginContainer2"] +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/Panel/MarginContainer2"] margin_left = 50.0 margin_top = 50.0 margin_right = 1070.0 @@ -74,17 +93,17 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"] +[node name="CenterContainer" type="CenterContainer" parent="MarginContainer/Panel/MarginContainer2/VBoxContainer"] margin_right = 1020.0 margin_bottom = 64.0 -[node name="TextureRect" type="TextureRect" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/CenterContainer"] +[node name="TextureRect" type="TextureRect" parent="MarginContainer/Panel/MarginContainer2/VBoxContainer/CenterContainer"] margin_left = 478.0 margin_right = 542.0 margin_bottom = 64.0 texture = ExtResource( 2 ) -[node name="Text" type="Label" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"] +[node name="Text" type="Label" parent="MarginContainer/Panel/MarginContainer2/VBoxContainer"] margin_top = 68.0 margin_right = 1020.0 margin_bottom = 724.0 @@ -94,26 +113,28 @@ text = "Le jeu est en pause" align = 1 valign = 1 -[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer"] +[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/Panel/MarginContainer2/VBoxContainer"] margin_top = 728.0 margin_right = 1020.0 margin_bottom = 780.0 custom_constants/separation = 50 alignment = 1 -[node name="MenuButton" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer" instance=ExtResource( 3 )] +[node name="MenuButton" parent="MarginContainer/Panel/MarginContainer2/VBoxContainer/HBoxContainer" instance=ExtResource( 3 )] margin_left = 355.0 margin_top = 0.0 margin_right = 455.0 margin_bottom = 52.0 text = "Menu" -[node name="ContinueButton" parent="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer" instance=ExtResource( 3 )] +[node name="ContinueButton" parent="MarginContainer/Panel/MarginContainer2/VBoxContainer/HBoxContainer" instance=ExtResource( 3 )] margin_left = 505.0 margin_top = 0.0 margin_right = 664.0 margin_bottom = 52.0 text = "Continuer" + +[node name="Tween" type="Tween" parent="."] [connection signal="pressed" from="BackgroundButton" to="." method="_on_BackgroundButton_pressed"] -[connection signal="pressed" from="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer/MenuButton" to="." method="_on_MenuButton_pressed"] -[connection signal="pressed" from="MarginContainer/ColorRect/MarginContainer2/VBoxContainer/HBoxContainer/ContinueButton" to="." method="_on_ContinueButton_pressed"] +[connection signal="pressed" from="MarginContainer/Panel/MarginContainer2/VBoxContainer/HBoxContainer/MenuButton" to="." method="_on_MenuButton_pressed"] +[connection signal="pressed" from="MarginContainer/Panel/MarginContainer2/VBoxContainer/HBoxContainer/ContinueButton" to="." method="_on_ContinueButton_pressed"]