diff options
Diffstat (limited to 'scene')
35 files changed, 456 insertions, 159 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 78e98deb93..23f6404e3e 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -1074,6 +1074,7 @@ Vector2 CanvasItem::make_canvas_position_local(const Vector2 &screen_point) cons Ref<InputEvent> CanvasItem::make_input_local(const Ref<InputEvent> &p_event) const { + ERR_FAIL_COND_V(p_event.is_null(), p_event); ERR_FAIL_COND_V(!is_inside_tree(), p_event); return p_event->xformed_by((get_canvas_transform() * get_global_transform()).affine_inverse()); diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index 375375285d..36c88e395a 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -218,12 +218,13 @@ void CollisionObject2D::shape_owner_set_transform(uint32_t p_owner, const Transf ERR_FAIL_COND(!shapes.has(p_owner)); ShapeData &sd = shapes[p_owner]; + sd.xform = p_transform; for (int i = 0; i < sd.shapes.size(); i++) { if (area) { - Physics2DServer::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, p_transform); + Physics2DServer::get_singleton()->area_set_shape_transform(rid, sd.shapes[i].index, sd.xform); } else { - Physics2DServer::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, p_transform); + Physics2DServer::get_singleton()->body_set_shape_transform(rid, sd.shapes[i].index, sd.xform); } } } @@ -387,7 +388,7 @@ String CollisionObject2D::get_configuration_warning() const { String warning = Node2D::get_configuration_warning(); if (shapes.empty()) { - if (warning == String()) { + if (!warning.empty()) { warning += "\n"; } warning += 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."); diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp index faa0a08d10..75315bfc6e 100644 --- a/scene/2d/cpu_particles_2d.cpp +++ b/scene/2d/cpu_particles_2d.cpp @@ -1410,7 +1410,7 @@ CPUParticles2D::CPUParticles2D() { set_emission_sphere_radius(1); set_emission_rect_extents(Vector2(1, 1)); - set_gravity(Vector2(0, 98.8)); + set_gravity(Vector2(0, 98)); for (int i = 0; i < PARAM_MAX; i++) { set_param_randomness(Parameter(i), 0); diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp index 4488dc501c..ad405fabbb 100644 --- a/scene/2d/line_2d.cpp +++ b/scene/2d/line_2d.cpp @@ -44,6 +44,7 @@ Line2D::Line2D() { _end_cap_mode = LINE_CAP_NONE; _width = 10; _default_color = Color(0.4, 0.5, 1); + _texture_mode = LINE_TEXTURE_NONE; _sharp_limit = 2.f; _round_precision = 8; } @@ -83,10 +84,10 @@ void Line2D::set_points(const PoolVector<Vector2> &p_points) { update(); } -void Line2D::set_width(float width) { - if (width < 0.0) - width = 0.0; - _width = width; +void Line2D::set_width(float p_width) { + if (p_width < 0.0) + p_width = 0.0; + _width = p_width; update(); } @@ -94,12 +95,32 @@ float Line2D::get_width() const { return _width; } +void Line2D::set_curve(const Ref<Curve> &p_curve) { + // Cleanup previous connection if any + if (_curve.is_valid()) { + _curve->disconnect(CoreStringNames::get_singleton()->changed, this, "_curve_changed"); + } + + _curve = p_curve; + + // Connect to the curve so the line will update when it is changed + if (_curve.is_valid()) { + _curve->connect(CoreStringNames::get_singleton()->changed, this, "_curve_changed"); + } + + update(); +} + +Ref<Curve> Line2D::get_curve() const { + return _curve; +} + PoolVector<Vector2> Line2D::get_points() const { return _points; } -void Line2D::set_point_position(int i, Vector2 pos) { - _points.set(i, pos); +void Line2D::set_point_position(int i, Vector2 p_pos) { + _points.set(i, p_pos); update(); } @@ -120,11 +141,11 @@ void Line2D::clear_points() { } } -void Line2D::add_point(Vector2 pos, int atpos) { - if (atpos < 0 || _points.size() < atpos) { - _points.append(pos); +void Line2D::add_point(Vector2 p_pos, int p_atpos) { + if (p_atpos < 0 || _points.size() < p_atpos) { + _points.append(p_pos); } else { - _points.insert(atpos, pos); + _points.insert(p_atpos, p_pos); } update(); } @@ -134,8 +155,8 @@ void Line2D::remove_point(int i) { update(); } -void Line2D::set_default_color(Color color) { - _default_color = color; +void Line2D::set_default_color(Color p_color) { + _default_color = p_color; update(); } @@ -143,18 +164,18 @@ Color Line2D::get_default_color() const { return _default_color; } -void Line2D::set_gradient(const Ref<Gradient> &gradient) { +void Line2D::set_gradient(const Ref<Gradient> &p_gradient) { // Cleanup previous connection if any if (_gradient.is_valid()) { - (**_gradient).disconnect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed"); + _gradient->disconnect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed"); } - _gradient = gradient; + _gradient = p_gradient; // Connect to the gradient so the line will update when the ColorRamp is changed if (_gradient.is_valid()) { - (**_gradient).connect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed"); + _gradient->connect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed"); } update(); @@ -164,8 +185,8 @@ Ref<Gradient> Line2D::get_gradient() const { return _gradient; } -void Line2D::set_texture(const Ref<Texture> &texture) { - _texture = texture; +void Line2D::set_texture(const Ref<Texture> &p_texture) { + _texture = p_texture; update(); } @@ -173,8 +194,8 @@ Ref<Texture> Line2D::get_texture() const { return _texture; } -void Line2D::set_texture_mode(const LineTextureMode mode) { - _texture_mode = mode; +void Line2D::set_texture_mode(const LineTextureMode p_mode) { + _texture_mode = p_mode; update(); } @@ -182,8 +203,8 @@ Line2D::LineTextureMode Line2D::get_texture_mode() const { return _texture_mode; } -void Line2D::set_joint_mode(LineJointMode mode) { - _joint_mode = mode; +void Line2D::set_joint_mode(LineJointMode p_mode) { + _joint_mode = p_mode; update(); } @@ -191,8 +212,8 @@ Line2D::LineJointMode Line2D::get_joint_mode() const { return _joint_mode; } -void Line2D::set_begin_cap_mode(LineCapMode mode) { - _begin_cap_mode = mode; +void Line2D::set_begin_cap_mode(LineCapMode p_mode) { + _begin_cap_mode = p_mode; update(); } @@ -200,8 +221,8 @@ Line2D::LineCapMode Line2D::get_begin_cap_mode() const { return _begin_cap_mode; } -void Line2D::set_end_cap_mode(LineCapMode mode) { - _end_cap_mode = mode; +void Line2D::set_end_cap_mode(LineCapMode p_mode) { + _end_cap_mode = p_mode; update(); } @@ -217,10 +238,10 @@ void Line2D::_notification(int p_what) { } } -void Line2D::set_sharp_limit(float limit) { - if (limit < 0.f) - limit = 0.f; - _sharp_limit = limit; +void Line2D::set_sharp_limit(float p_limit) { + if (p_limit < 0.f) + p_limit = 0.f; + _sharp_limit = p_limit; update(); } @@ -228,10 +249,10 @@ float Line2D::get_sharp_limit() const { return _sharp_limit; } -void Line2D::set_round_precision(int precision) { - if (precision < 1) - precision = 1; - _round_precision = precision; +void Line2D::set_round_precision(int p_precision) { + if (p_precision < 1) + p_precision = 1; + _round_precision = p_precision; update(); } @@ -267,10 +288,11 @@ void Line2D::_draw() { lb.round_precision = _round_precision; lb.sharp_limit = _sharp_limit; lb.width = _width; + lb.curve = *_curve; RID texture_rid; if (_texture.is_valid()) { - texture_rid = (**_texture).get_rid(); + texture_rid = _texture->get_rid(); lb.tile_aspect = _texture->get_size().aspect(); } @@ -311,6 +333,10 @@ void Line2D::_gradient_changed() { update(); } +void Line2D::_curve_changed() { + update(); +} + // static void Line2D::_bind_methods() { @@ -330,6 +356,9 @@ void Line2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_width", "width"), &Line2D::set_width); ClassDB::bind_method(D_METHOD("get_width"), &Line2D::get_width); + ClassDB::bind_method(D_METHOD("set_curve", "curve"), &Line2D::set_curve); + ClassDB::bind_method(D_METHOD("get_curve"), &Line2D::get_curve); + ClassDB::bind_method(D_METHOD("set_default_color", "color"), &Line2D::set_default_color); ClassDB::bind_method(D_METHOD("get_default_color"), &Line2D::get_default_color); @@ -359,6 +388,7 @@ void Line2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "width_curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "default_color"), "set_default_color", "get_default_color"); ADD_GROUP("Fill", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "Gradient"), "set_gradient", "get_gradient"); @@ -385,4 +415,5 @@ void Line2D::_bind_methods() { BIND_ENUM_CONSTANT(LINE_TEXTURE_STRETCH); ClassDB::bind_method(D_METHOD("_gradient_changed"), &Line2D::_gradient_changed); + ClassDB::bind_method(D_METHOD("_curve_changed"), &Line2D::_curve_changed); } diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h index 11be5055d4..14afa463ba 100644 --- a/scene/2d/line_2d.h +++ b/scene/2d/line_2d.h @@ -78,6 +78,9 @@ public: void set_width(float width); float get_width() const; + void set_curve(const Ref<Curve> &curve); + Ref<Curve> get_curve() const; + void set_default_color(Color color); Color get_default_color() const; @@ -113,6 +116,7 @@ protected: private: void _gradient_changed(); + void _curve_changed(); private: PoolVector<Vector2> _points; @@ -120,6 +124,7 @@ private: LineCapMode _begin_cap_mode; LineCapMode _end_cap_mode; float _width; + Ref<Curve> _curve; Color _default_color; Ref<Gradient> _gradient; Ref<Texture> _texture; diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp index eb09d3c9d3..9fe5fb98b6 100644 --- a/scene/2d/line_builder.cpp +++ b/scene/2d/line_builder.cpp @@ -95,6 +95,7 @@ static inline Vector2 interpolate(const Rect2 &r, const Vector2 &v) { LineBuilder::LineBuilder() { joint_mode = Line2D::LINE_JOINT_SHARP; width = 10; + curve = NULL; default_color = Color(0.4, 0.5, 1); gradient = NULL; sharp_limit = 2.f; @@ -136,8 +137,8 @@ void LineBuilder::build() { Vector2 pos1 = points[1]; Vector2 f0 = (pos1 - pos0).normalized(); Vector2 u0 = rotate90(f0); - Vector2 pos_up0 = pos0 + u0 * hw; - Vector2 pos_down0 = pos0 - u0 * hw; + Vector2 pos_up0 = pos0; + Vector2 pos_down0 = pos0; Color color0; Color color1; @@ -145,12 +146,30 @@ void LineBuilder::build() { float current_distance0 = 0.f; float current_distance1 = 0.f; float total_distance = 0.f; + float width_factor = 1.f; _interpolate_color = gradient != NULL; + bool retrieve_curve = curve != NULL; bool distance_required = _interpolate_color || + retrieve_curve || texture_mode == Line2D::LINE_TEXTURE_TILE || texture_mode == Line2D::LINE_TEXTURE_STRETCH; - if (distance_required) + if (distance_required) { total_distance = calculate_total_distance(points); + //Ajust totalDistance. + // The line's outer length will be a little higher due to begin and end caps + if (begin_cap_mode == Line2D::LINE_CAP_BOX || begin_cap_mode == Line2D::LINE_CAP_ROUND) { + if (retrieve_curve) + total_distance += width * curve->interpolate_baked(0.f) * 0.5f; + else + total_distance += width * 0.5f; + } + if (end_cap_mode == Line2D::LINE_CAP_BOX || end_cap_mode == Line2D::LINE_CAP_ROUND) { + if (retrieve_curve) + total_distance += width * curve->interpolate_baked(1.f) * 0.5f; + else + total_distance += width * 0.5f; + } + } if (_interpolate_color) color0 = gradient->get_color(0); else @@ -159,22 +178,28 @@ void LineBuilder::build() { float uvx0 = 0.f; float uvx1 = 0.f; + if (retrieve_curve) + width_factor = curve->interpolate_baked(0.f); + + pos_up0 += u0 * hw * width_factor; + pos_down0 -= u0 * hw * width_factor; + // Begin cap if (begin_cap_mode == Line2D::LINE_CAP_BOX) { // Push back first vertices a little bit - pos_up0 -= f0 * hw; - pos_down0 -= f0 * hw; - // The line's outer length will be a little higher due to begin and end caps - total_distance += width; - current_distance0 += hw; + pos_up0 -= f0 * hw * width_factor; + pos_down0 -= f0 * hw * width_factor; + + current_distance0 += hw * width_factor; current_distance1 = current_distance0; } else if (begin_cap_mode == Line2D::LINE_CAP_ROUND) { if (texture_mode == Line2D::LINE_TEXTURE_TILE) { - uvx0 = 0.5f / tile_aspect; + uvx0 = width_factor * 0.5f / tile_aspect; + } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) { + uvx0 = width * width_factor / total_distance; } - new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, fmin(uvx0 * 2, 1.f), 1.f)); - total_distance += width; - current_distance0 += hw; + new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, uvx0 * 2, 1.f)); + current_distance0 += hw * width_factor; current_distance1 = current_distance0; } @@ -206,13 +231,23 @@ void LineBuilder::build() { const float dp = u0.dot(f1); const Orientation orientation = (dp > 0.f ? UP : DOWN); + if (distance_required) { + current_distance1 += pos0.distance_to(pos1); + } + if (_interpolate_color) { + color1 = gradient->get_color_at_offset(current_distance1 / total_distance); + } + if (retrieve_curve) { + width_factor = curve->interpolate_baked(current_distance1 / total_distance); + } + Vector2 inner_normal0, inner_normal1; if (orientation == UP) { - inner_normal0 = u0 * hw; - inner_normal1 = u1 * hw; + inner_normal0 = u0 * hw * width_factor; + inner_normal1 = u1 * hw * width_factor; } else { - inner_normal0 = -u0 * hw; - inner_normal1 = -u1 * hw; + inner_normal0 = -u0 * hw * width_factor; + inner_normal1 = -u1 * hw * width_factor; } /* @@ -259,7 +294,8 @@ void LineBuilder::build() { Vector2 pos_up1, pos_down1; if (intersection_result == SEGMENT_INTERSECT) { // Fallback on bevel if sharp angle is too high (because it would produce very long miters) - if (current_joint_mode == Line2D::LINE_JOINT_SHARP && corner_pos_out.distance_squared_to(pos1) / hw_sq > sharp_limit_sq) { + float width_factor_sq = width_factor * width_factor; + if (current_joint_mode == Line2D::LINE_JOINT_SHARP && corner_pos_out.distance_squared_to(pos1) / (hw_sq * width_factor_sq) > sharp_limit_sq) { current_joint_mode = Line2D::LINE_JOINT_BEVEL; } if (current_joint_mode == Line2D::LINE_JOINT_SHARP) { @@ -271,9 +307,9 @@ void LineBuilder::build() { // Bevel or round if (orientation == UP) { pos_up1 = corner_pos_up; - pos_down1 = pos1 - u0 * hw; + pos_down1 = pos1 - u0 * hw * width_factor; } else { - pos_up1 = pos1 + u0 * hw; + pos_up1 = pos1 + u0 * hw * width_factor; pos_down1 = corner_pos_down; } } @@ -289,12 +325,6 @@ void LineBuilder::build() { // Add current line body quad // Triangles are clockwise - if (distance_required) { - current_distance1 += pos0.distance_to(pos1); - } - if (_interpolate_color) { - color1 = gradient->get_color_at_offset(current_distance1 / total_distance); - } if (texture_mode == Line2D::LINE_TEXTURE_TILE) { uvx1 = current_distance1 / (width * tile_aspect); } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) { @@ -315,15 +345,15 @@ void LineBuilder::build() { } else { if (orientation == UP) { pos_up0 = corner_pos_up; - pos_down0 = pos1 - u1 * hw; + pos_down0 = pos1 - u1 * hw * width_factor; } else { - pos_up0 = pos1 + u1 * hw; + pos_up0 = pos1 + u1 * hw * width_factor; pos_down0 = corner_pos_down; } } } else { - pos_up0 = pos1 + u1 * hw; - pos_down0 = pos1 - u1 * hw; + pos_up0 = pos1 + u1 * hw * width_factor; + pos_down0 = pos1 - u1 * hw * width_factor; } // From this point, bu0 and bd0 concern the next segment @@ -362,26 +392,28 @@ void LineBuilder::build() { strip_begin(pos_up0, pos_down0, color1, uvx1); } } - // Last (or only) segment - pos1 = points[points.size() - 1]; - Vector2 pos_up1 = pos1 + u0 * hw; - Vector2 pos_down1 = pos1 - u0 * hw; - - // End cap (box) - if (end_cap_mode == Line2D::LINE_CAP_BOX) { - pos_up1 += f0 * hw; - pos_down1 += f0 * hw; - } - if (distance_required) { current_distance1 += pos0.distance_to(pos1); } if (_interpolate_color) { color1 = gradient->get_color(gradient->get_points_count() - 1); } + if (retrieve_curve) { + width_factor = curve->interpolate_baked(1.f); + } + + Vector2 pos_up1 = pos1 + u0 * hw * width_factor; + Vector2 pos_down1 = pos1 - u0 * hw * width_factor; + + // End cap (box) + if (end_cap_mode == Line2D::LINE_CAP_BOX) { + pos_up1 += f0 * hw * width_factor; + pos_down1 += f0 * hw * width_factor; + } + if (texture_mode == Line2D::LINE_TEXTURE_TILE) { uvx1 = current_distance1 / (width * tile_aspect); } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) { @@ -394,7 +426,13 @@ void LineBuilder::build() { if (end_cap_mode == Line2D::LINE_CAP_ROUND) { // Note: color is not used in case we don't interpolate... Color color = _interpolate_color ? gradient->get_color(gradient->get_points_count() - 1) : Color(0, 0, 0); - new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f / tile_aspect, 0.f, 1.0f / tile_aspect, 1.f)); + float dist = 0; + if (texture_mode == Line2D::LINE_TEXTURE_TILE) { + dist = width_factor / tile_aspect; + } else if (texture_mode == Line2D::LINE_TEXTURE_STRETCH) { + dist = width * width_factor / total_distance; + } + new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f * dist, 0.f, dist, 1.f)); } } diff --git a/scene/2d/line_builder.h b/scene/2d/line_builder.h index b961385e33..91b4518f9b 100644 --- a/scene/2d/line_builder.h +++ b/scene/2d/line_builder.h @@ -45,6 +45,7 @@ public: Line2D::LineCapMode begin_cap_mode; Line2D::LineCapMode end_cap_mode; float width; + Curve *curve; Color default_color; Gradient *gradient; Line2D::LineTextureMode texture_mode; diff --git a/scene/2d/navigation_2d.cpp b/scene/2d/navigation_2d.cpp index 72b5f2fb12..f644db462b 100644 --- a/scene/2d/navigation_2d.cpp +++ b/scene/2d/navigation_2d.cpp @@ -92,7 +92,6 @@ void Navigation2D::_navpoly_link(int p_id) { if (!valid) { nm.polygons.pop_back(); ERR_CONTINUE(!valid); - continue; } p.center = center / plen; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 2bd9e5e2a2..95acf13fad 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -1541,7 +1541,7 @@ Vector2 KinematicCollision2D::get_remainder() const { return collision.remainder; } Object *KinematicCollision2D::get_local_shape() const { - ERR_FAIL_COND_V(!owner, NULL); + if (!owner) return NULL; uint32_t ownerid = owner->shape_find_owner(collision.local_shape); return owner->shape_owner_get_owner(ownerid); } diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index b3b6f3175d..fc53c9e4ac 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -30,9 +30,11 @@ #include "tile_map.h" +#include "collision_object_2d.h" #include "core/io/marshalls.h" #include "core/method_bind_ext.gen.inc" #include "core/os/os.h" +#include "scene/2d/area_2d.h" #include "servers/physics_2d_server.h" int TileMap::_get_quadrant_size() const { @@ -60,14 +62,21 @@ void TileMap::_notification(int p_what) { c = Object::cast_to<Node2D>(c->get_parent()); } + if (use_parent) { + _clear_quadrants(); + collision_parent = Object::cast_to<CollisionObject2D>(get_parent()); + } + pending_update = true; _recreate_quadrants(); update_dirty_quadrants(); RID space = get_world_2d()->get_space(); _update_quadrant_transform(); _update_quadrant_space(space); + update_configuration_warning(); } break; + case NOTIFICATION_EXIT_TREE: { _update_quadrant_space(RID()); @@ -82,30 +91,46 @@ void TileMap::_notification(int p_what) { q.navpoly_ids.clear(); } + if (collision_parent) { + collision_parent->remove_shape_owner(q.shape_owner_id); + q.shape_owner_id = -1; + } + for (Map<PosKey, Quadrant::Occluder>::Element *F = q.occluder_instances.front(); F; F = F->next()) { VS::get_singleton()->free(F->get().id); } q.occluder_instances.clear(); } + collision_parent = NULL; navigation = NULL; } break; + case NOTIFICATION_TRANSFORM_CHANGED: { //move stuff _update_quadrant_transform(); } break; + case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: { + + if (use_parent) { + _recreate_quadrants(); + } + + } break; } } void TileMap::_update_quadrant_space(const RID &p_space) { - for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { + if (!use_parent) { + for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_space(q.body, p_space); + Quadrant &q = E->get(); + Physics2DServer::get_singleton()->body_set_space(q.body, p_space); + } } } @@ -116,6 +141,10 @@ void TileMap::_update_quadrant_transform() { Transform2D global_transform = get_global_transform(); + Transform2D local_transform; + if (collision_parent) + local_transform = get_transform(); + Transform2D nav_rel; if (navigation) nav_rel = get_relative_transform_to_parent(navigation); @@ -125,8 +154,11 @@ void TileMap::_update_quadrant_transform() { Quadrant &q = E->get(); Transform2D xform; xform.set_origin(q.pos); - xform = global_transform * xform; - Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform); + + if (!use_parent) { + xform = global_transform * xform; + Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform); + } if (navigation) { for (Map<PosKey, Quadrant::NavPoly>::Element *F = q.navpoly_ids.front(); F; F = F->next()) { @@ -225,6 +257,34 @@ void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const xform.elements[2] += offset; } +void TileMap::_add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D> &p_shape, const TileSet::ShapeData &p_shape_data, const Transform2D &p_xform, const Vector2 &p_metadata) { + Physics2DServer *ps = Physics2DServer::get_singleton(); + + if (!use_parent) { + ps->body_add_shape(p_q.body, p_shape->get_rid(), p_xform); + ps->body_set_shape_metadata(p_q.body, shape_idx, p_metadata); + ps->body_set_shape_as_one_way_collision(p_q.body, shape_idx, p_shape_data.one_way_collision, p_shape_data.one_way_collision_margin); + + } else if (collision_parent) { + Transform2D xform = p_xform; + xform.set_origin(xform.get_origin() + p_q.pos); + + collision_parent->shape_owner_add_shape(p_q.shape_owner_id, p_shape); + + int real_index = collision_parent->shape_owner_get_shape_index(p_q.shape_owner_id, shape_idx); + RID rid = collision_parent->get_rid(); + + if (Object::cast_to<Area2D>(collision_parent) != NULL) { + ps->area_set_shape_transform(rid, real_index, get_transform() * xform); + } else { + ps->body_set_shape_transform(rid, real_index, get_transform() * xform); + ps->body_set_shape_metadata(rid, real_index, p_metadata); + ps->body_set_shape_as_one_way_collision(rid, real_index, p_shape_data.one_way_collision, p_shape_data.one_way_collision_margin); + } + } + shape_idx++; +} + void TileMap::update_dirty_quadrants() { if (!pending_update) @@ -268,7 +328,11 @@ void TileMap::update_dirty_quadrants() { q.canvas_items.clear(); - ps->body_clear_shapes(q.body); + if (!use_parent) { + ps->body_clear_shapes(q.body); + } else if (collision_parent) { + collision_parent->shape_owner_clear_shapes(q.shape_owner_id); + } int shape_idx = 0; if (navigation) { @@ -427,10 +491,7 @@ void TileMap::update_dirty_quadrants() { for (int k = 0; k < _shapes.size(); k++) { Ref<ConvexPolygonShape2D> convex = _shapes[k]; if (convex.is_valid()) { - ps->body_add_shape(q.body, convex->get_rid(), xform); - ps->body_set_shape_metadata(q.body, shape_idx, Vector2(E->key().x, E->key().y)); - ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[j].one_way_collision, shapes[j].one_way_collision_margin); - shape_idx++; + _add_shape(shape_idx, q, convex, shapes[j], xform, Vector2(E->key().x, E->key().y)); #ifdef DEBUG_ENABLED } else { print_error("The TileSet assigned to the TileMap " + get_name() + " has an invalid convex shape."); @@ -438,10 +499,7 @@ void TileMap::update_dirty_quadrants() { } } } else { - ps->body_add_shape(q.body, shape->get_rid(), xform); - ps->body_set_shape_metadata(q.body, shape_idx, Vector2(E->key().x, E->key().y)); - ps->body_set_shape_as_one_way_collision(q.body, shape_idx, shapes[j].one_way_collision, shapes[j].one_way_collision_margin); - shape_idx++; + _add_shape(shape_idx, q, shape, shapes[j], xform, Vector2(E->key().x, E->key().y)); } } } @@ -616,22 +674,29 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons xform.set_origin(q.pos); //q.canvas_item = VisualServer::get_singleton()->canvas_item_create(); - q.body = Physics2DServer::get_singleton()->body_create(); - Physics2DServer::get_singleton()->body_set_mode(q.body, use_kinematic ? Physics2DServer::BODY_MODE_KINEMATIC : Physics2DServer::BODY_MODE_STATIC); - - Physics2DServer::get_singleton()->body_attach_object_instance_id(q.body, get_instance_id()); - Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer); - Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask); - Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, friction); - Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, bounce); - - if (is_inside_tree()) { - xform = get_global_transform() * xform; - RID space = get_world_2d()->get_space(); - Physics2DServer::get_singleton()->body_set_space(q.body, space); - } + if (!use_parent) { + q.body = Physics2DServer::get_singleton()->body_create(); + Physics2DServer::get_singleton()->body_set_mode(q.body, use_kinematic ? Physics2DServer::BODY_MODE_KINEMATIC : Physics2DServer::BODY_MODE_STATIC); + + Physics2DServer::get_singleton()->body_attach_object_instance_id(q.body, get_instance_id()); + Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer); + Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask); + Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, friction); + Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, bounce); - Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform); + if (is_inside_tree()) { + xform = get_global_transform() * xform; + RID space = get_world_2d()->get_space(); + Physics2DServer::get_singleton()->body_set_space(q.body, space); + } + + Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform); + } else if (collision_parent) { + xform = get_transform() * xform; + q.shape_owner_id = collision_parent->create_shape_owner(this); + } else { + q.shape_owner_id = -1; + } rect_cache_dirty = true; quadrant_order_dirty = true; @@ -641,7 +706,12 @@ Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(cons void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) { Quadrant &q = Q->get(); - Physics2DServer::get_singleton()->free(q.body); + if (!use_parent) { + Physics2DServer::get_singleton()->free(q.body); + } else if (collision_parent) { + collision_parent->remove_shape_owner(q.shape_owner_id); + } + for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) { VisualServer::get_singleton()->free(E->get()); @@ -1135,20 +1205,24 @@ Rect2 TileMap::_edit_get_rect() const { void TileMap::set_collision_layer(uint32_t p_layer) { collision_layer = p_layer; - for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { + if (!use_parent) { + for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer); + Quadrant &q = E->get(); + Physics2DServer::get_singleton()->body_set_collision_layer(q.body, collision_layer); + } } } void TileMap::set_collision_mask(uint32_t p_mask) { collision_mask = p_mask; - for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { + if (!use_parent) { + for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask); + Quadrant &q = E->get(); + Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask); + } } } @@ -1184,13 +1258,40 @@ void TileMap::set_collision_use_kinematic(bool p_use_kinematic) { _recreate_quadrants(); } +bool TileMap::get_collision_use_parent() const { + + return use_parent; +} + +void TileMap::set_collision_use_parent(bool p_use_parent) { + + if (use_parent == p_use_parent) return; + + _clear_quadrants(); + + use_parent = p_use_parent; + set_notify_local_transform(use_parent); + + if (use_parent && is_inside_tree()) { + collision_parent = Object::cast_to<CollisionObject2D>(get_parent()); + } else { + collision_parent = NULL; + } + + _recreate_quadrants(); + _change_notify(); + update_configuration_warning(); +} + void TileMap::set_collision_friction(float p_friction) { friction = p_friction; - for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { + if (!use_parent) { + for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, p_friction); + Quadrant &q = E->get(); + Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, p_friction); + } } } @@ -1202,10 +1303,12 @@ float TileMap::get_collision_friction() const { void TileMap::set_collision_bounce(float p_bounce) { bounce = p_bounce; - for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { + if (!use_parent) { + for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) { - Quadrant &q = E->get(); - Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, p_bounce); + Quadrant &q = E->get(); + Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, p_bounce); + } } } float TileMap::get_collision_bounce() const { @@ -1404,6 +1507,12 @@ void TileMap::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(p); } +void TileMap::_validate_property(PropertyInfo &property) const { + if (use_parent && property.name != "collision_use_parent" && property.name.begins_with("collision_")) { + property.usage = PROPERTY_USAGE_NOEDITOR; + } +} + Vector2 TileMap::map_to_world(const Vector2 &p_pos, bool p_ignore_ofs) const { return _map_to_world(p_pos.x, p_pos.y, p_ignore_ofs); @@ -1552,6 +1661,20 @@ bool TileMap::get_clip_uv() const { return clip_uv; } +String TileMap::get_configuration_warning() const { + + String warning = Node2D::get_configuration_warning(); + + if (use_parent && !collision_parent) { + if (!warning.empty()) { + warning += "\n"; + } + return TTR("TileMap with Use Parent on needs a parent CollisionObject2D to give shapes to. Please use it as a child of Area2D, StaticBody2D, RigidBody2D, KinematicBody2D, etc. to give them a shape."); + } + + return warning; +} + void TileMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_tileset", "tileset"), &TileMap::set_tileset); @@ -1587,6 +1710,9 @@ void TileMap::_bind_methods() { ClassDB::bind_method(D_METHOD("set_collision_use_kinematic", "use_kinematic"), &TileMap::set_collision_use_kinematic); ClassDB::bind_method(D_METHOD("get_collision_use_kinematic"), &TileMap::get_collision_use_kinematic); + ClassDB::bind_method(D_METHOD("set_collision_use_parent", "use_parent"), &TileMap::set_collision_use_parent); + ClassDB::bind_method(D_METHOD("get_collision_use_parent"), &TileMap::get_collision_use_parent); + ClassDB::bind_method(D_METHOD("set_collision_layer", "layer"), &TileMap::set_collision_layer); ClassDB::bind_method(D_METHOD("get_collision_layer"), &TileMap::get_collision_layer); @@ -1652,6 +1778,7 @@ void TileMap::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_clip_uv"), "set_clip_uv", "get_clip_uv"); ADD_GROUP("Collision", "collision_"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_use_parent", PROPERTY_HINT_NONE, ""), "set_collision_use_parent", "get_collision_use_parent"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_use_kinematic", PROPERTY_HINT_NONE, ""), "set_collision_use_kinematic", "get_collision_use_kinematic"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision_friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_friction", "get_collision_friction"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision_bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_bounce", "get_collision_bounce"); @@ -1700,6 +1827,8 @@ TileMap::TileMap() { bounce = 0; mode = MODE_SQUARE; half_offset = HALF_OFFSET_DISABLED; + use_parent = false; + collision_parent = NULL; use_kinematic = false; navigation = NULL; y_sort_mode = false; @@ -1710,6 +1839,7 @@ TileMap::TileMap() { fp_adjust = 0.00001; tile_origin = TILE_ORIGIN_TOP_LEFT; set_notify_transform(true); + set_notify_local_transform(false); } TileMap::~TileMap() { diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h index 6a1467aa48..1caaefa213 100644 --- a/scene/2d/tile_map.h +++ b/scene/2d/tile_map.h @@ -37,6 +37,8 @@ #include "scene/2d/node_2d.h" #include "scene/resources/tile_set.h" +class CollisionObject2D; + class TileMap : public Node2D { GDCLASS(TileMap, Node2D); @@ -74,6 +76,8 @@ private: Mode mode; Transform2D custom_transform; HalfOffset half_offset; + bool use_parent; + CollisionObject2D *collision_parent; bool use_kinematic; Navigation2D *navigation; @@ -123,6 +127,7 @@ private: Vector2 pos; List<RID> canvas_items; RID body; + uint32_t shape_owner_id; SelfList<Quadrant> dirty_list; @@ -145,6 +150,7 @@ private: pos = q.pos; canvas_items = q.canvas_items; body = q.body; + shape_owner_id = q.shape_owner_id; cells = q.cells; navpoly_ids = q.navpoly_ids; occluder_instances = q.occluder_instances; @@ -154,6 +160,7 @@ private: pos = q.pos; canvas_items = q.canvas_items; body = q.body; + shape_owner_id = q.shape_owner_id; cells = q.cells; occluder_instances = q.occluder_instances; navpoly_ids = q.navpoly_ids; @@ -188,6 +195,8 @@ private: void _fix_cell_transform(Transform2D &xform, const Cell &p_cell, const Vector2 &p_offset, const Size2 &p_sc); + void _add_shape(int &shape_idx, const Quadrant &p_q, const Ref<Shape2D> &p_shape, const TileSet::ShapeData &p_shape_data, const Transform2D &p_xform, const Vector2 &p_metadata); + Map<PosKey, Quadrant>::Element *_create_quadrant(const PosKey &p_qk); void _erase_quadrant(Map<PosKey, Quadrant>::Element *Q); void _make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q, bool update = true); @@ -218,6 +227,7 @@ protected: void _notification(int p_what); static void _bind_methods(); + virtual void _validate_property(PropertyInfo &property) const; virtual void _changed_callback(Object *p_changed, const char *p_prop); public: @@ -271,6 +281,9 @@ public: void set_collision_use_kinematic(bool p_use_kinematic); bool get_collision_use_kinematic() const; + void set_collision_use_parent(bool p_use_parent); + bool get_collision_use_parent() const; + void set_collision_friction(float p_friction); float get_collision_friction() const; @@ -314,6 +327,8 @@ public: void set_clip_uv(bool p_enable); bool get_clip_uv() const; + String get_configuration_warning() const; + void fix_invalid_tiles(); void clear(); diff --git a/scene/3d/arvr_nodes.cpp b/scene/3d/arvr_nodes.cpp index 95eec41fb2..dfa8fce9be 100644 --- a/scene/3d/arvr_nodes.cpp +++ b/scene/3d/arvr_nodes.cpp @@ -264,6 +264,7 @@ void ARVRController::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rumble"), &ARVRController::get_rumble); ClassDB::bind_method(D_METHOD("set_rumble", "rumble"), &ARVRController::set_rumble); ADD_PROPERTY(PropertyInfo(Variant::REAL, "rumble", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_rumble", "get_rumble"); + ADD_PROPERTY_DEFAULT("rumble", 0.0); ClassDB::bind_method(D_METHOD("get_mesh"), &ARVRController::get_mesh); diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index 7a652ed65f..93954e758a 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -71,7 +71,7 @@ private: struct Output { AudioFilterSW filter; - AudioFilterSW::Processor filter_process[6]; + AudioFilterSW::Processor filter_process[8]; AudioFrame vol[4]; float filter_gain; float pitch_scale; diff --git a/scene/3d/navigation.cpp b/scene/3d/navigation.cpp index 612d91c6e1..12d562c0c6 100644 --- a/scene/3d/navigation.cpp +++ b/scene/3d/navigation.cpp @@ -90,7 +90,6 @@ void Navigation::_navmesh_link(int p_id) { if (!valid) { nm.polygons.pop_back(); ERR_CONTINUE(!valid); - continue; } p.center = center; diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index 3624e04434..d3aad7000d 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -1470,7 +1470,7 @@ Vector3 KinematicCollision::get_remainder() const { return collision.remainder; } Object *KinematicCollision::get_local_shape() const { - ERR_FAIL_COND_V(!owner, NULL); + if (!owner) return NULL; uint32_t ownerid = owner->shape_find_owner(collision.local_shape); return owner->shape_owner_get_owner(ownerid); } diff --git a/scene/3d/spatial.cpp b/scene/3d/spatial.cpp index efd418e3c7..1a41a31253 100644 --- a/scene/3d/spatial.cpp +++ b/scene/3d/spatial.cpp @@ -506,6 +506,8 @@ bool Spatial::is_set_as_toplevel() const { Ref<World> Spatial::get_world() const { ERR_FAIL_COND_V(!is_inside_world(), Ref<World>()); + ERR_FAIL_COND_V(!data.viewport, Ref<World>()); + return data.viewport->find_world(); } diff --git a/scene/3d/visual_instance.cpp b/scene/3d/visual_instance.cpp index 4bb4d18071..5141c84803 100644 --- a/scene/3d/visual_instance.cpp +++ b/scene/3d/visual_instance.cpp @@ -60,7 +60,7 @@ void VisualInstance::_notification(int p_what) { if (skeleton) VisualServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() ); */ - + ERR_FAIL_COND(get_world().is_null()); VisualServer::get_singleton()->instance_set_scenario(instance, get_world()->get_scenario()); _update_visibility(); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 58a0762469..b197971b61 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -173,7 +173,7 @@ void ColorPicker::_value_changed(double) { color.set_hsv(scroll[0]->get_value() / 360.0, scroll[1]->get_value() / 100.0, scroll[2]->get_value() / 100.0, - scroll[3]->get_value() / 100.0); + scroll[3]->get_value() / 255.0); } else { for (int i = 0; i < 4; i++) { color.components[i] = scroll[i]->get_value() / (raw_mode_enabled ? 1.0 : 255.0); @@ -209,17 +209,17 @@ void ColorPicker::_update_color(bool p_update_sliders) { if (hsv_mode_enabled) { for (int i = 0; i < 4; i++) { - scroll[i]->set_step(0.1); + scroll[i]->set_step(1.0); } - scroll[0]->set_max(360); + scroll[0]->set_max(359); scroll[0]->set_value(h * 360.0); scroll[1]->set_max(100); scroll[1]->set_value(s * 100.0); scroll[2]->set_max(100); scroll[2]->set_value(v * 100.0); - scroll[3]->set_max(100); - scroll[3]->set_value(color.components[3] * 100.0); + scroll[3]->set_max(255); + scroll[3]->set_value(color.components[3] * 255.0); } else { for (int i = 0; i < 4; i++) { if (raw_mode_enabled) { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 6e0e26312f..eccd42cb9f 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2249,6 +2249,7 @@ Ref<Theme> Control::get_theme() const { void Control::set_tooltip(const String &p_tooltip) { data.tooltip = p_tooltip; + update_configuration_warning(); } String Control::get_tooltip(const Point2 &p_pos) const { @@ -2540,6 +2541,7 @@ void Control::set_mouse_filter(MouseFilter p_filter) { ERR_FAIL_INDEX(p_filter, 3); data.mouse_filter = p_filter; + update_configuration_warning(); } Control::MouseFilter Control::get_mouse_filter() const { @@ -2703,6 +2705,20 @@ void Control::get_argument_options(const StringName &p_function, int p_idx, List } } } + +String Control::get_configuration_warning() const { + String warning = CanvasItem::get_configuration_warning(); + + if (data.mouse_filter == MOUSE_FILTER_IGNORE && data.tooltip != "") { + if (warning != String()) { + warning += "\n"; + } + warning += TTR("The Hint Tooltip won't be displayed as the control's Mouse Filter is set to \"Ignore\". To solve this, set the Mouse Filter to \"Stop\" or \"Pass\"."); + } + + return warning; +} + void Control::set_clip_contents(bool p_clip) { data.clip_contents = p_clip; diff --git a/scene/gui/control.h b/scene/gui/control.h index 2489a5eda4..1a59a6d2e4 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -487,6 +487,7 @@ public: bool is_visibility_clip_disabled() const; virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const; + virtual String get_configuration_warning() const; Control(); ~Control(); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index ba4d390fc5..04fb991f78 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -381,6 +381,18 @@ void FileDialog::_tree_item_activated() { } } +void FileDialog::update_file_name() { + int idx = filter->get_selected() - 1; + if ((idx == -1 && filter->get_item_count() == 2) || (filter->get_item_count() > 2 && idx >= 0 && idx < filter->get_item_count() - 2)) { + if (idx == -1) idx += 1; + String filter_str = filters[idx]; + String file_str = file->get_text(); + String base_name = file_str.get_basename(); + file_str = base_name + "." + filter_str.strip_edges().to_lower(); + file->set_text(file_str); + } +} + void FileDialog::update_file_list() { tree->clear(); @@ -506,6 +518,7 @@ void FileDialog::update_file_list() { void FileDialog::_filter_selected(int) { + update_file_name(); update_file_list(); } @@ -797,6 +810,7 @@ void FileDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("_select_drive"), &FileDialog::_select_drive); ClassDB::bind_method(D_METHOD("_make_dir"), &FileDialog::_make_dir); ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileDialog::_make_dir_confirm); + ClassDB::bind_method(D_METHOD("_update_file_name"), &FileDialog::update_file_name); ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list); ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir); ClassDB::bind_method(D_METHOD("_go_up"), &FileDialog::_go_up); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 9f7ea1a2f2..191af5fef3 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -102,6 +102,7 @@ private: bool invalidated; void update_dir(); + void update_file_name(); void update_file_list(); void update_filters(); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index e18387a52e..510f1b18ad 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -247,11 +247,11 @@ void Label::_notification(int p_what) { n = String::char_uppercase(n); } - float move = font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow, false); + float move = drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + shadow_ofs, c, n, font_color_shadow); if (use_outline) { - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, shadow_ofs.y), c, n, font_color_shadow, false); - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow, false); - font->draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow, false); + drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, shadow_ofs.y), c, n, font_color_shadow); + drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow); + drawer.draw_char(ci, Point2(x_ofs_shadow, y_ofs) + Vector2(-shadow_ofs.x, -shadow_ofs.y), c, n, font_color_shadow); } x_ofs_shadow += move; chars_total_shadow++; diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 872402e9e1..58671655dc 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -282,7 +282,7 @@ void OptionButton::_set_items(const Array &p_items) { void OptionButton::get_translatable_strings(List<String> *p_strings) const { - return popup->get_translatable_strings(p_strings); + popup->get_translatable_strings(p_strings); } void OptionButton::_bind_methods() { diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp index 553e133946..052c8ccd05 100644 --- a/scene/gui/reference_rect.cpp +++ b/scene/gui/reference_rect.cpp @@ -38,26 +38,41 @@ void ReferenceRect::_notification(int p_what) { if (!is_inside_tree()) return; - if (Engine::get_singleton()->is_editor_hint()) + if (Engine::get_singleton()->is_editor_hint() || !editor_only) draw_rect(Rect2(Point2(), get_size()), border_color, false); } } -void ReferenceRect::set_border_color(const Color &color) { - border_color = color; +void ReferenceRect::set_border_color(const Color &p_color) { + border_color = p_color; + update(); } Color ReferenceRect::get_border_color() const { return border_color; } +void ReferenceRect::set_editor_only(const bool &p_enabled) { + editor_only = p_enabled; + update(); +} + +bool ReferenceRect::get_editor_only() const { + return editor_only; +} + void ReferenceRect::_bind_methods() { ClassDB::bind_method(D_METHOD("get_border_color"), &ReferenceRect::get_border_color); ClassDB::bind_method(D_METHOD("set_border_color", "color"), &ReferenceRect::set_border_color); + ClassDB::bind_method(D_METHOD("get_editor_only"), &ReferenceRect::get_editor_only); + ClassDB::bind_method(D_METHOD("set_editor_only", "enabled"), &ReferenceRect::set_editor_only); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "border_color"), "set_border_color", "get_border_color"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "get_editor_only"); } ReferenceRect::ReferenceRect() { border_color = Color(1, 0, 0); + editor_only = true; } diff --git a/scene/gui/reference_rect.h b/scene/gui/reference_rect.h index de3ccaeeca..7a88333cf2 100644 --- a/scene/gui/reference_rect.h +++ b/scene/gui/reference_rect.h @@ -37,6 +37,7 @@ class ReferenceRect : public Control { GDCLASS(ReferenceRect, Control); Color border_color; + bool editor_only; protected: void _notification(int p_what); @@ -45,8 +46,11 @@ protected: public: ReferenceRect(); - void set_border_color(const Color &color); + void set_border_color(const Color &p_color); Color get_border_color() const; + + void set_editor_only(const bool &p_enabled); + bool get_editor_only() const; }; #endif // REFERENCE_RECT_H diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index fdd21f525b..a6e3d644f6 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -681,6 +681,13 @@ void TextEdit::_notification(int p_what) { } } + if (line_length_guideline) { + int x = xmargin_beg + cache.font->get_char_size('0').width * line_length_guideline_col - cursor.x_ofs; + if (x > xmargin_beg && x < xmargin_end) { + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(x, 0), Point2(x, size.height), cache.line_length_guideline_color); + } + } + int brace_open_match_line = -1; int brace_open_match_column = -1; bool brace_open_matching = false; @@ -1339,13 +1346,6 @@ void TextEdit::_notification(int p_what) { } } - if (line_length_guideline) { - int x = xmargin_beg + cache.font->get_char_size('0').width * line_length_guideline_col - cursor.x_ofs; - if (x > xmargin_beg && x < xmargin_end) { - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(x, 0), Point2(x, size.height), cache.line_length_guideline_color); - } - } - bool completion_below = false; if (completion_active) { // code completion box @@ -4817,14 +4817,18 @@ void TextEdit::deselect() { void TextEdit::select(int p_from_line, int p_from_column, int p_to_line, int p_to_column) { - if (p_from_line >= text.size()) + if (p_from_line < 0) + p_from_line = 0; + else if (p_from_line >= text.size()) p_from_line = text.size() - 1; if (p_from_column >= text[p_from_line].length()) p_from_column = text[p_from_line].length(); if (p_from_column < 0) p_from_column = 0; - if (p_to_line >= text.size()) + if (p_to_line < 0) + p_to_line = 0; + else if (p_to_line >= text.size()) p_to_line = text.size() - 1; if (p_to_column >= text[p_to_line].length()) p_to_column = text[p_to_line].length(); diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index e65314644e..88b942ee45 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -425,7 +425,7 @@ void HTTPRequest::_notification(int p_what) { void HTTPRequest::set_use_threads(bool p_use) { - ERR_FAIL_COND(status != HTTPClient::STATUS_DISCONNECTED); + ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED); use_threads = p_use; } @@ -436,7 +436,7 @@ bool HTTPRequest::is_using_threads() const { void HTTPRequest::set_body_size_limit(int p_bytes) { - ERR_FAIL_COND(status != HTTPClient::STATUS_DISCONNECTED); + ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED); body_size_limit = p_bytes; } @@ -448,7 +448,7 @@ int HTTPRequest::get_body_size_limit() const { void HTTPRequest::set_download_file(const String &p_file) { - ERR_FAIL_COND(status != HTTPClient::STATUS_DISCONNECTED); + ERR_FAIL_COND(get_http_client_status() != HTTPClient::STATUS_DISCONNECTED); download_to_file = p_file; } @@ -546,7 +546,6 @@ HTTPRequest::HTTPRequest() { downloaded = 0; body_size_limit = -1; file = NULL; - status = HTTPClient::STATUS_DISCONNECTED; } HTTPRequest::~HTTPRequest() { diff --git a/scene/main/http_request.h b/scene/main/http_request.h index baabda4010..2e58d579ba 100644 --- a/scene/main/http_request.h +++ b/scene/main/http_request.h @@ -88,8 +88,6 @@ private: int redirections; - HTTPClient::Status status; - bool _update_connection(); int max_redirects; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index a580a7f8ac..5888760973 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -71,6 +71,8 @@ void Node::_notification(int p_notification) { } break; case NOTIFICATION_ENTER_TREE: { + ERR_FAIL_COND(!get_viewport()); + ERR_FAIL_COND(!get_tree()); if (data.pause_mode == PAUSE_MODE_INHERIT) { @@ -94,6 +96,8 @@ void Node::_notification(int p_notification) { } break; case NOTIFICATION_EXIT_TREE: { + ERR_FAIL_COND(!get_viewport()); + ERR_FAIL_COND(!get_tree()); get_tree()->node_count--; orphan_node_count++; @@ -840,6 +844,8 @@ bool Node::is_processing_internal() const { void Node::set_process_priority(int p_priority) { data.process_priority = p_priority; + ERR_FAIL_COND(!data.tree); + if (is_processing()) data.tree->make_group_changed("idle_process"); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 7f0cebd492..0e7cec57a4 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -614,6 +614,7 @@ void SceneTree::finish() { root->_set_tree(NULL); root->_propagate_after_exit_tree(); memdelete(root); //delete root + root = NULL; } } @@ -1889,6 +1890,7 @@ void SceneTree::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "debug_navigation_hint"), "set_debug_navigation_hint", "is_debugging_navigation_hint"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_pause", "is_paused"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "refuse_new_network_connections"), "set_refuse_new_network_connections", "is_refusing_new_network_connections"); + ADD_PROPERTY_DEFAULT("refuse_new_network_connections", false); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_font_oversampling"), "set_use_font_oversampling", "is_using_font_oversampling"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "edited_scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_edited_scene_root", "get_edited_scene_root"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "current_scene", PROPERTY_HINT_RESOURCE_TYPE, "Node", 0), "set_current_scene", "get_current_scene"); @@ -1962,7 +1964,7 @@ bool SceneTree::is_using_font_oversampling() const { SceneTree::SceneTree() { - singleton = this; + if (singleton == NULL) singleton = this; _quit = false; accept_quit = true; quit_on_go_back = true; @@ -2107,4 +2109,11 @@ SceneTree::SceneTree() { } SceneTree::~SceneTree() { + if (root) { + root->_set_tree(NULL); + root->_propagate_after_exit_tree(); + memdelete(root); + } + + if (singleton == this) singleton = NULL; } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index dcd70a1844..8561d9aedb 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1701,6 +1701,8 @@ bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_che void Viewport::_gui_input_event(Ref<InputEvent> p_event) { + ERR_FAIL_COND(p_event.is_null()) + //? /* if (!is_visible()) { diff --git a/scene/resources/concave_polygon_shape_2d.cpp b/scene/resources/concave_polygon_shape_2d.cpp index 51dd91fff5..de853f0c30 100644 --- a/scene/resources/concave_polygon_shape_2d.cpp +++ b/scene/resources/concave_polygon_shape_2d.cpp @@ -104,4 +104,6 @@ void ConcavePolygonShape2D::_bind_methods() { ConcavePolygonShape2D::ConcavePolygonShape2D() : Shape2D(Physics2DServer::get_singleton()->concave_polygon_shape_create()) { + PoolVector<Vector2> empty; + set_segments(empty); } diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index a80a57a09c..691d73c181 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -184,7 +184,8 @@ void ParticlesMaterial::_update_shader() { } break; case EMISSION_SHAPE_DIRECTED_POINTS: { code += "uniform sampler2D emission_texture_normal : hint_black;\n"; - } //fallthrough + FALLTHROUGH; + } case EMISSION_SHAPE_POINTS: { code += "uniform sampler2D emission_texture_points : hint_black;\n"; code += "uniform int emission_texture_point_count;\n"; diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 3a0144849a..a5e9351753 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -1487,8 +1487,10 @@ uint32_t CubeMap::get_flags() const { void CubeMap::set_side(Side p_side, const Ref<Image> &p_image) { + ERR_FAIL_COND(p_image.is_null()); ERR_FAIL_COND(p_image->empty()); ERR_FAIL_INDEX(p_side, 6); + if (!_is_valid()) { format = p_image->get_format(); w = p_image->get_width(); |