Merge pull request #40145 from KoBeWi/bsm

Support built-in scripts for inspector categories
This commit is contained in:
Rémi Verschelde 2020-07-06 00:48:06 +02:00 committed by GitHub
commit eb1d4ea65d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 3 deletions

View File

@ -1592,8 +1592,10 @@ void EditorInspector::update_tree() {
} }
} }
if (category->icon.is_null()) { if (category->icon.is_null()) {
if (type != String()) { // Can happen for built-in scripts.
category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object"); category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
} }
}
category->label = type; category->label = type;
category->bg_color = get_theme_color("prop_category", "Editor"); category->bg_color = get_theme_color("prop_category", "Editor");
@ -2405,9 +2407,12 @@ void EditorInspector::_update_script_class_properties(const Object &p_object, Li
String n = EditorNode::get_editor_data().script_class_get_name(script->get_path()); String n = EditorNode::get_editor_data().script_class_get_name(script->get_path());
if (n.length()) { if (n.length()) {
classes.push_front(n); classes.push_front(n);
} else { } else if (script->get_path() != String() && script->get_path().find("::") == -1) {
n = script->get_path().get_file(); n = script->get_path().get_file();
classes.push_front(n); classes.push_front(n);
} else {
n = TTR("Built-in script");
classes.push_front(n);
} }
paths[n] = script->get_path(); paths[n] = script->get_path();
script = script->get_base_script(); script = script->get_base_script();
@ -2436,7 +2441,14 @@ void EditorInspector::_update_script_class_properties(const Object &p_object, Li
for (List<StringName>::Element *E = classes.front(); E; E = E->next()) { for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
StringName name = E->get(); StringName name = E->get();
String path = paths[name]; String path = paths[name];
Ref<Script> s = ResourceLoader::load(path, "Script"); Ref<Script> s;
if (path == String()) {
// Built-in script. It can't be inherited, so must be the script attached to the object.
s = p_object.get_script();
} else {
s = ResourceLoader::load(path, "Script");
}
ERR_FAIL_COND(!s->is_valid());
List<PropertyInfo> props; List<PropertyInfo> props;
s->get_script_property_list(&props); s->get_script_property_list(&props);