diff options
Diffstat (limited to 'scene/2d/remote_transform_2d.cpp')
-rw-r--r-- | scene/2d/remote_transform_2d.cpp | 70 |
1 files changed, 32 insertions, 38 deletions
diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index ec50f5f922..fe3e867424 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -29,14 +29,12 @@ /*************************************************************************/ #include "remote_transform_2d.h" -#include "scene/scene_string_names.h" void RemoteTransform2D::_update_cache() { - cache = ObjectID(); if (has_node(remote_node)) { Node *node = get_node(remote_node); - if (!node || this == node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) { + if (!node || this == node || node->is_ancestor_of(this) || this->is_ancestor_of(node)) { return; } @@ -45,23 +43,25 @@ void RemoteTransform2D::_update_cache() { } void RemoteTransform2D::_update_remote() { - - if (!is_inside_tree()) + if (!is_inside_tree()) { return; + } - if (cache.is_null()) + if (cache.is_null()) { return; + } Node2D *n = Object::cast_to<Node2D>(ObjectDB::get_instance(cache)); - if (!n) + if (!n) { return; + } - if (!n->is_inside_tree()) + if (!n->is_inside_tree()) { return; + } //todo make faster if (use_global_coordinates) { - if (update_remote_position && update_remote_rotation && update_remote_scale) { n->set_global_transform(get_global_transform()); } else { @@ -69,21 +69,23 @@ void RemoteTransform2D::_update_remote() { Transform2D our_trans = get_global_transform(); Vector2 n_scale = n->get_scale(); - if (!update_remote_position) + if (!update_remote_position) { our_trans.set_origin(n_trans.get_origin()); - if (!update_remote_rotation) + } + if (!update_remote_rotation) { our_trans.set_rotation(n_trans.get_rotation()); + } n->set_global_transform(our_trans); - if (update_remote_scale) + if (update_remote_scale) { n->set_scale(get_global_scale()); - else + } else { n->set_scale(n_scale); + } } } else { - if (update_remote_position && update_remote_rotation && update_remote_scale) { n->set_transform(get_transform()); } else { @@ -91,36 +93,36 @@ void RemoteTransform2D::_update_remote() { Transform2D our_trans = get_transform(); Vector2 n_scale = n->get_scale(); - if (!update_remote_position) + if (!update_remote_position) { our_trans.set_origin(n_trans.get_origin()); - if (!update_remote_rotation) + } + if (!update_remote_rotation) { our_trans.set_rotation(n_trans.get_rotation()); + } n->set_transform(our_trans); - if (update_remote_scale) + if (update_remote_scale) { n->set_scale(get_scale()); - else + } else { n->set_scale(n_scale); + } } } } void RemoteTransform2D::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - _update_cache(); } break; case NOTIFICATION_TRANSFORM_CHANGED: { - if (!is_inside_tree()) + if (!is_inside_tree()) { break; + } if (cache.is_valid()) { - _update_remote(); } @@ -129,18 +131,16 @@ void RemoteTransform2D::_notification(int p_what) { } void RemoteTransform2D::set_remote_node(const NodePath &p_remote_node) { - remote_node = p_remote_node; if (is_inside_tree()) { _update_cache(); _update_remote(); } - update_configuration_warning(); + update_configuration_warnings(); } NodePath RemoteTransform2D::get_remote_node() const { - return remote_node; } @@ -184,17 +184,17 @@ void RemoteTransform2D::force_update_cache() { _update_cache(); } -String RemoteTransform2D::get_configuration_warning() const { +TypedArray<String> RemoteTransform2D::get_configuration_warnings() const { + TypedArray<String> warnings = Node::get_configuration_warnings(); if (!has_node(remote_node) || !Object::cast_to<Node2D>(get_node(remote_node))) { - return TTR("Path property must point to a valid Node2D node to work."); + warnings.push_back(TTR("Path property must point to a valid Node2D node to work.")); } - return String(); + return warnings; } void RemoteTransform2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_remote_node", "path"), &RemoteTransform2D::set_remote_node); ClassDB::bind_method(D_METHOD("get_remote_node"), &RemoteTransform2D::get_remote_node); ClassDB::bind_method(D_METHOD("force_update_cache"), &RemoteTransform2D::force_update_cache); @@ -219,11 +219,5 @@ void RemoteTransform2D::_bind_methods() { } RemoteTransform2D::RemoteTransform2D() { - - use_global_coordinates = true; - update_remote_position = true; - update_remote_rotation = true; - update_remote_scale = true; - set_notify_transform(true); } |