generated from krampus/template-godot4
Confirm Quit dialog
This commit is contained in:
parent
2517468b73
commit
7e7b09ff60
|
@ -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!")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue