diff options
Diffstat (limited to 'editor/create_dialog.cpp')
-rw-r--r-- | editor/create_dialog.cpp | 97 |
1 files changed, 79 insertions, 18 deletions
diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 36978e37a5..3e0c1f2d53 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -40,6 +40,11 @@ void CreateDialog::popup_create(bool p_dont_clear, bool p_replace_mode) { + type_list.clear(); + ClassDB::get_class_list(&type_list); + ScriptServer::get_global_class_list(&type_list); + type_list.sort_custom<StringName::AlphCompare>(); + recent->clear(); FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::READ); @@ -173,10 +178,28 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p if (p_types.has(p_type)) return; - if (!ClassDB::is_parent_class(p_type, base_type) || p_type == base_type) + + bool cpp_type = ClassDB::class_exists(p_type); + EditorData &ed = EditorNode::get_singleton()->get_editor_data(); + + if (p_type == base_type) return; - String inherits = ClassDB::get_parent_class(p_type); + if (cpp_type) { + if (!ClassDB::is_parent_class(p_type, base_type)) + return; + } else { + if (!ScriptServer::is_global_class(p_type) || !ed.script_class_is_parent(p_type, base_type)) + return; + + String script_path = ScriptServer::get_global_class_path(p_type); + if (script_path.find("res://addons/", 0) != -1) { + if (!EditorNode::get_singleton()->is_addon_plugin_enabled(script_path.get_slicec('/', 3))) + return; + } + } + + String inherits = cpp_type ? ClassDB::get_parent_class(p_type) : ed.script_class_get_base(p_type); TreeItem *parent = p_root; @@ -189,17 +212,32 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p if (p_types.has(inherits)) parent = p_types[inherits]; + else if (ScriptServer::is_global_class(inherits)) + return; } + bool can_instance = (cpp_type && ClassDB::can_instance(p_type)) || ScriptServer::is_global_class(p_type); + TreeItem *item = search_options->create_item(parent); - item->set_text(0, p_type); - if (!ClassDB::can_instance(p_type)) { + if (cpp_type) { + item->set_text(0, p_type); + } else { + item->set_metadata(0, p_type); + item->set_text(0, p_type + " (" + ScriptServer::get_global_class_path(p_type).get_file() + ")"); + } + if (!can_instance) { item->set_custom_color(0, get_color("disabled_font_color", "Editor")); item->set_selectable(0, false); } else { bool is_search_subsequence = search_box->get_text().is_subsequence_ofi(p_type); String to_select_type = *to_select ? (*to_select)->get_text(0) : ""; - bool current_item_is_preffered = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(to_select_type, preferred_search_result_type); + to_select_type = to_select_type.split(" ")[0]; + bool current_item_is_preffered; + if (cpp_type) { + current_item_is_preffered = ClassDB::is_parent_class(p_type, preferred_search_result_type) && !ClassDB::is_parent_class(to_select_type, preferred_search_result_type); + } else { + current_item_is_preffered = ed.script_class_is_parent(p_type, preferred_search_result_type) && !ed.script_class_is_parent(to_select_type, preferred_search_result_type); + } if (*to_select && p_type.length() < (*to_select)->get_text(0).length()) { current_item_is_preffered = true; } @@ -217,16 +255,19 @@ void CreateDialog::add_type(const String &p_type, HashMap<String, TreeItem *> &p // don't collapse the root node collapse &= (item != p_root); // don't collapse abstract nodes on the first tree level - collapse &= ((parent != p_root) || (ClassDB::can_instance(p_type))); + collapse &= ((parent != p_root) || (can_instance)); item->set_collapsed(collapse); } const String &description = EditorHelp::get_doc_data()->class_list[p_type].brief_description; item->set_tooltip(0, description); - if (has_icon(p_type, "EditorIcons")) { + if (cpp_type && has_icon(p_type, "EditorIcons")) { item->set_icon(0, get_icon(p_type, "EditorIcons")); + } else if (!cpp_type && has_icon(ScriptServer::get_global_class_base(p_type), "EditorIcons")) { + + item->set_icon(0, get_icon(ScriptServer::get_global_class_base(p_type), "EditorIcons")); } p_types[p_type] = item; @@ -246,36 +287,43 @@ void CreateDialog::_update_search() { HashMap<String, TreeItem *> types; TreeItem *root = search_options->create_item(); + EditorData &ed = EditorNode::get_singleton()->get_editor_data(); root->set_text(0, base_type); if (has_icon(base_type, "EditorIcons")) { root->set_icon(0, get_icon(base_type, "EditorIcons")); } - List<StringName>::Element *I = type_list.front(); TreeItem *to_select = search_box->get_text() == base_type ? root : NULL; - for (; I; I = I->next()) { + for (List<StringName>::Element *I = type_list.front(); I; I = I->next()) { String type = I->get(); + bool cpp_type = ClassDB::class_exists(type); if (base_type == "Node" && type.begins_with("Editor")) continue; // do not show editor nodes - if (base_type == "Resource" && ClassDB::is_parent_class(type, "PluginScript")) - // PluginScript must be initialized before use, which is not possible here - continue; - - if (!ClassDB::can_instance(type)) + if (cpp_type && !ClassDB::can_instance(type)) continue; // can't create what can't be instanced + bool skip = false; + if (cpp_type) { + for (Set<StringName>::Element *E = type_blacklist.front(); E && !skip; E = E->next()) { + if (ClassDB::is_parent_class(type, E->get())) + skip = true; + } + if (skip) + continue; + } + if (search_box->get_text() == "") { add_type(type, types, root, &to_select); } else { bool found = false; String type = I->get(); - while (type != "" && ClassDB::is_parent_class(type, base_type) && type != base_type) { + while (type != "" && (cpp_type ? ClassDB::is_parent_class(type, base_type) : ed.script_class_is_parent(type, base_type)) && type != base_type) { if (search_box->get_text().is_subsequence_ofi(type)) { found = true; @@ -440,6 +488,17 @@ Object *CreateDialog::instance_selected() { custom = md; if (custom != String()) { + + if (ScriptServer::is_global_class(custom)) { + RES script = ResourceLoader::load(ScriptServer::get_global_class_path(custom)); + ERR_FAIL_COND_V(!script.is_valid(), NULL); + + Object *obj = ClassDB::instance(ScriptServer::get_global_class_base(custom)); + ERR_FAIL_COND_V(!obj, NULL); + + obj->set_script(script.get_ref_ptr()); + return obj; + } return EditorNode::get_editor_data().instance_custom_type(selected->get_text(0), custom); } else { return ClassDB::instance(selected->get_text(0)); @@ -641,9 +700,6 @@ CreateDialog::CreateDialog() { is_replace_mode = false; - ClassDB::get_class_list(&type_list); - type_list.sort_custom<StringName::AlphCompare>(); - set_resizable(true); HSplitContainer *hsc = memnew(HSplitContainer); @@ -706,4 +762,9 @@ CreateDialog::CreateDialog() { help_bit = memnew(EditorHelpBit); vbc->add_margin_child(TTR("Description:"), help_bit); help_bit->connect("request_hide", this, "_closed"); + + type_blacklist.insert("PluginScript"); // PluginScript must be initialized before use, which is not possible here + type_blacklist.insert("ScriptCreateDialog"); // This is an exposed editor Node that doesn't have an Editor prefix. + + EDITOR_DEF("interface/editors/derive_script_globals_by_name", true); } |