From 6a1888f5846fd6769d3338d3dcb4aa197568da40 Mon Sep 17 00:00:00 2001 From: smix8 <52464204+smix8@users.noreply.github.com> Date: Mon, 30 Jan 2023 14:53:08 +0100 Subject: [PATCH] Fix navigation related nodes not propagating parent class config warnings Fixes that navigation related nodes do not propagate config warnings from their parent classes. (cherry picked from commit b5213cceac9d88ee4ecafe2d9cdbf2eea5e0b1db) --- scene/2d/navigation_2d.cpp | 9 ++++++++- scene/2d/navigation_agent_2d.cpp | 9 +++++++-- scene/2d/navigation_obstacle_2d.cpp | 16 ++++++++++++---- scene/2d/navigation_polygon.cpp | 5 +---- scene/3d/navigation.cpp | 9 ++++++++- scene/3d/navigation_agent.cpp | 9 +++++++-- scene/3d/navigation_mesh_instance.cpp | 11 ++++++----- scene/3d/navigation_obstacle.cpp | 16 ++++++++++++---- 8 files changed, 61 insertions(+), 23 deletions(-) diff --git a/scene/2d/navigation_2d.cpp b/scene/2d/navigation_2d.cpp index c7cc67997fd..eaf0cabed2c 100644 --- a/scene/2d/navigation_2d.cpp +++ b/scene/2d/navigation_2d.cpp @@ -83,7 +83,14 @@ Vector Navigation2D::get_simple_path(const Vector2 &p_start, const Vect } String Navigation2D::get_configuration_warning() const { - return TTR("'Navigation2D' node and 'Navigation2D.get_simple_path()' are deprecated and will be removed in a future version. Use 'Navigation2DServer.map_get_path()' instead."); + String warning = Node2D::get_configuration_warning(); + + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("'Navigation2D' node and 'Navigation2D.get_simple_path()' are deprecated and will be removed in a future version. Use 'Navigation2DServer.map_get_path()' instead."); + + return warning; } Vector2 Navigation2D::get_closest_point(const Vector2 &p_point) const { diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index 0f05ad0d06b..ff015ee1db6 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -396,11 +396,16 @@ void NavigationAgent2D::_avoidance_done(Vector3 p_new_velocity) { } String NavigationAgent2D::get_configuration_warning() const { + String warning = Node::get_configuration_warning(); + if (!Object::cast_to(get_parent())) { - return TTR("The NavigationAgent2D can be used only under a Node2D inheriting parent node."); + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("The NavigationAgent2D can be used only under a Node2D inheriting parent node."); } - return String(); + return warning; } void NavigationAgent2D::update_navigation() { diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index c5dd4f171bb..e21f888a642 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -158,16 +158,24 @@ Node *NavigationObstacle2D::get_navigation_node() const { } String NavigationObstacle2D::get_configuration_warning() const { + String warning = Node::get_configuration_warning(); + if (!Object::cast_to(get_parent())) { - return TTR("The NavigationObstacle2D only serves to provide collision avoidance to a Node2D object."); + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("The NavigationObstacle2D only serves to provide collision avoidance to a Node2D object."); } if (Object::cast_to(get_parent())) { - return TTR("The NavigationObstacle2D is intended for constantly moving bodies like KinematicBody2D or RigidBody2D as it creates only an RVO avoidance radius and does not follow scene geometry exactly." - "\nNot constantly moving or complete static objects should be captured with a refreshed NavigationPolygon so agents can not only avoid them but also move along those objects outline at high detail"); + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("The NavigationObstacle2D is intended for constantly moving bodies like KinematicBody2D or RigidBody2D as it creates only an RVO avoidance radius and does not follow scene geometry exactly." + "\nNot constantly moving or complete static objects should be (re)baked to a NavigationMesh so agents can not only avoid them but also move along those objects outline at high detail"); } - return String(); + return warning; } void NavigationObstacle2D::initialize_agent() { diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp index b9c26738f6f..46d1026d276 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/2d/navigation_polygon.cpp @@ -582,11 +582,8 @@ void NavigationPolygonInstance::_map_changed(RID p_map) { } String NavigationPolygonInstance::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) { - return String(); - } - String warning = Node2D::get_configuration_warning(); + if (!navpoly.is_valid()) { if (warning != String()) { warning += "\n\n"; diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index 2f92716964a..f0a37f6187b 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -38,7 +38,14 @@ Vector Navigation::get_simple_path(const Vector3 &p_start, const Vector } String Navigation::get_configuration_warning() const { - return TTR("'Navigation' node and 'Navigation.get_simple_path()' are deprecated and will be removed in a future version. Use 'NavigationServer.map_get_path()' instead."); + String warning = Spatial::get_configuration_warning(); + + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("'Navigation' node and 'Navigation.get_simple_path()' are deprecated and will be removed in a future version. Use 'NavigationServer.map_get_path()' instead."); + + return warning; } Vector3 Navigation::get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision) const { diff --git a/scene/3d/navigation_agent.cpp b/scene/3d/navigation_agent.cpp index 0a6e1e42d11..b5659401199 100644 --- a/scene/3d/navigation_agent.cpp +++ b/scene/3d/navigation_agent.cpp @@ -405,11 +405,16 @@ void NavigationAgent::_avoidance_done(Vector3 p_new_velocity) { } String NavigationAgent::get_configuration_warning() const { + String warning = Node::get_configuration_warning(); + if (!Object::cast_to(get_parent())) { - return TTR("The NavigationAgent can be used only under a Spatial inheriting parent node."); + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("The NavigationAgent can be used only under a Spatial inheriting parent node."); } - return String(); + return warning; } void NavigationAgent::update_navigation() { diff --git a/scene/3d/navigation_mesh_instance.cpp b/scene/3d/navigation_mesh_instance.cpp index 61a76054936..74e78ccd42e 100644 --- a/scene/3d/navigation_mesh_instance.cpp +++ b/scene/3d/navigation_mesh_instance.cpp @@ -245,15 +245,16 @@ void NavigationMeshInstance::_bake_finished(Ref p_nav_mesh) { } String NavigationMeshInstance::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) { - return String(); - } + String warning = Spatial::get_configuration_warning(); if (!navmesh.is_valid()) { - return TTR("A NavigationMesh resource must be set or created for this node to work."); + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("A NavigationMesh resource must be set or created for this node to work."); } - return String(); + return warning; } void NavigationMeshInstance::_bind_methods() { diff --git a/scene/3d/navigation_obstacle.cpp b/scene/3d/navigation_obstacle.cpp index 6225913d2f4..6b6db6548ce 100644 --- a/scene/3d/navigation_obstacle.cpp +++ b/scene/3d/navigation_obstacle.cpp @@ -164,16 +164,24 @@ Node *NavigationObstacle::get_navigation_node() const { } String NavigationObstacle::get_configuration_warning() const { + String warning = Node::get_configuration_warning(); + if (!Object::cast_to(get_parent())) { - return TTR("The NavigationObstacle only serves to provide collision avoidance to a Spatial inheriting parent object."); + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("The NavigationObstacle only serves to provide collision avoidance to a Spatial inheriting parent object."); } if (Object::cast_to(get_parent())) { - return TTR("The NavigationObstacle is intended for constantly moving bodies like KinematicBody3D or RigidBody3D as it creates only an RVO avoidance radius and does not follow scene geometry exactly." - "\nNot constantly moving or complete static objects should be (re)baked to a NavigationMesh so agents can not only avoid them but also move along those objects outline at high detail"); + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("The NavigationObstacle is intended for constantly moving bodies like KinematicBody or RigidBody as it creates only an RVO avoidance radius and does not follow scene geometry exactly." + "\nNot constantly moving or complete static objects should be (re)baked to a NavigationMesh so agents can not only avoid them but also move along those objects outline at high detail"); } - return String(); + return warning; } void NavigationObstacle::initialize_agent() {