summaryrefslogtreecommitdiff
path: root/editor/editor_inspector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/editor_inspector.cpp')
-rw-r--r--editor/editor_inspector.cpp257
1 files changed, 117 insertions, 140 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp
index b9245fba80..4a3413d9ef 100644
--- a/editor/editor_inspector.cpp
+++ b/editor/editor_inspector.cpp
@@ -493,6 +493,7 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian
if (ss.is_valid()) {
found_state = true;
+ break;
}
if (node == edited_scene) {
//just in case
@@ -506,59 +507,71 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian
}
}
- if (p_current.get_type() == Variant::FLOAT && p_orig.get_type() == Variant::FLOAT) {
- float a = p_current;
- float b = p_orig;
+ return is_property_value_different(p_current, p_orig);
+}
- return !Math::is_equal_approx(a, b); //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error
+bool EditorPropertyRevert::is_property_value_different(const Variant &p_a, const Variant &p_b) {
+ if (p_a.get_type() == Variant::FLOAT && p_b.get_type() == Variant::FLOAT) {
+ //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error
+ return !Math::is_equal_approx((float)p_a, (float)p_b);
+ } else {
+ return p_a != p_b;
}
-
- return bool(Variant::evaluate(Variant::OP_NOT_EQUAL, p_current, p_orig));
}
-bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) {
- bool has_revert = false;
+Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property) {
+ // If the object implements property_can_revert, rely on that completely
+ // (i.e. don't then try to revert to default value - the property_get_revert implementation
+ // can do that if so desired)
+ if (p_object->has_method("property_can_revert") && p_object->call("property_can_revert", p_property)) {
+ return p_object->call("property_get_revert", p_property);
+ }
+ Ref<Script> scr = p_object->get_script();
Node *node = Object::cast_to<Node>(p_object);
-
if (node && EditorPropertyRevert::may_node_be_in_instance(node)) {
- //check for difference including instantiation
- Variant vorig;
- if (EditorPropertyRevert::get_instantiated_node_original_property(node, p_property, vorig)) {
- Variant v = p_object->get(p_property);
-
- if (EditorPropertyRevert::is_node_property_different(node, v, vorig)) {
- has_revert = true;
+ //if this node is an instance or inherits, but it has a script attached which is unrelated
+ //to the one set for the parent and also has a default value for the property, consider that
+ //has precedence over the value from the parent, because that is an explicit source of defaults
+ //closer in the tree to the current node
+ bool ignore_parent = false;
+ if (scr.is_valid()) {
+ Variant sorig;
+ if (EditorPropertyRevert::get_instantiated_node_original_property(node, "script", sorig) && !scr->inherits_script(sorig)) {
+ Variant dummy;
+ if (scr->get_property_default_value(p_property, dummy)) {
+ ignore_parent = true;
+ }
}
}
- } else {
- //check for difference against default class value instead
- Variant default_value = ClassDB::class_get_default_property_value(p_object->get_class_name(), p_property);
- if (default_value != Variant() && default_value != p_object->get(p_property)) {
- has_revert = true;
+
+ if (!ignore_parent) {
+ //check for difference including instantiation
+ Variant vorig;
+ if (EditorPropertyRevert::get_instantiated_node_original_property(node, p_property, vorig)) {
+ return vorig;
+ }
}
}
- // If the object implements property_can_revert, rely on that completely
- // (i.e. don't then try to revert to default value - the property_get_revert implementation
- // can do that if so desired)
- if (p_object->has_method("property_can_revert")) {
- has_revert = p_object->call("property_can_revert", p_property).operator bool();
- } else {
- if (!has_revert && !p_object->get_script().is_null()) {
- Ref<Script> scr = p_object->get_script();
- if (scr.is_valid()) {
- Variant orig_value;
- if (scr->get_property_default_value(p_property, orig_value)) {
- if (orig_value != p_object->get(p_property)) {
- has_revert = true;
- }
- }
- }
+ if (scr.is_valid()) {
+ Variant orig_value;
+ if (scr->get_property_default_value(p_property, orig_value)) {
+ return orig_value;
}
}
- return has_revert;
+ //report default class value instead
+ return ClassDB::class_get_default_property_value(p_object->get_class_name(), p_property);
+}
+
+bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) {
+ Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property);
+ if (revert_value.get_type() == Variant::NIL) {
+ return false;
+ }
+ Variant current_value = p_object->get(p_property);
+ return EditorPropertyRevert::is_property_value_different(current_value, revert_value);
}
void EditorProperty::update_reload_status() {
@@ -761,41 +774,11 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) {
}
if (revert_rect.has_point(mpos)) {
- Variant vorig;
-
- Node *node = Object::cast_to<Node>(object);
- if (node && EditorPropertyRevert::may_node_be_in_instance(node) && EditorPropertyRevert::get_instantiated_node_original_property(node, property, vorig)) {
- emit_changed(property, vorig.duplicate(true));
- update_property();
- return;
- }
-
- if (object->call("property_can_revert", property).operator bool()) {
- Variant rev = object->call("property_get_revert", property);
- emit_changed(property, rev);
- update_property();
- return;
- }
-
- if (!object->get_script().is_null()) {
- Ref<Script> scr = object->get_script();
- if (scr.is_valid()) {
- Variant orig_value;
- if (scr->get_property_default_value(property, orig_value)) {
- emit_changed(property, orig_value);
- update_property();
- return;
- }
- }
- }
-
- Variant default_value = ClassDB::class_get_default_property_value(object->get_class_name(), property);
- if (default_value != Variant()) {
- emit_changed(property, default_value);
- update_property();
- return;
- }
+ Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property);
+ emit_changed(property, revert_value);
+ update_property();
}
+
if (check_rect.has_point(mpos)) {
checked = !checked;
update();
@@ -1508,9 +1491,9 @@ String EditorInspector::get_selected_path() const {
}
void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<EditorInspectorPlugin> ped) {
- for (List<EditorInspectorPlugin::AddedEditor>::Element *F = ped->added_editors.front(); F; F = F->next()) {
- EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor);
- current_vbox->add_child(F->get().property_editor);
+ for (const EditorInspectorPlugin::AddedEditor &F : ped->added_editors) {
+ EditorProperty *ep = Object::cast_to<EditorProperty>(F.property_editor);
+ current_vbox->add_child(F.property_editor);
if (ep) {
ep->object = object;
@@ -1524,19 +1507,19 @@ void EditorInspector::_parse_added_editors(VBoxContainer *current_vbox, Ref<Edit
ep->connect("resource_selected", callable_mp(this, &EditorInspector::_resource_selected), varray(), CONNECT_DEFERRED);
ep->connect("object_id_selected", callable_mp(this, &EditorInspector::_object_id_selected), varray(), CONNECT_DEFERRED);
- if (F->get().properties.size()) {
- if (F->get().properties.size() == 1) {
+ if (F.properties.size()) {
+ if (F.properties.size() == 1) {
//since it's one, associate:
- ep->property = F->get().properties[0];
+ ep->property = F.properties[0];
ep->property_usage = 0;
}
- if (F->get().label != String()) {
- ep->set_label(F->get().label);
+ if (F.label != String()) {
+ ep->set_label(F.label);
}
- for (int i = 0; i < F->get().properties.size(); i++) {
- String prop = F->get().properties[i];
+ for (int i = 0; i < F.properties.size(); i++) {
+ String prop = F.properties[i];
if (!editor_property_map.has(prop)) {
editor_property_map[prop] = List<EditorProperty *>();
@@ -1648,8 +1631,7 @@ void EditorInspector::update_tree() {
Color sscolor = get_theme_color(SNAME("prop_subsection"), SNAME("Editor"));
- for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) {
- Ref<EditorInspectorPlugin> ped = E->get();
+ for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
ped->parse_begin(object);
_parse_added_editors(main_vbox, ped);
}
@@ -1746,8 +1728,7 @@ void EditorInspector::update_tree() {
category->set_tooltip(p.name + "::" + (class_descr_cache[type2] == "" ? "" : class_descr_cache[type2]));
}
- for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) {
- Ref<EditorInspectorPlugin> ped = E->get();
+ for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
ped->parse_category(object, p.name);
_parse_added_editors(main_vbox, ped);
}
@@ -1948,36 +1929,35 @@ void EditorInspector::update_tree() {
doc_hint = descr;
}
- for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) {
- Ref<EditorInspectorPlugin> ped = E->get();
+ for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
bool exclusive = ped->parse_property(object, p.type, p.name, p.hint, p.hint_string, p.usage, wide_editors);
List<EditorInspectorPlugin::AddedEditor> editors = ped->added_editors; //make a copy, since plugins may be used again in a sub-inspector
ped->added_editors.clear();
- for (List<EditorInspectorPlugin::AddedEditor>::Element *F = editors.front(); F; F = F->next()) {
- EditorProperty *ep = Object::cast_to<EditorProperty>(F->get().property_editor);
+ for (const EditorInspectorPlugin::AddedEditor &F : editors) {
+ EditorProperty *ep = Object::cast_to<EditorProperty>(F.property_editor);
if (ep) {
//set all this before the control gets the ENTER_TREE notification
ep->object = object;
- if (F->get().properties.size()) {
- if (F->get().properties.size() == 1) {
+ if (F.properties.size()) {
+ if (F.properties.size() == 1) {
//since it's one, associate:
- ep->property = F->get().properties[0];
+ ep->property = F.properties[0];
ep->property_usage = p.usage;
//and set label?
}
- if (F->get().label != String()) {
- ep->set_label(F->get().label);
+ if (F.label != String()) {
+ ep->set_label(F.label);
} else {
- //use existin one
+ // Use the existing one.
ep->set_label(name);
}
- for (int i = 0; i < F->get().properties.size(); i++) {
- String prop = F->get().properties[i];
+ for (int i = 0; i < F.properties.size(); i++) {
+ String prop = F.properties[i];
if (!editor_property_map.has(prop)) {
editor_property_map[prop] = List<EditorProperty *>();
@@ -1995,7 +1975,7 @@ void EditorInspector::update_tree() {
ep->set_deletable(deletable_properties);
}
- current_vbox->add_child(F->get().property_editor);
+ current_vbox->add_child(F.property_editor);
if (ep) {
ep->connect("property_changed", callable_mp(this, &EditorInspector::_property_changed));
@@ -2031,8 +2011,7 @@ void EditorInspector::update_tree() {
}
}
- for (List<Ref<EditorInspectorPlugin>>::Element *E = valid_plugins.front(); E; E = E->next()) {
- Ref<EditorInspectorPlugin> ped = E->get();
+ for (Ref<EditorInspectorPlugin> &ped : valid_plugins) {
ped->parse_end();
_parse_added_editors(main_vbox, ped);
}
@@ -2045,10 +2024,10 @@ void EditorInspector::update_property(const String &p_prop) {
return;
}
- for (List<EditorProperty *>::Element *E = editor_property_map[p_prop].front(); E; E = E->next()) {
- E->get()->update_property();
- E->get()->update_reload_status();
- E->get()->update_cache();
+ for (EditorProperty *E : editor_property_map[p_prop]) {
+ E->update_property();
+ E->update_reload_status();
+ E->update_cache();
}
}
@@ -2157,24 +2136,24 @@ bool EditorInspector::is_using_folding() {
}
void EditorInspector::collapse_all_folding() {
- for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) {
- E->get()->fold();
+ for (EditorInspectorSection *E : sections) {
+ E->fold();
}
for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
- for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
- E->get()->collapse_all_folding();
+ for (EditorProperty *E : F->get()) {
+ E->collapse_all_folding();
}
}
}
void EditorInspector::expand_all_folding() {
- for (List<EditorInspectorSection *>::Element *E = sections.front(); E; E = E->next()) {
- E->get()->unfold();
+ for (EditorInspectorSection *E : sections) {
+ E->unfold();
}
for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
- for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
- E->get()->expand_all_folding();
+ for (EditorProperty *E : F->get()) {
+ E->expand_all_folding();
}
}
}
@@ -2239,9 +2218,9 @@ void EditorInspector::_edit_request_change(Object *p_object, const String &p_pro
void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bool p_refresh_all, const String &p_changed_field) {
if (autoclear && editor_property_map.has(p_name)) {
- for (List<EditorProperty *>::Element *E = editor_property_map[p_name].front(); E; E = E->next()) {
- if (E->get()->is_checkable()) {
- E->get()->set_checked(true);
+ for (EditorProperty *E : editor_property_map[p_name]) {
+ if (E->is_checkable()) {
+ E->set_checked(true);
}
}
}
@@ -2308,8 +2287,8 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo
}
if (editor_property_map.has(p_name)) {
- for (List<EditorProperty *>::Element *E = editor_property_map[p_name].front(); E; E = E->next()) {
- E->get()->update_reload_status();
+ for (EditorProperty *E : editor_property_map[p_name]) {
+ E->update_reload_status();
}
}
}
@@ -2367,7 +2346,6 @@ void EditorInspector::_property_keyed(const String &p_path, bool p_advance) {
}
void EditorInspector::_property_deleted(const String &p_path) {
- print_line("deleted pressed?");
if (!object) {
return;
}
@@ -2396,10 +2374,10 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) {
Variant to_create;
List<PropertyInfo> pinfo;
object->get_property_list(&pinfo);
- for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
- if (E->get().name == p_path) {
+ for (const PropertyInfo &E : pinfo) {
+ if (E.name == p_path) {
Callable::CallError ce;
- Variant::construct(E->get().type, to_create, nullptr, 0, ce);
+ Variant::construct(E.type, to_create, nullptr, 0, ce);
break;
}
}
@@ -2407,10 +2385,10 @@ void EditorInspector::_property_checked(const String &p_path, bool p_checked) {
}
if (editor_property_map.has(p_path)) {
- for (List<EditorProperty *>::Element *E = editor_property_map[p_path].front(); E; E = E->next()) {
- E->get()->update_property();
- E->get()->update_reload_status();
- E->get()->update_cache();
+ for (EditorProperty *E : editor_property_map[p_path]) {
+ E->update_property();
+ E->update_reload_status();
+ E->update_cache();
}
}
@@ -2427,9 +2405,9 @@ void EditorInspector::_property_selected(const String &p_path, int p_focusable)
if (F->key() == property_selected) {
continue;
}
- for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
- if (E->get()->is_selected()) {
- E->get()->deselect();
+ for (EditorProperty *E : F->get()) {
+ if (E->is_selected()) {
+ E->deselect();
}
}
}
@@ -2486,11 +2464,11 @@ void EditorInspector::_notification(int p_what) {
refresh_countdown -= get_process_delta_time();
if (refresh_countdown <= 0) {
for (Map<StringName, List<EditorProperty *>>::Element *F = editor_property_map.front(); F; F = F->next()) {
- for (List<EditorProperty *>::Element *E = F->get().front(); E; E = E->next()) {
- if (!E->get()->is_cache_valid()) {
- E->get()->update_property();
- E->get()->update_reload_status();
- E->get()->update_cache();
+ for (EditorProperty *E : F->get()) {
+ if (!E->is_cache_valid()) {
+ E->update_property();
+ E->update_reload_status();
+ E->update_cache();
}
}
}
@@ -2509,10 +2487,10 @@ void EditorInspector::_notification(int p_what) {
while (pending.size()) {
StringName prop = pending.front()->get();
if (editor_property_map.has(prop)) {
- for (List<EditorProperty *>::Element *E = editor_property_map[prop].front(); E; E = E->next()) {
- E->get()->update_property();
- E->get()->update_reload_status();
- E->get()->update_cache();
+ for (EditorProperty *E : editor_property_map[prop]) {
+ E->update_property();
+ E->update_reload_status();
+ E->update_cache();
}
}
pending.erase(pending.front());
@@ -2600,8 +2578,7 @@ void EditorInspector::_update_script_class_properties(const Object &p_object, Li
}
Set<StringName> added;
- for (List<Ref<Script>>::Element *E = classes.front(); E; E = E->next()) {
- Ref<Script> s = E->get();
+ for (const Ref<Script> &s : classes) {
String path = s->get_path();
String name = EditorNode::get_editor_data().script_class_get_name(path);
if (name.is_empty()) {