diff options
Diffstat (limited to 'editor/create_dialog.cpp')
-rw-r--r-- | editor/create_dialog.cpp | 67 |
1 files changed, 37 insertions, 30 deletions
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 4ac32d7317..785476d75b 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -126,10 +126,6 @@ bool CreateDialog::_should_hide_type(const String &p_type) const { return true; // Do not show editor nodes. } - if (p_type == base_type && !EditorNode::get_editor_data().get_custom_types().has(p_type)) { - return true; // Root is already added. - } - if (ClassDB::class_exists(p_type)) { if (!ClassDB::can_instantiate(p_type) || ClassDB::is_virtual(p_type)) { return true; // Can't create abstract or virtual class. @@ -217,18 +213,18 @@ void CreateDialog::_add_type(const String &p_type, const TypeCategory p_type_cat inherited_type = TypeCategory::CPP_TYPE; } else if (p_type_category == TypeCategory::PATH_TYPE) { ERR_FAIL_COND(!ResourceLoader::exists(p_type, "Script")); - Ref<Script> script = ResourceLoader::load(p_type, "Script"); - ERR_FAIL_COND(script.is_null()); + Ref<Script> scr = ResourceLoader::load(p_type, "Script"); + ERR_FAIL_COND(scr.is_null()); - Ref<Script> base = script->get_base_script(); + Ref<Script> base = scr->get_base_script(); if (base.is_null()) { String extends; - script->get_language()->get_global_class_name(script->get_path(), &extends); + scr->get_language()->get_global_class_name(scr->get_path(), &extends); inherits = extends; inherited_type = TypeCategory::CPP_TYPE; } else { - inherits = script->get_language()->get_global_class_name(base->get_path()); + inherits = scr->get_language()->get_global_class_name(base->get_path()); if (inherits.is_empty()) { inherits = base->get_path(); inherited_type = TypeCategory::PATH_TYPE; @@ -236,18 +232,18 @@ void CreateDialog::_add_type(const String &p_type, const TypeCategory p_type_cat } } else { if (ScriptServer::is_global_class(p_type)) { - Ref<Script> script = EditorNode::get_editor_data().script_class_load_script(p_type); - ERR_FAIL_COND(script.is_null()); + Ref<Script> scr = EditorNode::get_editor_data().script_class_load_script(p_type); + ERR_FAIL_COND(scr.is_null()); - Ref<Script> base = script->get_base_script(); + Ref<Script> base = scr->get_base_script(); if (base.is_null()) { String extends; - script->get_language()->get_global_class_name(script->get_path(), &extends); + scr->get_language()->get_global_class_name(scr->get_path(), &extends); inherits = extends; inherited_type = TypeCategory::CPP_TYPE; } else { - inherits = script->get_language()->get_global_class_name(base->get_path()); + inherits = scr->get_language()->get_global_class_name(base->get_path()); if (inherits.is_empty()) { inherits = base->get_path(); inherited_type = TypeCategory::PATH_TYPE; @@ -288,12 +284,21 @@ 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; + bool is_experimental = EditorHelp::get_doc_data()->class_list[p_type].is_experimental; + + if (is_deprecated) { + r_item->add_button(0, get_theme_icon("StatusError", SNAME("EditorIcons")), 0, false, TTR("This class is marked as deprecated.")); + } else if (is_experimental) { + r_item->add_button(0, get_theme_icon("NodeWarning", SNAME("EditorIcons")), 0, false, TTR("This class is marked as experimental.")); } if (!search_box->get_text().is_empty()) { @@ -302,7 +307,7 @@ void CreateDialog::_configure_search_option_item(TreeItem *r_item, const String // Don't collapse the root node or an abstract node on the first tree level. bool should_collapse = p_type != base_type && (r_item->get_parent()->get_text(0) != base_type || can_instantiate); - if (should_collapse && bool(EditorSettings::get_singleton()->get("docks/scene_tree/start_create_dialog_fully_expanded"))) { + if (should_collapse && bool(EDITOR_GET("docks/scene_tree/start_create_dialog_fully_expanded"))) { should_collapse = false; // Collapse all nodes anyway. } r_item->set_collapsed(should_collapse); @@ -334,6 +339,11 @@ String CreateDialog::_top_result(const Vector<String> p_candidates, const String } float CreateDialog::_score_type(const String &p_type, const String &p_search) const { + if (p_type == p_search) { + // Always favor an exact match (case-sensitive), since clicking a favorite will set the search text to the type. + return 1.0f; + } + float inverse_length = 1.f / float(p_type.length()); // Favor types where search term is a substring close to the start of the type. @@ -342,13 +352,13 @@ float CreateDialog::_score_type(const String &p_type, const String &p_search) co float score = (pos > -1) ? 1.0f - w * MIN(1, 3 * pos * inverse_length) : MAX(0.f, .9f - w); // Favor shorter items: they resemble the search term more. - w = 0.1f; - score *= (1 - w) + w * (p_search.length() * inverse_length); + w = 0.9f; + score *= (1 - w) + w * MIN(1.0f, p_search.length() * inverse_length); - score *= _is_type_preferred(p_type) ? 1.0f : 0.8f; + score *= _is_type_preferred(p_type) ? 1.0f : 0.9f; // Add score for being a favorite type. - score *= (favorite_list.find(p_type) > -1) ? 1.0f : 0.7f; + score *= (favorite_list.find(p_type) > -1) ? 1.0f : 0.8f; // Look through at most 5 recent items bool in_recent = false; @@ -358,7 +368,7 @@ float CreateDialog::_score_type(const String &p_type, const String &p_search) co break; } } - score *= in_recent ? 1.0f : 0.8f; + score *= in_recent ? 1.0f : 0.9f; return score; } @@ -491,7 +501,7 @@ String CreateDialog::get_selected_type() { return selected->get_text(0); } -Variant CreateDialog::instance_selected() { +Variant CreateDialog::instantiate_selected() { TreeItem *selected = search_options->get_selected(); if (!selected) { @@ -509,7 +519,7 @@ Variant CreateDialog::instance_selected() { n->set_name(custom); } } else { - obj = EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom); + obj = EditorNode::get_editor_data().instantiate_custom_type(selected->get_text(0), custom); } } else { obj = ClassDB::instantiate(selected->get_text(0)); @@ -742,10 +752,7 @@ CreateDialog::CreateDialog() { favorites->connect("cell_selected", callable_mp(this, &CreateDialog::_favorite_selected)); favorites->connect("item_activated", callable_mp(this, &CreateDialog::_favorite_activated)); favorites->add_theme_constant_override("draw_guides", 1); -#ifndef _MSC_VER -#warning cannot forward drag data to a non control, must be fixed -#endif - //favorites->set_drag_forwarding(this); + favorites->set_drag_forwarding(this); fav_vb->add_margin_child(TTR("Favorites:"), favorites, true); VBoxContainer *rec_vb = memnew(VBoxContainer); |