diff options
Diffstat (limited to 'scene/2d')
29 files changed, 107 insertions, 85 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp index 257e334873..d3783aadd1 100644 --- a/scene/2d/animated_sprite_2d.cpp +++ b/scene/2d/animated_sprite_2d.cpp @@ -437,7 +437,7 @@ TypedArray<String> AnimatedSprite2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (frames.is_null()) { - warnings.push_back(TTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite to display frames.")); + warnings.push_back(RTR("A SpriteFrames resource must be created or set in the \"Frames\" property in order for AnimatedSprite to display frames.")); } return warnings; diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp index 7f7eae51a6..61a17a4845 100644 --- a/scene/2d/canvas_modulate.cpp +++ b/scene/2d/canvas_modulate.cpp @@ -86,7 +86,7 @@ TypedArray<String> CanvasModulate::get_configuration_warnings() const { get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes); if (nodes.size() > 1) { - warnings.push_back(TTR("Only one visible CanvasModulate is allowed per scene (or set of instantiated scenes). The first created one will work, while the rest will be ignored.")); + warnings.push_back(RTR("Only one visible CanvasModulate is allowed per scene (or set of instantiated scenes). The first created one will work, while the rest will be ignored.")); } } diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index fbfe1d7eff..50863f2c4d 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -558,7 +558,7 @@ TypedArray<String> CollisionObject2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (shapes.is_empty()) { - warnings.push_back(TTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape2D or CollisionPolygon2D as a child to define its shape.")); + warnings.push_back(RTR("This node has no shape, so it can't collide or interact with other objects.\nConsider adding a CollisionShape2D or CollisionPolygon2D as a child to define its shape.")); } return warnings; diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp index e3939130ec..c8986e3c94 100644 --- a/scene/2d/collision_polygon_2d.cpp +++ b/scene/2d/collision_polygon_2d.cpp @@ -238,20 +238,20 @@ TypedArray<String> CollisionPolygon2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!Object::cast_to<CollisionObject2D>(get_parent())) { - warnings.push_back(TTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidDynamicBody2D, CharacterBody2D, etc. to give them a shape.")); + warnings.push_back(RTR("CollisionPolygon2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidDynamicBody2D, CharacterBody2D, etc. to give them a shape.")); } int polygon_count = polygon.size(); if (polygon_count == 0) { - warnings.push_back(TTR("An empty CollisionPolygon2D has no effect on collision.")); + warnings.push_back(RTR("An empty CollisionPolygon2D has no effect on collision.")); } else { bool solids = build_mode == BUILD_SOLIDS; if (solids) { if (polygon_count < 3) { - warnings.push_back(TTR("Invalid polygon. At least 3 points are needed in 'Solids' build mode.")); + warnings.push_back(RTR("Invalid polygon. At least 3 points are needed in 'Solids' build mode.")); } } else if (polygon_count < 2) { - warnings.push_back(TTR("Invalid polygon. At least 2 points are needed in 'Segments' build mode.")); + warnings.push_back(RTR("Invalid polygon. At least 2 points are needed in 'Segments' build mode.")); } } diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp index db9a745436..dd47ae6cb5 100644 --- a/scene/2d/collision_shape_2d.cpp +++ b/scene/2d/collision_shape_2d.cpp @@ -171,16 +171,16 @@ TypedArray<String> CollisionShape2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!Object::cast_to<CollisionObject2D>(get_parent())) { - warnings.push_back(TTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidDynamicBody2D, CharacterBody2D, etc. to give them a shape.")); + warnings.push_back(RTR("CollisionShape2D only serves to provide a collision shape to a CollisionObject2D derived node. Please only use it as a child of Area2D, StaticBody2D, RigidDynamicBody2D, CharacterBody2D, etc. to give them a shape.")); } if (!shape.is_valid()) { - warnings.push_back(TTR("A shape must be provided for CollisionShape2D to function. Please create a shape resource for it!")); + warnings.push_back(RTR("A shape must be provided for CollisionShape2D to function. Please create a shape resource for it!")); } Ref<ConvexPolygonShape2D> convex = shape; Ref<ConcavePolygonShape2D> concave = shape; if (convex.is_valid() || concave.is_valid()) { - warnings.push_back(TTR("Polygon-based shapes are not meant be used nor edited directly through the CollisionShape2D node. Please use the CollisionPolygon2D node instead.")); + warnings.push_back(RTR("Polygon-based shapes are not meant be used nor edited directly through the CollisionShape2D node. Please use the CollisionPolygon2D node instead.")); } return warnings; diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index dd9df3c485..24c66622f1 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -250,7 +250,7 @@ TypedArray<String> CPUParticles2D::get_configuration_warnings() const { if (get_material().is_null() || (mat && !mat->get_particles_animation())) { if (get_param_max(PARAM_ANIM_SPEED) != 0.0 || get_param_max(PARAM_ANIM_OFFSET) != 0.0 || get_param_curve(PARAM_ANIM_SPEED).is_valid() || get_param_curve(PARAM_ANIM_OFFSET).is_valid()) { - warnings.push_back(TTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.")); + warnings.push_back(RTR("CPUParticles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.")); } } @@ -743,7 +743,7 @@ void CPUParticles2D::_particles_process(double p_delta) { real_t angle1_rad = direction.angle() + Math::deg2rad((Math::randf() * 2.0 - 1.0) * spread); Vector2 rot = Vector2(Math::cos(angle1_rad), Math::sin(angle1_rad)); - p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], (real_t)Math::randf()); + p.velocity = rot * Math::lerp(parameters_min[PARAM_INITIAL_LINEAR_VELOCITY], parameters_max[PARAM_INITIAL_LINEAR_VELOCITY], (real_t)Math::randf()); real_t base_angle = tex_angle * Math::lerp(parameters_min[PARAM_ANGLE], parameters_max[PARAM_ANGLE], p.angle_rand); p.rotation = Math::deg2rad(base_angle); diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp index 8b0840e7c8..04518dff97 100644 --- a/scene/2d/gpu_particles_2d.cpp +++ b/scene/2d/gpu_particles_2d.cpp @@ -287,15 +287,24 @@ bool GPUParticles2D::get_fractional_delta() const { return fractional_delta; } +void GPUParticles2D::set_interpolate(bool p_enable) { + interpolate = p_enable; + RS::get_singleton()->particles_set_interpolate(particles, p_enable); +} + +bool GPUParticles2D::get_interpolate() const { + return interpolate; +} + TypedArray<String> GPUParticles2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (RenderingServer::get_singleton()->is_low_end()) { - warnings.push_back(TTR("GPU-based particles are not supported by the OpenGL video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles2D\" option for this purpose.")); + warnings.push_back(RTR("GPU-based particles are not supported by the OpenGL video driver.\nUse the CPUParticles2D node instead. You can use the \"Convert to CPUParticles2D\" option for this purpose.")); } if (process_material.is_null()) { - warnings.push_back(TTR("A material to process the particles is not assigned, so no behavior is imprinted.")); + warnings.push_back(RTR("A material to process the particles is not assigned, so no behavior is imprinted.")); } else { CanvasItemMaterial *mat = Object::cast_to<CanvasItemMaterial>(get_material().ptr()); @@ -304,7 +313,7 @@ TypedArray<String> GPUParticles2D::get_configuration_warnings() const { if (process && (process->get_param_max(ParticlesMaterial::PARAM_ANIM_SPEED) != 0.0 || process->get_param_max(ParticlesMaterial::PARAM_ANIM_OFFSET) != 0.0 || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_SPEED).is_valid() || process->get_param_texture(ParticlesMaterial::PARAM_ANIM_OFFSET).is_valid())) { - warnings.push_back(TTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.")); + warnings.push_back(RTR("Particles2D animation requires the usage of a CanvasItemMaterial with \"Particles Animation\" enabled.")); } } } @@ -543,6 +552,7 @@ void GPUParticles2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &GPUParticles2D::set_use_local_coordinates); ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &GPUParticles2D::set_fixed_fps); ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &GPUParticles2D::set_fractional_delta); + ClassDB::bind_method(D_METHOD("set_interpolate", "enable"), &GPUParticles2D::set_interpolate); ClassDB::bind_method(D_METHOD("set_process_material", "material"), &GPUParticles2D::set_process_material); ClassDB::bind_method(D_METHOD("set_speed_scale", "scale"), &GPUParticles2D::set_speed_scale); ClassDB::bind_method(D_METHOD("set_collision_base_size", "size"), &GPUParticles2D::set_collision_base_size); @@ -558,6 +568,7 @@ void GPUParticles2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &GPUParticles2D::get_use_local_coordinates); ClassDB::bind_method(D_METHOD("get_fixed_fps"), &GPUParticles2D::get_fixed_fps); ClassDB::bind_method(D_METHOD("get_fractional_delta"), &GPUParticles2D::get_fractional_delta); + ClassDB::bind_method(D_METHOD("get_interpolate"), &GPUParticles2D::get_interpolate); ClassDB::bind_method(D_METHOD("get_process_material"), &GPUParticles2D::get_process_material); ClassDB::bind_method(D_METHOD("get_speed_scale"), &GPUParticles2D::get_speed_scale); ClassDB::bind_method(D_METHOD("get_collision_base_size"), &GPUParticles2D::get_collision_base_size); @@ -601,6 +612,7 @@ void GPUParticles2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio"); ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interpolate"), "set_interpolate", "get_interpolate"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta"); ADD_GROUP("Collision", "collision_"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_base_size", PROPERTY_HINT_RANGE, "0,128,0.01,or_greater"), "set_collision_base_size", "get_collision_base_size"); @@ -644,6 +656,7 @@ GPUParticles2D::GPUParticles2D() { set_lifetime(1); set_fixed_fps(0); set_fractional_delta(true); + set_interpolate(true); set_pre_process_time(0); set_explosiveness_ratio(0); set_randomness_ratio(0); diff --git a/scene/2d/gpu_particles_2d.h b/scene/2d/gpu_particles_2d.h index fc95ae27b2..852270dd3c 100644 --- a/scene/2d/gpu_particles_2d.h +++ b/scene/2d/gpu_particles_2d.h @@ -58,6 +58,7 @@ private: bool local_coords; int fixed_fps; bool fractional_delta; + bool interpolate = true; #ifdef TOOLS_ENABLED bool show_visibility_rect; #endif @@ -133,6 +134,9 @@ public: void set_fractional_delta(bool p_enable); bool get_fractional_delta() const; + void set_interpolate(bool p_enable); + bool get_interpolate() const; + void set_draw_order(DrawOrder p_order); DrawOrder get_draw_order() const; diff --git a/scene/2d/joint_2d.cpp b/scene/2d/joint_2d.cpp index c2773191ea..cd82b47333 100644 --- a/scene/2d/joint_2d.cpp +++ b/scene/2d/joint_2d.cpp @@ -77,15 +77,15 @@ void Joint2D::_update_joint(bool p_only_free) { bool valid = false; if (node_a && !body_a && node_b && !body_b) { - warning = TTR("Node A and Node B must be PhysicsBody2Ds"); + warning = RTR("Node A and Node B must be PhysicsBody2Ds"); } else if (node_a && !body_a) { - warning = TTR("Node A must be a PhysicsBody2D"); + warning = RTR("Node A must be a PhysicsBody2D"); } else if (node_b && !body_b) { - warning = TTR("Node B must be a PhysicsBody2D"); + warning = RTR("Node B must be a PhysicsBody2D"); } else if (!body_a || !body_b) { - warning = TTR("Joint is not connected to two PhysicsBody2Ds"); + warning = RTR("Joint is not connected to two PhysicsBody2Ds"); } else if (body_a == body_b) { - warning = TTR("Node A and Node B must be different PhysicsBody2Ds"); + warning = RTR("Node A and Node B must be different PhysicsBody2Ds"); } else { warning = String(); valid = true; diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp index ba168eeb86..b09b1b5047 100644 --- a/scene/2d/light_2d.cpp +++ b/scene/2d/light_2d.cpp @@ -394,7 +394,7 @@ TypedArray<String> PointLight2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!texture.is_valid()) { - warnings.push_back(TTR("A texture with the shape of the light must be supplied to the \"Texture\" property.")); + warnings.push_back(RTR("A texture with the shape of the light must be supplied to the \"Texture\" property.")); } return warnings; diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp index 0310817592..c4e57b375d 100644 --- a/scene/2d/light_occluder_2d.cpp +++ b/scene/2d/light_occluder_2d.cpp @@ -250,11 +250,11 @@ TypedArray<String> LightOccluder2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!occluder_polygon.is_valid()) { - warnings.push_back(TTR("An occluder polygon must be set (or drawn) for this occluder to take effect.")); + warnings.push_back(RTR("An occluder polygon must be set (or drawn) for this occluder to take effect.")); } if (occluder_polygon.is_valid() && occluder_polygon->get_polygon().size() == 0) { - warnings.push_back(TTR("The occluder polygon for this occluder is empty. Please draw a polygon.")); + warnings.push_back(RTR("The occluder polygon for this occluder is empty. Please draw a polygon.")); } return warnings; diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index 78b5a39e9a..91549d75f0 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -58,6 +58,9 @@ void NavigationAgent2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_path_max_distance", "max_speed"), &NavigationAgent2D::set_path_max_distance); ClassDB::bind_method(D_METHOD("get_path_max_distance"), &NavigationAgent2D::get_path_max_distance); + ClassDB::bind_method(D_METHOD("set_navigable_layers", "navigable_layers"), &NavigationAgent2D::set_navigable_layers); + ClassDB::bind_method(D_METHOD("get_navigable_layers"), &NavigationAgent2D::get_navigable_layers); + ClassDB::bind_method(D_METHOD("set_target_location", "location"), &NavigationAgent2D::set_target_location); ClassDB::bind_method(D_METHOD("get_target_location"), &NavigationAgent2D::get_target_location); ClassDB::bind_method(D_METHOD("get_next_location"), &NavigationAgent2D::get_next_location); @@ -79,6 +82,7 @@ void NavigationAgent2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_horizon", PROPERTY_HINT_RANGE, "0.1,10000,0.01"), "set_time_horizon", "get_time_horizon"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_speed", PROPERTY_HINT_RANGE, "0.1,100000,0.01"), "set_max_speed", "get_max_speed"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_max_distance", PROPERTY_HINT_RANGE, "10,100,1"), "set_path_max_distance", "get_path_max_distance"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "navigable_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigable_layers", "get_navigable_layers"); ADD_SIGNAL(MethodInfo("path_changed")); ADD_SIGNAL(MethodInfo("target_reached")); @@ -127,8 +131,11 @@ NavigationAgent2D::~NavigationAgent2D() { } void NavigationAgent2D::set_navigable_layers(uint32_t p_layers) { + bool layers_changed = navigable_layers != p_layers; navigable_layers = p_layers; - update_navigation(); + if (layers_changed) { + _request_repath(); + } } uint32_t NavigationAgent2D::get_navigable_layers() const { @@ -174,10 +181,7 @@ real_t NavigationAgent2D::get_path_max_distance() { void NavigationAgent2D::set_target_location(Vector2 p_location) { target_location = p_location; - navigation_path.clear(); - target_reached = false; - navigation_finished = false; - update_frame_id = 0; + _request_repath(); } Vector2 NavigationAgent2D::get_target_location() const { @@ -244,7 +248,7 @@ TypedArray<String> NavigationAgent2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!Object::cast_to<Node2D>(get_parent())) { - warnings.push_back(TTR("The NavigationAgent2D can be used only under a Node2D node.")); + warnings.push_back(RTR("The NavigationAgent2D can be used only under a Node2D node.")); } return warnings; @@ -312,6 +316,13 @@ void NavigationAgent2D::update_navigation() { } } +void NavigationAgent2D::_request_repath() { + navigation_path.clear(); + target_reached = false; + navigation_finished = false; + update_frame_id = 0; +} + void NavigationAgent2D::_check_distance_to_target() { if (!target_reached) { if (distance_to_target() < target_desired_distance) { diff --git a/scene/2d/navigation_agent_2d.h b/scene/2d/navigation_agent_2d.h index dcedc6506a..2fb6fab91c 100644 --- a/scene/2d/navigation_agent_2d.h +++ b/scene/2d/navigation_agent_2d.h @@ -139,6 +139,7 @@ public: private: void update_navigation(); + void _request_repath(); void _check_distance_to_target(); }; diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index 65f7adb7a6..d1e5bc11bc 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -100,7 +100,7 @@ TypedArray<String> NavigationObstacle2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!Object::cast_to<Node2D>(get_parent())) { - warnings.push_back(TTR("The NavigationObstacle2D only serves to provide collision avoidance to a Node2D object.")); + warnings.push_back(RTR("The NavigationObstacle2D only serves to provide collision avoidance to a Node2D object.")); } return warnings; diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp index 34ac02a82a..261d371dc4 100644 --- a/scene/2d/navigation_region_2d.cpp +++ b/scene/2d/navigation_region_2d.cpp @@ -517,7 +517,7 @@ TypedArray<String> NavigationRegion2D::get_configuration_warnings() const { if (is_visible_in_tree() && is_inside_tree()) { if (!navpoly.is_valid()) { - warnings.push_back(TTR("A NavigationMesh resource must be set or created for this node to work. Please set a property or draw a polygon.")); + warnings.push_back(RTR("A NavigationMesh resource must be set or created for this node to work. Please set a property or draw a polygon.")); } } diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp index dd88bda304..42c8daa4c7 100644 --- a/scene/2d/node_2d.cpp +++ b/scene/2d/node_2d.cpp @@ -133,7 +133,7 @@ void Node2D::_update_transform() { void Node2D::set_position(const Point2 &p_pos) { if (_xform_dirty) { - ((Node2D *)this)->_update_xform_values(); + const_cast<Node2D *>(this)->_update_xform_values(); } position = p_pos; _update_transform(); @@ -141,7 +141,7 @@ void Node2D::set_position(const Point2 &p_pos) { void Node2D::set_rotation(real_t p_radians) { if (_xform_dirty) { - ((Node2D *)this)->_update_xform_values(); + const_cast<Node2D *>(this)->_update_xform_values(); } rotation = p_radians; _update_transform(); @@ -149,7 +149,7 @@ void Node2D::set_rotation(real_t p_radians) { void Node2D::set_skew(real_t p_radians) { if (_xform_dirty) { - ((Node2D *)this)->_update_xform_values(); + const_cast<Node2D *>(this)->_update_xform_values(); } skew = p_radians; _update_transform(); @@ -157,7 +157,7 @@ void Node2D::set_skew(real_t p_radians) { void Node2D::set_scale(const Size2 &p_scale) { if (_xform_dirty) { - ((Node2D *)this)->_update_xform_values(); + const_cast<Node2D *>(this)->_update_xform_values(); } scale = p_scale; // Avoid having 0 scale values, can lead to errors in physics and rendering. @@ -172,14 +172,14 @@ void Node2D::set_scale(const Size2 &p_scale) { Point2 Node2D::get_position() const { if (_xform_dirty) { - ((Node2D *)this)->_update_xform_values(); + const_cast<Node2D *>(this)->_update_xform_values(); } return position; } real_t Node2D::get_rotation() const { if (_xform_dirty) { - ((Node2D *)this)->_update_xform_values(); + const_cast<Node2D *>(this)->_update_xform_values(); } return rotation; @@ -187,7 +187,7 @@ real_t Node2D::get_rotation() const { real_t Node2D::get_skew() const { if (_xform_dirty) { - ((Node2D *)this)->_update_xform_values(); + const_cast<Node2D *>(this)->_update_xform_values(); } return skew; @@ -195,7 +195,7 @@ real_t Node2D::get_skew() const { Size2 Node2D::get_scale() const { if (_xform_dirty) { - ((Node2D *)this)->_update_xform_values(); + const_cast<Node2D *>(this)->_update_xform_values(); } return scale; diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp index dcbb6507f5..335f2404f2 100644 --- a/scene/2d/parallax_background.cpp +++ b/scene/2d/parallax_background.cpp @@ -163,15 +163,15 @@ Vector2 ParallaxBackground::get_final_offset() const { void ParallaxBackground::_bind_methods() { ClassDB::bind_method(D_METHOD("_camera_moved"), &ParallaxBackground::_camera_moved); - ClassDB::bind_method(D_METHOD("set_scroll_offset", "ofs"), &ParallaxBackground::set_scroll_offset); + ClassDB::bind_method(D_METHOD("set_scroll_offset", "offset"), &ParallaxBackground::set_scroll_offset); ClassDB::bind_method(D_METHOD("get_scroll_offset"), &ParallaxBackground::get_scroll_offset); - ClassDB::bind_method(D_METHOD("set_scroll_base_offset", "ofs"), &ParallaxBackground::set_scroll_base_offset); + ClassDB::bind_method(D_METHOD("set_scroll_base_offset", "offset"), &ParallaxBackground::set_scroll_base_offset); ClassDB::bind_method(D_METHOD("get_scroll_base_offset"), &ParallaxBackground::get_scroll_base_offset); ClassDB::bind_method(D_METHOD("set_scroll_base_scale", "scale"), &ParallaxBackground::set_scroll_base_scale); ClassDB::bind_method(D_METHOD("get_scroll_base_scale"), &ParallaxBackground::get_scroll_base_scale); - ClassDB::bind_method(D_METHOD("set_limit_begin", "ofs"), &ParallaxBackground::set_limit_begin); + ClassDB::bind_method(D_METHOD("set_limit_begin", "offset"), &ParallaxBackground::set_limit_begin); ClassDB::bind_method(D_METHOD("get_limit_begin"), &ParallaxBackground::get_limit_begin); - ClassDB::bind_method(D_METHOD("set_limit_end", "ofs"), &ParallaxBackground::set_limit_end); + ClassDB::bind_method(D_METHOD("set_limit_end", "offset"), &ParallaxBackground::set_limit_end); ClassDB::bind_method(D_METHOD("get_limit_end"), &ParallaxBackground::get_limit_end); ClassDB::bind_method(D_METHOD("set_ignore_camera_zoom", "ignore"), &ParallaxBackground::set_ignore_camera_zoom); ClassDB::bind_method(D_METHOD("is_ignore_camera_zoom"), &ParallaxBackground::is_ignore_camera_zoom); diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp index 849412a7ae..9e8ab224dc 100644 --- a/scene/2d/parallax_layer.cpp +++ b/scene/2d/parallax_layer.cpp @@ -143,7 +143,7 @@ TypedArray<String> ParallaxLayer::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!Object::cast_to<ParallaxBackground>(get_parent())) { - warnings.push_back(TTR("ParallaxLayer node only works when set as child of a ParallaxBackground node.")); + warnings.push_back(RTR("ParallaxLayer node only works when set as child of a ParallaxBackground node.")); } return warnings; diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index d001652ca3..a21cb7db62 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -263,7 +263,7 @@ TypedArray<String> PathFollow2D::get_configuration_warnings() const { if (is_visible_in_tree() && is_inside_tree()) { if (!Object::cast_to<Path2D>(get_parent())) { - warnings.push_back(TTR("PathFollow2D only works when set as a child of a Path2D node.")); + warnings.push_back(RTR("PathFollow2D only works when set as a child of a Path2D node.")); } } @@ -311,7 +311,7 @@ void PathFollow2D::set_offset(real_t p_offset) { if (path->get_curve().is_valid()) { real_t path_length = path->get_curve()->get_baked_length(); - if (loop) { + if (loop && path_length) { offset = Math::fposmod(offset, path_length); if (!Math::is_zero_approx(p_offset) && Math::is_zero_approx(offset)) { offset = path_length; diff --git a/scene/2d/physical_bone_2d.cpp b/scene/2d/physical_bone_2d.cpp index 1fc4b651d8..2999736d64 100644 --- a/scene/2d/physical_bone_2d.cpp +++ b/scene/2d/physical_bone_2d.cpp @@ -110,15 +110,15 @@ TypedArray<String> PhysicalBone2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!parent_skeleton) { - warnings.push_back(TTR("A PhysicalBone2D only works with a Skeleton2D or another PhysicalBone2D as a parent node!")); + warnings.push_back(RTR("A PhysicalBone2D only works with a Skeleton2D or another PhysicalBone2D as a parent node!")); } if (parent_skeleton && bone2d_index <= -1) { - warnings.push_back(TTR("A PhysicalBone2D needs to be assigned to a Bone2D node in order to function! Please set a Bone2D node in the inspector.")); + warnings.push_back(RTR("A PhysicalBone2D needs to be assigned to a Bone2D node in order to function! Please set a Bone2D node in the inspector.")); } if (!child_joint) { PhysicalBone2D *parent_bone = Object::cast_to<PhysicalBone2D>(get_parent()); if (parent_bone) { - warnings.push_back(TTR("A PhysicalBone2D node should have a Joint2D-based child node to keep bones connected! Please add a Joint2D-based node as a child to this node!")); + warnings.push_back(RTR("A PhysicalBone2D node should have a Joint2D-based child node to keep bones connected! Please add a Joint2D-based node as a child to this node!")); } } diff --git a/scene/2d/physical_bone_2d.h b/scene/2d/physical_bone_2d.h index 9f31c22031..22d329c320 100644 --- a/scene/2d/physical_bone_2d.h +++ b/scene/2d/physical_bone_2d.h @@ -49,7 +49,7 @@ private: NodePath bone2d_nodepath; bool follow_bone_when_simulating = false; - Joint2D *child_joint; + Joint2D *child_joint = nullptr; bool auto_configure_joint = true; bool simulate_physics = false; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index dc1378f14b..677878d40f 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -58,7 +58,11 @@ Ref<KinematicCollision2D> PhysicsBody2D::_move(const Vector2 &p_distance, bool p PhysicsServer2D::MotionParameters parameters(get_global_transform(), p_distance, p_margin); PhysicsServer2D::MotionResult result; - if (move_and_collide(parameters, result, p_test_only)) { + + bool collided = move_and_collide(parameters, result, p_test_only); + + // Don't report collision when the whole motion is done. + if (collided && result.collision_safe_fraction < 1) { // Create a new instance when the cached reference is invalid or still in use in script. if (motion_cache.is_null() || motion_cache->reference_get_count() > 1) { motion_cache.instantiate(); @@ -277,7 +281,7 @@ void AnimatableBody2D::_update_kinematic_motion() { } void AnimatableBody2D::_body_state_changed_callback(void *p_instance, PhysicsDirectBodyState2D *p_state) { - AnimatableBody2D *body = (AnimatableBody2D *)p_instance; + AnimatableBody2D *body = static_cast<AnimatableBody2D *>(p_instance); body->_body_state_changed(p_state); } @@ -443,7 +447,7 @@ struct _RigidDynamicBody2DInOut { }; void RigidDynamicBody2D::_body_state_changed_callback(void *p_instance, PhysicsDirectBodyState2D *p_state) { - RigidDynamicBody2D *body = (RigidDynamicBody2D *)p_instance; + RigidDynamicBody2D *body = static_cast<RigidDynamicBody2D *>(p_instance); body->_body_state_changed(p_state); } @@ -925,7 +929,7 @@ TypedArray<String> RigidDynamicBody2D::get_configuration_warnings() const { TypedArray<String> warnings = CollisionObject2D::get_configuration_warnings(); if (ABS(t.elements[0].length() - 1.0) > 0.05 || ABS(t.elements[1].length() - 1.0) > 0.05) { - warnings.push_back(TTR("Size changes to RigidDynamicBody2D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); + warnings.push_back(RTR("Size changes to RigidDynamicBody2D will be overridden by the physics engine when running.\nChange the size in children collision shapes instead.")); } return warnings; @@ -1761,7 +1765,7 @@ void CharacterBody2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "floor_block_on_wall"), "set_floor_block_on_wall_enabled", "is_floor_block_on_wall_enabled"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "floor_max_angle", PROPERTY_HINT_RANGE, "0,180,0.1,radians"), "set_floor_max_angle", "get_floor_max_angle"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "floor_snap_length", PROPERTY_HINT_RANGE, "0,32,0.1,or_greater"), "set_floor_snap_length", "get_floor_snap_length"); - ADD_GROUP("Moving platform", "moving_platform"); + ADD_GROUP("Moving Platform", "moving_platform"); ADD_PROPERTY(PropertyInfo(Variant::INT, "moving_platform_apply_velocity_on_leave", PROPERTY_HINT_ENUM, "Always,Upward Only,Never", PROPERTY_USAGE_DEFAULT), "set_moving_platform_apply_velocity_on_leave", "get_moving_platform_apply_velocity_on_leave"); ADD_PROPERTY(PropertyInfo(Variant::INT, "moving_platform_floor_layers", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_moving_platform_floor_layers", "get_moving_platform_floor_layers"); ADD_PROPERTY(PropertyInfo(Variant::INT, "moving_platform_wall_layers", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_moving_platform_wall_layers", "get_moving_platform_wall_layers"); diff --git a/scene/2d/position_2d.cpp b/scene/2d/position_2d.cpp index 518593cee1..d946ea63bf 100644 --- a/scene/2d/position_2d.cpp +++ b/scene/2d/position_2d.cpp @@ -30,8 +30,6 @@ #include "position_2d.h" -const real_t DEFAULT_GIZMO_EXTENTS = 10.0; - void Position2D::_draw_cross() { const real_t extents = get_gizmo_extents(); @@ -103,28 +101,19 @@ void Position2D::_notification(int p_what) { } void Position2D::set_gizmo_extents(real_t p_extents) { - if (p_extents == DEFAULT_GIZMO_EXTENTS) { - set_meta("_gizmo_extents_", Variant()); - } else { - set_meta("_gizmo_extents_", p_extents); - } - + gizmo_extents = p_extents; update(); } real_t Position2D::get_gizmo_extents() const { - if (has_meta("_gizmo_extents_")) { - return get_meta("_gizmo_extents_"); - } else { - return DEFAULT_GIZMO_EXTENTS; - } + return gizmo_extents; } void Position2D::_bind_methods() { - ClassDB::bind_method(D_METHOD("_set_gizmo_extents", "extents"), &Position2D::set_gizmo_extents); - ClassDB::bind_method(D_METHOD("_get_gizmo_extents"), &Position2D::get_gizmo_extents); + ClassDB::bind_method(D_METHOD("set_gizmo_extents", "extents"), &Position2D::set_gizmo_extents); + ClassDB::bind_method(D_METHOD("get_gizmo_extents"), &Position2D::get_gizmo_extents); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gizmo_extents", PROPERTY_HINT_RANGE, "0,1000,0.1,or_greater", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_gizmo_extents", "_get_gizmo_extents"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "gizmo_extents", PROPERTY_HINT_RANGE, "0,1000,0.1,or_greater"), "set_gizmo_extents", "get_gizmo_extents"); } Position2D::Position2D() { diff --git a/scene/2d/position_2d.h b/scene/2d/position_2d.h index 4ef07eb05c..99b0266130 100644 --- a/scene/2d/position_2d.h +++ b/scene/2d/position_2d.h @@ -36,6 +36,8 @@ class Position2D : public Node2D { GDCLASS(Position2D, Node2D); + real_t gizmo_extents = 10.0; + void _draw_cross(); protected: diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp index 429f0f6f6f..6c4bfd58ce 100644 --- a/scene/2d/remote_transform_2d.cpp +++ b/scene/2d/remote_transform_2d.cpp @@ -187,7 +187,7 @@ 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))) { - warnings.push_back(TTR("Path property must point to a valid Node2D node to work.")); + warnings.push_back(RTR("Path property must point to a valid Node2D node to work.")); } return warnings; diff --git a/scene/2d/shape_cast_2d.cpp b/scene/2d/shape_cast_2d.cpp index a2c5d73b59..a2f4b16ed3 100644 --- a/scene/2d/shape_cast_2d.cpp +++ b/scene/2d/shape_cast_2d.cpp @@ -382,7 +382,7 @@ TypedArray<String> ShapeCast2D::get_configuration_warnings() const { TypedArray<String> warnings = Node2D::get_configuration_warnings(); if (shape.is_null()) { - warnings.push_back(TTR("This node cannot interact with other objects unless a Shape2D is assigned.")); + warnings.push_back(RTR("This node cannot interact with other objects unless a Shape2D is assigned.")); } return warnings; } diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index 360650c724..aa039e07ee 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -438,14 +438,14 @@ TypedArray<String> Bone2D::get_configuration_warnings() const { TypedArray<String> warnings = Node::get_configuration_warnings(); if (!skeleton) { if (parent_bone) { - warnings.push_back(TTR("This Bone2D chain should end at a Skeleton2D node.")); + warnings.push_back(RTR("This Bone2D chain should end at a Skeleton2D node.")); } else { - warnings.push_back(TTR("A Bone2D only works with a Skeleton2D or another Bone2D as parent node.")); + warnings.push_back(RTR("A Bone2D only works with a Skeleton2D or another Bone2D as parent node.")); } } if (rest == Transform2D(0, 0, 0, 0, 0, 0)) { - warnings.push_back(TTR("This bone lacks a proper REST pose. Go to the Skeleton2D node and set one.")); + warnings.push_back(RTR("This bone lacks a proper REST pose. Go to the Skeleton2D node and set one.")); } return warnings; diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index db33e6561a..cab57146b1 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -2143,7 +2143,7 @@ void TileMap::set_pattern(int p_layer, Vector2i p_position, const Ref<TileMapPat TypedArray<Vector2i> used_cells = p_pattern->get_used_cells(); for (int i = 0; i < used_cells.size(); i++) { Vector2i coords = map_pattern(p_position, used_cells[i], p_pattern); - set_cell(p_layer, coords, p_pattern->get_cell_source_id(coords), p_pattern->get_cell_atlas_coords(coords), p_pattern->get_cell_alternative_tile(coords)); + set_cell(p_layer, coords, p_pattern->get_cell_source_id(used_cells[i]), p_pattern->get_cell_atlas_coords(used_cells[i]), p_pattern->get_cell_alternative_tile(used_cells[i])); } } @@ -2512,10 +2512,10 @@ void TileMap::_set_tile_data(int p_layer, const Vector<int> &p_data) { uint32_t v = decode_uint32(&local[4]); // Extract the transform flags that used to be in the tilemap. - bool flip_h = v & (1 << 29); - bool flip_v = v & (1 << 30); - bool transpose = v & (1 << 31); - v &= (1 << 29) - 1; + bool flip_h = v & (1UL << 29); + bool flip_v = v & (1UL << 30); + bool transpose = v & (1UL << 31); + v &= (1UL << 29) - 1; // Extract autotile/atlas coords. int16_t coord_x = 0; @@ -3586,7 +3586,7 @@ TypedArray<String> TileMap::get_configuration_warnings() const { // Check if we have a non-sorted layer in a Z-index with a Y-sorted layer. for (int layer = 0; layer < (int)layers.size(); layer++) { if (!layers[layer].y_sort_enabled && y_sorted_z_index.has(layers[layer].z_index)) { - warnings.push_back(TTR("A Y-sorted layer has the same Z-index value as a not Y-sorted layer.\nThis may lead to unwanted behaviors, as a layer that is not Y-sorted will be Y-sorted as a whole with tiles from Y-sorted layers.")); + warnings.push_back(RTR("A Y-sorted layer has the same Z-index value as a not Y-sorted layer.\nThis may lead to unwanted behaviors, as a layer that is not Y-sorted will be Y-sorted as a whole with tiles from Y-sorted layers.")); break; } } diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index 9a68c17269..4a4a2a1da0 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -190,7 +190,7 @@ String TouchScreenButton::get_action() const { void TouchScreenButton::input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); - if (!get_tree()) { + if (!is_visible_in_tree()) { return; } @@ -198,8 +198,6 @@ void TouchScreenButton::input(const Ref<InputEvent> &p_event) { return; } - ERR_FAIL_COND(!is_visible_in_tree()); - const InputEventScreenTouch *st = Object::cast_to<InputEventScreenTouch>(*p_event); if (passby_press) { |