diff options
author | bruvzg <7645683+bruvzg@users.noreply.github.com> | 2023-02-15 16:35:16 +0200 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-03-13 14:48:33 +0100 |
commit | 764fe8ac519bc37b3f17926fa02c25609de528ed (patch) | |
tree | 5c4a7f60131dbebbc7a23c3e4da725298a4e03e0 | |
parent | d9297844915abae44f295ddf8064ace8051a2c58 (diff) |
Automatically reparent editor message dialogs to avoid error spam.
(cherry picked from commit 921f3b7589084e07a4b6eefd89ec7fe81857a8b7)
-rw-r--r-- | editor/editor_node.cpp | 132 | ||||
-rw-r--r-- | editor/editor_node.h | 11 | ||||
-rw-r--r-- | editor/editor_plugin.cpp | 1 | ||||
-rw-r--r-- | editor/export/project_export.cpp | 2 | ||||
-rw-r--r-- | editor/progress_dialog.cpp | 4 | ||||
-rw-r--r-- | scene/main/window.cpp | 7 |
6 files changed, 113 insertions, 44 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6c521afd14..72fcdcfc4b 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -151,6 +151,51 @@ EditorNode *EditorNode::singleton = nullptr; // The metadata key used to store and retrieve the version text to copy to the clipboard. static const String META_TEXT_TO_COPY = "text_to_copy"; +class AcceptDialogAutoReparent : public AcceptDialog { + GDCLASS(AcceptDialogAutoReparent, AcceptDialog); + +protected: + void _notification(int p_what) { + if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { + if (!is_visible()) { + Node *p = get_parent(); + if (p) { + p->remove_child(this); + } + } + } + } + +public: + void attach_and_popup_centered() { + EditorNode *ed = EditorNode::get_singleton(); + if (ed && !is_inside_tree()) { + Window *w = ed->get_window(); + while (w && w->get_exclusive_child()) { + w = w->get_exclusive_child(); + } + if (w && w != this) { + w->add_child(this); + popup_centered(); + } + } + } + + void attach_and_popup_centered_ratio(float p_ratio = 0.8) { + EditorNode *ed = EditorNode::get_singleton(); + if (ed && !is_inside_tree()) { + Window *w = ed->get_window(); + while (w && w->get_exclusive_child()) { + w = w->get_exclusive_child(); + } + if (w && w != this) { + w->add_child(this); + popup_centered_ratio(p_ratio); + } + } + } +}; + void EditorNode::disambiguate_filenames(const Vector<String> p_full_paths, Vector<String> &r_filenames) { ERR_FAIL_COND_MSG(p_full_paths.size() != r_filenames.size(), vformat("disambiguate_filenames requires two string vectors of same length (%d != %d).", p_full_paths.size(), r_filenames.size())); @@ -615,6 +660,21 @@ void EditorNode::_notification(int p_what) { if (progress_dialog) { progress_dialog->queue_free(); } + if (load_error_dialog) { + load_error_dialog->queue_free(); + } + if (execute_output_dialog) { + execute_output_dialog->queue_free(); + } + if (warning) { + warning->queue_free(); + } + if (accept) { + accept->queue_free(); + } + if (save_accept) { + save_accept->queue_free(); + } editor_data.save_editor_external_data(); FileAccess::set_file_close_fail_notify_callback(nullptr); log->deinit(); // Do not get messages anymore. @@ -4278,9 +4338,11 @@ void EditorNode::add_io_error(const String &p_error) { void EditorNode::_load_error_notify(void *p_ud, const String &p_text) { EditorNode *en = static_cast<EditorNode *>(p_ud); - en->load_errors->add_image(en->gui_base->get_theme_icon(SNAME("Error"), SNAME("EditorIcons"))); - en->load_errors->add_text(p_text + "\n"); - en->load_error_dialog->popup_centered_ratio(0.5); + if (en && en->load_error_dialog) { + en->load_errors->add_image(en->gui_base->get_theme_icon(SNAME("Error"), SNAME("EditorIcons"))); + en->load_errors->add_text(p_text + "\n"); + en->load_error_dialog->attach_and_popup_centered_ratio(0.5); + } } bool EditorNode::_find_scene_in_use(Node *p_node, const String &p_path) const { @@ -4651,23 +4713,27 @@ Error EditorNode::export_preset(const String &p_preset, const String &p_path, bo void EditorNode::show_accept(const String &p_text, const String &p_title) { current_menu_option = -1; - accept->set_ok_button_text(p_title); - accept->set_text(p_text); - accept->popup_centered(); + if (accept) { + accept->set_ok_button_text(p_title); + accept->set_text(p_text); + accept->attach_and_popup_centered(); + } } void EditorNode::show_save_accept(const String &p_text, const String &p_title) { current_menu_option = -1; - save_accept->set_ok_button_text(p_title); - save_accept->set_text(p_text); - save_accept->popup_centered(); + if (save_accept) { + save_accept->set_ok_button_text(p_title); + save_accept->set_text(p_text); + save_accept->attach_and_popup_centered(); + } } void EditorNode::show_warning(const String &p_text, const String &p_title) { - if (warning->is_inside_tree()) { + if (warning) { warning->set_text(p_text); warning->set_title(p_title); - warning->popup_centered(); + warning->attach_and_popup_centered(); } else { WARN_PRINT(p_title + " " + p_text); } @@ -6565,11 +6631,13 @@ static void _execute_thread(void *p_ud) { } int EditorNode::execute_and_show_output(const String &p_title, const String &p_path, const List<String> &p_arguments, bool p_close_on_ok, bool p_close_on_errors) { - execute_output_dialog->set_title(p_title); - execute_output_dialog->get_ok_button()->set_disabled(true); - execute_outputs->clear(); - execute_outputs->set_scroll_follow(true); - execute_output_dialog->popup_centered_ratio(); + if (execute_output_dialog) { + execute_output_dialog->set_title(p_title); + execute_output_dialog->get_ok_button()->set_disabled(true); + execute_outputs->clear(); + execute_outputs->set_scroll_follow(true); + execute_output_dialog->attach_and_popup_centered_ratio(); + } ExecuteThreadArgs eta; eta.path = p_path; @@ -6587,6 +6655,7 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p String to_add = eta.output.substr(prev_len, eta.output.length()); prev_len = eta.output.length(); execute_outputs->add_text(to_add); + DisplayServer::get_singleton()->process_events(); // Get rid of pending events. Main::iteration(); } } @@ -6596,14 +6665,16 @@ int EditorNode::execute_and_show_output(const String &p_title, const String &p_p eta.execute_output_thread.wait_to_finish(); execute_outputs->add_text("\nExit Code: " + itos(eta.exitcode)); - if (p_close_on_errors && eta.exitcode != 0) { - execute_output_dialog->hide(); - } - if (p_close_on_ok && eta.exitcode == 0) { - execute_output_dialog->hide(); - } + if (execute_output_dialog) { + if (p_close_on_errors && eta.exitcode != 0) { + execute_output_dialog->hide(); + } + if (p_close_on_ok && eta.exitcode == 0) { + execute_output_dialog->hide(); + } - execute_output_dialog->get_ok_button()->set_disabled(false); + execute_output_dialog->get_ok_button()->set_disabled(false); + } return eta.exitcode; } @@ -7174,12 +7245,10 @@ EditorNode::EditorNode() { prev_scene->set_position(Point2(3, 24)); prev_scene->hide(); - accept = memnew(AcceptDialog); - gui_base->add_child(accept); + accept = memnew(AcceptDialogAutoReparent); accept->connect("confirmed", callable_mp(this, &EditorNode::_menu_confirm_current)); - save_accept = memnew(AcceptDialog); - gui_base->add_child(save_accept); + save_accept = memnew(AcceptDialogAutoReparent); save_accept->connect("confirmed", callable_mp(this, &EditorNode::_menu_option).bind((int)MenuOptions::FILE_SAVE_AS_SCENE)); project_export = memnew(ProjectExportDialog); @@ -7224,9 +7293,8 @@ EditorNode::EditorNode() { gui_base->add_child(fbx_importer_manager); #endif - warning = memnew(AcceptDialog); + warning = memnew(AcceptDialogAutoReparent); warning->add_button(TTR("Copy Text"), true, "copy"); - gui_base->add_child(warning); warning->connect("custom_action", callable_mp(this, &EditorNode::_copy_warning)); ED_SHORTCUT("editor/next_tab", TTR("Next Scene Tab"), KeyModifierMask::CMD_OR_CTRL + Key::TAB); @@ -7994,17 +8062,15 @@ EditorNode::EditorNode() { set_process_shortcut_input(true); load_errors = memnew(RichTextLabel); - load_error_dialog = memnew(AcceptDialog); + load_error_dialog = memnew(AcceptDialogAutoReparent); load_error_dialog->add_child(load_errors); load_error_dialog->set_title(TTR("Load Errors")); - gui_base->add_child(load_error_dialog); execute_outputs = memnew(RichTextLabel); execute_outputs->set_selection_enabled(true); - execute_output_dialog = memnew(AcceptDialog); + execute_output_dialog = memnew(AcceptDialogAutoReparent); execute_output_dialog->add_child(execute_outputs); execute_output_dialog->set_title(""); - gui_base->add_child(execute_output_dialog); EditorFileSystem::get_singleton()->connect("sources_changed", callable_mp(this, &EditorNode::_sources_changed)); EditorFileSystem::get_singleton()->connect("filesystem_changed", callable_mp(this, &EditorNode::_fs_changed)); diff --git a/editor/editor_node.h b/editor/editor_node.h index 6a9d052791..66a3bf5be2 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -45,6 +45,7 @@ typedef void (*EditorPluginInitializeCallback)(); typedef bool (*EditorBuildCallback)(); class AcceptDialog; +class AcceptDialogAutoReparent; class AudioStreamPreviewGenerator; class BackgroundProgress; class CenterContainer; @@ -370,10 +371,10 @@ private: PluginConfigDialog *plugin_config_dialog = nullptr; RichTextLabel *load_errors = nullptr; - AcceptDialog *load_error_dialog = nullptr; + AcceptDialogAutoReparent *load_error_dialog = nullptr; RichTextLabel *execute_outputs = nullptr; - AcceptDialog *execute_output_dialog = nullptr; + AcceptDialogAutoReparent *execute_output_dialog = nullptr; Ref<Theme> theme; @@ -388,10 +389,10 @@ private: ConfirmationDialog *import_confirmation = nullptr; ConfirmationDialog *pick_main_scene = nullptr; Button *select_current_scene_button = nullptr; - AcceptDialog *accept = nullptr; - AcceptDialog *save_accept = nullptr; + AcceptDialogAutoReparent *accept = nullptr; + AcceptDialogAutoReparent *save_accept = nullptr; EditorAbout *about = nullptr; - AcceptDialog *warning = nullptr; + AcceptDialogAutoReparent *warning = nullptr; int overridden_default_layout = -1; Ref<ConfigFile> default_layout; diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index 7b01ae69bf..fb2110dea3 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -137,6 +137,7 @@ Vector<Ref<Texture2D>> EditorInterface::make_mesh_previews(const Vector<Ref<Mesh RS::get_singleton()->instance_set_transform(light_instance2, xform * Transform3D().looking_at(Vector3(+1, -1, -2), Vector3(0, 1, 0))); ep.step(TTR("Thumbnail..."), i); + DisplayServer::get_singleton()->process_events(); Main::iteration(); Main::iteration(); Ref<Image> img = RS::get_singleton()->texture_2d_get(viewport_texture); diff --git a/editor/export/project_export.cpp b/editor/export/project_export.cpp index e9ea0012be..a7ac95bd5b 100644 --- a/editor/export/project_export.cpp +++ b/editor/export/project_export.cpp @@ -943,8 +943,8 @@ void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) { } void ProjectExportDialog::_open_export_template_manager() { - EditorNode::get_singleton()->open_export_template_manager(); hide(); + EditorNode::get_singleton()->open_export_template_manager(); } void ProjectExportDialog::_validate_export_path(const String &p_path) { diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index 9695a7042d..4d76fdc997 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -221,9 +221,7 @@ bool ProgressDialog::task_step(const String &p_task, const String &p_state, int t.state->set_text(p_state); last_progress_tick = OS::get_singleton()->get_ticks_usec(); - if (cancel_hb->is_visible()) { - DisplayServer::get_singleton()->process_events(); - } + DisplayServer::get_singleton()->process_events(); #ifndef ANDROID_ENABLED Main::iteration(); // this will not work on a lot of platforms, so it's only meant for the editor diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 59e3d307c6..9fb4ed458f 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -1365,8 +1365,11 @@ void Window::_window_input(const Ref<InputEvent> &p_ev) { emit_signal(SceneStringNames::get_singleton()->window_input, p_ev); - push_input(p_ev); - if (!is_input_handled()) { + if (is_inside_tree()) { + push_input(p_ev); + } + + if (!is_input_handled() && is_inside_tree()) { push_unhandled_input(p_ev); } } |