From c195c0df6b36debc870216dd42e49fbda70fa861 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 17 May 2016 18:27:15 -0300 Subject: -Added configuration warning system for nodes -Added a new "add" and "instance" buttons for scene tree -Added a vformat() function to ease translation work --- scene/3d/body_shape.cpp | 13 +++++++++++++ scene/3d/body_shape.h | 3 +++ scene/3d/collision_polygon.cpp | 13 +++++++++++++ scene/3d/collision_polygon.h | 2 ++ scene/3d/navigation_mesh.cpp | 22 ++++++++++++++++++++++ scene/3d/navigation_mesh.h | 2 ++ scene/3d/scenario_fx.cpp | 27 ++++++++++++++++++++++++++- scene/3d/scenario_fx.h | 2 ++ scene/3d/spatial_sample_player.cpp | 11 +++++++++++ scene/3d/spatial_sample_player.h | 1 + 10 files changed, 95 insertions(+), 1 deletion(-) (limited to 'scene/3d') diff --git a/scene/3d/body_shape.cpp b/scene/3d/body_shape.cpp index 3a47371de3..e62ab394af 100644 --- a/scene/3d/body_shape.cpp +++ b/scene/3d/body_shape.cpp @@ -398,6 +398,19 @@ int CollisionShape::_get_update_shape_index() const{ return update_shape_index; } +String CollisionShape::get_configuration_warning() const { + + if (!get_parent()->cast_to()) { + return TTR("CollisionShape only serves to provide a collision shape to a CollisionObject derived node. Please only use it as a child of Area, StaticBody, RigidBody, KinematicBody, etc. to give them a shape."); + } + + if (!shape.is_valid()) { + return TTR("A shape must be provided for CollisionShape to function. Please create a shape resource for it!"); + } + + return String(); +} + void CollisionShape::_bind_methods() { diff --git a/scene/3d/body_shape.h b/scene/3d/body_shape.h index dd005c0edd..a3289bf26a 100644 --- a/scene/3d/body_shape.h +++ b/scene/3d/body_shape.h @@ -90,6 +90,9 @@ public: int get_collision_object_shape_index() const { return _get_update_shape_index(); } + + String get_configuration_warning() const; + CollisionShape(); ~CollisionShape(); }; diff --git a/scene/3d/collision_polygon.cpp b/scene/3d/collision_polygon.cpp index 3b14e1d767..e05f29714b 100644 --- a/scene/3d/collision_polygon.cpp +++ b/scene/3d/collision_polygon.cpp @@ -231,6 +231,19 @@ float CollisionPolygon::get_depth() const { return depth; } +String CollisionPolygon::get_configuration_warning() const { + + if (!get_parent()->cast_to()) { + return TTR("CollisionPolygon only serves to provide a collision shape to a CollisionObject derived node. Please only use it as a child of Area, StaticBody, RigidBody, KinematicBody, etc. to give them a shape."); + } + + if (polygon.empty()) { + return TTR("An empty CollisionPolygon has no effect on collision."); + + } + + return String(); +} void CollisionPolygon::_bind_methods() { diff --git a/scene/3d/collision_polygon.h b/scene/3d/collision_polygon.h index 9b9afea34f..3d190a02b3 100644 --- a/scene/3d/collision_polygon.h +++ b/scene/3d/collision_polygon.h @@ -55,6 +55,8 @@ public: int get_collision_object_first_shape() const { return shape_from; } int get_collision_object_last_shape() const { return shape_to; } + String get_configuration_warning() const; + CollisionPolygon(); }; diff --git a/scene/3d/navigation_mesh.cpp b/scene/3d/navigation_mesh.cpp index a238a8ff22..3adf282f13 100644 --- a/scene/3d/navigation_mesh.cpp +++ b/scene/3d/navigation_mesh.cpp @@ -329,6 +329,7 @@ void NavigationMeshInstance::set_navigation_mesh(const Ref& p_na nav_id = navigation->navmesh_create(navmesh,get_relative_transform(navigation),this); } update_gizmo(); + update_configuration_warning(); } @@ -337,6 +338,27 @@ Ref NavigationMeshInstance::get_navigation_mesh() const{ return navmesh; } +String NavigationMeshInstance::get_configuration_warning() const { + + if (!is_visible() || !is_inside_tree()) + return String(); + + if (!navmesh.is_valid()) { + return TTR("A NavigationMesh resource must be set or created for this node to work."); + } + const Spatial *c=this; + while(c) { + + if (c->cast_to()) + return String(); + + c=c->get_parent()->cast_to(); + } + + return TTR("NavigationMeshInstance must be a child or grandchild to a Navigation node. It only provides navigation data."); +} + + void NavigationMeshInstance::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_navigation_mesh","navmesh"),&NavigationMeshInstance::set_navigation_mesh); diff --git a/scene/3d/navigation_mesh.h b/scene/3d/navigation_mesh.h index 1e53b2127a..cb3b5d95f6 100644 --- a/scene/3d/navigation_mesh.h +++ b/scene/3d/navigation_mesh.h @@ -78,6 +78,8 @@ public: void set_navigation_mesh(const Ref& p_navmesh); Ref get_navigation_mesh() const; + String get_configuration_warning() const; + NavigationMeshInstance(); }; diff --git a/scene/3d/scenario_fx.cpp b/scene/3d/scenario_fx.cpp index 2e22ab36d3..f01c2263fb 100644 --- a/scene/3d/scenario_fx.cpp +++ b/scene/3d/scenario_fx.cpp @@ -40,12 +40,17 @@ void WorldEnvironment::_notification(int p_what) { WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding."); } get_world()->set_environment(environment); + add_to_group("_world_environment_"+itos(get_world()->get_scenario().get_id())); + } } else if (p_what==NOTIFICATION_EXIT_WORLD) { - if (environment.is_valid() && get_world()->get_environment()==environment) + if (environment.is_valid() && get_world()->get_environment()==environment) { get_world()->set_environment(Ref()); + remove_from_group("_world_environment_"+itos(get_world()->get_scenario().get_id())); + + } } } @@ -53,6 +58,7 @@ void WorldEnvironment::set_environment(const Ref& p_environment) { if (is_inside_world() && environment.is_valid() && get_world()->get_environment()==environment) { get_world()->set_environment(Ref()); + remove_from_group("_world_environment_"+itos(get_world()->get_scenario().get_id())); //clean up } @@ -63,7 +69,11 @@ void WorldEnvironment::set_environment(const Ref& p_environment) { WARN_PRINT("World already has an environment (Another WorldEnvironment?), overriding."); } get_world()->set_environment(environment); + add_to_group("_world_environment_"+itos(get_world()->get_scenario().get_id())); + } + + update_configuration_warning(); } Ref WorldEnvironment::get_environment() const { @@ -71,6 +81,21 @@ Ref WorldEnvironment::get_environment() const { return environment; } +String WorldEnvironment::get_configuration_warning() const { + + if (!is_visible() || !is_inside_tree() || !environment.is_valid()) + return String(); + + List nodes; + get_tree()->get_nodes_in_group("_world_environment_"+itos(get_world()->get_scenario().get_id()),&nodes); + + if (nodes.size()>1) { + return TTR("Only one WorldEnvironment is allowed per scene (or set of instanced scenes)."); + } + + return String(); +} + void WorldEnvironment::_bind_methods() { diff --git a/scene/3d/scenario_fx.h b/scene/3d/scenario_fx.h index a3c13e03a1..a73c455918 100644 --- a/scene/3d/scenario_fx.h +++ b/scene/3d/scenario_fx.h @@ -51,6 +51,8 @@ public: void set_environment(const Ref& p_environment); Ref get_environment() const; + String get_configuration_warning() const; + WorldEnvironment(); }; diff --git a/scene/3d/spatial_sample_player.cpp b/scene/3d/spatial_sample_player.cpp index 7114fd4b77..0df921f208 100644 --- a/scene/3d/spatial_sample_player.cpp +++ b/scene/3d/spatial_sample_player.cpp @@ -104,6 +104,7 @@ void SpatialSamplePlayer::set_sample_library(const Ref& p_library library=p_library; _change_notify(); + update_configuration_warning(); } Ref SpatialSamplePlayer::get_sample_library() const { @@ -190,6 +191,16 @@ void SpatialSamplePlayer::stop_all() { } } +String SpatialSamplePlayer::get_configuration_warning() const { + + if (library.is_null()) { + return TTR("A SampleLibrary resource must be created or set in the 'samples' property in order for SpatialSamplePlayer to play sound."); + } + + return String(); +} + + void SpatialSamplePlayer::_bind_methods() { diff --git a/scene/3d/spatial_sample_player.h b/scene/3d/spatial_sample_player.h index 037cdc906a..257f6d0dc3 100644 --- a/scene/3d/spatial_sample_player.h +++ b/scene/3d/spatial_sample_player.h @@ -78,6 +78,7 @@ public: void stop_voice(VoiceID p_voice); void stop_all(); + String get_configuration_warning() const; SpatialSamplePlayer(); ~SpatialSamplePlayer(); -- cgit v1.2.3