Merge pull request #45265 from KoBeWi/children_editing_2077

Change how editable children data is stored
This commit is contained in:
Rémi Verschelde 2021-01-18 12:30:38 +01:00 committed by GitHub
commit 5496174dd4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 19 deletions

View File

@ -2140,7 +2140,6 @@ void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_prop
if (n == edited_scene) { if (n == edited_scene) {
edited_scene = newnode; edited_scene = newnode;
editor->set_edited_scene(newnode); editor->set_edited_scene(newnode);
newnode->set_editable_instances(n->get_editable_instances());
} }
//small hack to make collisionshapes and other kind of nodes to work //small hack to make collisionshapes and other kind of nodes to work

View File

@ -1920,32 +1920,22 @@ String Node::get_editor_description() const {
void Node::set_editable_instance(Node *p_node, bool p_editable) { void Node::set_editable_instance(Node *p_node, bool p_editable) {
ERR_FAIL_NULL(p_node); ERR_FAIL_NULL(p_node);
ERR_FAIL_COND(!is_a_parent_of(p_node)); ERR_FAIL_COND(!is_a_parent_of(p_node));
NodePath p = get_path_to(p_node);
if (!p_editable) { if (!p_editable) {
data.editable_instances.erase(p); p_node->data.editable_instance = false;
// Avoid this flag being needlessly saved; // Avoid this flag being needlessly saved;
// also give more visual feedback if editable children is re-enabled // also give more visual feedback if editable children is re-enabled
set_display_folded(false); set_display_folded(false);
} else { } else {
data.editable_instances[p] = true; p_node->data.editable_instance = true;
} }
} }
bool Node::is_editable_instance(const Node *p_node) const { bool Node::is_editable_instance(const Node *p_node) const {
if (!p_node) { if (!p_node) {
return false; //easier, null is never editable :) return false; // Easier, null is never editable. :)
} }
ERR_FAIL_COND_V(!is_a_parent_of(p_node), false); ERR_FAIL_COND_V(!is_a_parent_of(p_node), false);
NodePath p = get_path_to(p_node); return p_node->data.editable_instance;
return data.editable_instances.has(p);
}
void Node::set_editable_instances(const HashMap<NodePath, int> &p_editable_instances) {
data.editable_instances = p_editable_instances;
}
HashMap<NodePath, int> Node::get_editable_instances() const {
return data.editable_instances;
} }
void Node::set_scene_instance_state(const Ref<SceneState> &p_state) { void Node::set_scene_instance_state(const Ref<SceneState> &p_state) {

View File

@ -88,8 +88,6 @@ private:
Ref<SceneState> instance_state; Ref<SceneState> instance_state;
Ref<SceneState> inherited_state; Ref<SceneState> inherited_state;
HashMap<NodePath, int> editable_instances;
Node *parent = nullptr; Node *parent = nullptr;
Node *owner = nullptr; Node *owner = nullptr;
Vector<Node *> children; Vector<Node *> children;
@ -136,6 +134,7 @@ private:
bool use_placeholder = false; bool use_placeholder = false;
bool display_folded = false; bool display_folded = false;
bool editable_instance = false;
mutable NodePath *path_cache = nullptr; mutable NodePath *path_cache = nullptr;
@ -325,8 +324,6 @@ public:
void set_editable_instance(Node *p_node, bool p_editable); void set_editable_instance(Node *p_node, bool p_editable);
bool is_editable_instance(const Node *p_node) const; bool is_editable_instance(const Node *p_node) const;
void set_editable_instances(const HashMap<NodePath, int> &p_editable_instances);
HashMap<NodePath, int> get_editable_instances() const;
/* NOTIFICATIONS */ /* NOTIFICATIONS */