From 12e948b026d581b05eb712b8fff031c3f33b6348 Mon Sep 17 00:00:00 2001 From: Lazy-Rabbit-2001 <2733679597@qq.com> Date: Thu, 12 Dec 2024 10:57:50 +0800 Subject: [PATCH] simplified the code and optimization --- doc/classes/EditorInterface.xml | 2 +- editor/editor_interface.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index a7e1f28aca6e..d291a9e35587 100644 --- a/doc/classes/EditorInterface.xml +++ b/doc/classes/EditorInterface.xml @@ -281,7 +281,7 @@ Pops up an editor dialog for creating an object. The [param callback] must take a single argument of type [StringName] which will contain the type name of the selected object or be empty if no item is selected. - The [param base_type] specifies the base type of objects to display. If you set this to "Resource", all items shown in the create dialog are derived from [Resource]. + The [param base_type] specifies the base type of objects to display. For example, if you set this to "Resource", all types derived from [Resource] will display in the create dialog. The [param current_type] will be passed in the search box of the create dialog, and the specified type can be immediately selected when the dialog pops up. If the [param current_type] is not derived from [param base_type], there will be no result of the type in the dialog. The [param dialog_title] allows you to define a custom title for the dialog. This is useful if you want to accurately hint the usage of the dialog. If the [param dialog_title] is an empty string, the dialog will use "Create New 'Base Type'" as the default title. The [param type_blocklist] contains a list of type names, and the types in the blocklist will be hidden from the create dialog. diff --git a/editor/editor_interface.cpp b/editor/editor_interface.cpp index 373c4a8a38e7..a7e8f100bf26 100644 --- a/editor/editor_interface.cpp +++ b/editor/editor_interface.cpp @@ -537,11 +537,11 @@ void EditorInterface::popup_create_dialog(const Callable &p_callback, const Stri } create_dialog->set_type_suffixes(suffix_map); - const bool is_type_valid = ClassDB::class_exists(p_base_type) || ScriptServer::is_global_class(p_base_type); - if (!is_type_valid) { + String safe_base_type = p_base_type; + if (p_base_type.is_empty() || (!ClassDB::class_exists(p_base_type) && !ScriptServer::is_global_class(p_base_type))) { ERR_PRINT(vformat("Invalid base type '%s'. The base type has fallen back to 'Object'.", p_base_type)); + safe_base_type = "Object"; } - const String safe_base_type = !p_base_type.is_empty() && is_type_valid ? p_base_type : "Object"; create_dialog->set_base_type(safe_base_type); create_dialog->popup_create(false, true, p_current_type, "");