Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose Node.is_part_of_edited_scene() #85515

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,12 @@
[method request_ready] resets it back to [code]false[/code].
</description>
</method>
<method name="is_part_of_edited_scene" qualifiers="const">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is_part_of_edited_scene and not is_inside_edited_scene? I mean, I kind of get why, but it does not quite roll off the tongue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk, IMO this name is fine.
Also the method was changed a bit to include siblings of the scene, so is_inside_edited_scene() would be less accurate.

<return type="bool" />
<description>
Returns [code]true[/code] if the node is part of the scene currently opened in the editor.
</description>
</method>
<method name="is_physics_interpolated" qualifiers="const">
<return type="bool" />
<description>
Expand Down
8 changes: 4 additions & 4 deletions scene/2d/audio_listener_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool AudioListener2D::_set(const StringName &p_name, const Variant &p_value) {

bool AudioListener2D::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name == "current") {
if (is_inside_tree() && get_tree()->is_node_being_edited(this)) {
if (is_part_of_edited_scene()) {
r_ret = current;
} else {
r_ret = is_current();
Expand All @@ -63,13 +63,13 @@ void AudioListener2D::_get_property_list(List<PropertyInfo> *p_list) const {
void AudioListener2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (!get_tree()->is_node_being_edited(this) && current) {
if (!is_part_of_edited_scene() && current) {
make_current();
}
} break;

case NOTIFICATION_EXIT_TREE: {
if (!get_tree()->is_node_being_edited(this)) {
if (!is_part_of_edited_scene()) {
if (is_current()) {
clear_current();
current = true; // Keep it true.
Expand Down Expand Up @@ -98,7 +98,7 @@ void AudioListener2D::clear_current() {
}

bool AudioListener2D::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
if (is_inside_tree() && !is_part_of_edited_scene()) {
return get_viewport()->get_audio_listener_2d() == this;
} else {
return current;
Expand Down
8 changes: 4 additions & 4 deletions scene/3d/audio_listener_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bool AudioListener3D::_set(const StringName &p_name, const Variant &p_value) {

bool AudioListener3D::_get(const StringName &p_name, Variant &r_ret) const {
if (p_name == "current") {
if (is_inside_tree() && get_tree()->is_node_being_edited(this)) {
if (is_part_of_edited_scene()) {
r_ret = current;
} else {
r_ret = is_current();
Expand All @@ -81,7 +81,7 @@ void AudioListener3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
bool first_listener = get_viewport()->_audio_listener_3d_add(this);
if (!get_tree()->is_node_being_edited(this) && (current || first_listener)) {
if (!is_part_of_edited_scene() && (current || first_listener)) {
make_current();
}
} break;
Expand All @@ -91,7 +91,7 @@ void AudioListener3D::_notification(int p_what) {
} break;

case NOTIFICATION_EXIT_WORLD: {
if (!get_tree()->is_node_being_edited(this)) {
if (!is_part_of_edited_scene()) {
if (is_current()) {
clear_current();
current = true; //keep it true
Expand Down Expand Up @@ -133,7 +133,7 @@ void AudioListener3D::clear_current() {
}

bool AudioListener3D::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
if (is_inside_tree() && !is_part_of_edited_scene()) {
return get_viewport()->get_audio_listener_3d() == this;
} else {
return current;
Expand Down
6 changes: 3 additions & 3 deletions scene/3d/camera_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void Camera3D::_update_camera() {

RenderingServer::get_singleton()->camera_set_transform(camera, get_camera_transform());

if (get_tree()->is_node_being_edited(this) || !is_current()) {
if (is_part_of_edited_scene() || !is_current()) {
return;
}

Expand Down Expand Up @@ -126,7 +126,7 @@ void Camera3D::_notification(int p_what) {
} break;

case NOTIFICATION_EXIT_WORLD: {
if (!get_tree()->is_node_being_edited(this)) {
if (!is_part_of_edited_scene()) {
if (is_current()) {
clear_current();
current = true; //keep it true
Expand Down Expand Up @@ -286,7 +286,7 @@ void Camera3D::set_current(bool p_enabled) {
}

bool Camera3D::is_current() const {
if (is_inside_tree() && !get_tree()->is_node_being_edited(this)) {
if (is_inside_tree() && !is_part_of_edited_scene()) {
return get_viewport()->get_camera_3d() == this;
} else {
return current;
Expand Down
6 changes: 3 additions & 3 deletions scene/3d/node_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void Node3D::_notification(int p_what) {
}

#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
if (is_part_of_edited_scene()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SNAME("_request_gizmo_for_id"), get_instance_id());
}
#endif
Expand Down Expand Up @@ -582,7 +582,7 @@ void Node3D::set_subgizmo_selection(Ref<Node3DGizmo> p_gizmo, int p_id, Transfor
return;
}

if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
if (is_part_of_edited_scene()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_set_subgizmo_selection, this, p_gizmo, p_id, p_transform);
}
#endif
Expand All @@ -599,7 +599,7 @@ void Node3D::clear_subgizmo_selection() {
return;
}

if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
if (is_part_of_edited_scene()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_clear_subgizmo_selection, this);
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/file_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void FileDialog::_focus_file_text() {
int lp = file->get_text().rfind(".");
if (lp != -1) {
file->select(0, lp);
if (file->is_inside_tree() && !get_tree()->is_node_being_edited(file)) {
if (file->is_inside_tree() && !is_part_of_edited_scene()) {
file->grab_focus();
}
}
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/line_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ void LineEdit::_notification(int p_what) {
switch (p_what) {
#ifdef TOOLS_ENABLED
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint() && !get_tree()->is_node_being_edited(this)) {
if (Engine::get_singleton()->is_editor_hint() && !is_part_of_edited_scene()) {
set_caret_blink_enabled(EDITOR_GET("text_editor/appearance/caret/caret_blink"));
set_caret_blink_interval(EDITOR_GET("text_editor/appearance/caret/caret_blink_interval"));

Expand Down
1 change: 1 addition & 0 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3520,6 +3520,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_node_and_resource", "path"), &Node::_get_node_and_resource);

ClassDB::bind_method(D_METHOD("is_inside_tree"), &Node::is_inside_tree);
ClassDB::bind_method(D_METHOD("is_part_of_edited_scene"), &Node::is_part_of_edited_scene);
ClassDB::bind_method(D_METHOD("is_ancestor_of", "node"), &Node::is_ancestor_of);
ClassDB::bind_method(D_METHOD("is_greater_than", "node"), &Node::is_greater_than);
ClassDB::bind_method(D_METHOD("get_path"), &Node::get_path);
Expand Down
2 changes: 2 additions & 0 deletions scene/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ class Node : public Object {
bool is_property_pinned(const StringName &p_property) const;
virtual StringName get_property_store_alias(const StringName &p_property) const;
bool is_part_of_edited_scene() const;
#else
bool is_part_of_edited_scene() const { return false; }
#endif
void get_storable_properties(HashSet<StringName> &r_storable_properties) const;

Expand Down
7 changes: 0 additions & 7 deletions scene/main/scene_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,6 @@ void SceneTree::set_quit_on_go_back(bool p_enable) {
quit_on_go_back = p_enable;
}

#ifdef TOOLS_ENABLED

bool SceneTree::is_node_being_edited(const Node *p_node) const {
return Engine::get_singleton()->is_editor_hint() && edited_scene_root && (edited_scene_root->is_ancestor_of(p_node) || edited_scene_root == p_node);
}
#endif

#ifdef DEBUG_ENABLED
void SceneTree::set_debug_collisions_hint(bool p_enabled) {
debug_collisions_hint = p_enabled;
Expand Down
6 changes: 0 additions & 6 deletions scene/main/scene_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,6 @@ class SceneTree : public MainLoop {
_FORCE_INLINE_ double get_physics_process_time() const { return physics_process_time; }
_FORCE_INLINE_ double get_process_time() const { return process_time; }

#ifdef TOOLS_ENABLED
bool is_node_being_edited(const Node *p_node) const;
#else
bool is_node_being_edited(const Node *p_node) const { return false; }
#endif

void set_pause(bool p_enabled);
bool is_paused() const;

Expand Down
Loading