From 7e7b09ff6084b8a08a8064b858878cf5f7410335 Mon Sep 17 00:00:00 2001 From: Rob Kelly Date: Tue, 19 Nov 2024 15:51:42 -0700 Subject: [PATCH] Confirm Quit dialog --- src/game/game.gd | 9 ++++++ src/ui/menus/pause_menu/pause_menu.gd | 9 ++++++ src/ui/menus/pause_menu/pause_menu.tscn | 42 +++++++++++++++++++++++++ src/ui/shot_hud/shot_hud.tscn | 3 +- 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/game/game.gd b/src/game/game.gd index 542b9d3..e12434a 100644 --- a/src/game/game.gd +++ b/src/game/game.gd @@ -99,3 +99,12 @@ func _process(_delta: float) -> void: if not _loading_resources and loading_screen.visible: loader_transition.play("fade_out") + + +func _notification(what: int) -> void: + if what == NOTIFICATION_WM_CLOSE_REQUEST: + # Handle close request here + # TODO: save? + get_tree().quit() + elif what == NOTIFICATION_CRASH: + print_debug("CRASHING!") diff --git a/src/ui/menus/pause_menu/pause_menu.gd b/src/ui/menus/pause_menu/pause_menu.gd index a7a9b3a..5a6715b 100644 --- a/src/ui/menus/pause_menu/pause_menu.gd +++ b/src/ui/menus/pause_menu/pause_menu.gd @@ -2,6 +2,7 @@ extends Control ## Menu shown in-game when the user presses pause. @onready var menu_list: VBoxContainer = %MenuList +@onready var quit_confirm: CenterContainer = %QuitConfirm func _ready() -> void: @@ -34,4 +35,12 @@ func settings() -> void: func quit() -> void: + quit_confirm.show() + + +func cancel_quit() -> void: + quit_confirm.hide() + + +func confirm_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 index 51d8cae..c1b2ff2 100644 --- a/src/ui/menus/pause_menu/pause_menu.tscn +++ b/src/ui/menus/pause_menu/pause_menu.tscn @@ -63,6 +63,48 @@ theme_type_variation = &"PauseMenuButton" theme_override_colors/font_color = Color(1, 0.36, 0.36, 1) text = "Quit" +[node name="QuitConfirm" type="CenterContainer" parent="."] +unique_name_in_owner = true +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="PanelContainer" type="PanelContainer" parent="QuitConfirm"] +layout_mode = 2 + +[node name="MarginContainer" type="MarginContainer" parent="QuitConfirm/PanelContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 8 +theme_override_constants/margin_top = 8 +theme_override_constants/margin_right = 8 +theme_override_constants/margin_bottom = 8 + +[node name="VBoxContainer" type="VBoxContainer" parent="QuitConfirm/PanelContainer/MarginContainer"] +layout_mode = 2 + +[node name="Label" type="Label" parent="QuitConfirm/PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +text = "Quit to desktop?" + +[node name="HBoxContainer" type="HBoxContainer" parent="QuitConfirm/PanelContainer/MarginContainer/VBoxContainer"] +layout_mode = 2 +theme_override_constants/separation = 16 + +[node name="CancelButton" type="Button" parent="QuitConfirm/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +text = "Cancel" + +[node name="ConfirmQuitButton" type="Button" parent="QuitConfirm/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer"] +layout_mode = 2 +size_flags_horizontal = 3 +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"] +[connection signal="pressed" from="QuitConfirm/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/CancelButton" to="." method="cancel_quit"] +[connection signal="pressed" from="QuitConfirm/PanelContainer/MarginContainer/VBoxContainer/HBoxContainer/ConfirmQuitButton" to="." method="confirm_quit"] diff --git a/src/ui/shot_hud/shot_hud.tscn b/src/ui/shot_hud/shot_hud.tscn index 25a43d3..0678541 100644 --- a/src/ui/shot_hud/shot_hud.tscn +++ b/src/ui/shot_hud/shot_hud.tscn @@ -692,8 +692,9 @@ anchors_preset = -1 anchor_top = 1.0 anchor_right = 0.333 anchor_bottom = 1.0 -offset_top = -98.0 +offset_top = 20.0 offset_right = 40.0 +offset_bottom = 118.0 grow_vertical = 0 theme_override_constants/margin_left = 16 theme_override_constants/margin_bottom = 16