From c1023157eb761efcda07c3fa2015517b8a3621e1 Mon Sep 17 00:00:00 2001 From: Tomasz Chabora Date: Mon, 6 Apr 2020 01:06:10 +0200 Subject: [PATCH] Remove Node.get_position_in_parent() --- doc/classes/Node.xml | 9 +-------- editor/editor_properties.cpp | 2 +- editor/plugins/script_editor_plugin.cpp | 2 +- editor/property_editor.cpp | 2 +- editor/scene_tree_dock.cpp | 6 +++--- modules/visual_script/visual_script_editor.cpp | 2 +- scene/gui/control.cpp | 4 ++-- scene/main/canvas_layer.cpp | 8 ++++---- scene/main/instance_placeholder.cpp | 2 +- scene/main/node.cpp | 11 +++-------- scene/main/node.h | 2 -- 11 files changed, 18 insertions(+), 32 deletions(-) diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index d7bff83575ef..8c588f037369 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -238,7 +238,7 @@ - Returns the node's index, i.e. its position among the siblings of its parent. + Returns the node's order in the scene tree branch. For example, if called on the first child node the position is [code]0[/code]. @@ -331,13 +331,6 @@ Returns the time elapsed since the last physics-bound frame (see [method _physics_process]). This is always a constant value in physics processing unless the frames per second is changed via [member Engine.iterations_per_second]. - - - - - Returns the node's order in the scene tree branch. For example, if called on the first child node the position is [code]0[/code]. - - diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 1f3ff1b33255..cf478f20e565 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -2196,7 +2196,7 @@ void EditorPropertyResource::_menu_option(int p_which) { file_system_dock->navigate_to_path(res->get_path()); // Ensure that the FileSystem dock is visible. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control(); - tab_container->set_current_tab(file_system_dock->get_position_in_parent()); + tab_container->set_current_tab(file_system_dock->get_index()); } break; default: { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index dd80fff0087c..0b97ade27815 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -1243,7 +1243,7 @@ void ScriptEditor::_menu_option(int p_option) { file_system_dock->navigate_to_path(path); // Ensure that the FileSystem dock is visible. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control(); - tab_container->set_current_tab(file_system_dock->get_position_in_parent()); + tab_container->set_current_tab(file_system_dock->get_index()); } } break; case CLOSE_DOCS: { diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 444cae42c511..978c95b9c8eb 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -257,7 +257,7 @@ void CustomPropertyEditor::_menu_option(int p_which) { file_system_dock->navigate_to_path(r->get_path()); // Ensure that the FileSystem dock is visible. TabContainer *tab_container = (TabContainer *)file_system_dock->get_parent_control(); - tab_container->set_current_tab(file_system_dock->get_position_in_parent()); + tab_container->set_current_tab(file_system_dock->get_index()); } break; default: { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index eaefd04c6baf..a729f6212303 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -1535,7 +1535,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V if (p_nodes[ni] == p_new_parent) return; // Attempt to reparent to itself. - if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_position_in_parent()) + if (p_nodes[ni]->get_parent() != p_new_parent || p_position_in_parent + ni != p_nodes[ni]->get_index()) no_change = false; } @@ -1644,7 +1644,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V owners.push_back(E->get()); } - int child_pos = node->get_position_in_parent(); + int child_pos = node->get_index(); editor_data->get_undo_redo().add_undo_method(node->get_parent(), "add_child", node); editor_data->get_undo_redo().add_undo_method(node->get_parent(), "move_child", node, child_pos); @@ -1918,7 +1918,7 @@ Node *SceneTreeDock::_get_selection_group_tail(Node *p_node, List p_list Node *tail = p_node; Node *parent = tail->get_parent(); - for (int i = p_node->get_position_in_parent(); i < parent->get_child_count(); i++) { + for (int i = p_node->get_index(); i < parent->get_child_count(); i++) { Node *sibling = parent->get_child(i); if (p_list.find(sibling)) diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 30522930c7af..ab528fac3068 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -1262,7 +1262,7 @@ void VisualScriptEditor::_add_func_input() { } func_input_vbox->add_child(hbox); - hbox->set_meta("id", hbox->get_position_in_parent()); + hbox->set_meta("id", hbox->get_index()); delete_button->connect("pressed", callable_mp(this, &VisualScriptEditor::_remove_func_input), varray(hbox)); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 775f863a4fdd..b4dc37c74fba 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1893,7 +1893,7 @@ static Control *_next_control(Control *p_from) { return nullptr; } - int next = p_from->get_position_in_parent(); + int next = p_from->get_index(); ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr); for (int i = (next + 1); i < parent->get_child_count(); i++) { @@ -2032,7 +2032,7 @@ Control *Control::find_prev_valid_focus() const { } else { - for (int i = (from->get_position_in_parent() - 1); i >= 0; i--) { + for (int i = (from->get_index() - 1); i >= 0; i--) { Control *c = Object::cast_to(from->get_parent()->get_child(i)); diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index 15f64390de1c..c1caa943e3a4 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -35,7 +35,7 @@ void CanvasLayer::set_layer(int p_xform) { layer = p_xform; if (viewport.is_valid()) - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); } int CanvasLayer::get_layer() const { @@ -151,7 +151,7 @@ void CanvasLayer::_notification(int p_what) { viewport = vp->get_viewport_rid(); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); _update_follow_viewport(); @@ -167,7 +167,7 @@ void CanvasLayer::_notification(int p_what) { case NOTIFICATION_MOVED_IN_PARENT: { if (is_inside_tree()) - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); } break; } @@ -214,7 +214,7 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) { viewport = vp->get_viewport_rid(); RenderingServer::get_singleton()->viewport_attach_canvas(viewport, canvas); - RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_position_in_parent()); + RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index()); RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform); } } diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index 78958a7a1c6d..062b221c84ac 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -95,7 +95,7 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Refset_name(get_name()); - int pos = get_position_in_parent(); + int pos = get_index(); for (List::Element *E = stored_values.front(); E; E = E->next()) { scene->set(E->get().name, E->get().value); diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 6b46ffd8ad51..50f3bf834f34 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -1268,7 +1268,7 @@ void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_uniq add_child(p_child, p_legible_unique_name); if (is_a_parent_of(p_node)) { - move_child(p_child, p_node->get_position_in_parent() + 1); + move_child(p_child, p_node->get_index() + 1); } else { WARN_PRINT("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent."); } @@ -1918,6 +1918,7 @@ int Node::get_index() const { return data.pos; } + void Node::remove_and_skip() { ERR_FAIL_COND(!data.parent); @@ -2042,11 +2043,6 @@ bool Node::get_scene_instance_load_placeholder() const { return data.use_placeholder; } -int Node::get_position_in_parent() const { - - return data.pos; -} - Node *Node::_duplicate(int p_flags, Map *r_duplimap) const { Node *node = nullptr; @@ -2215,7 +2211,7 @@ Node *Node::_duplicate(int p_flags, Map *r_duplimap) const } parent->add_child(dup); - int pos = E->get()->get_position_in_parent(); + int pos = E->get()->get_index(); if (pos < parent->get_child_count() - 1) { @@ -2860,7 +2856,6 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("get_pause_mode"), &Node::get_pause_mode); ClassDB::bind_method(D_METHOD("can_process"), &Node::can_process); ClassDB::bind_method(D_METHOD("print_stray_nodes"), &Node::_print_stray_nodes); - ClassDB::bind_method(D_METHOD("get_position_in_parent"), &Node::get_position_in_parent); ClassDB::bind_method(D_METHOD("set_display_folded", "fold"), &Node::set_display_folded); ClassDB::bind_method(D_METHOD("is_displayed_folded"), &Node::is_displayed_folded); diff --git a/scene/main/node.h b/scene/main/node.h index 292ec0e29137..5de07d506e80 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -369,8 +369,6 @@ class Node : public Object { void set_process_unhandled_key_input(bool p_enable); bool is_processing_unhandled_key_input() const; - int get_position_in_parent() const; - Node *duplicate(int p_flags = DUPLICATE_GROUPS | DUPLICATE_SIGNALS | DUPLICATE_SCRIPTS) const; Node *duplicate_and_reown(const Map &p_reown_map) const; #ifdef TOOLS_ENABLED