Skip to content

Commit

Permalink
~65 pause menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cho committed Jun 15, 2024
1 parent d3b8d74 commit fd1b2ef
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 13 deletions.
6 changes: 6 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ left_click={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(827, 18),"global_position":Vector2(835, 98),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
pause={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":80,"key_label":0,"unicode":112,"echo":false,"script":null)
]
}

[layer_names]

Expand Down
9 changes: 9 additions & 0 deletions scenes/main/main.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ extends Node

@export var end_screen_scene: PackedScene

var paused_menu_scene = preload("res://scenes/ui/pause_menu.tscn")


func _ready():
%Player.health_component.died.connect(on_player_died)



func _unhandled_input(event):
if event.is_action_pressed("pause"):
add_child(paused_menu_scene.instantiate())
get_tree().root.set_input_as_handled()


func on_player_died():
var end_screen_instance = end_screen_scene.instantiate() as EndScreen
add_child(end_screen_instance)
Expand Down
3 changes: 2 additions & 1 deletion scenes/ui/options_menu.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
[ext_resource type="PackedScene" uid="uid://dumjej53vmw4d" path="res://scenes/ui/sound_button.tscn" id="3_n6dag"]

[node name="OptionsMenu" type="CanvasLayer"]
layer = 2
script = ExtResource("1_hm70i")

[node name="TileMap" type="TileMap" parent="."]
Expand Down Expand Up @@ -101,4 +102,4 @@ size_flags_horizontal = 8
text = "Back"

[node name="Vignette" parent="." instance=ExtResource("2_utlq5")]
layer = 2
layer = 3
66 changes: 66 additions & 0 deletions scenes/ui/pause_menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
extends CanvasLayer
class_name PauseMenu

@onready var panel_container = %PanelContainer

var options_scene = preload("res://scenes/ui/options_menu.tscn")
var is_closing := false


func _ready():
get_tree().paused = true
panel_container.pivot_offset = panel_container.size / 2

%ResumeButton.pressed.connect(on_resume_pressed)
%OptionsButton.pressed.connect(on_options_pressed)
%QuitButton.pressed.connect(on_quit_pressed)

$AnimationPlayer.play("default")

var tween = create_tween()
tween.tween_property(panel_container, "scale", Vector2.ZERO, 0)
tween.tween_property(panel_container, "scale", Vector2.ONE, 0.3) \
.set_ease(Tween.EASE_OUT) \
.set_trans(Tween.TRANS_BACK)


func _unhandled_input(event):
if event.is_action_pressed("pause"):
close()
get_tree().root.set_input_as_handled()


func close():
if is_closing:
return
is_closing = true

$AnimationPlayer.play_backwards("default")
var tween = create_tween()
tween.tween_property(panel_container, "scale", Vector2.ONE, 0)
tween.tween_property(panel_container, "scale", Vector2.ZERO, 0.3) \
.set_ease(Tween.EASE_IN) \
.set_trans(Tween.TRANS_BACK)
await tween.finished

get_tree().paused = false
queue_free()


func on_resume_pressed():
close()


func on_options_pressed():
var options_instance = options_scene.instantiate() as OptionsMenu
add_child(options_instance)
options_instance.back_pressed.connect(on_options_closed.bind(options_instance))


func on_options_closed(options_instance: OptionsMenu):
options_instance.queue_free()


func on_quit_pressed():
get_tree().paused = false
get_tree().change_scene_to_file("res://scenes/ui/main_menu.tscn")
130 changes: 130 additions & 0 deletions scenes/ui/pause_menu.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
[gd_scene load_steps=7 format=3 uid="uid://cqicho1cntsmr"]

[ext_resource type="Script" path="res://scenes/ui/pause_menu.gd" id="1_eis7e"]
[ext_resource type="PackedScene" uid="uid://dumjej53vmw4d" path="res://scenes/ui/sound_button.tscn" id="3_wj4n0"]

[sub_resource type="Animation" id="Animation_tcekb"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("ColorRect:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}

[sub_resource type="Animation" id="Animation_pcewe"]
resource_name = "out"
length = 0.15
step = 0.05
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("ColorRect:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.15),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
}

[sub_resource type="Animation" id="Animation_oqfrt"]
resource_name = "default"
length = 0.15
step = 0.05
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("ColorRect:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.15),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
}

[sub_resource type="AnimationLibrary" id="AnimationLibrary_4gbqw"]
_data = {
"RESET": SubResource("Animation_tcekb"),
"default": SubResource("Animation_oqfrt"),
"out": SubResource("Animation_pcewe")
}

[node name="PauseMenu" type="CanvasLayer"]
process_mode = 3
script = ExtResource("1_eis7e")

[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
libraries = {
"": SubResource("AnimationLibrary_4gbqw")
}

[node name="ColorRect" type="ColorRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.607843, 0.298039, 0.639216, 0.352941)

[node name="MarginContainer" type="MarginContainer" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="PanelContainer" type="PanelContainer" parent="MarginContainer"]
unique_name_in_owner = true
custom_minimum_size = Vector2(180, 140)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4

[node name="MarginContainer" type="MarginContainer" parent="MarginContainer/PanelContainer"]
layout_mode = 2
theme_override_constants/margin_left = 8
theme_override_constants/margin_right = 8
theme_override_constants/margin_bottom = 8

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer"]
custom_minimum_size = Vector2(150, 2.08165e-12)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 4

[node name="Label" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
layout_mode = 2
theme_type_variation = &"BlueOutlineLabel"
theme_override_font_sizes/font_size = 32
text = "PAUSED"
horizontal_alignment = 1

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
custom_minimum_size = Vector2(100, 2.08165e-12)
layout_mode = 2
size_flags_horizontal = 4

[node name="ResumeButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer" instance=ExtResource("3_wj4n0")]
unique_name_in_owner = true
layout_mode = 2
text = "Resume"

[node name="OptionsButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer" instance=ExtResource("3_wj4n0")]
unique_name_in_owner = true
layout_mode = 2
text = "Options"

[node name="QuitButton" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer/VBoxContainer" instance=ExtResource("3_wj4n0")]
unique_name_in_owner = true
layout_mode = 2
text = "Quit to Menu"
24 changes: 12 additions & 12 deletions scenes/ui/upgrade_screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@
[ext_resource type="PackedScene" uid="uid://n7p1t353jjgd" path="res://scenes/ui/ability_upgrade_card.tscn" id="1_1o8ra"]
[ext_resource type="Script" path="res://scenes/ui/upgrade_screen.gd" id="1_oekd0"]

[sub_resource type="Animation" id="Animation_ynt2q"]
resource_name = "in"
length = 0.15
step = 0.05
[sub_resource type="Animation" id="Animation_adju6"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("ColorRect:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.15),
"transitions": PackedFloat32Array(1, 1),
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
"values": [Color(1, 1, 1, 1)]
}

[sub_resource type="Animation" id="Animation_adju6"]
length = 0.001
[sub_resource type="Animation" id="Animation_ynt2q"]
resource_name = "in"
length = 0.15
step = 0.05
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("ColorRect:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"times": PackedFloat32Array(0, 0.15),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1)]
}

[sub_resource type="Animation" id="Animation_c5l1u"]
Expand Down

0 comments on commit fd1b2ef

Please sign in to comment.