diff options
Diffstat (limited to 'editor/create_dialog.cpp')
-rw-r--r-- | editor/create_dialog.cpp | 80 |
1 files changed, 51 insertions, 29 deletions
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 75fff03297..73468f8ce0 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -53,13 +53,15 @@ void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode, const St if (f) { TreeItem *root = recent->create_item(); + String icon_fallback = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object"; + while (!f->eof_reached()) { String l = f->get_line().strip_edges(); String name = l.split(" ")[0]; if ((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name)) { TreeItem *ti = recent->create_item(root); ti->set_text(0, l); - ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(l, base_type)); + ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(name, icon_fallback)); } } @@ -248,7 +250,8 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p const String &description = DTR(EditorHelp::get_doc_data()->class_list[p_type].brief_description); item->set_tooltip(0, description); - item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, base_type)); + String icon_fallback = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object"; + item->set_icon(0, EditorNode::get_singleton()->get_class_icon(p_type, icon_fallback)); p_types[p_type] = item; } @@ -305,9 +308,8 @@ void CreateDialog::_update_search() { EditorData &ed = EditorNode::get_editor_data(); root->set_text(0, base_type); - if (search_options->has_theme_icon(base_type, "EditorIcons")) { - root->set_icon(0, search_options->get_theme_icon(base_type, "EditorIcons")); - } + String base_icon = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object"; + root->set_icon(0, search_options->get_theme_icon(base_icon, "EditorIcons")); TreeItem *to_select = search_box->get_text() == base_type ? root : nullptr; @@ -345,20 +347,22 @@ void CreateDialog::_update_search() { } else { bool found = false; String type2 = type; + bool cpp_type2 = cpp_type; if (!cpp_type && !search_loaded_scripts.has(type)) { search_loaded_scripts[type] = ed.script_class_load_script(type); } - while (type2 != "" && (cpp_type ? ClassDB::is_parent_class(type2, base_type) : ed.script_class_is_parent(type2, base_type)) && type2 != base_type) { + while (type2 != "" && (cpp_type2 ? ClassDB::is_parent_class(type2, base_type) : ed.script_class_is_parent(type2, base_type)) && type2 != base_type) { if (search_box->get_text().is_subsequence_ofi(type2)) { found = true; break; } - type2 = cpp_type ? ClassDB::get_parent_class(type2) : ed.script_class_get_base(type2); + type2 = cpp_type2 ? ClassDB::get_parent_class(type2) : ed.script_class_get_base(type2); + cpp_type2 = cpp_type2 || ClassDB::class_exists(type2); // Built-in class can't inherit from custom type, so we can skip the check if it's already true. - if (!cpp_type && !search_loaded_scripts.has(type2)) { + if (!cpp_type2 && !search_loaded_scripts.has(type2)) { search_loaded_scripts[type2] = ed.script_class_load_script(type2); } } @@ -393,9 +397,7 @@ void CreateDialog::_update_search() { TreeItem *item = search_options->create_item(ti); item->set_metadata(0, type); item->set_text(0, ct[i].name); - if (ct[i].icon.is_valid()) { - item->set_icon(0, ct[i].icon); - } + item->set_icon(0, ct[i].icon.is_valid() ? ct[i].icon : search_options->get_theme_icon(base_icon, "EditorIcons")); if (!to_select || ct[i].name == search_box->get_text()) { to_select = item; @@ -511,30 +513,45 @@ String CreateDialog::get_selected_type() { Object *CreateDialog::instance_selected() { TreeItem *selected = search_options->get_selected(); - if (selected) { - Variant md = selected->get_metadata(0); + if (!selected) { + return nullptr; + } - String custom; - if (md.get_type() != Variant::NIL) { - custom = md; - } + Variant md = selected->get_metadata(0); + String custom; + if (md.get_type() != Variant::NIL) { + custom = md; + } - if (custom != String()) { - if (ScriptServer::is_global_class(custom)) { - Object *obj = EditorNode::get_editor_data().script_class_instance(custom); - Node *n = Object::cast_to<Node>(obj); - if (n) { - n->set_name(custom); - } - return obj; + Object *obj = nullptr; + + if (!custom.empty()) { + if (ScriptServer::is_global_class(custom)) { + obj = EditorNode::get_editor_data().script_class_instance(custom); + Node *n = Object::cast_to<Node>(obj); + if (n) { + n->set_name(custom); } - return EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom); + obj = n; } else { - return ClassDB::instance(selected->get_text(0)); + obj = EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom); + } + } else { + obj = ClassDB::instance(selected->get_text(0)); + } + + // Check if any Object-type property should be instantiated. + List<PropertyInfo> pinfo; + obj->get_property_list(&pinfo); + + for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { + if (E->get().type == Variant::OBJECT && E->get().usage & PROPERTY_USAGE_EDITOR_INSTANTIATE_OBJECT) { + Object *prop = ClassDB::instance(E->get().class_name); + obj->set(E->get().name, prop); } } - return nullptr; + return obj; } void CreateDialog::_item_selected() { @@ -598,16 +615,21 @@ void CreateDialog::_save_favorite_list() { void CreateDialog::_update_favorite_list() { favorites->clear(); + TreeItem *root = favorites->create_item(); + + String icon_fallback = search_options->has_theme_icon(base_type, "EditorIcons") ? base_type : "Object"; + for (int i = 0; i < favorite_list.size(); i++) { String l = favorite_list[i]; String name = l.split(" ")[0]; if (!((ClassDB::class_exists(name) || ScriptServer::is_global_class(name)) && !_is_class_disabled_by_feature_profile(name))) { continue; } + TreeItem *ti = favorites->create_item(root); ti->set_text(0, l); - ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(l, base_type)); + ti->set_icon(0, EditorNode::get_singleton()->get_class_icon(name, icon_fallback)); } emit_signal("favorites_updated"); } |