added pause menu in level and ability to load levels from main menu

This commit is contained in:
KingGurke 2023-10-02 16:35:08 +02:00
parent f51914161e
commit b0475b1697
9 changed files with 190 additions and 37 deletions

13
src/gui/menu/level.gd Normal file
View file

@ -0,0 +1,13 @@
extends Control
func _on_continue_button_pressed():
get_tree().current_scene.pause()
func _on_menu_button_pressed():
get_tree().current_scene.pause()
get_tree().change_scene_to_file("res://src/gui/menu/main.tscn")
func _on_options_button_pressed():
var options = load("res://src/gui/menu/options.tscn").instantiate()
get_parent().add_child((options))
hide()

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=2 format=3 uid="uid://dyo5dblkfivwn"]
[gd_scene load_steps=3 format=3 uid="uid://dyo5dblkfivwn"]
[ext_resource type="Theme" uid="uid://dpktnl3r5wul1" path="res://src/gui/menu_theme.tres" id="1_62uke"]
[ext_resource type="Script" path="res://src/gui/menu/level.gd" id="2_6ldjx"]
[node name="level" type="Control"]
layout_mode = 3
@ -10,3 +11,73 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("1_62uke")
script = ExtResource("2_6ldjx")
[node name="Pause" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -131.0
offset_top = -231.0
offset_right = 132.0
offset_bottom = 169.0
grow_horizontal = 2
grow_vertical = 2
[node name="Label" type="Label" parent="Pause"]
layout_mode = 1
anchors_preset = 5
anchor_left = 0.5
anchor_right = 0.5
offset_left = -52.0
offset_top = 24.0
offset_right = 52.0
offset_bottom = 50.0
grow_horizontal = 2
text = "PAUSED"
horizontal_alignment = 1
[node name="VBoxContainer" type="VBoxContainer" parent="Pause"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -59.5
offset_top = 3.0
offset_right = 60.5
offset_bottom = 131.0
grow_horizontal = 2
grow_vertical = 2
[node name="ContinueButton" type="Button" parent="Pause/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "CONTINUE"
[node name="OptionsButton" type="Button" parent="Pause/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "OPTIONS"
[node name="MenuButton" type="Button" parent="Pause/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "TO MENU"
[connection signal="pressed" from="Pause/VBoxContainer/ContinueButton" to="." method="_on_continue_button_pressed"]
[connection signal="pressed" from="Pause/VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"]
[connection signal="pressed" from="Pause/VBoxContainer/MenuButton" to="." method="_on_menu_button_pressed"]

View file

@ -6,7 +6,7 @@ extends Control
# Called when the node enters the scene tree for the first time.
func _ready():
$VBoxContainer/StartButton.grab_focus()
$Main/VBoxContainer/StartButton.grab_focus()
# Called every frame. 'delta' is the elapsed time since the previous frame.
@ -22,7 +22,8 @@ func _on_start_button_pressed():
func _on_options_button_pressed():
var options = load("res://src/gui/menu/options.tscn").instantiate()
get_tree().current_scene.add_child((options))
get_parent().add_child((options))
hide()
func _on_quit_button_pressed():
get_tree().quit()

View file

@ -65,39 +65,57 @@ grow_horizontal = 2
grow_vertical = 2
theme = SubResource("Theme_67fiq")
script = ExtResource("1_p5r7q")
main_menu = NodePath("VBoxContainer")
main_menu = NodePath("Main")
level_select = NodePath("LevelSelect")
[node name="VBoxContainer" type="VBoxContainer" parent="."]
[node name="Main" type="Panel" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -200.0
offset_top = -44.0
offset_right = 200.0
offset_bottom = 156.0
offset_left = -131.0
offset_top = -231.0
offset_right = 132.0
offset_bottom = 169.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="Main"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -59.5
offset_top = 3.0
offset_right = 60.5
offset_bottom = 131.0
grow_horizontal = 2
grow_vertical = 2
alignment = 1
[node name="StartButton" type="Button" parent="VBoxContainer"]
[node name="StartButton" type="Button" parent="Main/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
focus_neighbor_top = NodePath("../QuitButton")
text = "Start!
"
text = "PLAY"
[node name="OptionsButton" type="Button" parent="VBoxContainer"]
[node name="OptionsButton" type="Button" parent="Main/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
text = "Options
"
size_flags_horizontal = 4
text = "OPTIONS"
[node name="QuitButton" type="Button" parent="VBoxContainer"]
[node name="QuitButton" type="Button" parent="Main/VBoxContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
focus_neighbor_bottom = NodePath("../StartButton")
text = "Quit"
text = "QUIT"
[node name="LevelSelect" type="Panel" parent="."]
visible = false
@ -212,18 +230,6 @@ layout_mode = 2
size_flags_horizontal = 4
text = "12"
[node name="MarginContainer" type="MarginContainer" parent="LevelSelect/VBoxContainer"]
layout_mode = 2
theme_override_constants/margin_top = 20
[node name="BackButton" type="Button" parent="LevelSelect/VBoxContainer/MarginContainer"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 2
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "Back"
[node name="Label" type="Label" parent="LevelSelect"]
layout_mode = 1
anchors_preset = 5
@ -237,15 +243,34 @@ grow_horizontal = 2
text = "LEVEL SELECT"
horizontal_alignment = 1
[node name="BackButton" type="Button" parent="LevelSelect"]
custom_minimum_size = Vector2(120, 40)
layout_mode = 1
anchors_preset = 7
anchor_left = 0.5
anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -60.0
offset_top = -109.0
offset_right = 60.0
offset_bottom = -69.0
grow_horizontal = 2
grow_vertical = 0
size_flags_horizontal = 4
size_flags_vertical = 8
focus_neighbor_bottom = NodePath("../StartButton")
text = "BACK"
[node name="MenuMusic" type="AudioStreamPlayer" parent="."]
stream = ExtResource("2_yc480")
volume_db = -29.953
autoplay = true
bus = &"Music"
[connection signal="pressed" from="VBoxContainer/StartButton" to="." method="_on_start_button_pressed"]
[connection signal="pressed" from="VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"]
[connection signal="pressed" from="VBoxContainer/QuitButton" to="." method="_on_quit_button_pressed"]
[connection signal="pressed" from="Main/VBoxContainer/StartButton" to="." method="_on_start_button_pressed"]
[connection signal="pressed" from="Main/VBoxContainer/OptionsButton" to="." method="_on_options_button_pressed"]
[connection signal="pressed" from="Main/VBoxContainer/QuitButton" to="." method="_on_quit_button_pressed"]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/1" to="." method="_on_level_button_pressed" binds= [1]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/2" to="." method="_on_level_button_pressed" binds= [2]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row1/3" to="." method="_on_level_button_pressed" binds= [3]]
@ -258,4 +283,4 @@ bus = &"Music"
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/10" to="." method="_on_level_button_pressed" binds= [10]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/11" to="." method="_on_level_button_pressed" binds= [11]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/VBoxContainer2/Row3/12" to="." method="_on_level_button_pressed" binds= [12]]
[connection signal="pressed" from="LevelSelect/VBoxContainer/MarginContainer/BackButton" to="." method="_on_back_button_pressed"]
[connection signal="pressed" from="LevelSelect/BackButton" to="." method="_on_back_button_pressed"]

View file

@ -1,4 +1,5 @@
extends Control
func _on_back_button_pressed():
get_parent().get_child(0).show()
queue_free()

View file

@ -129,9 +129,9 @@ anchor_top = 1.0
anchor_right = 0.5
anchor_bottom = 1.0
offset_left = -60.0
offset_top = -64.0
offset_top = -109.0
offset_right = 60.0
offset_bottom = -24.0
offset_bottom = -69.0
grow_horizontal = 2
grow_vertical = 0
size_flags_horizontal = 4