From 2517468b73ac6ef161db24ca86be0041f9f6aba2 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Tue, 19 Nov 2024 15:44:47 -0700 Subject: [PATCH] Pause menu --- project.godot | 5 ++ src/ui/main_theme.tres | 13 ++++- src/ui/menus/pause_menu/pause_menu.gd | 37 ++++++++++++++ src/ui/menus/pause_menu/pause_menu.tscn | 68 +++++++++++++++++++++++++ src/ui/shot_hud/shot_hud.tscn | 2 +- src/ui/world_ui.gd | 18 +++++++ 6 files changed, 141 insertions(+), 2 deletions(-) create mode 100644 src/ui/menus/pause_menu/pause_menu.gd create mode 100644 src/ui/menus/pause_menu/pause_menu.tscn diff --git a/project.godot b/project.godot index 92b570a..7d3de2a 100644 --- a/project.godot +++ b/project.godot @@ -170,6 +170,11 @@ debug_4={ "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":4194335,"key_label":0,"unicode":0,"location":0,"echo":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,"location":0,"echo":false,"script":null) +] +} [layer_names] diff --git a/src/ui/main_theme.tres b/src/ui/main_theme.tres index 4e438c0..5d28770 100644 --- a/src/ui/main_theme.tres +++ b/src/ui/main_theme.tres @@ -1,9 +1,13 @@ -[gd_resource type="Theme" load_steps=3 format=3 uid="uid://diodjft5u2cck"] +[gd_resource type="Theme" load_steps=5 format=3 uid="uid://diodjft5u2cck"] [ext_resource type="FontFile" uid="uid://dsa0oh7c0h4pu" path="res://assets/fonts/Racing_Sans_One/RacingSansOne-Regular.ttf" id="1_3rv2b"] [ext_resource type="FontFile" uid="uid://comihs66wounx" path="res://assets/fonts/Dokdo/Dokdo-Regular.ttf" id="1_eha6a"] +[ext_resource type="FontFile" uid="uid://b6gxwgomstkgu" path="res://assets/fonts/Geo/Geo-Italic.ttf" id="2_5ty6u"] +[ext_resource type="FontFile" uid="uid://s4c1kf0rk2mb" path="res://assets/fonts/Geo/Geo-Regular.ttf" id="3_cee6l"] [resource] +default_font = ExtResource("3_cee6l") +default_font_size = 18 ClubSelectLabel/base_type = &"Label" ClubSelectLabel/colors/font_color = Color(1, 0.933333, 0.894118, 1) ClubSelectLabel/colors/font_outline_color = Color(0, 0, 0, 1) @@ -17,6 +21,13 @@ ClubSelectLabelDisabled/base_type = &"ClubSelectLabel" ClubSelectLabelDisabled/colors/font_color = Color(0.4, 0.3848, 0.376, 1) ClubSelectLabelDisabled/colors/font_outline_color = Color(0.2, 0.2, 0.2, 1) ClubSelectLabelDisabled/colors/font_shadow_color = Color(0.2, 0.2, 0.2, 1) +ClubSelectLabelDisabled/font_sizes/font_size = 84 +ClubSelectLabelDisabled/fonts/font = ExtResource("1_3rv2b") +PauseMenuButton/base_type = &"Button" +PauseMenuButton/colors/font_outline_color = Color(0, 0, 0, 1) +PauseMenuButton/constants/outline_size = 6 +PauseMenuButton/font_sizes/font_size = 32 +PauseMenuButton/fonts/font = ExtResource("2_5ty6u") ShotFeedback/base_type = &"RichTextLabel" ShotFeedback/colors/font_shadow_color = Color(0, 0, 0, 1) ShotFeedback/constants/shadow_offset_x = 6 diff --git a/src/ui/menus/pause_menu/pause_menu.gd b/src/ui/menus/pause_menu/pause_menu.gd new file mode 100644 index 0000000..a7a9b3a --- /dev/null +++ b/src/ui/menus/pause_menu/pause_menu.gd @@ -0,0 +1,37 @@ +extends Control +## Menu shown in-game when the user presses pause. + +@onready var menu_list: VBoxContainer = %MenuList + + +func _ready() -> void: + Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE) + + +func _exit_tree() -> void: + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + + +func _unhandled_key_input(event: InputEvent) -> void: + if event.is_action_pressed("pause"): + resume() + + +func _unhide() -> void: + menu_list.show() + + +func _hide() -> void: + menu_list.hide() + + +func resume() -> void: + queue_free() + + +func settings() -> void: + pass # TODO + + +func quit() -> void: + get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST) diff --git a/src/ui/menus/pause_menu/pause_menu.tscn b/src/ui/menus/pause_menu/pause_menu.tscn new file mode 100644 index 0000000..51d8cae --- /dev/null +++ b/src/ui/menus/pause_menu/pause_menu.tscn @@ -0,0 +1,68 @@ +[gd_scene load_steps=3 format=3 uid="uid://byvjsvavbg5xe"] + +[ext_resource type="FontFile" uid="uid://b6gxwgomstkgu" path="res://assets/fonts/Geo/Geo-Italic.ttf" id="1_4nw1f"] +[ext_resource type="Script" path="res://src/ui/menus/pause_menu/pause_menu.gd" id="1_rd0j2"] + +[node name="PauseMenu" type="Control"] +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_rd0j2") + +[node name="Shade" type="ColorRect" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +color = Color(0, 0, 0, 0.156863) + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 1 +anchors_preset = 3 +anchor_left = 1.0 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 0 +grow_vertical = 0 +theme_override_constants/margin_right = 160 +theme_override_constants/margin_bottom = 160 + +[node name="MenuList" type="VBoxContainer" parent="MarginContainer"] +unique_name_in_owner = true +layout_mode = 2 + +[node name="Label" type="Label" parent="MarginContainer/MenuList"] +layout_mode = 2 +theme_override_colors/font_color = Color(1, 1, 1, 1) +theme_override_colors/font_outline_color = Color(0, 0, 0, 1) +theme_override_constants/outline_size = 8 +theme_override_fonts/font = ExtResource("1_4nw1f") +theme_override_font_sizes/font_size = 72 +text = "Paused" + +[node name="ResumeButton" type="Button" parent="MarginContainer/MenuList"] +layout_mode = 2 +theme_type_variation = &"PauseMenuButton" +text = "Resume" + +[node name="SettingsButton" type="Button" parent="MarginContainer/MenuList"] +layout_mode = 2 +theme_type_variation = &"PauseMenuButton" +text = "Settings" + +[node name="QuitButton" type="Button" parent="MarginContainer/MenuList"] +layout_mode = 2 +theme_type_variation = &"PauseMenuButton" +theme_override_colors/font_color = Color(1, 0.36, 0.36, 1) +text = "Quit" + +[connection signal="pressed" from="MarginContainer/MenuList/ResumeButton" to="." method="resume"] +[connection signal="pressed" from="MarginContainer/MenuList/SettingsButton" to="." method="settings"] +[connection signal="pressed" from="MarginContainer/MenuList/QuitButton" to="." method="quit"] diff --git a/src/ui/shot_hud/shot_hud.tscn b/src/ui/shot_hud/shot_hud.tscn index 293d80c..25a43d3 100644 --- a/src/ui/shot_hud/shot_hud.tscn +++ b/src/ui/shot_hud/shot_hud.tscn @@ -499,7 +499,7 @@ anchor_right = 1.0 anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 -mouse_filter = 1 +mouse_filter = 2 script = ExtResource("1_x5b4c") [node name="WoahNiceFeedback" type="RichTextLabel" parent="."] diff --git a/src/ui/world_ui.gd b/src/ui/world_ui.gd index 8155e76..90a79eb 100644 --- a/src/ui/world_ui.gd +++ b/src/ui/world_ui.gd @@ -1,8 +1,26 @@ class_name WorldUI extends Control ## Container & accessor for the world UI. +@export var pause_scene := preload("res://src/ui/menus/pause_menu/pause_menu.tscn") + @onready var hud_container: Control = %HUDContainer +func _unhandled_key_input(event: InputEvent) -> void: + if event.is_action_pressed("pause"): + pause() + + func add_player_hud(hud: ShotHUD) -> void: hud_container.add_child(hud) + + +func pause() -> void: + var menu := pause_scene.instantiate() + add_child(menu) + menu.tree_exiting.connect(_unpause) + get_tree().paused = true + + +func _unpause() -> void: + get_tree().paused = false