Pause Menu

This commit is contained in:
AXVIII3 2023-04-15 17:00:52 +05:30
parent 91920d15b1
commit c4f75e56e9
7 changed files with 518 additions and 4 deletions

View file

@ -41,7 +41,7 @@
[ext_resource type="StyleBox" uid="uid://0jfr1uwuog0s" path="res://Assets/UI/Slider/v/background.tres" id="39_dl1e4"] [ext_resource type="StyleBox" uid="uid://0jfr1uwuog0s" path="res://Assets/UI/Slider/v/background.tres" id="39_dl1e4"]
[ext_resource type="FontFile" uid="uid://dqdeftjkwxe64" path="res://Assets/Fonts/Dogica/dogicapixel.ttf" id="40_bmcvq"] [ext_resource type="FontFile" uid="uid://dqdeftjkwxe64" path="res://Assets/Fonts/Dogica/dogicapixel.ttf" id="40_bmcvq"]
[sub_resource type="Image" id="Image_6lyhf"] [sub_resource type="Image" id="Image_1msbu"]
data = { data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0), "data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0),
"format": "RGBA8", "format": "RGBA8",
@ -51,7 +51,7 @@ data = {
} }
[sub_resource type="ImageTexture" id="ImageTexture_g5bup"] [sub_resource type="ImageTexture" id="ImageTexture_g5bup"]
image = SubResource("Image_6lyhf") image = SubResource("Image_1msbu")
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_sj7h5"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_sj7h5"]

75
Prefabs/pause_menu.tscn Normal file
View file

