You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Global class names (and GDScript support for it)
This commit is contained in:
@@ -243,6 +243,18 @@ void CreateDialog::_update_search() {
|
||||
_parse_fs(EditorFileSystem::get_singleton()->get_filesystem());
|
||||
*/
|
||||
|
||||
List<StringName> global_classes;
|
||||
ScriptServer::get_global_class_list(&global_classes);
|
||||
|
||||
Map<String, List<String> > global_class_map;
|
||||
for (List<StringName>::Element *E = global_classes.front(); E; E = E->next()) {
|
||||
String base = ScriptServer::get_global_class_base(E->get());
|
||||
if (!global_class_map.has(base)) {
|
||||
global_class_map[base] = List<String>();
|
||||
}
|
||||
global_class_map[base].push_back(E->get());
|
||||
}
|
||||
|
||||
HashMap<String, TreeItem *> types;
|
||||
|
||||
TreeItem *root = search_options->create_item();
|
||||
@@ -293,6 +305,32 @@ void CreateDialog::_update_search() {
|
||||
add_type(I->get(), types, root, &to_select);
|
||||
}
|
||||
|
||||
if (global_class_map.has(type) && ClassDB::is_parent_class(type, base_type)) {
|
||||
for (List<String>::Element *J = global_class_map[type].front(); J; J = J->next()) {
|
||||
bool show = search_box->get_text().is_subsequence_ofi(J->get());
|
||||
|
||||
if (!show)
|
||||
continue;
|
||||
|
||||
if (!types.has(type))
|
||||
add_type(type, types, root, &to_select);
|
||||
|
||||
TreeItem *ti;
|
||||
if (types.has(type))
|
||||
ti = types[type];
|
||||
else
|
||||
ti = search_options->get_root();
|
||||
|
||||
TreeItem *item = search_options->create_item(ti);
|
||||
item->set_metadata(0, J->get());
|
||||
item->set_text(0, J->get() + " (" + ScriptServer::get_global_class_path(J->get()).get_file() + ")");
|
||||
item->set_icon(0, _get_editor_icon(type));
|
||||
if (!to_select || J->get() == search_box->get_text()) {
|
||||
to_select = item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (EditorNode::get_editor_data().get_custom_types().has(type) && ClassDB::is_parent_class(type, base_type)) {
|
||||
//there are custom types based on this... cool.
|
||||
|
||||
@@ -444,6 +482,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));
|
||||
|
||||
Reference in New Issue
Block a user