diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_inspector.cpp | 112 | ||||
-rw-r--r-- | editor/editor_inspector.h | 17 | ||||
-rw-r--r-- | editor/editor_node.cpp | 4 | ||||
-rw-r--r-- | editor/editor_node.h | 1 |
4 files changed, 31 insertions, 103 deletions
diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 75b364089d..8be4a118e6 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -36,50 +36,6 @@ #include "multi_node_edit.h" #include "scene/resources/packed_scene.h" -EditorDefaultClassValueCache *EditorDefaultClassValueCache::singleton = NULL; - -EditorDefaultClassValueCache *EditorDefaultClassValueCache::get_singleton() { - return singleton; -} - -Variant EditorDefaultClassValueCache::get_default_value(const StringName &p_class, const StringName &p_property) { - - if (!default_values.has(p_class)) { - - default_values[p_class] = Map<StringName, Variant>(); - - if (ClassDB::can_instance(p_class)) { - - Object *c = ClassDB::instance(p_class); - List<PropertyInfo> plist; - c->get_property_list(&plist); - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (E->get().usage & PROPERTY_USAGE_EDITOR) { - - Variant v = c->get(E->get().name); - default_values[p_class][E->get().name] = v; - } - } - memdelete(c); - } - } - - if (!default_values.has(p_class)) { - return Variant(); - } - - if (!default_values[p_class].has(p_property)) { - return Variant(); - } - - return default_values[p_class][p_property]; -} - -EditorDefaultClassValueCache::EditorDefaultClassValueCache() { - ERR_FAIL_COND(singleton != NULL); - singleton = this; -} - Size2 EditorProperty::get_minimum_size() const { Size2 ms; @@ -418,14 +374,24 @@ bool EditorProperty::_get_instanced_node_original_property(const StringName &p_p node = node->get_owner(); } + if (!found) { + //if not found, try default class value + Variant attempt = ClassDB::class_get_default_property_value(object->get_class_name(), property); + if (attempt.get_type() != Variant::NIL) { + found = true; + value = attempt; + } + } + return found; } -bool EditorProperty::_is_property_different(const Variant &p_current, const Variant &p_orig, int p_usage) { +bool EditorProperty::_is_property_different(const Variant &p_current, const Variant &p_orig) { // this is a pretty difficult function, because a property may not be saved but may have // the flag to not save if one or if zero + //make sure there is an actual state { Node *node = Object::cast_to<Node>(object); if (!node) @@ -459,15 +425,6 @@ bool EditorProperty::_is_property_different(const Variant &p_current, const Vari return false; //pointless to check if we are not comparing against anything. } - if (p_orig.get_type() == Variant::NIL) { - // not found (was not saved) - // check if it was not saved due to being zero or one - if (p_current.is_zero() && property_usage & PROPERTY_USAGE_STORE_IF_NONZERO) - return false; - if (p_current.is_one() && property_usage & PROPERTY_USAGE_STORE_IF_NONONE) - return false; - } - if (p_current.get_type() == Variant::REAL && p_orig.get_type() == Variant::REAL) { float a = p_current; float b = p_orig; @@ -478,23 +435,6 @@ bool EditorProperty::_is_property_different(const Variant &p_current, const Vari return bool(Variant::evaluate(Variant::OP_NOT_EQUAL, p_current, p_orig)); } -bool EditorProperty::_is_instanced_node_with_original_property_different() { - - bool mbi = _might_be_in_instance(); - if (mbi) { - Variant vorig; - int usage = property_usage & (PROPERTY_USAGE_STORE_IF_NONONE | PROPERTY_USAGE_STORE_IF_NONZERO); - if (_get_instanced_node_original_property(property, vorig) || usage) { - Variant v = object->get(property); - - if (_is_property_different(v, vorig, usage)) { - return true; - } - } - } - return false; -} - void EditorProperty::update_reload_status() { if (property == StringName()) @@ -502,15 +442,23 @@ void EditorProperty::update_reload_status() { bool has_reload = false; - if (EditorDefaultClassValueCache::get_singleton()) { - Variant default_value = EditorDefaultClassValueCache::get_singleton()->get_default_value(object->get_class_name(), property); + if (_might_be_in_instance()) { + //check for difference including instantiation + Variant vorig; + if (_get_instanced_node_original_property(property, vorig)) { + Variant v = object->get(property); + + if (_is_property_different(v, vorig)) { + has_reload = true; + } + } + } else { + //check for difference against default class value instead + Variant default_value = ClassDB::class_get_default_property_value(object->get_class_name(), property); if (default_value != Variant() && default_value != object->get(property)) { has_reload = true; } } - if (_is_instanced_node_with_original_property_different()) { - has_reload = true; - } if (object->call("property_can_revert", property).operator bool()) { @@ -714,13 +662,11 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { } } - if (EditorDefaultClassValueCache::get_singleton()) { - Variant default_value = EditorDefaultClassValueCache::get_singleton()->get_default_value(object->get_class_name(), property); - if (default_value != Variant()) { - emit_signal("property_changed", property, default_value); - update_property(); - return; - } + Variant default_value = ClassDB::class_get_default_property_value(object->get_class_name(), property); + if (default_value != Variant()) { + emit_signal("property_changed", property, default_value); + update_property(); + return; } } if (check_rect.has_point(mb->get_position())) { diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 350debcb7b..57d1ab6fb3 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -37,20 +37,6 @@ class UndoRedo; -class EditorDefaultClassValueCache : public Object { - GDCLASS(EditorDefaultClassValueCache, Object) - - Map<StringName, Map<StringName, Variant> > default_values; - - static EditorDefaultClassValueCache *singleton; - -public: - static EditorDefaultClassValueCache *get_singleton(); - - Variant get_default_value(const StringName &p_class, const StringName &p_property); - EditorDefaultClassValueCache(); -}; - class EditorProperty : public Container { GDCLASS(EditorProperty, Container) @@ -85,8 +71,7 @@ private: bool draw_top_bg; bool _might_be_in_instance(); - bool _is_property_different(const Variant &p_current, const Variant &p_orig, int p_usage); - bool _is_instanced_node_with_original_property_different(); + bool _is_property_different(const Variant &p_current, const Variant &p_orig); bool _get_instanced_node_original_property(const StringName &p_prop, Variant &value); void _focusable_focused(int p_index); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 81bcbd63a1..bc517933ba 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4767,8 +4767,6 @@ EditorNode::EditorNode() { ResourceLoader::set_timestamp_on_load(true); ResourceSaver::set_timestamp_on_save(true); - default_value_cache = memnew(EditorDefaultClassValueCache); - { //register importers at the beginning, so dialogs are created with the right extensions Ref<ResourceImporterTexture> import_texture; import_texture.instance(); @@ -5897,7 +5895,7 @@ EditorNode::~EditorNode() { memdelete(editor_plugins_force_input_forwarding); memdelete(file_server); memdelete(progress_hb); - memdelete(default_value_cache); + EditorSettings::destroy(); } diff --git a/editor/editor_node.h b/editor/editor_node.h index 0b82555acf..b828a4d7d5 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -272,7 +272,6 @@ private: Ref<Theme> theme; - EditorDefaultClassValueCache *default_value_cache; PopupMenu *recent_scenes; SceneTreeDock *scene_tree_dock; InspectorDock *inspector_dock; |