From ba542444e3f81498eb3a9851a1b17cbf828abe61 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Wed, 19 Oct 2022 01:58:13 -0500 Subject: Don't allow instancing virtual node types in the Create New Node dialog --- core/object/class_db.cpp | 8 +++++++- editor/create_dialog.cpp | 8 ++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 41585943b3..0863dea053 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -31,6 +31,7 @@ #include "class_db.h" #include "core/config/engine.h" +#include "core/object/script_language.h" #include "core/os/mutex.h" #include "core/version.h" @@ -376,7 +377,12 @@ bool ClassDB::is_virtual(const StringName &p_class) { OBJTYPE_RLOCK; ClassInfo *ti = classes.getptr(p_class); - ERR_FAIL_COND_V_MSG(!ti, false, "Cannot get class '" + String(p_class) + "'."); + if (!ti) { + if (!ScriptServer::is_global_class(p_class)) { + ERR_FAIL_V_MSG(false, "Cannot get class '" + String(p_class) + "'."); + } + return false; + } #ifdef TOOLS_ENABLED if (ti->api == API_EDITOR && !Engine::get_singleton()->is_editor_hint()) { return false; diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 6142856f75..545b0895b0 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -284,12 +284,12 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String bool can_instantiate = (p_type_category == TypeCategory::CPP_TYPE && ClassDB::can_instantiate(p_type)) || p_type_category == TypeCategory::OTHER_TYPE; - if (!can_instantiate) { - r_item->set_custom_color(0, search_options->get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); + if (can_instantiate && !ClassDB::is_virtual(p_type)) { + r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback)); + } else { r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, "NodeDisabled")); + r_item->set_custom_color(0, search_options->get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"))); r_item->set_selectable(0, false); - } else { - r_item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback)); } bool is_deprecated = EditorHelp::get_doc_data()->class_list[p_type].is_deprecated; -- cgit v1.2.3 From 2557ea9d33489ebca24e8840a77bfee821c8b1a0 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Fri, 21 Oct 2022 15:30:06 -0500 Subject: Don't allow instancing virtual resources in the resource picker dialog --- editor/editor_resource_picker.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/editor/editor_resource_picker.cpp b/editor/editor_resource_picker.cpp index 7c1e3e63ef..0b38996b2d 100644 --- a/editor/editor_resource_picker.cpp +++ b/editor/editor_resource_picker.cpp @@ -570,13 +570,17 @@ void EditorResourcePicker::_get_allowed_types(bool p_with_convert, HashSetinsert(base); + if (!ClassDB::is_virtual(base)) { + p_vector->insert(base); + } // If we hit a familiar base type, take all the data from cache. if (allowed_types_cache.has(base)) { List allowed_subtypes = allowed_types_cache[base]; for (const StringName &subtype_name : allowed_subtypes) { - p_vector->insert(subtype_name); + if (!ClassDB::is_virtual(subtype_name)) { + p_vector->insert(subtype_name); + } } } else { List allowed_subtypes; @@ -586,13 +590,17 @@ void EditorResourcePicker::_get_allowed_types(bool p_with_convert, HashSetinsert(subtype_name); + if (!ClassDB::is_virtual(subtype_name)) { + p_vector->insert(subtype_name); + } allowed_subtypes.push_back(subtype_name); } for (const StringName &subtype_name : global_classes) { if (EditorNode::get_editor_data().script_class_is_parent(subtype_name, base)) { - p_vector->insert(subtype_name); + if (!ClassDB::is_virtual(subtype_name)) { + p_vector->insert(subtype_name); + } allowed_subtypes.push_back(subtype_name); } } -- cgit v1.2.3