Adds a popup on crash, wait for it to close to quit the game (#447)

This commit is contained in:
Julian Murgia
2021-11-18 20:52:54 +01:00
committed by GitHub
parent 0684563758
commit 6393a7edd8
7 changed files with 80 additions and 21 deletions

View File

@@ -5,6 +5,10 @@ extends Node2D
class_name ESCGame class_name ESCGame
# Emitted when the user has confirmed the crash popup
signal crash_popup_confirmed
# Editor debug modes # Editor debug modes
# NONE - No debugging # NONE - No debugging
# MOUSE_TOOLTIP_LIMITS - Visualize the tooltip limits # MOUSE_TOOLTIP_LIMITS - Visualize the tooltip limits
@@ -303,3 +307,8 @@ func show_main_menu():
# Hides the main menu. Reimplement to hide a specific UI. # Hides the main menu. Reimplement to hide a specific UI.
func hide_main_menu(): func hide_main_menu():
pass pass
# Shows the crash popup when a crash occurs
func show_crash_popup() -> void:
pass

View File

@@ -105,15 +105,21 @@ func warning(string: String, args = []):
if _get_log_level() >= LOG_WARNING and !crashed: if _get_log_level() >= LOG_WARNING and !crashed:
var argsstr = str(args) if !args.empty() else "" var argsstr = str(args) if !args.empty() else ""
_log("(W)\t" + string + " \t" + argsstr, true) _log("(W)\t" + string + " \t" + argsstr, true)
if ProjectSettings.get_setting("escoria/debug/terminate_on_warnings"): if ProjectSettings.get_setting("escoria/debug/terminate_on_warnings"):
_perform_stack_trace_log() _perform_stack_trace_log()
_log("%s\n- %s" % [
ProjectSettings.get_setting("escoria/debug/crash_message"),
log_file.get_path_absolute()
])
crashed = true crashed = true
escoria.quit()
assert(false) var files = "- %s" % log_file.get_path_absolute()
var message = ProjectSettings.get_setting(
"escoria/debug/crash_message"
) % files
_log(message, true)
escoria.main.current_scene.game.show_crash_popup(
[log_file.get_path_absolute()]
)
# Log an error message # Log an error message
@@ -126,22 +132,28 @@ func error(string: String, args = [], do_savegame: bool = true):
if _get_log_level() >= LOG_ERROR and !crashed: if _get_log_level() >= LOG_ERROR and !crashed:
var argsstr = str(args) if !args.empty() else "" var argsstr = str(args) if !args.empty() else ""
_log("(E)\t" + string + " \t" + argsstr, true) _log("(E)\t" + string + " \t" + argsstr, true)
if ProjectSettings.get_setting("escoria/debug/terminate_on_errors"): if ProjectSettings.get_setting("escoria/debug/terminate_on_errors"):
_perform_stack_trace_log() _perform_stack_trace_log()
crashed = true
if do_savegame: if do_savegame:
_perform_save_game_log() _perform_save_game_log()
_log("%s\n- %s\n- %s" % [ var files_to_send: Array = [
ProjectSettings.get_setting("escoria/debug/crash_message"),
log_file.get_path_absolute().get_base_dir().plus_file( log_file.get_path_absolute().get_base_dir().plus_file(
escoria.save_manager.crash_savegame_filename.get_file() escoria.save_manager.crash_savegame_filename.get_file()
), ),
log_file.get_path_absolute() log_file.get_path_absolute()
]) ]
crashed = true var files = "- %s\n- %s" % files_to_send
escoria.quit() var message = ProjectSettings.get_setting(
assert(false) "escoria/debug/crash_message"
) % files
_log(message, true)
escoria.main.current_scene.game.show_crash_popup(files_to_send)
# Log a warning message about an ESC file # Log a warning message about an ESC file

View File

@@ -40,11 +40,9 @@ func set_scene(p_scene: Node) -> void:
if current_scene != null: if current_scene != null:
clear_scene() clear_scene()
if p_scene.is_inside_tree() and p_scene.get_parent() != self: if not p_scene.is_inside_tree():
p_scene.get_parent().remove_child(p_scene) add_child(p_scene)
move_child(p_scene, 0)
add_child(p_scene)
move_child(p_scene, 0)
current_scene = p_scene current_scene = p_scene
check_game_scene_methods() check_game_scene_methods()
@@ -163,3 +161,4 @@ func check_game_scene_methods():
assert(current_scene.game.has_method("show_ui")) assert(current_scene.game.has_method("show_ui"))
assert(current_scene.game.has_method("_on_event_done")) assert(current_scene.game.has_method("_on_event_done"))
assert(current_scene.game.has_method("show_crash_popup"))

View File

@@ -226,7 +226,7 @@ func set_escoria_debug_settings():
ProjectSettings.set_setting( ProjectSettings.set_setting(
"escoria/debug/crash_message", "escoria/debug/crash_message",
"We're sorry, but the game crashed. Please send us the " + "We're sorry, but the game crashed. Please send us the " +
"following files:\n" "following files:\n\n%s"
) )
var property_info = { var property_info = {
"name": "escoria/debug/crash_message", "name": "escoria/debug/crash_message",

View File

@@ -226,9 +226,29 @@ func pause_game():
escoria.main.current_scene.hide() escoria.main.current_scene.hide()
escoria.set_game_paused(true) escoria.set_game_paused(true)
func _on_MenuButton_pressed() -> void: func _on_MenuButton_pressed() -> void:
pause_game() pause_game()
func _on_action_finished() -> void: func _on_action_finished() -> void:
verbs_menu.unselect_actions() verbs_menu.unselect_actions()
func show_crash_popup(files = []) -> void:
connect("crash_popup_confirmed", escoria, "quit",
[], CONNECT_ONESHOT)
var crash_popup = AcceptDialog.new()
crash_popup.popup_exclusive = true
crash_popup.pause_mode = Node.PAUSE_MODE_PROCESS
add_child(crash_popup)
var files_to_send: String = ""
for file in files:
files_to_send += "- %s\n" % file
crash_popup.dialog_text = tr(ProjectSettings.get_setting(
"escoria/debug/crash_message")
) % files_to_send
crash_popup.popup_centered()
escoria.set_game_paused(true)
yield(crash_popup, "confirmed")
emit_signal("crash_popup_confirmed")

View File

@@ -209,3 +209,22 @@ func _on_action_finished():
func _on_MenuButton_pressed() -> void: func _on_MenuButton_pressed() -> void:
pause_game() pause_game()
func show_crash_popup(files = []) -> void:
connect("crash_popup_confirmed", escoria, "quit",
[], CONNECT_ONESHOT)
var crash_popup = AcceptDialog.new()
crash_popup.popup_exclusive = true
crash_popup.pause_mode = Node.PAUSE_MODE_PROCESS
add_child(crash_popup)
var files_to_send: String = ""
for file in files:
files_to_send += "- %s\n" % file
crash_popup.dialog_text = tr(ProjectSettings.get_setting(
"escoria/debug/crash_message")
) % files_to_send
crash_popup.popup_centered()
escoria.set_game_paused(true)
yield(crash_popup, "confirmed")
emit_signal("crash_popup_confirmed")