From 4c4c08c568ea60a71ba97f7e03ffc09809a30add Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Mon, 18 Sep 2023 15:55:01 -0500 Subject: [PATCH] Add a warning for when the scene root node is transformed --- editor/gui/scene_tree_editor.cpp | 26 +++++++++++++++++++++++--- editor/gui/scene_tree_editor.h | 1 + 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/editor/gui/scene_tree_editor.cpp b/editor/gui/scene_tree_editor.cpp index a3e62c298f79..fab22fdbd561 100644 --- a/editor/gui/scene_tree_editor.cpp +++ b/editor/gui/scene_tree_editor.cpp @@ -55,6 +55,27 @@ 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()) { + if (Object::cast_to(p_node)) { + // 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. + Node2D *node_2d = Object::cast_to(p_node); + 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.")); + } + } + if (Object::cast_to(p_node)) { + Node3D *node_3d = Object::cast_to(p_node); + 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.")); + } + } + } + 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; @@ -129,7 +150,7 @@ void SceneTreeEditor::_cell_button_pressed(Object *p_item, int p_column, int p_i } undo_redo->commit_action(); } else if (p_id == BUTTON_WARNING) { - const PackedStringArray warnings = n->get_configuration_warnings(); + const PackedStringArray warnings = _get_node_configuration_warnings(n); if (warnings.is_empty()) { return; @@ -291,8 +312,7 @@ void SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { } if (can_rename) { //should be can edit.. - - const PackedStringArray warnings = p_node->get_configuration_warnings(); + const PackedStringArray warnings = _get_node_configuration_warnings(p_node); const int num_warnings = warnings.size(); if (num_warnings > 0) { StringName warning_icon; diff --git a/editor/gui/scene_tree_editor.h b/editor/gui/scene_tree_editor.h index b4d9644f167a..386e478a6777 100644 --- a/editor/gui/scene_tree_editor.h +++ b/editor/gui/scene_tree_editor.h @@ -75,6 +75,7 @@ class SceneTreeEditor : public Control { int blocked; void _compute_hash(Node *p_node, uint64_t &hash); + PackedStringArray _get_node_configuration_warnings(Node *p_node); void _add_nodes(Node *p_node, TreeItem *p_parent); void _test_update_tree();