Jelajahi Sumber

:tada: Add pause menu

DricomDragon 1 tahun lalu
induk
melakukan
a48dd90de8

+ 24 - 0
godot/component/ui/pause/pause_menu.gd

@@ -0,0 +1,24 @@
+extends VSplitContainer
+
+
+func _unhandled_input(event: InputEvent) -> void:
+	if event.is_action_released("ui_cancel") and not get_tree().is_paused():
+		get_tree().set_pause(true)
+		show()
+
+
+func _on_resume_button_pressed():
+	hide()
+	get_tree().set_pause(false)
+
+
+func _on_title_button_pressed():
+	pass # Replace with function body.
+
+
+func _on_quit_button_pressed():
+	get_tree().quit()
+
+
+func _on_visibility_changed():
+	%ResumeButton.grab_focus()

+ 55 - 0
godot/component/ui/pause/pause_menu.tscn

@@ -0,0 +1,55 @@
+[gd_scene load_steps=4 format=3 uid="uid://c68bdcjpdm1y2"]
+
+[ext_resource type="Script" path="res://component/ui/pause/pause_menu.gd" id="1_yqs56"]
+
+[sub_resource type="InputEventAction" id="InputEventAction_ucj0l"]
+action = &"ui_cancel"
+
+[sub_resource type="Shortcut" id="Shortcut_2elwo"]
+events = [SubResource("InputEventAction_ucj0l")]
+
+[node name="PauseMenu" type="VSplitContainer"]
+process_mode = 3
+visible = false
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+size_flags_horizontal = 4
+script = ExtResource("1_yqs56")
+
+[node name="Title" type="Label" parent="."]
+layout_mode = 2
+theme_override_font_sizes/font_size = 40
+text = "Pause"
+horizontal_alignment = 1
+
+[node name="Buttons" type="VBoxContainer" parent="."]
+process_mode = 2
+layout_mode = 2
+size_flags_horizontal = 4
+size_flags_vertical = 4
+
+[node name="ResumeButton" type="Button" parent="Buttons"]
+unique_name_in_owner = true
+layout_mode = 2
+theme_override_font_sizes/font_size = 33
+text = "Resume"
+
+[node name="TitleButton" type="Button" parent="Buttons"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 33
+disabled = true
+text = "Return to title screen"
+
+[node name="QuitButton" type="Button" parent="Buttons"]
+layout_mode = 2
+theme_override_font_sizes/font_size = 33
+shortcut = SubResource("Shortcut_2elwo")
+text = "Quit"
+
+[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
+[connection signal="pressed" from="Buttons/ResumeButton" to="." method="_on_resume_button_pressed"]
+[connection signal="pressed" from="Buttons/TitleButton" to="." method="_on_title_button_pressed"]
+[connection signal="pressed" from="Buttons/QuitButton" to="." method="_on_quit_button_pressed"]

+ 6 - 0
godot/project.godot

@@ -34,6 +34,12 @@ ui_select={
 "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"echo":false,"script":null)
 ]
 }
+ui_cancel={
+"deadzone": 0.5,
+"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194305,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null)
+, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":6,"pressure":0.0,"pressed":true,"script":null)
+]
+}
 move_left={
 "deadzone": 0.2,
 "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":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)

+ 4 - 1
godot/run/levels/infinite_level.tscn

@@ -1,4 +1,4 @@
-[gd_scene load_steps=23 format=3 uid="uid://7ivipmwaw24t"]
+[gd_scene load_steps=24 format=3 uid="uid://7ivipmwaw24t"]
 
 [ext_resource type="Texture2D" uid="uid://cgwafs6ukpm7y" path="res://component/entity/ground/ground051.jpg" id="1_3ytcp"]
 [ext_resource type="Script" path="res://run/levels/camera_tracker.gd" id="1_qdm47"]
@@ -16,6 +16,7 @@
 [ext_resource type="PackedScene" uid="uid://uy3pgfv4q3iy" path="res://component/ui/title/title_screen.tscn" id="13_2xijd"]
 [ext_resource type="PackedScene" uid="uid://bohus0ptrc77h" path="res://component/entity/buildings/summit_gate/summit_gate.tscn" id="14_ky6m3"]
 [ext_resource type="Texture2D" uid="uid://daewyr44tkkm0" path="res://effect/sky/sky_stk.jpg" id="15_5bqty"]
+[ext_resource type="PackedScene" uid="uid://c68bdcjpdm1y2" path="res://component/ui/pause/pause_menu.tscn" id="16_orqqe"]
 
 [sub_resource type="BoxShape3D" id="BoxShape3D_ctk0t"]
 size = Vector3(500, 10, 500)
@@ -187,6 +188,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -63.9918, 0, 0)
 
 [node name="TitleScreen" parent="." instance=ExtResource("13_2xijd")]
 
+[node name="PauseMenu" parent="." instance=ExtResource("16_orqqe")]
+
 [node name="WorldEnvironment" type="WorldEnvironment" parent="."]
 environment = SubResource("Environment_jdyq3")