FBX: Disable importer when canceling FBX2glTF setup

Pretty hacky solution but it's better than an infinite loop.

All this import setup needs to be redone, it's very difficult to properly
bail out from an invalid import without triggering reimport loops.

Also fix underline not visible at default editor scale in LinkButton.

Fixes #73319.
This commit is contained in:
Rémi Verschelde 2023-03-03 13:10:06 +01:00
parent 61d2c85511
commit d81e6ee024
No known key found for this signature in database
GPG key ID: C3336907360768E1
4 changed files with 33 additions and 5 deletions

View file

@ -30,6 +30,8 @@
#include "fbx_importer_manager.h"
#include "core/config/project_settings.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/gui/link_button.h"
@ -47,9 +49,19 @@ void FBXImporterManager::show_dialog(bool p_exclusive) {
fbx_path->set_text(fbx2gltf_path);
_validate_path(fbx2gltf_path);
set_flag(Window::FLAG_BORDERLESS, p_exclusive); // Avoid closing accidentally .
// If exclusive, we're importing a FBX file, there's no exit.
is_importing = p_exclusive;
set_flag(Window::FLAG_BORDERLESS, p_exclusive); // Avoid closing accidentally.
set_close_on_escape(!p_exclusive);
if (is_importing) {
get_cancel_button()->set_text(TTR("Disable FBX & Restart"));
get_cancel_button()->set_tooltip_text(TTR("Canceling this dialog will disable the FBX importer.\nYou can re-enable it in the Project Settings under Filesystem > Import > FBX > Enabled.\n\nThe editor will restart as importers are registered when the editor starts."));
} else {
get_cancel_button()->set_text(TTR("Cancel"));
get_cancel_button()->set_tooltip_text("");
}
popup_centered();
}
@ -96,6 +108,17 @@ void FBXImporterManager::_path_confirmed() {
EditorSettings::get_singleton()->save();
}
void FBXImporterManager::_cancel_setup() {
if (!is_importing) {
return; // No worry.
}
// No escape.
ProjectSettings::get_singleton()->set("filesystem/import/fbx/enabled", false);
ProjectSettings::get_singleton()->save();
EditorNode::get_singleton()->save_all_scenes();
EditorNode::get_singleton()->restart_editor();
}
void FBXImporterManager::_browse_install() {
if (fbx_path->get_text() != String()) {
browse_dialog->set_current_file(fbx_path->get_text());
@ -140,6 +163,7 @@ FBXImporterManager::FBXImporterManager() {
fbx_path->connect("text_changed", callable_mp(this, &FBXImporterManager::_validate_path));
get_ok_button()->set_text(TTR("Confirm Path"));
get_cancel_button()->connect("pressed", callable_mp(this, &FBXImporterManager::_cancel_setup));
browse_dialog = memnew(EditorFileDialog);
browse_dialog->set_access(EditorFileDialog::ACCESS_FILESYSTEM);

View file

@ -38,6 +38,8 @@
class FBXImporterManager : public ConfirmationDialog {
GDCLASS(FBXImporterManager, ConfirmationDialog)
bool is_importing = false;
Label *message = nullptr;
LineEdit *fbx_path = nullptr;
Button *fbx_path_browse = nullptr;
@ -47,6 +49,7 @@ class FBXImporterManager : public ConfirmationDialog {
void _validate_path(const String &p_path);
void _select_file(const String &p_path);
void _path_confirmed();
void _cancel_setup();
void _browse_install();
void _link_clicked();

View file

@ -143,8 +143,8 @@ void initialize_gltf_module(ModuleInitializationLevel p_level) {
EditorPlugins::add_by_type<SceneExporterGLTFPlugin>();
// Project settings defined here so doctool finds them.
GLOBAL_DEF_RST("filesystem/import/blender/enabled", true);
GLOBAL_DEF_RST("filesystem/import/fbx/enabled", true);
GLOBAL_DEF_RST_BASIC("filesystem/import/blender/enabled", true);
GLOBAL_DEF_RST_BASIC("filesystem/import/fbx/enabled", true);
GDREGISTER_CLASS(EditorSceneFormatImporterBlend);
GDREGISTER_CLASS(EditorSceneFormatImporterFBX);
// Can't (a priori) run external app on these platforms.

View file

@ -243,11 +243,12 @@ void LinkButton::_notification(int p_what) {
if (do_underline) {
int underline_spacing = theme_cache.underline_spacing + text_buf->get_line_underline_position();
int y = text_buf->get_line_ascent() + underline_spacing;
int underline_thickness = MAX(1, text_buf->get_line_underline_thickness());
if (is_layout_rtl()) {
draw_line(Vector2(size.width - width, y), Vector2(size.width, y), color, text_buf->get_line_underline_thickness());
draw_line(Vector2(size.width - width, y), Vector2(size.width, y), color, underline_thickness);
} else {
draw_line(Vector2(0, y), Vector2(width, y), color, text_buf->get_line_underline_thickness());
draw_line(Vector2(0, y), Vector2(width, y), color, underline_thickness);
}
}
} break;