Skip to content

Commit

Permalink
[TODO AMEND] Move _get_node_configuration_warnings into `SceneTreeE…
Browse files Browse the repository at this point in the history
…ditor`

Will be amended to the other commits once the discussion regarding
this change is resolved. Until then, I'd like to have it easily revertable.
  • Loading branch information
RedMser committed Jan 22, 2025
1 parent 649e3c0 commit 7fb441d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 22 deletions.
21 changes: 0 additions & 21 deletions editor/gui/scene_tree_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,6 @@ Node *SceneTreeEditor::get_scene_node() const {
return get_tree()->get_edited_scene_root();
}

PackedStringArray SceneTreeEditor::_get_node_configuration_warnings(Node *p_node) {
PackedStringArray warnings = p_node->get_configuration_warnings();
if (p_node == get_scene_node()) {
Node2D *node_2d = Object::cast_to<Node2D>(p_node);
if (node_2d) {
// Note: Warn for Node2D but not all CanvasItems, don't warn for Control nodes.
// Control nodes may have reasons to use a transformed root node like anchors.
if (!node_2d->get_transform().is_equal_approx(Transform2D())) {
warnings.append(TTR("The root node of a scene is recommended to not be transformed, since instances of the scene will usually override this. Reset the transform and reload the scene to remove this warning."));
}
}
Node3D *node_3d = Object::cast_to<Node3D>(p_node);
if (node_3d) {
if (!node_3d->get_transform().is_equal_approx(Transform3D())) {
warnings.append(TTR("The root node of a scene is recommended to not be transformed, since instances of the scene will usually override this. Reset the transform and reload the scene to remove this warning."));
}
}
}
return warnings;
}

void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_id, MouseButton p_button) {
if (p_button != MouseButton::LEFT) {
return;
Expand Down
1 change: 0 additions & 1 deletion editor/gui/scene_tree_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class SceneTreeEditor : public Control {

void _compute_hash(Node *p_node, uint64_t &hash);
void _reset();
PackedStringArray _get_node_configuration_warnings(Node *p_node);

void _update_node_path(Node *p_node, bool p_recursive = true);
void _update_node_subtree(Node *p_node, TreeItem *p_parent, bool p_force = false);
Expand Down
16 changes: 16 additions & 0 deletions scene/2d/node_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,22 @@ Point2 Node2D::to_global(Point2 p_local) const {
return get_global_transform().xform(p_local);
}

#ifdef TOOLS_ENABLED
Vector<ConfigurationInfo> Node2D::get_configuration_info() const {
Vector<ConfigurationInfo> infos = CanvasItem::get_configuration_info();

// Note: Warn for Node2D but not all CanvasItems, don't warn for Control nodes.
// Control nodes may have reasons to use a transformed root node like anchors.
if (!get_transform().is_equal_approx(Transform2D())) {
CONFIG_WARNING_P(
TTR("The root node of a scene is recommended to not be transformed, since instances of the scene will usually override this. Reset the transform to remove this warning."),
"transform");
}

return infos;
}
#endif

void Node2D::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_ENTER_TREE: {
Expand Down
4 changes: 4 additions & 0 deletions scene/2d/node_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class Node2D : public CanvasItem {

Transform2D get_transform() const override;

#ifdef TOOLS_ENABLED
Vector<ConfigurationInfo> get_configuration_info() const override;
#endif

Node2D() {}
};

Expand Down
14 changes: 14 additions & 0 deletions scene/3d/node_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,20 @@ NodePath Node3D::get_visibility_parent() const {
return visibility_parent_path;
}

#ifdef TOOLS_ENABLED
Vector<ConfigurationInfo> Node3D::get_configuration_info() const {
Vector<ConfigurationInfo> infos = Node::get_configuration_info();

if (!get_transform().is_equal_approx(Transform3D())) {
CONFIG_WARNING_P(
TTR("The root node of a scene is recommended to not be transformed, since instances of the scene will usually override this. Reset the transform to remove this warning."),
"transform");
}

return infos;
}
#endif

void Node3D::_validate_property(PropertyInfo &p_property) const {
if (data.rotation_edit_mode != ROTATION_EDIT_MODE_BASIS && p_property.name == "basis") {
p_property.usage = 0;
Expand Down
4 changes: 4 additions & 0 deletions scene/3d/node_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ class Node3D : public Node {
void set_visibility_parent(const NodePath &p_path);
NodePath get_visibility_parent() const;

#ifdef TOOLS_ENABLED
Vector<ConfigurationInfo> get_configuration_info() const override;
#endif

Node3D();
~Node3D();
};
Expand Down

0 comments on commit 7fb441d

Please sign in to comment.