@ -0,0 +1,75 @@
[gd_scene load_steps=4 format=3 uid="uid://dtiav1qdm1p34"]
[ext_resource type="Script" path="res://Scripts/UI/PauseMenu.gd" id="1_cbyrt"]
[ext_resource type="PackedScene" uid="uid://btxarutbkchmb" path="res://Prefabs/Settings Menu.tscn" id="3_2e10l"]
[ext_resource type="Theme" uid="uid://b0b3fxesfrpb7" path="res://Assets/UI/Theme.tres" id="3_vxkyu"]
[node name="PauseMenu" type="Control" node_paths=PackedStringArray("default_focus")]
process_mode = 3
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_cbyrt")
settings_scene = ExtResource("3_2e10l")
default_focus = NodePath("CanvasLayer/VBoxContainer/CenterContainer/ResumeButton")
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="ColorRect" type="ColorRect" parent="CanvasLayer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0.576471, 0.831373, 0.709804, 0.392157)
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer"]
custom_minimum_size = Vector2(500, 600)
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("3_vxkyu")
theme_override_constants/separation = 10
alignment = 1
[node name="CenterContainer" type="CenterContainer" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2
[node name="ResumeButton" type="Button" parent="CanvasLayer/VBoxContainer/CenterContainer"]
custom_minimum_size = Vector2(500, 40)
layout_mode = 2
text = "Resume"
[node name="CenterContainer2" type="CenterContainer" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2
[node name="MainMenuButton" type="Button" parent="CanvasLayer/VBoxContainer/CenterContainer2"]
custom_minimum_size = Vector2(500, 40)
layout_mode = 2
text = "Main Menu"
[node name="CenterContainer3" type="CenterContainer" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2
[node name="SettingsButton" type="Button" parent="CanvasLayer/VBoxContainer/CenterContainer3"]
custom_minimum_size = Vector2(500, 40)
layout_mode = 2
text = "Settings Menu"
[node name="CenterContainer4" type="CenterContainer" parent="CanvasLayer/VBoxContainer"]
layout_mode = 2
[node name="QuitButton" type="Button" parent="CanvasLayer/VBoxContainer/CenterContainer4"]
custom_minimum_size = Vector2(500, 40)
layout_mode = 2
text = "Quit"
[connection signal="pressed" from="CanvasLayer/VBoxContainer/CenterContainer/ResumeButton" to="." method="_on_resume_button_pressed"]
[connection signal="pressed" from="CanvasLayer/VBoxContainer/CenterContainer2/MainMenuButton" to="." method="_on_main_menu_button_pressed"]
[connection signal="pressed" from="CanvasLayer/VBoxContainer/CenterContainer3/SettingsButton" to="." method="_on_settings_button_pressed"]
[connection signal="pressed" from="CanvasLayer/VBoxContainer/CenterContainer4/QuitButton" to="." method="_on_quit_button_pressed"]

192
Scenes/GamePauseTest.tscn Normal file

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
[gd_scene load_steps=16 format=3 uid="uid://cukyb513fah1u"] [gd_scene load_steps=16 format=3 uid="uid://cukyb513fah1u"]
[ext_resource type="Script" path="res://Scripts/UI/MainMenuManager.gd" id="1_qepq0"] [ext_resource type="Script" path="res://Scripts/UI/MainMenuManager.gd" id="1_qepq0"]
[ext_resource type="PackedScene" uid="uid://c4btepmue6d7p" path="res://Scenes/Game.tscn" id="2_28004"] [ext_resource type="PackedScene" uid="uid://beio3828jo4ht" path="res://Scenes/GamePauseTest.tscn" id="2_63cnr"]
[ext_resource type="PackedScene" uid="uid://btxarutbkchmb" path="res://Prefabs/Settings Menu.tscn" id="3_r3r61"] [ext_resource type="PackedScene" uid="uid://btxarutbkchmb" path="res://Prefabs/Settings Menu.tscn" id="3_r3r61"]
[ext_resource type="Theme" uid="uid://b0b3fxesfrpb7" path="res://Assets/UI/Theme.tres" id="4_bmt8e"] [ext_resource type="Theme" uid="uid://b0b3fxesfrpb7" path="res://Assets/UI/Theme.tres" id="4_bmt8e"]
[ext_resource type="Texture2D" uid="uid://tjxkew3m4v8m" path="res://Assets/Sprites/UI/Shadow.png" id="5_wt601"] [ext_resource type="Texture2D" uid="uid://tjxkew3m4v8m" path="res://Assets/Sprites/UI/Shadow.png" id="5_wt601"]
@ -70,7 +70,7 @@ grow_vertical = 2
size_flags_horizontal = 6 size_flags_horizontal = 6
size_flags_vertical = 3 size_flags_vertical = 3
script = ExtResource("1_qepq0") script = ExtResource("1_qepq0")
game_scene = ExtResource("2_28004") game_scene = ExtResource("2_63cnr")
settings_scene = ExtResource("3_r3r61") settings_scene = ExtResource("3_r3r61")
default_focus = NodePath("VBoxContainer/MarginBox2/ButtonsVbox/PlayButton") default_focus = NodePath("VBoxContainer/MarginBox2/ButtonsVbox/PlayButton")
autostart_animations = Array[NodePath]([NodePath("Decorations/Left Decor/Jesus/AnimationPlayer"), NodePath("Decorations/Right Decor/GoodBunny/AnimationPlayer")]) autostart_animations = Array[NodePath]([NodePath("Decorations/Left Decor/Jesus/AnimationPlayer"), NodePath("Decorations/Right Decor/GoodBunny/AnimationPlayer")])

169
Scenes/Test.tscn Normal file
View file

@ -0,0 +1,169 @@
[gd_scene load_steps=16 format=3 uid="uid://cugui0mjc6cfe"]
[ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="1_s4utw"]
[ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="2_yhpwh"]
[ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="3_dvklj"]
[ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="4_0fyd5"]
[ext_resource type="Script" path="res://Scripts/PlayerController.gd" id="5_uv7bh"]
[ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="6_es2l8"]
[ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="7_8kdie"]
[ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="8_wx0kk"]
[sub_resource type="Animation" id="Animation_kdxam"]
resource_name = "Idle"
length = 0.1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Player Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="Animation" id="Animation_dwpep"]
resource_name = "MoveDown"
length = 0.8
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Player Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = false
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [0, 1, 2, 3, 4, 5, 6, 7]
}
[sub_resource type="Animation" id="Animation_2jvl5"]
resource_name = "MoveLeft"
length = 0.8
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Player Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [24, 25, 26, 27, 28, 29, 30, 31]
}
[sub_resource type="Animation" id="Animation_4ig1u"]
resource_name = "MoveRight"
length = 0.8
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Player Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [8, 9, 10, 11, 12, 13, 14, 15]
}
[sub_resource type="Animation" id="Animation_pswkh"]
resource_name = "MoveUp"
length = 0.8
loop_mode = 1
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Player Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7),
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1, 1, 1),
"update": 1,
"values": [16, 17, 18, 19, 20, 21, 22, 23]
}
[sub_resource type="Animation" id="Animation_o3hln"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("Player Sprite:frame")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [0]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_bi1h3"]
_data = {
"Idle": SubResource("Animation_kdxam"),
"MoveDown": SubResource("Animation_dwpep"),
"MoveLeft": SubResource("Animation_2jvl5"),
"MoveRight": SubResource("Animation_4ig1u"),
"MoveUp": SubResource("Animation_pswkh"),
"RESET": SubResource("Animation_o3hln")
}
[node name="Player Movement" type="Node2D"]
[node name="Map Generator" type="TileMap" parent="."]
scale = Vector2(1.5, 1.5)
tile_set = ExtResource("1_s4utw")
cell_quadrant_size = 32
format = 2
script = ExtResource("2_yhpwh")
start_area_corner_size = 3
[node name="Bunny Generator" type="Node" parent="." node_paths=PackedStringArray("player")]
script = ExtResource("3_dvklj")
bunny_prefab = ExtResource("4_0fyd5")
player = NodePath("../Player")
[node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")]
position = Vector2(1440, 810)
collision_layer = 0
script = ExtResource("5_uv7bh")
speed = 60
animation_player = NodePath("Player Animator")
[node name="Player Sprite" type="Sprite2D" parent="Player"]
position = Vector2(0, -20)
texture = ExtResource("6_es2l8")
hframes = 8
vframes = 4
[node name="Player Collider" type="CollisionPolygon2D" parent="Player"]
position = Vector2(2, -24)
polygon = PackedVector2Array(12, 32, -16, 32, -16, -24, 12, -24)
[node name="Player Camera" type="Camera2D" parent="Player"]
position = Vector2(-1, -25)
zoom = Vector2(3, 3)
position_smoothing_enabled = true
drag_horizontal_enabled = true
drag_vertical_enabled = true
editor_draw_drag_margin = true
[node name="Player Animator" type="AnimationPlayer" parent="Player"]
libraries = {
"": SubResource("AnimationLibrary_bi1h3")
}
[node name="WeaponController" type="Node2D" parent="Player"]
position = Vector2(0, -16)
script = ExtResource("7_8kdie")
projectile_prefab = ExtResource("8_wx0kk")

38
Scripts/UI/MenuButton.gd Normal file
View file

@ -0,0 +1,38 @@
extends TextureButton
@export var text : String = "Sample Text"
@export var pointer_margin_from_center : int = 100
@export var leftPointer : Sprite2D
@export var rightPointer : Sprite2D
@export var textBox : RichTextLabel
# Engine Callbacks
func _ready():
textBox.parse_bbcode("[center] %s [/center]" % [text])
pass
func _process(_delta):
handle_hover_and_focus()
handle_x_position()
func handle_hover_and_focus() -> void:
if has_focus():
leftPointer.visible = true
rightPointer.visible = true
elif is_hovered():
leftPointer.visible = true
leftPointer.modulate.a = 0.5
rightPointer.visible = true
rightPointer.modulate.a = 0.5
else:
leftPointer.visible = false
leftPointer.modulate.a = 1
rightPointer.visible = false
rightPointer.modulate.a = 1
pass
func handle_x_position() -> void:
var center_x = get_parent().position.x + (get_parent().size.x / 2.0)
leftPointer.global_position.x = center_x - pointer_margin_from_center
rightPointer.global_position.x = center_x + pointer_margin_from_center
pass

40
Scripts/UI/PauseMenu.gd Normal file
View file

@ -0,0 +1,40 @@
extends Control
@export var menu_scene : String = "res://Scenes/Main Menu.tscn"
@export var settings_scene : Resource
@export var default_focus : Button
func _ready():
for child in get_children():
child.visible = false
pass
func _input(event):
if (event.is_action_pressed("ui_cancel")):
if get_tree().paused: default_focus.grab_focus()
get_tree().paused = !get_tree().paused
for child in get_children():
child.visible = get_tree().paused
pass
func _on_resume_button_pressed():
get_tree().paused = false
for child in get_children():
child.visible = false
pass
func _on_settings_button_pressed():
var settings_scene_instance = load(settings_scene.resource_path).instantiate()
get_tree().current_scene.add_child(settings_scene_instance)
pass
func _on_quit_button_pressed():
get_tree().quit()
pass
func _on_main_menu_button_pressed():
get_tree().paused = false
load(menu_scene)
get_tree().change_scene_to_file(menu_scene)
pass