Skip to content

Commit

Permalink
Remove Node.get_position_in_parent()
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Apr 5, 2020
1 parent 4a0e99f commit c102315
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 32 deletions.
9 changes: 1 addition & 8 deletions doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@
<return type="int">
</return>
<description>
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].
</description>
</method>
<method name="get_network_master" qualifiers="const">
Expand Down Expand Up @@ -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].
</description>
</method>
<method name="get_position_in_parent" qualifiers="const">
<return type="int">
</return>
<description>
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].
</description>
</method>
<method name="get_process_delta_time" qualifiers="const">
<return type="float">
</return>
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {

Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/script_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion editor/property_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: {

Expand Down
6 changes: 3 additions & 3 deletions editor/scene_tree_dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1918,7 +1918,7 @@ Node *SceneTreeDock::_get_selection_group_tail(Node *p_node, List<Node *> 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))
Expand Down
2 changes: 1 addition & 1 deletion modules/visual_script/visual_script_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
4 changes: 2 additions & 2 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {

Expand Down Expand Up @@ -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<Control>(from->get_parent()->get_child(i));

Expand Down
8 changes: 4 additions & 4 deletions scene/main/canvas_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();

Expand All @@ -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;
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion scene/main/instance_placeholder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ Node *InstancePlaceholder::create_instance(bool p_replace, const Ref<PackedScene
if (!scene)
return nullptr;
scene->set_name(get_name());
int pos = get_position_in_parent();
int pos = get_index();

for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) {
scene->set(E->get().name, E->get().value);
Expand Down
11 changes: 3 additions & 8 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down Expand Up @@ -1918,6 +1918,7 @@ int Node::get_index() const {

return data.pos;
}

void Node::remove_and_skip() {

ERR_FAIL_COND(!data.parent);
Expand Down Expand Up @@ -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<const Node *, Node *> *r_duplimap) const {

Node *node = nullptr;
Expand Down Expand Up @@ -2215,7 +2211,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *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) {

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions scene/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Node *, Node *> &p_reown_map) const;
#ifdef TOOLS_ENABLED
Expand Down

0 comments on commit c102315

Please sign in to comment.