Compare commits

...

4 commits

12 changed files with 180 additions and 26 deletions

44
addons/transit/Transit.gd Normal file
View file

@ -0,0 +1,44 @@
extends Control
signal scene_changed
const DEFAULT_DURATION := 0.2
const DEFAULT_DELAY := 0.0
onready var _animator := $AnimationPlayer
onready var _curtain := $CanvasLayer/ColorRect
func set_color(color: Color):
color.a = _curtain.color.a
_curtain.color = color
func change_scene(path: String, duration: float = DEFAULT_DURATION, delay: float = DEFAULT_DELAY):
if duration <= 0.0:
push_error("TRANSIT ERROR: change_scene duration must be > 0. Defaulting to %s" % DEFAULT_DURATION)
duration = DEFAULT_DURATION
if delay < 0.0:
push_error("TRANSIT ERROR: change_scene delay must be >= 0. Defaulting to %s" % DEFAULT_DELAY)
delay = DEFAULT_DELAY
# disable mouse interaction while fading out
_curtain.mouse_filter = MOUSE_FILTER_STOP
if delay > 0:
yield(get_tree().create_timer(delay), "timeout")
_animator.playback_speed = 1.0 / duration
_animator.play("fade")
yield(_animator, "animation_finished")
var err := get_tree().change_scene(path)
if err:
push_error("TRANSIT ERROR: Failed to change scene to %s: %s" % [path, err])
# re-enable mouse interaction before fading back in
_curtain.mouse_filter = MOUSE_FILTER_IGNORE
_animator.play_backwards("fade")
yield(_animator, "animation_finished")
emit_signal("scene_changed")

View file

@ -0,0 +1,42 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://addons/transit/Transit.gd" type="Script" id=1]
[sub_resource type="Animation" id=1]
resource_name = "fade"
step = 0.2
tracks/0/type = "value"
tracks/0/path = NodePath("CanvasLayer/ColorRect:color:a")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 1 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 0,
"values": [ 0.0, 1.0 ]
}
[node name="Transit" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
anims/fade = SubResource( 1 )
[node name="CanvasLayer" type="CanvasLayer" parent="."]
layer = 128
[node name="ColorRect" type="ColorRect" parent="CanvasLayer"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
color = Color( 0, 0, 0, 0 )
__meta__ = {
"_edit_use_anchors_": false
}

View file

@ -58,7 +58,8 @@ config/icon="res://icon.png"
DialogicSingleton="*res://addons/dialogic/Other/DialogicSingleton.gd"
Signals="*res://mini-game/scripts/Signals.gd"
BackgroundMusic="*res://scenes/BackgroundMusic.tscn"
BackgroundMusic="*res://scenes/autoload/BackgroundMusic.tscn"
Transit="*res://addons/transit/Transit.tscn"
[display]

View file

@ -3,7 +3,7 @@ extends Control
func load_main_menu():
get_tree().change_scene("res://scenes/MainMenu.tscn")
Transit.change_scene("res://scenes/MainMenu.tscn", 0.2)
func _on_BackButton_pressed():

4
scenes/ExitScene.gd Normal file
View file

@ -0,0 +1,4 @@
extends ColorRect
func _ready():
get_tree().quit(0)

12
scenes/ExitScene.tscn Normal file
View file

@ -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
}

View file

@ -2,16 +2,20 @@ extends Control
var MAIN_MENU_MUSIC = "res://music/menu_principal.ogg"
onready var exit_button = $MarginContainer/VBoxContainer/HBoxContainer/CenterContainer/VBoxContainer/MarginContainer2/ExitButton
func _ready():
BackgroundMusic.crossfade_to(MAIN_MENU_MUSIC, -10, 1)
if OS.get_name() == "HTML5":
exit_button.hide()
func load_main_game():
get_tree().change_scene("res://scenes/Main.tscn")
Transit.change_scene("res://scenes/Main.tscn", 0.5)
func load_credits():
get_tree().change_scene("res://scenes/Credits.tscn")
Transit.change_scene("res://scenes/Credits.tscn", 0.2)
func _on_NewGameButton_pressed():
@ -19,12 +23,13 @@ func _on_NewGameButton_pressed():
load_main_game()
func _on_ContinueButton_pressed():
load_main_game()
func _on_ExitButton_pressed():
get_tree().quit(0)
Transit.change_scene("res://scenes/ExitScene.tscn", 0.2)
func _on_CreditsButton_pressed():

View file

@ -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():
get_tree().change_scene("res://scenes/MainMenu.tscn")
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()

View file

@ -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"]

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://scenes/BackgroundMusic.gd" type="Script" id=1]
[ext_resource path="res://scenes/autoload/BackgroundMusic.gd" type="Script" id=1]
[node name="BackgroundMusic" type="Control"]
pause_mode = 2

View file

@ -90,4 +90,4 @@ func _on_GaugesTimer_timeout():
func _on_ExitButton_pressed():
get_tree().change_scene("res://scenes/MainMenu.tscn")
Transit.change_scene("res://scenes/MainMenu.tscn", 0.5)