Add script class categories to EditorInspector.

(cherry picked from commit 644de52ca9)
This commit is contained in:
willnationsdev 2019-09-28 22:27:10 -05:00 committed by Rémi Verschelde
parent 1dd2cf7914
commit 8a02f221b4
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 102 additions and 5 deletions

View file

@ -1480,9 +1480,9 @@ void EditorInspector::update_tree() {
String group_base;
VBoxContainer *category_vbox = NULL;
List<PropertyInfo>
plist;
List<PropertyInfo> plist;
object->get_property_list(&plist, true);
_update_script_class_properties(*object, plist);
HashMap<String, VBoxContainer *> item_path;
Map<VBoxContainer *, EditorInspectorSection *> section_map;
@ -1538,7 +1538,28 @@ void EditorInspector::update_tree() {
category_vbox = NULL; //reset
String type = p.name;
category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
if (!ClassDB::class_exists(type) && !ScriptServer::is_global_class(type) && p.hint_string.length() && FileAccess::exists(p.hint_string)) {
Ref<Script> s = ResourceLoader::load(p.hint_string, "Script");
String base_type;
if (s.is_valid()) {
base_type = s->get_instance_base_type();
}
while (s.is_valid()) {
StringName name = EditorNode::get_editor_data().script_class_get_name(s->get_path());
String icon_path = EditorNode::get_editor_data().script_class_get_icon_path(name);
if (name != StringName() && icon_path.length()) {
category->icon = ResourceLoader::load(icon_path, "Texture");
break;
}
s = s->get_base_script();
}
if (category->icon.is_null() && has_icon(base_type, "EditorIcons")) {
category->icon = get_icon(base_type, "EditorIcons");
}
}
if (category->icon.is_null()) {
category->icon = EditorNode::get_singleton()->get_class_icon(type, "Object");
}
category->label = type;
category->bg_color = get_color("prop_category", "Editor");
@ -2312,6 +2333,83 @@ void EditorInspector::_feature_profile_changed() {
update_tree();
}
void EditorInspector::_update_script_class_properties(const Object &p_object, List<PropertyInfo> &r_list) const {
Ref<Script> script = p_object.get_script();
if (script.is_null()) {
return;
}
List<StringName> classes;
Map<StringName, String> paths;
// NodeC -> NodeB -> NodeA
while (script.is_valid()) {
String n = EditorNode::get_editor_data().script_class_get_name(script->get_path());
if (n.length()) {
classes.push_front(n);
} else {
n = script->get_path().get_file();
classes.push_front(n);
}
paths[n] = script->get_path();
script = script->get_base_script();
}
if (classes.empty()) {
return;
}
// Script Variables -> to insert: NodeC..B..A -> bottom (insert_here)
List<PropertyInfo>::Element *script_variables = NULL;
List<PropertyInfo>::Element *bottom = NULL;
List<PropertyInfo>::Element *insert_here = NULL;
for (List<PropertyInfo>::Element *E = r_list.front(); E; E = E->next()) {
PropertyInfo &pi = E->get();
if (pi.name != "Script Variables") {
continue;
}
script_variables = E;
bottom = r_list.insert_after(script_variables, PropertyInfo());
insert_here = bottom;
break;
}
Set<StringName> added;
for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
StringName name = E->get();
String path = paths[name];
Ref<Script> s = ResourceLoader::load(path, "Script");
List<PropertyInfo> props;
s->get_script_property_list(&props);
// Script Variables -> NodeA -> bottom (insert_here)
List<PropertyInfo>::Element *category = r_list.insert_before(insert_here, PropertyInfo(Variant::NIL, name, PROPERTY_HINT_NONE, path, PROPERTY_USAGE_CATEGORY));
// Script Variables -> NodeA -> A props... -> bottom (insert_here)
for (List<PropertyInfo>::Element *P = props.front(); P; P = P->next()) {
PropertyInfo &pi = P->get();
if (added.has(pi.name)) {
continue;
}
added.insert(pi.name);
r_list.insert_before(insert_here, pi);
}
// Script Variables -> NodeA (insert_here) -> A props... -> bottom
insert_here = category;
}
// NodeC -> C props... -> NodeB..C..
r_list.erase(script_variables);
List<PropertyInfo>::Element *to_delete = bottom->next();
while (to_delete && !(to_delete->get().usage & PROPERTY_USAGE_CATEGORY)) {
r_list.erase(to_delete);
to_delete = bottom->next();
}
r_list.erase(bottom);
}
void EditorInspector::_bind_methods() {
ClassDB::bind_method("_property_changed", &EditorInspector::_property_changed, DEFVAL(""), DEFVAL(false));

View file

@ -325,6 +325,7 @@ class EditorInspector : public ScrollContainer {
void _vscroll_changed(double);
void _feature_profile_changed();
void _update_script_class_properties(const Object &p_object, List<PropertyInfo> &r_list) const;
bool _is_property_disabled_by_feature_profile(const StringName &p_property);

View file

@ -3952,8 +3952,6 @@ Ref<Texture> EditorNode::get_class_icon(const String &p_class, const String &p_f
if (icon.is_null()) {
icon = gui_base->get_icon(ScriptServer::get_global_class_base(name), "EditorIcons");
}
return icon;
}
const Map<String, Vector<EditorData::CustomType> > &p_map = EditorNode::get_editor_data().get_custom_types();