diff --git a/doc/classes/EditorInterface.xml b/doc/classes/EditorInterface.xml index 624e8285208..d291a9e3558 100644 --- a/doc/classes/EditorInterface.xml +++ b/doc/classes/EditorInterface.xml @@ -270,6 +270,35 @@ Plays the main scene. + + + + + + + + + + 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. 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. + The [param type_suffixes] is a dictionary, with keys being [StringName]s and values being [String]s. Custom suffixes override the default suffixes which are file names of their scripts. For example, if you set a custom suffix as "Custom Suffix" for a global script type, + [codeblock lang=text] + Node + |- MyCustomNode (my_custom_node.gd) + [/codeblock] + will be + [codeblock lang=text] + Node + |- MyCustomNode (Custom Suffix) + [/codeblock] + Bear in mind that when a built-in type does not have any custom suffix, its suffix will be removed. The suffix of a type created from a script will fall back to its script file name. For global types by scripts, if you customize their suffixes to an empty string, their suffixes will be removed. + [b]Note:[/b] Trying to list the base type in the [param type_blocklist] will hide all types derived from the base type from the create dialog. + + diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index c66adb63e86..9c2de726e83 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -145,6 +145,11 @@ bool CreateDialog::_should_hide_type(const StringName &p_type) const { return true; // Parent type is blacklisted. } } + for (const StringName &F : custom_type_blocklist) { + if (ClassDB::is_parent_class(p_type, F)) { + return true; // Parent type is excluded in custom type blocklist. + } + } } else { if (!ScriptServer::is_global_class(p_type)) { return true; @@ -154,8 +159,12 @@ bool CreateDialog::_should_hide_type(const StringName &p_type) const { } StringName native_type = ScriptServer::get_global_class_native_base(p_type); - if (ClassDB::class_exists(native_type) && !ClassDB::can_instantiate(native_type)) { - return true; + if (ClassDB::class_exists(native_type)) { + if (!ClassDB::can_instantiate(native_type)) { + return true; + } else if (custom_type_blocklist.has(p_type) || custom_type_blocklist.has(native_type)) { + return true; + } } String script_path = ScriptServer::get_global_class_path(p_type); @@ -283,15 +292,27 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const StringN bool is_abstract = false; if (p_type_category == TypeCategory::CPP_TYPE) { r_item->set_text(0, p_type); + if (custom_type_suffixes.has(p_type)) { + String suffix = custom_type_suffixes.get(p_type); + if (!suffix.is_empty()) { + r_item->set_suffix(0, "(" + suffix + ")"); + } + } } else if (p_type_category == TypeCategory::PATH_TYPE) { r_item->set_text(0, "\"" + p_type + "\""); } else if (script_type) { r_item->set_metadata(0, p_type); r_item->set_text(0, p_type); String script_path = ScriptServer::get_global_class_path(p_type); - r_item->set_suffix(0, "(" + script_path.get_file() + ")"); - Ref