diff options
Diffstat (limited to 'scene')
69 files changed, 620 insertions, 487 deletions
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 6fff7ac0a4..bb914b90fc 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -399,7 +399,7 @@ void Area2D::set_monitoring(bool p_enable) { if (p_enable == monitoring) return; if (locked) { - ERR_EXPLAIN("Function blocked during in/out signal. Use call_deferred(\"set_enable_monitoring\",true/false)"); + ERR_EXPLAIN("Function blocked during in/out signal. Use call_deferred(\"set_monitoring\",true/false)"); } ERR_FAIL_COND(locked); diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index ed602bbc70..fc67d28a29 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -54,7 +54,7 @@ void AudioStreamPlayer2D::_mix_audio() { int buffer_size = mix_buffer.size(); //mix - stream_playback->mix(buffer, 1.0, buffer_size); + stream_playback->mix(buffer, pitch_scale, buffer_size); //write all outputs for (int i = 0; i < output_count; i++) { @@ -195,7 +195,7 @@ void AudioStreamPlayer2D::_notification(int p_what) { float dist = global_pos.distance_to(screen_in_global); //distance to screen center if (dist > max_distance) - continue; //cant hear this sound in this viewport + continue; //can't hear this sound in this viewport float multiplier = Math::pow(1.0f - dist / max_distance, attenuation); multiplier *= Math::db2linear(volume_db); //also apply player volume! @@ -279,6 +279,13 @@ float AudioStreamPlayer2D::get_volume_db() const { return volume_db; } +void AudioStreamPlayer2D::set_pitch_scale(float p_pitch_scale) { + pitch_scale = p_pitch_scale; +} +float AudioStreamPlayer2D::get_pitch_scale() const { + return pitch_scale; +} + void AudioStreamPlayer2D::play(float p_from_pos) { if (stream_playback.is_valid()) { @@ -419,6 +426,9 @@ void AudioStreamPlayer2D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer2D::set_volume_db); ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer2D::get_volume_db); + ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer2D::set_pitch_scale); + ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer2D::get_pitch_scale); + ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer2D::play, DEFVAL(0.0)); ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer2D::seek); ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer2D::stop); @@ -448,6 +458,7 @@ void AudioStreamPlayer2D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE, "-80,24"), "set_volume_db", "get_volume_db"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,32,0.01"), "set_pitch_scale", "get_pitch_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_RANGE, "1,65536,1"), "set_max_distance", "get_max_distance"); @@ -461,6 +472,7 @@ void AudioStreamPlayer2D::_bind_methods() { AudioStreamPlayer2D::AudioStreamPlayer2D() { volume_db = 0; + pitch_scale = 1.0; autoplay = false; setseek = -1; active = false; diff --git a/scene/2d/audio_stream_player_2d.h b/scene/2d/audio_stream_player_2d.h index 39bc985f58..9ae8e3a518 100644 --- a/scene/2d/audio_stream_player_2d.h +++ b/scene/2d/audio_stream_player_2d.h @@ -70,6 +70,7 @@ private: volatile float setplay; float volume_db; + float pitch_scale; bool autoplay; StringName bus; @@ -98,6 +99,9 @@ public: void set_volume_db(float p_volume); float get_volume_db() const; + void set_pitch_scale(float p_pitch_scale); + float get_pitch_scale() const; + void play(float p_from_pos = 0.0); void seek(float p_seconds); void stop(); diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index e7e62a197c..d172da5bd9 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -91,8 +91,8 @@ Transform2D Camera2D::get_camera_transform() { if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) { if (h_drag_enabled && !Engine::get_singleton()->is_editor_hint()) { - camera_pos.x = MIN(camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT])); - camera_pos.x = MAX(camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT])); + camera_pos.x = MIN(camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT])); + camera_pos.x = MAX(camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT])); } else { if (h_ofs < 0) { @@ -104,8 +104,8 @@ Transform2D Camera2D::get_camera_transform() { if (v_drag_enabled && !Engine::get_singleton()->is_editor_hint()) { - camera_pos.y = MIN(camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM])); - camera_pos.y = MAX(camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP])); + camera_pos.y = MIN(camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP])); + camera_pos.y = MAX(camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM])); } else { diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 12d6f32567..87bcdae527 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -101,7 +101,7 @@ void CanvasItemMaterial::_update_shader() { case LIGHT_MODE_UNSHADED: code += ",unshaded"; break; case LIGHT_MODE_LIGHT_ONLY: code += ",light_only"; break; } - code += ";\n"; //thats it. + code += ";\n"; //that's it. ShaderData shader_data; shader_data.shader = VS::get_singleton()->shader_create(); diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp index e451e7a65b..8350e7c48a 100644 --- a/scene/2d/collision_object_2d.cpp +++ b/scene/2d/collision_object_2d.cpp @@ -328,6 +328,20 @@ void CollisionObject2D::_update_pickable() { Physics2DServer::get_singleton()->body_set_pickable(rid, pickable); } +String CollisionObject2D::get_configuration_warning() const { + + String warning = Node2D::get_configuration_warning(); + + if (shapes.empty()) { + if (warning == String()) { + warning += "\n"; + } + warning += TTR("This node has no children shapes, so it can't interact with the space.\nConsider adding CollisionShape2D or CollisionPolygon2D children nodes to define its shape."); + } + + return warning; +} + void CollisionObject2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject2D::get_rid); diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h index ee3cea46a5..6da63d1a0b 100644 --- a/scene/2d/collision_object_2d.h +++ b/scene/2d/collision_object_2d.h @@ -107,6 +107,8 @@ public: void set_pickable(bool p_enabled); bool is_pickable() const; + String get_configuration_warning() const; + _FORCE_INLINE_ RID get_rid() const { return rid; } CollisionObject2D(); diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp index 7a96a54854..329382c034 100644 --- a/scene/2d/joints_2d.cpp +++ b/scene/2d/joints_2d.cpp @@ -75,8 +75,7 @@ void Joint2D::_update_joint(bool p_only_free) { ba = body_a->get_rid(); bb = body_b->get_rid(); - if (exclude_from_collision) - Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); + Physics2DServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); } void Joint2D::set_node_a(const NodePath &p_node_a) { diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp index 2c8f509bd3..052a0ac026 100644 --- a/scene/2d/path_2d.cpp +++ b/scene/2d/path_2d.cpp @@ -39,7 +39,7 @@ Rect2 Path2D::_edit_get_rect() const { - if (curve->get_point_count() == 0) + if (!curve.is_valid() || curve->get_point_count() == 0) return Rect2(0, 0, 0, 0); Rect2 aabb = Rect2(curve->get_point_position(0), Vector2(0, 0)); diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 1b25b3588a..cc99ce5f49 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -244,6 +244,7 @@ void RigidBody2D::_body_enter_tree(ObjectID p_id) { Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); + ERR_FAIL_COND(!contact_monitor); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(E->get().in_scene); @@ -266,6 +267,7 @@ void RigidBody2D::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); + ERR_FAIL_COND(!contact_monitor); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->get().in_scene); @@ -291,6 +293,7 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap Object *obj = ObjectDB::get_instance(objid); Node *node = Object::cast_to<Node>(obj); + ERR_FAIL_COND(!contact_monitor); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(objid); /*if (obj) { @@ -763,6 +766,14 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) { for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) { //clean up mess + Object *obj = ObjectDB::get_instance(E->key()); + Node *node = Object::cast_to<Node>(obj); + + if (node) { + + node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree); + } } memdelete(contact_monitor); @@ -807,7 +818,7 @@ String RigidBody2D::get_configuration_warning() const { if (warning != String()) { warning += "\n"; } - warning += TTR("Size changes to RigidBody2D (in character or rigid modes) will be overriden by the physics engine when running.\nChange the size in children collision shapes instead."); + warning += TTR("Size changes to RigidBody2D (in character or rigid modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); } return warning; diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index cf2a47f14c..d448ef024d 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -57,18 +57,18 @@ void AudioStreamPlayer3D::_mix_audio() { //mix if (output_count > 0 || out_of_range_mode == OUT_OF_RANGE_MIX) { - float pitch_scale = 0.0; + float output_pitch_scale = 0.0; if (output_count) { //used for doppler, not realistic but good enough for (int i = 0; i < output_count; i++) { - pitch_scale += outputs[i].pitch_scale; + output_pitch_scale += outputs[i].pitch_scale; } - pitch_scale /= float(output_count); + output_pitch_scale /= float(output_count); } else { - pitch_scale = 1.0; + output_pitch_scale = 1.0; } - stream_playback->mix(buffer, pitch_scale, buffer_size); + stream_playback->mix(buffer, pitch_scale * output_pitch_scale, buffer_size); } //write all outputs @@ -320,7 +320,7 @@ void AudioStreamPlayer3D::_notification(int p_what) { total_max = MAX(total_max, cam_area_pos.length()); } if (total_max > max_distance) { - continue; //cant hear this sound in this camera + continue; //can't hear this sound in this camera } } @@ -607,6 +607,13 @@ float AudioStreamPlayer3D::get_max_db() const { return max_db; } +void AudioStreamPlayer3D::set_pitch_scale(float p_pitch_scale) { + pitch_scale = p_pitch_scale; +} +float AudioStreamPlayer3D::get_pitch_scale() const { + return pitch_scale; +} + void AudioStreamPlayer3D::play(float p_from_pos) { if (stream_playback.is_valid()) { @@ -832,6 +839,9 @@ void AudioStreamPlayer3D::_bind_methods() { ClassDB::bind_method(D_METHOD("set_max_db", "max_db"), &AudioStreamPlayer3D::set_max_db); ClassDB::bind_method(D_METHOD("get_max_db"), &AudioStreamPlayer3D::get_max_db); + ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer3D::set_pitch_scale); + ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer3D::get_pitch_scale); + ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer3D::play, DEFVAL(0.0)); ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer3D::seek); ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer3D::stop); @@ -885,6 +895,7 @@ void AudioStreamPlayer3D::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "unit_db", PROPERTY_HINT_RANGE, "-80,80"), "set_unit_db", "get_unit_db"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "unit_size", PROPERTY_HINT_RANGE, "0.1,100,0.1"), "set_unit_size", "get_unit_size"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_db", PROPERTY_HINT_RANGE, "-24,6"), "set_max_db", "get_max_db"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,32,0.01"), "set_pitch_scale", "get_pitch_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_distance", PROPERTY_HINT_RANGE, "0,65536,1"), "set_max_distance", "get_max_distance"); @@ -921,6 +932,7 @@ AudioStreamPlayer3D::AudioStreamPlayer3D() { unit_size = 1; attenuation_model = ATTENUATION_INVERSE_DISTANCE; max_db = 3; + pitch_scale = 1.0; autoplay = false; setseek = -1; active = false; diff --git a/scene/3d/audio_stream_player_3d.h b/scene/3d/audio_stream_player_3d.h index 9a1f369da2..1fcb83cf21 100644 --- a/scene/3d/audio_stream_player_3d.h +++ b/scene/3d/audio_stream_player_3d.h @@ -106,6 +106,7 @@ private: float unit_db; float unit_size; float max_db; + float pitch_scale; bool autoplay; StringName bus; @@ -153,6 +154,9 @@ public: void set_max_db(float p_boost); float get_max_db() const; + void set_pitch_scale(float p_pitch_scale); + float get_pitch_scale() const; + void play(float p_from_pos = 0.0); void seek(float p_seconds); void stop(); diff --git a/scene/3d/camera.h b/scene/3d/camera.h index 3fd3303a25..e2679870de 100644 --- a/scene/3d/camera.h +++ b/scene/3d/camera.h @@ -97,7 +97,7 @@ protected: void _update_camera_mode(); void _notification(int p_what); - virtual void _validate_property(PropertyInfo &property) const; + virtual void _validate_property(PropertyInfo &p_property) const; static void _bind_methods(); diff --git a/scene/3d/collision_object.cpp b/scene/3d/collision_object.cpp index b246fe75f4..07235b3da4 100644 --- a/scene/3d/collision_object.cpp +++ b/scene/3d/collision_object.cpp @@ -365,6 +365,20 @@ bool CollisionObject::get_capture_input_on_drag() const { return capture_input_on_drag; } +String CollisionObject::get_configuration_warning() const { + + String warning = Spatial::get_configuration_warning(); + + if (shapes.empty()) { + if (warning == String()) { + warning += "\n"; + } + warning += TTR("This node has no children shapes, so it can't interact with the space.\nConsider adding CollisionShape or CollisionPolygon children nodes to define its shape."); + } + + return warning; +} + CollisionObject::CollisionObject() { capture_input_on_drag = false; diff --git a/scene/3d/collision_object.h b/scene/3d/collision_object.h index c58e02848f..f31d65e411 100644 --- a/scene/3d/collision_object.h +++ b/scene/3d/collision_object.h @@ -109,6 +109,8 @@ public: _FORCE_INLINE_ RID get_rid() const { return rid; } + virtual String get_configuration_warning() const; + CollisionObject(); ~CollisionObject(); }; diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index a15a7dcead..25acd6deb0 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -258,6 +258,7 @@ void RigidBody::_body_enter_tree(ObjectID p_id) { Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); + ERR_FAIL_COND(!contact_monitor); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(E->get().in_tree); @@ -281,6 +282,7 @@ void RigidBody::_body_exit_tree(ObjectID p_id) { Object *obj = ObjectDB::get_instance(p_id); Node *node = Object::cast_to<Node>(obj); ERR_FAIL_COND(!node); + ERR_FAIL_COND(!contact_monitor); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id); ERR_FAIL_COND(!E); ERR_FAIL_COND(!E->get().in_tree); @@ -306,6 +308,7 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, Object *obj = ObjectDB::get_instance(objid); Node *node = Object::cast_to<Node>(obj); + ERR_FAIL_COND(!contact_monitor); Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(objid); ERR_FAIL_COND(!body_in && !E); @@ -719,6 +722,14 @@ void RigidBody::set_contact_monitor(bool p_enabled) { for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) { //clean up mess + Object *obj = ObjectDB::get_instance(E->key()); + Node *node = Object::cast_to<Node>(obj); + + if (node) { + + node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree); + } } memdelete(contact_monitor); @@ -772,7 +783,7 @@ String RigidBody::get_configuration_warning() const { if (warning != String()) { warning += "\n"; } - warning += TTR("Size changes to RigidBody (in character or rigid modes) will be overriden by the physics engine when running.\nChange the size in children collision shapes instead."); + warning += TTR("Size changes to RigidBody (in character or rigid modes) will be overridden by the physics engine when running.\nChange the size in children collision shapes instead."); } return warning; diff --git a/scene/3d/physics_joint.cpp b/scene/3d/physics_joint.cpp index fed6d76f65..2e9f1a241a 100644 --- a/scene/3d/physics_joint.cpp +++ b/scene/3d/physics_joint.cpp @@ -71,8 +71,7 @@ void Joint::_update_joint(bool p_only_free) { ba = body_a->get_rid(); bb = body_b->get_rid(); - if (exclude_from_collision) - PhysicsServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid()); + PhysicsServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); } void Joint::set_node_a(const NodePath &p_node_a) { diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index 99541db4d3..d3a13c741e 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -61,7 +61,7 @@ bool Skeleton::_set(const StringName &p_path, const Variant &p_value) { set_bone_enabled(which, p_value); else if (what == "pose") set_bone_pose(which, p_value); - else if (what == "bound_childs") { + else if (what == "bound_children") { Array children = p_value; if (is_inside_tree()) { @@ -105,7 +105,7 @@ bool Skeleton::_get(const StringName &p_path, Variant &r_ret) const { r_ret = is_bone_enabled(which); else if (what == "pose") r_ret = get_bone_pose(which); - else if (what == "bound_childs") { + else if (what == "bound_children") { Array children; for (const List<uint32_t>::Element *E = bones[which].nodes_bound.front(); E; E = E->next()) { @@ -134,7 +134,7 @@ void Skeleton::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::TRANSFORM, prep + "rest")); p_list->push_back(PropertyInfo(Variant::BOOL, prep + "enabled")); p_list->push_back(PropertyInfo(Variant::TRANSFORM, prep + "pose", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::ARRAY, prep + "bound_childs")); + p_list->push_back(PropertyInfo(Variant::ARRAY, prep + "bound_children")); } } diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index de0d4216d9..d693670055 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -83,12 +83,12 @@ class Skeleton : public Spatial { Array _get_bound_child_nodes_to_bone(int p_bone) const { Array bound; - List<Node *> childs; - get_bound_child_nodes_to_bone(p_bone, &childs); + List<Node *> children; + get_bound_child_nodes_to_bone(p_bone, &children); - for (int i = 0; i < childs.size(); i++) { + for (int i = 0; i < children.size(); i++) { - bound.push_back(childs[i]); + bound.push_back(children[i]); } return bound; } diff --git a/scene/3d/vehicle_body.cpp b/scene/3d/vehicle_body.cpp index aeee51c4b2..ed3bde9504 100644 --- a/scene/3d/vehicle_body.cpp +++ b/scene/3d/vehicle_body.cpp @@ -572,7 +572,7 @@ void VehicleBody::_resolve_single_bilateral(PhysicsDirectBodyState *s, const Vec b2invmass); // FIXME: rel_vel assignment here is overwritten by the following assignment. - // What seemes to be intented in the next next assignment is: rel_vel = normal.dot(rel_vel); + // What seemes to be intended in the next next assignment is: rel_vel = normal.dot(rel_vel); // Investigate why. real_t rel_vel = jac.getRelativeVelocity( s->get_linear_velocity(), diff --git a/scene/3d/voxel_light_baker.cpp b/scene/3d/voxel_light_baker.cpp index e1717a56f3..d389b69ef3 100644 --- a/scene/3d/voxel_light_baker.cpp +++ b/scene/3d/voxel_light_baker.cpp @@ -461,16 +461,16 @@ void VoxelLightBaker::_plot_face(int p_idx, int p_level, int p_x, int p_y, int p } } - if (bake_cells[p_idx].childs[i] == CHILD_EMPTY) { + if (bake_cells[p_idx].children[i] == CHILD_EMPTY) { //sub cell must be created uint32_t child_idx = bake_cells.size(); - bake_cells[p_idx].childs[i] = child_idx; + bake_cells[p_idx].children[i] = child_idx; bake_cells.resize(bake_cells.size() + 1); bake_cells[child_idx].level = p_level + 1; } - _plot_face(bake_cells[p_idx].childs[i], p_level + 1, nx, ny, nz, p_vtx, p_normal, p_uv, p_material, aabb); + _plot_face(bake_cells[p_idx].children[i], p_level + 1, nx, ny, nz, p_vtx, p_normal, p_uv, p_material, aabb); } } } @@ -700,7 +700,7 @@ void VoxelLightBaker::_init_light_plot(int p_idx, int p_level, int p_x, int p_y, int half = (1 << (cell_subdiv - 1)) >> (p_level + 1); for (int i = 0; i < 8; i++) { - uint32_t child = bake_cells[p_idx].childs[i]; + uint32_t child = bake_cells[p_idx].children[i]; if (child == CHILD_EMPTY) continue; @@ -809,7 +809,7 @@ uint32_t VoxelLightBaker::_find_cell_at_pos(const Cell *cells, int x, int y, int ofs_z += half; } - cell = bc->childs[child]; + cell = bc->children[child]; if (cell == CHILD_EMPTY) return CHILD_EMPTY; @@ -1257,7 +1257,7 @@ void VoxelLightBaker::_fixup_plot(int p_idx, int p_level) { for (int i = 0; i < 8; i++) { - uint32_t child = bake_cells[p_idx].childs[i]; + uint32_t child = bake_cells[p_idx].children[i]; if (child == CHILD_EMPTY) continue; @@ -1483,7 +1483,7 @@ void VoxelLightBaker::_sample_baked_octree_filtered_and_anisotropic(const Vector ofs_z += half; } - cell = bc->childs[child]; + cell = bc->children[child]; if (cell == CHILD_EMPTY) break; @@ -1766,7 +1766,7 @@ Vector3 VoxelLightBaker::_compute_ray_trace_at_pos(const Vector3 &p_pos, const V ofs_z += half; } - cell = bc->childs[child]; + cell = bc->children[child]; if (unlikely(cell == CHILD_EMPTY)) break; @@ -1928,7 +1928,7 @@ Error VoxelLightBaker::make_lightmap(const Transform &p_xform, Ref<Mesh> &p_mesh for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (lightmap_ptr[i * width + j].normal == Vector3()) - continue; //empty, dont write over it anyway + continue; //empty, don't write over it anyway float gauss_sum = gauss_kernel[0]; Vector3 accum = lightmap_ptr[i * width + j].pos * gauss_kernel[0]; for (int k = 1; k < 4; k++) { @@ -2191,7 +2191,7 @@ PoolVector<int> VoxelLightBaker::create_gi_probe_data() { for (int i = 0; i < bake_cells.size(); i++) { for (int j = 0; j < 8; j++) { - w32[ofs++] = bake_cells[i].childs[j]; + w32[ofs++] = bake_cells[i].children[j]; } { //albedo @@ -2275,7 +2275,7 @@ void VoxelLightBaker::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Re for (int i = 0; i < 8; i++) { - uint32_t child = bake_cells[p_idx].childs[i]; + uint32_t child = bake_cells[p_idx].children[i]; if (child == CHILD_EMPTY || child >= max_original_cells) continue; @@ -2290,7 +2290,7 @@ void VoxelLightBaker::_debug_mesh(int p_idx, int p_level, const AABB &p_aabb, Re if (i & 4) aabb.position.z += aabb.size.z; - _debug_mesh(bake_cells[p_idx].childs[i], p_level + 1, aabb, p_multimesh, idx, p_mode); + _debug_mesh(bake_cells[p_idx].children[i], p_level + 1, aabb, p_multimesh, idx, p_mode); } } } @@ -2423,7 +2423,7 @@ PoolVector<uint8_t> VoxelLightBaker::create_capture_octree(int p_subdiv) { } for (int j = 0; j < 8; j++) { - uint32_t child = bake_cells[demap[i]].childs[j]; + uint32_t child = bake_cells[demap[i]].children[j]; octree[i].children[j] = child == CHILD_EMPTY ? CHILD_EMPTY : remap[child]; } } diff --git a/scene/3d/voxel_light_baker.h b/scene/3d/voxel_light_baker.h index d270a26a2a..6a1f1253a3 100644 --- a/scene/3d/voxel_light_baker.h +++ b/scene/3d/voxel_light_baker.h @@ -60,7 +60,7 @@ private: struct Cell { - uint32_t childs[8]; + uint32_t children[8]; float albedo[3]; //albedo in RGB24 float emission[3]; //accumulated light in 16:16 fixed point (needs to be integer for moving lights fast) float normal[3]; @@ -70,7 +70,7 @@ private: Cell() { for (int i = 0; i < 8; i++) { - childs[i] = CHILD_EMPTY; + children[i] = CHILD_EMPTY; } for (int i = 0; i < 3; i++) { diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index d1829ce4d4..9db4a5fb04 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -78,9 +78,6 @@ bool AnimationPlayer::_set(const StringName &p_name, const Variant &p_value) { set_blend_time(from, to, time); } - } else if (p_name == SceneStringNames::get_singleton()->autoplay) { - autoplay = p_value; - } else return false; @@ -123,9 +120,6 @@ bool AnimationPlayer::_get(const StringName &p_name, Variant &r_ret) const { } r_ret = array; - } else if (name == "autoplay") { - r_ret = autoplay; - } else return false; @@ -172,7 +166,6 @@ void AnimationPlayer::_get_property_list(List<PropertyInfo> *p_list) const { } p_list->push_back(PropertyInfo(Variant::ARRAY, "blend_times", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); - p_list->push_back(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR)); } void AnimationPlayer::advance(float p_time) { @@ -977,6 +970,7 @@ bool AnimationPlayer::is_playing() const { return true; */ } + void AnimationPlayer::set_current_animation(const String &p_anim) { if (p_anim == "[stop]" || p_anim == "") { @@ -986,13 +980,6 @@ void AnimationPlayer::set_current_animation(const String &p_anim) { } else { // Same animation, do not replay from start } - - /* - ERR_FAIL_COND(!animation_set.has(p_anim)); - playback.current.pos = 0; - playback.current.from = &animation_set[p_anim]; - playback.assigned = p_anim; - */ } String AnimationPlayer::get_current_animation() const { @@ -1000,6 +987,23 @@ String AnimationPlayer::get_current_animation() const { return (is_playing() ? playback.assigned : ""); } +void AnimationPlayer::set_assigned_animation(const String &p_anim) { + + if (is_playing()) { + play(p_anim); + } else { + ERR_FAIL_COND(!animation_set.has(p_anim)); + playback.current.pos = 0; + playback.current.from = &animation_set[p_anim]; + playback.assigned = p_anim; + } +} + +String AnimationPlayer::get_assigned_animation() const { + + return playback.assigned; +} + void AnimationPlayer::stop(bool p_reset) { Playback &c = playback; @@ -1301,6 +1305,8 @@ void AnimationPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_current_animation", "anim"), &AnimationPlayer::set_current_animation); ClassDB::bind_method(D_METHOD("get_current_animation"), &AnimationPlayer::get_current_animation); + ClassDB::bind_method(D_METHOD("set_assigned_animation", "anim"), &AnimationPlayer::set_assigned_animation); + ClassDB::bind_method(D_METHOD("get_assigned_animation"), &AnimationPlayer::get_assigned_animation); ClassDB::bind_method(D_METHOD("queue", "name"), &AnimationPlayer::queue); ClassDB::bind_method(D_METHOD("clear_queue"), &AnimationPlayer::clear_queue); @@ -1331,6 +1337,7 @@ void AnimationPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "root_node"), "set_root", "get_root"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_animation", PROPERTY_HINT_ENUM, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_ANIMATE_AS_TRIGGER), "set_current_animation", "get_current_animation"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "assigned_animation", PROPERTY_HINT_NONE, "", 0), "set_assigned_animation", "get_assigned_animation"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "autoplay", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_autoplay", "get_autoplay"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_length", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_length"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "current_animation_position", PROPERTY_HINT_NONE, "", 0), "", "get_current_animation_position"); diff --git a/scene/animation/animation_player.h b/scene/animation/animation_player.h index ef1720443f..ef758bac44 100644 --- a/scene/animation/animation_player.h +++ b/scene/animation/animation_player.h @@ -284,6 +284,8 @@ public: bool is_playing() const; String get_current_animation() const; void set_current_animation(const String &p_anim); + String get_assigned_animation() const; + void set_assigned_animation(const String &p_anim); void stop_all(); void set_active(bool p_active); bool is_active() const; diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 000dbb9cbd..49013b160a 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -219,9 +219,9 @@ void Tween::_bind_methods() { ClassDB::bind_method(D_METHOD("targeting_property", "object", "property", "initial", "initial_val", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_property, DEFVAL(0)); ClassDB::bind_method(D_METHOD("targeting_method", "object", "method", "initial", "initial_method", "final_val", "duration", "trans_type", "ease_type", "delay"), &Tween::targeting_method, DEFVAL(0)); - ADD_SIGNAL(MethodInfo("tween_started", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key"))); - ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key"), PropertyInfo(Variant::REAL, "elapsed"), PropertyInfo(Variant::OBJECT, "value"))); - ADD_SIGNAL(MethodInfo("tween_completed", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::STRING, "key"))); + ADD_SIGNAL(MethodInfo("tween_started", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"))); + ADD_SIGNAL(MethodInfo("tween_step", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"), PropertyInfo(Variant::REAL, "elapsed"), PropertyInfo(Variant::OBJECT, "value"))); + ADD_SIGNAL(MethodInfo("tween_completed", PropertyInfo(Variant::OBJECT, "object"), PropertyInfo(Variant::NODE_PATH, "key"))); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "repeat"), "set_repeat", "is_repeat"); ADD_PROPERTY(PropertyInfo(Variant::INT, "playback_process_mode", PROPERTY_HINT_ENUM, "Physics,Idle"), "set_tween_process_mode", "get_tween_process_mode"); diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp index cf070c2235..408c00334a 100644 --- a/scene/audio/audio_player.cpp +++ b/scene/audio/audio_player.cpp @@ -45,7 +45,7 @@ void AudioStreamPlayer::_mix_internal(bool p_fadeout) { } //mix - stream_playback->mix(buffer, 1.0, buffer_size); + stream_playback->mix(buffer, pitch_scale, buffer_size); //multiply volume interpolating to avoid clicks if this changes float target_volume = p_fadeout ? -80.0 : volume_db; @@ -126,8 +126,8 @@ void AudioStreamPlayer::_notification(int p_what) { if (!active || (setseek < 0 && !stream_playback->is_playing())) { active = false; - emit_signal("finished"); set_process_internal(false); + emit_signal("finished"); } } @@ -177,6 +177,13 @@ float AudioStreamPlayer::get_volume_db() const { return volume_db; } +void AudioStreamPlayer::set_pitch_scale(float p_pitch_scale) { + pitch_scale = p_pitch_scale; +} +float AudioStreamPlayer::get_pitch_scale() const { + return pitch_scale; +} + void AudioStreamPlayer::play(float p_from_pos) { if (stream_playback.is_valid()) { @@ -297,6 +304,9 @@ void AudioStreamPlayer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_volume_db", "volume_db"), &AudioStreamPlayer::set_volume_db); ClassDB::bind_method(D_METHOD("get_volume_db"), &AudioStreamPlayer::get_volume_db); + ClassDB::bind_method(D_METHOD("set_pitch_scale", "pitch_scale"), &AudioStreamPlayer::set_pitch_scale); + ClassDB::bind_method(D_METHOD("get_pitch_scale"), &AudioStreamPlayer::get_pitch_scale); + ClassDB::bind_method(D_METHOD("play", "from_position"), &AudioStreamPlayer::play, DEFVAL(0.0)); ClassDB::bind_method(D_METHOD("seek", "to_position"), &AudioStreamPlayer::seek); ClassDB::bind_method(D_METHOD("stop"), &AudioStreamPlayer::stop); @@ -320,6 +330,7 @@ void AudioStreamPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "AudioStream"), "set_stream", "get_stream"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE, "-80,24"), "set_volume_db", "get_volume_db"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "pitch_scale", PROPERTY_HINT_RANGE, "0.01,32,0.01"), "set_pitch_scale", "get_pitch_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "playing", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_playing", "is_playing"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "is_autoplay_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mix_target", PROPERTY_HINT_ENUM, "Stereo,Surround,Center"), "set_mix_target", "get_mix_target"); @@ -335,6 +346,7 @@ void AudioStreamPlayer::_bind_methods() { AudioStreamPlayer::AudioStreamPlayer() { mix_volume_db = 0; + pitch_scale = 1.0; volume_db = 0; autoplay = false; setseek = -1; diff --git a/scene/audio/audio_player.h b/scene/audio/audio_player.h index 4fee30c0c2..21189aea6d 100644 --- a/scene/audio/audio_player.h +++ b/scene/audio/audio_player.h @@ -54,6 +54,7 @@ private: volatile bool active; float mix_volume_db; + float pitch_scale; float volume_db; bool autoplay; StringName bus; @@ -81,6 +82,9 @@ public: void set_volume_db(float p_volume); float get_volume_db() const; + void set_pitch_scale(float p_pitch_scale); + float get_pitch_scale() const; + void play(float p_from_pos = 0.0); void seek(float p_seconds); void stop(); diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 8b9469021c..9dfd388c3d 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -311,10 +311,6 @@ void BaseButton::set_disabled(bool p_disabled) { status.disabled = p_disabled; update(); _change_notify("disabled"); - if (p_disabled) - set_focus_mode(FOCUS_NONE); - else - set_focus_mode(enabled_focus_mode); } bool BaseButton::is_disabled() const { diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index 9e0e1493d1..6917e112ab 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -90,8 +90,8 @@ public: /* Signals */ - bool is_pressed() const; ///< return wether button is pressed (toggled in) - bool is_pressing() const; ///< return wether button is pressed (toggled in) + bool is_pressed() const; ///< return whether button is pressed (toggled in) + bool is_pressing() const; ///< return whether button is pressed (toggled in) bool is_hovered() const; void set_pressed(bool p_pressed); ///only works in toggle mode diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index d9d033dfb9..01415594d3 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -2013,7 +2013,7 @@ Control *Control::find_prev_valid_focus() const { if (from->is_set_as_toplevel() || !Object::cast_to<Control>(from->get_parent())) { - //find last of the childs + //find last of the children prev_child = _prev_control(from); diff --git a/scene/gui/control.h b/scene/gui/control.h index 2d61ecb2af..51325f27b5 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -317,11 +317,11 @@ public: /* POSITIONING */ - void set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin = false); + void set_anchors_preset(LayoutPreset p_preset, bool p_keep_margin = true); void set_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0); void set_anchors_and_margins_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0); - void set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin = false, bool p_push_opposite_anchor = true); + void set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin = true, bool p_push_opposite_anchor = true); float get_anchor(Margin p_margin) const; void set_margin(Margin p_margin, float p_value); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 1b5014367b..38ce91a4df 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -1147,9 +1147,18 @@ void GraphEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("is_node_connected", "from", "from_port", "to", "to_port"), &GraphEdit::is_node_connected); ClassDB::bind_method(D_METHOD("disconnect_node", "from", "from_port", "to", "to_port"), &GraphEdit::disconnect_node); ClassDB::bind_method(D_METHOD("get_connection_list"), &GraphEdit::_get_connection_list); + ClassDB::bind_method(D_METHOD("clear_connections"), &GraphEdit::clear_connections); ClassDB::bind_method(D_METHOD("get_scroll_ofs"), &GraphEdit::get_scroll_ofs); ClassDB::bind_method(D_METHOD("set_scroll_ofs", "ofs"), &GraphEdit::set_scroll_ofs); + ClassDB::bind_method(D_METHOD("add_valid_right_disconnect_type", "type"), &GraphEdit::add_valid_right_disconnect_type); + ClassDB::bind_method(D_METHOD("remove_valid_right_disconnect_type", "type"), &GraphEdit::remove_valid_right_disconnect_type); + ClassDB::bind_method(D_METHOD("add_valid_left_disconnect_type", "type"), &GraphEdit::add_valid_left_disconnect_type); + ClassDB::bind_method(D_METHOD("remove_valid_left_disconnect_type", "type"), &GraphEdit::remove_valid_left_disconnect_type); + ClassDB::bind_method(D_METHOD("add_valid_connection_type", "from_type", "to_type"), &GraphEdit::add_valid_connection_type); + ClassDB::bind_method(D_METHOD("remove_valid_connection_type", "from_type", "to_type"), &GraphEdit::remove_valid_connection_type); + ClassDB::bind_method(D_METHOD("is_valid_connection_type", "from_type", "to_type"), &GraphEdit::is_valid_connection_type); + ClassDB::bind_method(D_METHOD("set_zoom", "p_zoom"), &GraphEdit::set_zoom); ClassDB::bind_method(D_METHOD("get_zoom"), &GraphEdit::get_zoom); diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index 8c3f835be3..c2b8a7dfab 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -43,107 +43,118 @@ void GridContainer::_notification(int p_what) { int hsep = get_constant("hseparation"); int vsep = get_constant("vseparation"); + int max_col = MIN(get_child_count(), columns); + int max_row = get_child_count() / columns; - int idx = 0; - int max_row = 0; - int max_col = 0; - - Size2 size = get_size(); - + // Compute the per-column/per-row data for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; - int row = idx / columns; - int col = idx % columns; + int row = i / columns; + int col = i % columns; Size2i ms = c->get_combined_minimum_size(); if (col_minw.has(col)) col_minw[col] = MAX(col_minw[col], ms.width); else col_minw[col] = ms.width; - if (row_minh.has(row)) row_minh[row] = MAX(row_minh[row], ms.height); else row_minh[row] = ms.height; - //print_line("store row "+itos(row)+" mw "+itos(ms.height)); - - if (c->get_h_size_flags() & SIZE_EXPAND) + if (c->get_h_size_flags() & SIZE_EXPAND) { col_expanded.insert(col); - if (c->get_v_size_flags() & SIZE_EXPAND) + } + if (c->get_v_size_flags() & SIZE_EXPAND) { row_expanded.insert(row); - - max_col = MAX(col, max_col); - max_row = MAX(row, max_row); - idx++; + } } - Size2 ms; - int expand_rows = 0; - int expand_cols = 0; - + // Evaluate the remaining space for expanded columns/rows + Size2 remaining_space = get_size(); for (Map<int, int>::Element *E = col_minw.front(); E; E = E->next()) { - ms.width += E->get(); - if (col_expanded.has(E->key())) - expand_cols++; + if (!col_expanded.has(E->key())) + remaining_space.width -= E->get(); } for (Map<int, int>::Element *E = row_minh.front(); E; E = E->next()) { - ms.height += E->get(); - if (row_expanded.has(E->key())) - expand_rows++; + if (!row_expanded.has(E->key())) + remaining_space.height -= E->get(); + } + remaining_space.height -= vsep * (max_row - 1); + remaining_space.width -= hsep * (max_col - 1); + + bool can_fit = false; + while (!can_fit) { + // Check if all minwidth constraints are ok if we use the remaining space + can_fit = true; + int max_index = 0; + for (Set<int>::Element *E = col_expanded.front(); E; E = E->next()) { + if (col_minw[E->get()] > col_minw[max_index]) { + max_index = col_minw[E->get()]; + } + if (can_fit && (remaining_space.width / col_expanded.size()) < col_minw[E->get()]) { + can_fit = false; + } + } + + // If not, the column with maximum minwidth is not expanded + if (!can_fit) { + col_expanded.erase(max_index); + remaining_space.width -= col_minw[max_index]; + } } - ms.height += vsep * max_row; - ms.width += hsep * max_col; + can_fit = false; + while (!can_fit) { + // Check if all minwidth constraints are ok if we use the remaining space + can_fit = true; + int max_index = 0; + for (Set<int>::Element *E = row_expanded.front(); E; E = E->next()) { + if (row_minh[E->get()] > row_minh[max_index]) { + max_index = row_minh[E->get()]; + } + if (can_fit && (remaining_space.height / row_expanded.size()) < row_minh[E->get()]) { + can_fit = false; + } + } + + // If not, the row with maximum minwidth is not expanded + if (!can_fit) { + row_expanded.erase(max_index); + remaining_space.height -= row_minh[max_index]; + } + } - int row_expand = expand_rows ? (size.y - ms.y) / expand_rows : 0; - int col_expand = expand_cols ? (size.x - ms.x) / expand_cols : 0; + // Finally, fit the nodes + int col_expand = remaining_space.width / col_expanded.size(); + int row_expand = remaining_space.height / row_expanded.size(); int col_ofs = 0; int row_ofs = 0; - idx = 0; for (int i = 0; i < get_child_count(); i++) { - Control *c = Object::cast_to<Control>(get_child(i)); if (!c || !c->is_visible_in_tree()) continue; - int row = idx / columns; - int col = idx % columns; + int row = i / columns; + int col = i % columns; if (col == 0) { col_ofs = 0; - if (row > 0 && row_minh.has(row - 1)) - row_ofs += row_minh[row - 1] + vsep + (row_expanded.has(row - 1) ? row_expand : 0); + if (row > 0) + row_ofs += ((row_expanded.has(row - 1)) ? row_expand : row_minh[row - 1]) + vsep; } - Size2 s; - if (col_minw.has(col)) - s.width = col_minw[col]; - if (row_minh.has(row)) - s.height = row_minh[row]; - - if (row_expanded.has(row)) - s.height += row_expand; - if (col_expanded.has(col)) - s.width += col_expand; - Point2 p(col_ofs, row_ofs); + Size2 s((col_expanded.has(col)) ? col_expand : col_minw[col], (row_expanded.has(row)) ? row_expand : row_minh[row]); - //print_line("col: "+itos(col)+" row: "+itos(row)+" col_ofs: "+itos(col_ofs)+" row_ofs: "+itos(row_ofs)); fit_child_in_rect(c, Rect2(p, s)); - //print_line("col: "+itos(col)+" row: "+itos(row)+" rect: "+Rect2(p,s)); - - if (col_minw.has(col)) { - col_ofs += col_minw[col] + hsep + (col_expanded.has(col) ? col_expand : 0); - } - idx++; + col_ofs += s.width + hsep; } } break; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 77d3a34c66..fe85d04003 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -517,11 +517,11 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { emit_signal("item_rmb_selected", i, get_local_mouse_position()); } else { - bool selected = !items[i].selected; + bool selected = items[i].selected; select(i, select_mode == SELECT_SINGLE || !mb->get_command()); - if (selected) { + if (!selected || allow_reselect) { if (select_mode == SELECT_SINGLE) { emit_signal("item_selected", i); } else @@ -1241,6 +1241,7 @@ int ItemList::find_metadata(const Variant &p_metadata) const { } void ItemList::set_allow_rmb_select(bool p_allow) { + allow_rmb_select = p_allow; } @@ -1249,6 +1250,16 @@ bool ItemList::get_allow_rmb_select() const { return allow_rmb_select; } +void ItemList::set_allow_reselect(bool p_allow) { + + allow_reselect = p_allow; +} + +bool ItemList::get_allow_reselect() const { + + return allow_reselect; +} + void ItemList::set_icon_scale(real_t p_scale) { icon_scale = p_scale; } @@ -1404,6 +1415,9 @@ void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("set_allow_rmb_select", "allow"), &ItemList::set_allow_rmb_select); ClassDB::bind_method(D_METHOD("get_allow_rmb_select"), &ItemList::get_allow_rmb_select); + ClassDB::bind_method(D_METHOD("set_allow_reselect", "allow"), &ItemList::set_allow_reselect); + ClassDB::bind_method(D_METHOD("get_allow_reselect"), &ItemList::get_allow_reselect); + ClassDB::bind_method(D_METHOD("set_auto_height", "enable"), &ItemList::set_auto_height); ClassDB::bind_method(D_METHOD("has_auto_height"), &ItemList::has_auto_height); @@ -1422,6 +1436,7 @@ void ItemList::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items"); ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Multi"), "set_select_mode", "get_select_mode"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_reselect"), "set_allow_reselect", "get_allow_reselect"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select"); ADD_PROPERTYNO(PropertyInfo(Variant::INT, "max_text_lines"), "set_max_text_lines", "get_max_text_lines"); ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "auto_height"), "set_auto_height", "has_auto_height"); @@ -1432,7 +1447,7 @@ void ItemList::_bind_methods() { ADD_GROUP("Icon", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_mode", PROPERTY_HINT_ENUM, "Top,Left"), "set_icon_mode", "get_icon_mode"); ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "icon_scale"), "set_icon_scale", "get_icon_scale"); - ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "fixed_icon_size"), "set_fixed_icon_size", "get_fixed_icon_size"); + ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "fixed_icon_size"), "set_fixed_icon_size", "get_fixed_icon_size"); BIND_ENUM_CONSTANT(ICON_MODE_TOP); BIND_ENUM_CONSTANT(ICON_MODE_LEFT); @@ -1476,6 +1491,7 @@ ItemList::ItemList() { ensure_selected_visible = false; defer_select_single = -1; allow_rmb_select = false; + allow_reselect = false; do_autoscroll_to_bottom = false; icon_scale = 1.0f; diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index 24e9498044..7f34a250bd 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -106,6 +106,8 @@ private: bool allow_rmb_select; + bool allow_reselect; + real_t icon_scale; bool do_autoscroll_to_bottom; @@ -198,6 +200,9 @@ public: void set_allow_rmb_select(bool p_allow); bool get_allow_rmb_select() const; + void set_allow_reselect(bool p_allow); + bool get_allow_reselect() const; + void ensure_current_is_visible(); void sort_items_by_text(); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 524a68a116..03dc6686b8 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -30,6 +30,7 @@ #include "line_edit.h" #include "label.h" +#include "message_queue.h" #include "os/keyboard.h" #include "os/os.h" #include "print_string.h" @@ -800,7 +801,12 @@ void LineEdit::paste_text() { if (selection.enabled) selection_delete(); append_at_cursor(paste_buffer); - _text_changed(); + if (!text_changed_dirty) { + if (is_inside_tree()) { + MessageQueue::get_singleton()->push_call(this, "_text_changed"); + } + text_changed_dirty = true; + } } } @@ -974,7 +980,12 @@ void LineEdit::delete_text(int p_from_column, int p_to_column) { window_pos = cursor_pos; } - _text_changed(); + if (!text_changed_dirty) { + if (is_inside_tree()) { + MessageQueue::get_singleton()->push_call(this, "_text_changed"); + } + text_changed_dirty = true; + } } void LineEdit::set_text(String p_text) { @@ -1341,6 +1352,7 @@ void LineEdit::_text_changed() { void LineEdit::_emit_text_change() { emit_signal("text_changed", text); _change_notify("text"); + text_changed_dirty = false; } void LineEdit::_clear_redo() { @@ -1373,6 +1385,7 @@ void LineEdit::_create_undo_state() { void LineEdit::_bind_methods() { + ClassDB::bind_method(D_METHOD("_text_changed"), &LineEdit::_text_changed); ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &LineEdit::_toggle_draw_caret); #ifdef TOOLS_ENABLED @@ -1458,6 +1471,7 @@ LineEdit::LineEdit() { window_has_focus = true; max_length = 0; pass = false; + text_changed_dirty = false; placeholder_alpha = 0.6; deselect(); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index e15980d3c4..e3ad3b17f1 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -67,6 +67,7 @@ private: bool editable; bool pass; + bool text_changed_dirty; String undo_text; String text; diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 413edca218..33b3d46486 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -462,9 +462,9 @@ void ScrollContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_enable_v_scroll", "enable"), &ScrollContainer::set_enable_v_scroll); ClassDB::bind_method(D_METHOD("is_v_scroll_enabled"), &ScrollContainer::is_v_scroll_enabled); ClassDB::bind_method(D_METHOD("_update_scrollbar_position"), &ScrollContainer::_update_scrollbar_position); - ClassDB::bind_method(D_METHOD("set_h_scroll", "val"), &ScrollContainer::set_h_scroll); + ClassDB::bind_method(D_METHOD("set_h_scroll", "value"), &ScrollContainer::set_h_scroll); ClassDB::bind_method(D_METHOD("get_h_scroll"), &ScrollContainer::get_h_scroll); - ClassDB::bind_method(D_METHOD("set_v_scroll", "val"), &ScrollContainer::set_v_scroll); + ClassDB::bind_method(D_METHOD("set_v_scroll", "value"), &ScrollContainer::set_v_scroll); ClassDB::bind_method(D_METHOD("get_v_scroll"), &ScrollContainer::get_v_scroll); ADD_GROUP("Scroll", "scroll_"); diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 3c5d524d80..145981d498 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -185,17 +185,22 @@ void SpinBox::_line_edit_focus_exit() { _text_entered(line_edit->get_text()); } +inline void SpinBox::_adjust_width_for_icon(const Ref<Texture> icon) { + + int w = icon->get_width(); + if (w != last_w) { + line_edit->set_margin(MARGIN_RIGHT, -w); + last_w = w; + } +} + void SpinBox::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { Ref<Texture> updown = get_icon("updown"); - int w = updown->get_width(); - if (w != last_w) { - line_edit->set_margin(MARGIN_RIGHT, -w); - last_w = w; - } + _adjust_width_for_icon(updown); RID ci = get_canvas_item(); Size2i size = get_size(); @@ -207,6 +212,7 @@ void SpinBox::_notification(int p_what) { //_value_changed(0); } else if (p_what == NOTIFICATION_ENTER_TREE) { + _adjust_width_for_icon(get_icon("updown")); _value_changed(0); } } diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h index b8565ec082..8863f44bef 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -62,6 +62,8 @@ class SpinBox : public Range { void _line_edit_focus_exit(); + inline void _adjust_width_for_icon(const Ref<Texture> icon); + protected: void _gui_input(const Ref<InputEvent> &p_event); diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index e1d49019b3..bf7033e8ba 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -61,127 +61,69 @@ Control *SplitContainer::_getch(int p_idx) const { } void SplitContainer::_resort() { - - /* First pass, determine minimum size AND amount of stretchable elements */ - int axis = vertical ? 1 : 0; - bool has_first = _getch(0); - bool has_second = _getch(1); + Control *first = _getch(0); + Control *second = _getch(1); - if (!has_first && !has_second) { - return; - } else if (!(has_first && has_second)) { - if (has_first) + // If we have only one element + if (!first || !second) { + if (first) { fit_child_in_rect(_getch(0), Rect2(Point2(), get_size())); - else + } else if (second) { fit_child_in_rect(_getch(1), Rect2(Point2(), get_size())); - + } return; } - Control *first = _getch(0); - Control *second = _getch(1); - - bool ratiomode = false; - bool expand_first_mode = false; - + // Determine expanded children + bool first_expanded = false; + bool second_expanded = false; if (vertical) { - - ratiomode = first->get_v_size_flags() & SIZE_EXPAND && second->get_v_size_flags() & SIZE_EXPAND; - expand_first_mode = first->get_v_size_flags() & SIZE_EXPAND && !(second->get_v_size_flags() & SIZE_EXPAND); + first_expanded = first->get_v_size_flags() & SIZE_EXPAND; + second_expanded = second->get_v_size_flags() & SIZE_EXPAND; } else { - - ratiomode = first->get_h_size_flags() & SIZE_EXPAND && second->get_h_size_flags() & SIZE_EXPAND; - expand_first_mode = first->get_h_size_flags() & SIZE_EXPAND && !(second->get_h_size_flags() & SIZE_EXPAND); + first_expanded = first->get_h_size_flags() & SIZE_EXPAND; + second_expanded = second->get_h_size_flags() & SIZE_EXPAND; } - int sep = get_constant("separation"); + // Determine the separation between items Ref<Texture> g = get_icon("grabber"); - + int sep = get_constant("separation"); if (dragger_visibility == DRAGGER_HIDDEN_COLLAPSED) { sep = 0; } else { sep = MAX(sep, vertical ? g->get_height() : g->get_width()); } - int total = vertical ? get_size().height : get_size().width; - - total -= sep; - - int minimum = 0; - + // Compute the minimum size Size2 ms_first = first->get_combined_minimum_size(); Size2 ms_second = second->get_combined_minimum_size(); - if (vertical) { - minimum = ms_first.height + ms_second.height; - } else { - minimum = ms_first.width + ms_second.width; - } - - int available = total - minimum; - if (available < 0) - available = 0; - - middle_sep = 0; - - if (collapsed) { - - if (ratiomode) { - - int first_ratio = first->get_stretch_ratio(); - int second_ratio = second->get_stretch_ratio(); - - float ratio = float(first_ratio) / (first_ratio + second_ratio); - - middle_sep = ms_first[axis] + available * ratio; - - } else if (expand_first_mode) { - - middle_sep = get_size()[axis] - ms_second[axis] - sep; - } else { - - middle_sep = ms_first[axis]; - } - } else if (ratiomode) { - - int first_ratio = first->get_stretch_ratio(); - int second_ratio = second->get_stretch_ratio(); - - float ratio = float(first_ratio) / (first_ratio + second_ratio); - - if (expand_ofs < -(available * ratio)) - expand_ofs = -(available * ratio); - else if (expand_ofs > (available * (1.0 - ratio))) - expand_ofs = (available * (1.0 - ratio)); - - middle_sep = ms_first[axis] + available * ratio + expand_ofs; - } else if (expand_first_mode) { + float ratio = first->get_stretch_ratio() / (first->get_stretch_ratio() + second->get_stretch_ratio()); - if (expand_ofs > 0) - expand_ofs = 0; - else if (expand_ofs < -available) - expand_ofs = -available; - - middle_sep = get_size()[axis] - ms_second[axis] - sep + expand_ofs; + int no_offset_middle_sep = 0; + if (first_expanded && second_expanded) { + no_offset_middle_sep = get_size()[axis] * ratio - sep / 2; + } else if (first_expanded) { + no_offset_middle_sep = get_size()[axis] - ms_second[axis] - sep; } else { + no_offset_middle_sep = ms_first[axis]; + } - if (expand_ofs < 0) - expand_ofs = 0; - else if (expand_ofs > available) - expand_ofs = available; - - middle_sep = ms_first[axis] + expand_ofs; + middle_sep = no_offset_middle_sep; + middle_sep += (collapsed) ? 0 : split_offset; + middle_sep = MIN(middle_sep, get_size()[axis] - ms_second[axis] - sep); + middle_sep = MAX(middle_sep, ms_first[axis]); + if (!collapsed) { + split_offset = middle_sep - no_offset_middle_sep; } if (vertical) { - fit_child_in_rect(first, Rect2(Point2(0, 0), Size2(get_size().width, middle_sep))); int sofs = middle_sep + sep; fit_child_in_rect(second, Rect2(Point2(0, sofs), Size2(get_size().width, get_size().height - sofs))); } else { - fit_child_in_rect(first, Rect2(Point2(0, 0), Size2(middle_sep, get_size().height))); int sofs = middle_sep + sep; fit_child_in_rect(second, Rect2(Point2(sofs, 0), Size2(get_size().width - sofs, get_size().height))); @@ -290,7 +232,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { dragging = true; drag_from = mb->get_position().y; - drag_ofs = expand_ofs; + drag_ofs = split_offset; } } else { @@ -298,7 +240,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { dragging = true; drag_from = mb->get_position().x; - drag_ofs = expand_ofs; + drag_ofs = split_offset; } } } else { @@ -312,7 +254,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid() && dragging) { - expand_ofs = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from); + split_offset = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from); queue_sort(); emit_signal("dragged", get_split_offset()); } @@ -343,16 +285,16 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const void SplitContainer::set_split_offset(int p_offset) { - if (expand_ofs == p_offset) + if (split_offset == p_offset) return; - expand_ofs = p_offset; + split_offset = p_offset; queue_sort(); } int SplitContainer::get_split_offset() const { - return expand_ofs; + return split_offset; } void SplitContainer::set_collapsed(bool p_collapsed) { @@ -407,7 +349,7 @@ void SplitContainer::_bind_methods() { SplitContainer::SplitContainer(bool p_vertical) { mouse_inside = false; - expand_ofs = 0; + split_offset = 0; middle_sep = 0; vertical = p_vertical; dragging = false; diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h index a31dc766d2..321f7fd3b7 100644 --- a/scene/gui/split_container.h +++ b/scene/gui/split_container.h @@ -46,7 +46,7 @@ public: private: bool vertical; - int expand_ofs; + int split_offset; int middle_sep; bool dragging; int drag_from; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 439b0ce605..f728490136 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -455,7 +455,7 @@ void TextEdit::_update_selection_mode_word() { end += 1; } - // inital selection + // initial selection if (!selection.active) { select(row, beg, row, end); selection.selecting_column = beg; @@ -888,9 +888,9 @@ void TextEdit::_notification(int p_what) { VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, char_w, get_row_height()), cache.selection_color); } } else { - // if it has text, then draw current line marker in the margin, as line number ect will draw over it, draw the rest of line marker later. + // if it has text, then draw current line marker in the margin, as line number etc will draw over it, draw the rest of line marker later. if (line == cursor.line && highlight_current_line) { - VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg, get_row_height()), cache.current_line_color); + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(0, ofs_y, xmargin_beg + ofs_x, get_row_height()), cache.current_line_color); } } @@ -937,7 +937,7 @@ void TextEdit::_notification(int p_what) { cache.font->draw(ci, Point2(cache.style_normal->get_margin(MARGIN_LEFT) + cache.breakpoint_gutter_width + ofs_x, ofs_y + cache.font->get_ascent()), fc, cache.line_number_color); } - //loop through charcters in one line + //loop through characters in one line for (int j = 0; j < str.length(); j++) { //look for keyword @@ -1119,6 +1119,19 @@ void TextEdit::_notification(int p_what) { if ((char_ofs + char_margin) < xmargin_beg) { char_ofs += char_w; + + // line highlighting handle horizontal clipping + if (line == cursor.line && highlight_current_line) { + + if (j == str.length() - 1) { + // end of line when last char is skipped + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, xmargin_end - (xmargin_beg + ofs_x), get_row_height()), cache.current_line_color); + + } else if ((char_ofs + char_margin) > xmargin_beg) { + // char next to margin is skipped + VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(xmargin_beg + ofs_x, ofs_y, (char_ofs + char_margin) - xmargin_beg, get_row_height()), cache.current_line_color); + } + } continue; } @@ -1762,15 +1775,16 @@ void TextEdit::indent_left() { void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) const { float rows = p_mouse.y; + rows -= cache.style_normal->get_margin(MARGIN_TOP); + rows += (CLAMP(v_scroll->get_value() - get_line_scroll_pos(true), 0, 1) * get_row_height()); rows /= get_row_height(); - rows += v_scroll->get_value(); - int row = Math::floor(rows); + int first_vis_line = CLAMP(cursor.line_ofs, 0, text.size() - 1); + int row = first_vis_line + Math::floor(rows); if (is_hiding_enabled()) { // row will be offset by the hidden rows - int lsp = get_line_scroll_pos(true); - int f_ofs = num_lines_from(CLAMP(cursor.line_ofs, 0, text.size() - 1), MIN(row + 1 - cursor.line_ofs, text.size() - cursor.line_ofs)) - 1; - row = cursor.line_ofs + f_ofs; + int f_ofs = num_lines_from(first_vis_line, rows + 1) - 1; + row = first_vis_line + f_ofs; row = CLAMP(row, 0, text.size() - num_lines_from(text.size() - 1, -1)); } @@ -3117,7 +3131,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - if (!scancode_handled && !k->get_command()) { //for german kbds + if (!scancode_handled && !k->get_command()) { //for German kbds if (k->get_unicode() >= 32) { diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 07c9894611..6bd3b26280 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -29,6 +29,8 @@ /*************************************************************************/ #include "texture_button.h" +#include "core/typedefs.h" +#include <stdlib.h> Size2 TextureButton::get_minimum_size() const { @@ -58,10 +60,50 @@ bool TextureButton::has_point(const Point2 &p_point) const { if (click_mask.is_valid()) { - Point2i p = p_point; - if (p.x < 0 || p.x >= click_mask->get_size().width || p.y < 0 || p.y >= click_mask->get_size().height) + Point2 point = p_point; + Rect2 rect = Rect2(); + Size2 mask_size = click_mask->get_size(); + + if (_tile) { + // if the stretch mode is tile we offset the point to keep it inside the mask size + rect.size = mask_size; + if (_position_rect.has_point(point)) { + int cols = (int)Math::ceil(_position_rect.size.x / mask_size.x); + int rows = (int)Math::ceil(_position_rect.size.y / mask_size.y); + int col = (int)(point.x / mask_size.x) % cols; + int row = (int)(point.y / mask_size.y) % rows; + point.x -= mask_size.x * col; + point.y -= mask_size.y * row; + } + } else { + // we need to transform the point from our scaled / translated image back to our mask image + Point2 ofs = _position_rect.position; + Size2 scale = mask_size / _position_rect.size; + + switch (stretch_mode) { + case STRETCH_KEEP_ASPECT_COVERED: { + // if the stretch mode is aspect covered the image uses a texture region so we need to take that into account + float min = MIN(scale.x, scale.y); + scale.x = min; + scale.y = min; + ofs -= _texture_region.position / min; + } break; + } + + // offset and scale the new point position to adjust it to the bitmask size + point -= ofs; + point *= scale; + + // finally, we need to check if the point is inside a rectangle with a position >= 0,0 and a size <= mask_size + rect.position = Point2(MAX(0, _texture_region.position.x), MAX(0, _texture_region.position.y)); + rect.size = Size2(MIN(mask_size.x, _texture_region.size.x), MIN(mask_size.y, _texture_region.size.y)); + } + + if (!rect.has_point(point)) { return false; + } + Point2i p = point; return click_mask->get_bit(p); } @@ -118,8 +160,8 @@ void TextureButton::_notification(int p_what) { if (texdraw.is_valid()) { Point2 ofs; Size2 size = texdraw->get_size(); - Rect2 tex_regin = Rect2(Point2(), texdraw->get_size()); - bool tile = false; + _texture_region = Rect2(Point2(), texdraw->get_size()); + _tile = false; if (expand) { switch (stretch_mode) { case STRETCH_KEEP: @@ -130,7 +172,7 @@ void TextureButton::_notification(int p_what) { break; case STRETCH_TILE: size = get_size(); - tile = true; + _tile = true; break; case STRETCH_KEEP_CENTERED: ofs = (get_size() - texdraw->get_size()) / 2; @@ -161,14 +203,15 @@ void TextureButton::_notification(int p_what) { float scale = scaleSize.width > scaleSize.height ? scaleSize.width : scaleSize.height; Size2 scaledTexSize = tex_size * scale; Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f; - tex_regin = Rect2(ofs, size / scale); + _texture_region = Rect2(ofs, size / scale); } break; } } - if (tile) - draw_texture_rect(texdraw, Rect2(ofs, size), tile); + _position_rect = Rect2(ofs, size); + if (_tile) + draw_texture_rect(texdraw, _position_rect, _tile); else - draw_texture_rect_region(texdraw, Rect2(ofs, size), tex_regin); + draw_texture_rect_region(texdraw, _position_rect, _texture_region); } if (has_focus() && focused.is_valid()) { @@ -299,4 +342,8 @@ TextureButton::StretchMode TextureButton::get_stretch_mode() const { TextureButton::TextureButton() { expand = false; stretch_mode = STRETCH_SCALE; + + _texture_region = Rect2(); + _position_rect = Rect2(); + _tile = false; } diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h index 1cf4b66413..d42df390e8 100644 --- a/scene/gui/texture_button.h +++ b/scene/gui/texture_button.h @@ -58,6 +58,10 @@ private: bool expand; StretchMode stretch_mode; + Rect2 _texture_region; + Rect2 _position_rect; + bool _tile; + protected: virtual Size2 get_minimum_size() const; virtual bool has_point(const Point2 &p_point) const; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index a4b703af9e..e12044fca2 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -45,12 +45,12 @@ void TreeItem::move_to_top() { - if (!parent || parent->childs == this) + if (!parent || parent->children == this) return; //already on top TreeItem *prev = get_prev(); prev->next = next; - next = parent->childs; - parent->childs = this; + next = parent->children; + parent->children = this; } void TreeItem::move_to_bottom() { @@ -65,7 +65,7 @@ void TreeItem::move_to_bottom() { if (prev) { prev->next = next; } else { - parent->childs = next; + parent->children = next; } last->next = this; next = NULL; @@ -368,10 +368,10 @@ TreeItem *TreeItem::get_next() { TreeItem *TreeItem::get_prev() { - if (!parent || parent->childs == this) + if (!parent || parent->children == this) return NULL; - TreeItem *prev = parent->childs; + TreeItem *prev = parent->children; while (prev && prev->next != this) prev = prev->next; @@ -385,7 +385,7 @@ TreeItem *TreeItem::get_parent() { TreeItem *TreeItem::get_children() { - return childs; + return children; } TreeItem *TreeItem::get_prev_visible() { @@ -402,10 +402,10 @@ TreeItem *TreeItem::get_prev_visible() { } else { current = prev; - while (!current->collapsed && current->childs) { + while (!current->collapsed && current->children) { //go to the very end - current = current->childs; + current = current->children; while (current->next) current = current->next; } @@ -418,9 +418,9 @@ TreeItem *TreeItem::get_next_visible() { TreeItem *current = this; - if (!current->collapsed && current->childs) { + if (!current->collapsed && current->children) { - current = current->childs; + current = current->children; } else if (current->next) { @@ -444,7 +444,7 @@ TreeItem *TreeItem::get_next_visible() { void TreeItem::remove_child(TreeItem *p_item) { ERR_FAIL_NULL(p_item); - TreeItem **c = &childs; + TreeItem **c = &children; while (*c) { @@ -802,16 +802,16 @@ void TreeItem::_bind_methods() { void TreeItem::clear_children() { - TreeItem *c = childs; + TreeItem *c = children; while (c) { TreeItem *aux = c; c = c->get_next(); - aux->parent = 0; // so it wont try to recursively autoremove from me in here + aux->parent = 0; // so it won't try to recursively autoremove from me in here memdelete(aux); } - childs = 0; + children = 0; }; TreeItem::TreeItem(Tree *p_tree) { @@ -823,7 +823,7 @@ TreeItem::TreeItem(Tree *p_tree) { parent = 0; // parent item next = 0; // next in list - childs = 0; //child items + children = 0; //child items } TreeItem::~TreeItem() { @@ -977,9 +977,9 @@ int Tree::get_item_height(TreeItem *p_item) const { int height = compute_item_height(p_item); height += cache.vseparation; - if (!p_item->collapsed) { /* if not collapsed, check the childs */ + if (!p_item->collapsed) { /* if not collapsed, check the children */ - TreeItem *c = p_item->childs; + TreeItem *c = p_item->children; while (c) { @@ -1386,7 +1386,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } } - if (!p_item->disable_folding && !hide_folding && p_item->childs) { //has childs, draw the guide box + if (!p_item->disable_folding && !hide_folding && p_item->children) { //has children, draw the guide box Ref<Texture> arrow; @@ -1413,9 +1413,9 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 children_pos.y += htotal; } - if (!p_item->collapsed) { /* if not collapsed, check the childs */ + if (!p_item->collapsed) { /* if not collapsed, check the children */ - TreeItem *c = p_item->childs; + TreeItem *c = p_item->children; while (c) { @@ -1569,7 +1569,7 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c *r_in_range = false; } - TreeItem *c = p_current->childs; + TreeItem *c = p_current->children; while (c) { @@ -1635,7 +1635,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool if (!p_item->disable_folding && !hide_folding && (p_pos.x >= x_ofs && p_pos.x < (x_ofs + cache.item_margin))) { - if (p_item->childs) + if (p_item->children) p_item->set_collapsed(!p_item->is_collapsed()); return -1; //handled! @@ -1942,9 +1942,9 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool new_pos.y -= item_h; } - if (!p_item->collapsed) { /* if not collapsed, check the childs */ + if (!p_item->collapsed) { /* if not collapsed, check the children */ - TreeItem *c = p_item->childs; + TreeItem *c = p_item->children; while (c) { @@ -2988,7 +2988,7 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) { ti->cells.resize(columns.size()); TreeItem *prev = NULL; - TreeItem *c = p_parent->childs; + TreeItem *c = p_parent->children; int idx = 0; while (c) { @@ -3003,7 +3003,7 @@ TreeItem *Tree::create_item(TreeItem *p_parent, int p_idx) { if (prev) prev->next = ti; else - p_parent->childs = ti; + p_parent->children = ti; ti->parent = p_parent; } else { @@ -3036,8 +3036,8 @@ TreeItem *Tree::get_last_item() { if (last->next) last = last->next; - else if (last->childs) - last = last->childs; + else if (last->children) + last = last->children; else break; } @@ -3208,9 +3208,9 @@ TreeItem *Tree::get_next_selected(TreeItem *p_item) { p_item = root; } else { - if (p_item->childs) { + if (p_item->children) { - p_item = p_item->childs; + p_item = p_item->children; } else if (p_item->next) { @@ -3325,9 +3325,9 @@ int Tree::get_item_offset(TreeItem *p_item) const { ofs += compute_item_height(it) + cache.vseparation; - if (it->childs && !it->collapsed) { + if (it->children && !it->collapsed) { - it = it->childs; + it = it->children; } else if (it->next) { @@ -3548,7 +3548,7 @@ TreeItem *Tree::_find_item_at_pos(TreeItem *p_item, const Point2 &p_pos, int &r_ } if (p_item->is_collapsed()) - return NULL; // do not try childs, it's collapsed + return NULL; // do not try children, it's collapsed TreeItem *n = p_item->get_children(); while (n) { @@ -3821,7 +3821,7 @@ void Tree::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_rmb_select"), "set_allow_rmb_select", "get_allow_rmb_select"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_folding"), "set_hide_folding", "is_folding_hidden"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_root"), "set_hide_root", "is_root_hidden"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "drop_mode_flags", PROPERTY_HINT_FLAGS, "On Item,Inbetween"), "set_drop_mode_flags", "get_drop_mode_flags"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "drop_mode_flags", PROPERTY_HINT_FLAGS, "On Item,In between"), "set_drop_mode_flags", "get_drop_mode_flags"); ADD_PROPERTY(PropertyInfo(Variant::INT, "select_mode", PROPERTY_HINT_ENUM, "Single,Row,Multi"), "set_select_mode", "get_select_mode"); ADD_SIGNAL(MethodInfo("item_selected")); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 709ff73971..2a8546a743 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -144,13 +144,13 @@ private: Vector<Cell> cells; - bool collapsed; // wont show childs + bool collapsed; // won't show children bool disable_folding; int custom_min_height; TreeItem *parent; // parent item TreeItem *next; // next in list - TreeItem *childs; //child items + TreeItem *children; //child items Tree *tree; //tree (for reference) TreeItem(Tree *p_tree); diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp index af849589cf..ac5e6020eb 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/viewport_container.cpp @@ -30,6 +30,7 @@ #include "viewport_container.h" +#include "core/engine.h" #include "scene/main/viewport.h" Size2 ViewportContainer::get_minimum_size() const { @@ -139,8 +140,34 @@ void ViewportContainer::_notification(int p_what) { } } +void ViewportContainer::_input(const Ref<InputEvent> &p_event) { + + if (Engine::get_singleton()->is_editor_hint()) + return; + + Transform2D xform = get_global_transform(); + + if (stretch) { + Transform2D scale_xf; + scale_xf.scale(Vector2(shrink, shrink)); + xform *= scale_xf; + } + + Ref<InputEvent> ev = p_event->xformed_by(xform.affine_inverse()); + + for (int i = 0; i < get_child_count(); i++) { + + Viewport *c = Object::cast_to<Viewport>(get_child(i)); + if (!c || c->is_input_disabled()) + continue; + + c->input(ev); + } +} + void ViewportContainer::_bind_methods() { + ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input); ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch); ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled); @@ -155,4 +182,5 @@ ViewportContainer::ViewportContainer() { stretch = false; shrink = 1; + set_process_input(true); } diff --git a/scene/gui/viewport_container.h b/scene/gui/viewport_container.h index cd8b4dd5c1..45c4cd03a1 100644 --- a/scene/gui/viewport_container.h +++ b/scene/gui/viewport_container.h @@ -48,6 +48,7 @@ public: void set_stretch(bool p_enable); bool is_stretch_enabled() const; + void _input(const Ref<InputEvent> &p_event); void set_stretch_shrink(int p_shrink); int get_stretch_shrink() const; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 148cdaf526..ac85dd64af 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -184,7 +184,7 @@ void Node::_propagate_ready() { } void Node::_propagate_enter_tree() { - // this needs to happen to all childs before any enter_tree + // this needs to happen to all children before any enter_tree if (data.parent) { data.tree = data.parent->data.tree; @@ -1202,13 +1202,13 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { unique = false; } else { //check if exists - Node **childs = data.children.ptrw(); + Node **children = data.children.ptrw(); int cc = data.children.size(); for (int i = 0; i < cc; i++) { - if (childs[i] == p_child) + if (children[i] == p_child) continue; - if (childs[i]->data.name == p_child->data.name) { + if (children[i]->data.name == p_child->data.name) { unique = false; break; } @@ -1311,7 +1311,7 @@ void Node::_add_child_nocheck(Node *p_child, const StringName &p_name) { } /* Notify */ - //recognize childs created in this node constructor + //recognize children created in this node constructor p_child->data.parent_owned = data.in_constructor; add_child_notify(p_child); } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 1a2ea796bd..1ff1f4b6d8 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -196,8 +196,6 @@ void Viewport::_update_stretch_transform() { if (size_override_stretch && size_override) { - //print_line("sive override size "+size_override_size); - //print_line("rect size "+size); stretch_transform = Transform2D(); Size2 scale = size / (size_override_size + size_override_margin * 2); stretch_transform.scale(scale); @@ -211,114 +209,6 @@ void Viewport::_update_stretch_transform() { _update_global_transform(); } -void Viewport::_update_rect() { - - if (!is_inside_tree()) - return; - - /*if (!render_target && parent_control) { - - Control *c = parent_control; - - rect.pos=Point2(); - rect.size=c->get_size(); - }*/ - /* - VisualServer::ViewportRect vr; - vr.x=rect.pos.x; - vr.y=rect.pos.y; - - if (render_target) { - vr.x=0; - vr.y=0; - } - vr.width=rect.size.width; - vr.height=rect.size.height; - - VisualServer::get_singleton()->viewport_set_rect(viewport,vr); - last_vp_rect=rect; - - if (canvas_item.is_valid()) { - VisualServer::get_singleton()->canvas_item_set_custom_rect(canvas_item,true,rect); - } - - emit_signal("size_changed"); - texture->emit_changed(); -*/ -} - -void Viewport::_parent_resized() { - - _update_rect(); -} - -void Viewport::_parent_draw() { -} - -void Viewport::_parent_visibility_changed() { - - /* - if (parent_control) { - - Control *c = parent_control; - VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,c->is_visible_in_tree()); - - _update_listener(); - _update_listener_2d(); - } -*/ -} - -void Viewport::_vp_enter_tree() { - - /* if (parent_control) { - - Control *cparent=parent_control; - RID parent_ci = cparent->get_canvas_item(); - ERR_FAIL_COND(!parent_ci.is_valid()); - canvas_item = VisualServer::get_singleton()->canvas_item_create(); - - VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent_ci); - VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,false); - //VisualServer::get_singleton()->canvas_item_attach_viewport(canvas_item,viewport); - parent_control->connect("resized",this,"_parent_resized"); - parent_control->connect("visibility_changed",this,"_parent_visibility_changed"); - } else if (!parent){ - - //VisualServer::get_singleton()->viewport_attach_to_screen(viewport,0); - - } -*/ -} - -void Viewport::_vp_exit_tree() { - - /* - if (parent_control) { - - parent_control->disconnect("resized",this,"_parent_resized"); - } - - if (parent_control) { - - parent_control->disconnect("visibility_changed",this,"_parent_visibility_changed"); - } - - if (canvas_item.is_valid()) { - - VisualServer::get_singleton()->free(canvas_item); - canvas_item=RID(); - - } - - if (!parent) { - - VisualServer::get_singleton()->viewport_detach(viewport); - - } -*/ -} - void Viewport::update_worlds() { if (!is_inside_tree()) @@ -376,7 +266,6 @@ void Viewport::_notification(int p_what) { _update_listener(); _update_listener_2d(); - _update_rect(); find_world_2d()->_register_viewport(this, Rect2()); @@ -436,11 +325,6 @@ void Viewport::_notification(int p_what) { if (world_2d.is_valid()) world_2d->_remove_viewport(this); - /* - if (!render_target) - _vp_exit_tree(); - */ - VisualServer::get_singleton()->viewport_set_scenario(viewport, RID()); // SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); VisualServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); @@ -718,7 +602,6 @@ void Viewport::set_size(const Size2 &p_size) { size = p_size.floor(); VS::get_singleton()->viewport_set_size(viewport, size.width, size.height); - _update_rect(); _update_stretch_transform(); emit_signal("size_changed"); @@ -1167,7 +1050,7 @@ void Viewport::set_size_override(bool p_enable, const Size2 &p_size, const Vecto size_override_size = p_size; } size_override_margin = p_margin; - _update_rect(); + _update_stretch_transform(); emit_signal("size_changed"); } @@ -1186,9 +1069,6 @@ void Viewport::set_size_override_stretch(bool p_enable) { return; size_override_stretch = p_enable; - if (size_override) { - _update_rect(); - } _update_stretch_transform(); } @@ -2684,9 +2564,6 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_transparent_background", "enable"), &Viewport::set_transparent_background); ClassDB::bind_method(D_METHOD("has_transparent_background"), &Viewport::has_transparent_background); - ClassDB::bind_method(D_METHOD("_parent_visibility_changed"), &Viewport::_parent_visibility_changed); - - ClassDB::bind_method(D_METHOD("_parent_resized"), &Viewport::_parent_resized); ClassDB::bind_method(D_METHOD("_vp_input"), &Viewport::_vp_input); ClassDB::bind_method(D_METHOD("_vp_input_text", "text"), &Viewport::_vp_input_text); ClassDB::bind_method(D_METHOD("_vp_unhandled_input"), &Viewport::_vp_unhandled_input); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 48e2929e54..07bbd3f1fa 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -206,12 +206,6 @@ private: void _test_new_mouseover(ObjectID new_collider); Map<ObjectID, uint64_t> physics_2d_mouseover; - void _update_rect(); - - void _parent_resized(); - void _parent_draw(); - void _parent_visibility_changed(); - Ref<World2D> world_2d; Ref<World> world; Ref<World> own_world; @@ -294,9 +288,6 @@ private: _FORCE_INLINE_ Transform2D _get_input_pre_xform() const; - void _vp_enter_tree(); - void _vp_exit_tree(); - void _vp_input(const Ref<InputEvent> &p_ev); void _vp_input_text(const String &p_text); void _vp_unhandled_input(const Ref<InputEvent> &p_ev); diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 2dee74f561..bb0cf168af 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -201,6 +201,8 @@ static ResourceFormatLoaderDynamicFont *resource_loader_dynamic_font = NULL; static ResourceFormatLoaderStreamTexture *resource_loader_stream_texture = NULL; +static ResourceFormatLoaderBMFont *resource_loader_bmfont = NULL; + static ResourceFormatSaverShader *resource_saver_shader = NULL; static ResourceFormatLoaderShader *resource_loader_shader = NULL; @@ -233,6 +235,9 @@ void register_scene_types() { resource_loader_shader = memnew(ResourceFormatLoaderShader); ResourceLoader::add_resource_format_loader(resource_loader_shader, true); + resource_loader_bmfont = memnew(ResourceFormatLoaderBMFont); + ResourceLoader::add_resource_format_loader(resource_loader_bmfont, true); + OS::get_singleton()->yield(); //may take time to init ClassDB::register_class<Object>(); @@ -652,6 +657,9 @@ void unregister_scene_types() { if (resource_loader_shader) { memdelete(resource_loader_shader); } + if (resource_loader_bmfont) { + memdelete(resource_loader_bmfont); + } SpatialMaterial::finish_shaders(); ParticlesMaterial::finish_shaders(); diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 6e58bc88d7..7a1fffaa26 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1603,19 +1603,19 @@ float Animation::get_step() const { return step; } -void Animation::copy_track(int src_track, Ref<Animation> p_to_animation) { +void Animation::copy_track(int p_track, Ref<Animation> p_to_animation) { ERR_FAIL_COND(p_to_animation.is_null()); - ERR_FAIL_INDEX(src_track, get_track_count()); + ERR_FAIL_INDEX(p_track, get_track_count()); int dst_track = p_to_animation->get_track_count(); - p_to_animation->add_track(track_get_type(src_track)); - - p_to_animation->track_set_path(dst_track, track_get_path(src_track)); - p_to_animation->track_set_imported(dst_track, track_is_imported(src_track)); - p_to_animation->track_set_enabled(dst_track, track_is_enabled(src_track)); - p_to_animation->track_set_interpolation_type(dst_track, track_get_interpolation_type(src_track)); - p_to_animation->track_set_interpolation_loop_wrap(dst_track, track_get_interpolation_loop_wrap(src_track)); - for (int i = 0; i < track_get_key_count(src_track); i++) { - p_to_animation->track_insert_key(dst_track, track_get_key_time(src_track, i), track_get_key_value(src_track, i), track_get_key_transition(src_track, i)); + p_to_animation->add_track(track_get_type(p_track)); + + p_to_animation->track_set_path(dst_track, track_get_path(p_track)); + p_to_animation->track_set_imported(dst_track, track_is_imported(p_track)); + p_to_animation->track_set_enabled(dst_track, track_is_enabled(p_track)); + p_to_animation->track_set_interpolation_type(dst_track, track_get_interpolation_type(p_track)); + p_to_animation->track_set_interpolation_loop_wrap(dst_track, track_get_interpolation_loop_wrap(p_track)); + for (int i = 0; i < track_get_key_count(p_track); i++) { + p_to_animation->track_insert_key(dst_track, track_get_key_time(p_track, i), track_get_key_value(p_track, i), track_get_key_transition(p_track, i)); } } diff --git a/scene/resources/audio_stream_sample.cpp b/scene/resources/audio_stream_sample.cpp index 93ed700482..b77143cd9d 100644 --- a/scene/resources/audio_stream_sample.cpp +++ b/scene/resources/audio_stream_sample.cpp @@ -77,7 +77,7 @@ void AudioStreamPlaybackSample::seek(float p_time) { if (base->format == AudioStreamSample::FORMAT_IMA_ADPCM) return; //no seeking in ima-adpcm - float max = get_length(); + float max = base->get_length(); if (p_time < 0) { p_time = 0; } else if (p_time >= max) { @@ -390,22 +390,6 @@ void AudioStreamPlaybackSample::mix(AudioFrame *p_buffer, float p_rate_scale, in } } -float AudioStreamPlaybackSample::get_length() const { - - int len = base->data_bytes; - switch (base->format) { - case AudioStreamSample::FORMAT_8_BITS: len /= 1; break; - case AudioStreamSample::FORMAT_16_BITS: len /= 2; break; - case AudioStreamSample::FORMAT_IMA_ADPCM: len *= 2; break; - } - - if (base->stereo) { - len /= 2; - } - - return float(len) / base->mix_rate; -} - AudioStreamPlaybackSample::AudioStreamPlaybackSample() { active = false; @@ -469,6 +453,22 @@ bool AudioStreamSample::is_stereo() const { return stereo; } +float AudioStreamSample::get_length() const { + + int len = data_bytes; + switch (format) { + case AudioStreamSample::FORMAT_8_BITS: len /= 1; break; + case AudioStreamSample::FORMAT_16_BITS: len /= 2; break; + case AudioStreamSample::FORMAT_IMA_ADPCM: len *= 2; break; + } + + if (stereo) { + len /= 2; + } + + return float(len) / mix_rate; +} + void AudioStreamSample::set_data(const PoolVector<uint8_t> &p_data) { AudioServer::get_singleton()->lock(); diff --git a/scene/resources/audio_stream_sample.h b/scene/resources/audio_stream_sample.h index 41754301eb..5fe65c194e 100644 --- a/scene/resources/audio_stream_sample.h +++ b/scene/resources/audio_stream_sample.h @@ -77,8 +77,6 @@ public: virtual void mix(AudioFrame *p_buffer, float p_rate_scale, int p_frames); - virtual float get_length() const; //if supported, otherwise return 0 - AudioStreamPlaybackSample(); }; @@ -137,6 +135,8 @@ public: void set_stereo(bool p_enable); bool is_stereo() const; + virtual float get_length() const; //if supported, otherwise return 0 + void set_data(const PoolVector<uint8_t> &p_data); PoolVector<uint8_t> get_data() const; diff --git a/scene/resources/color_ramp.cpp b/scene/resources/color_ramp.cpp index 8c09130873..b2f586d02d 100644 --- a/scene/resources/color_ramp.cpp +++ b/scene/resources/color_ramp.cpp @@ -71,8 +71,8 @@ void Gradient::_bind_methods() { ClassDB::bind_method(D_METHOD(COLOR_RAMP_SET_COLORS, "colors"), &Gradient::set_colors); ClassDB::bind_method(D_METHOD(COLOR_RAMP_GET_COLORS), &Gradient::get_colors); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "offsets"), COLOR_RAMP_SET_OFFSETS, COLOR_RAMP_GET_OFFSETS); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "colors"), COLOR_RAMP_SET_COLORS, COLOR_RAMP_GET_COLORS); + ADD_PROPERTY(PropertyInfo(Variant::POOL_REAL_ARRAY, "offsets"), COLOR_RAMP_SET_OFFSETS, COLOR_RAMP_GET_OFFSETS); + ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "colors"), COLOR_RAMP_SET_COLORS, COLOR_RAMP_GET_COLORS); } Vector<float> Gradient::get_offsets() const { diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index b35a9ae963..e9d5ca969e 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -35,13 +35,7 @@ bool DynamicFontData::CacheID::operator<(CacheID right) const { - if (size < right.size) - return true; - if (mipmaps != right.mipmaps) - return right.mipmaps; - if (filter != right.filter) - return right.filter; - return false; + return key < right.key; } Ref<DynamicFontAtSize> DynamicFontData::_get_dynamic_font_at_size(CacheID p_cache_id) { @@ -654,6 +648,7 @@ DynamicFontAtSize::~DynamicFontAtSize() { FT_Done_FreeType(library); } font->size_cache.erase(id); + font.unref(); } ///////////////////////// @@ -983,7 +978,7 @@ void DynamicFont::update_oversampling() { while (E) { if (E->self()->data_at_size.is_valid() && E->self()->data_at_size->update_oversampling()) { - changed.push_back(E->self()); + changed.push_back(Ref<DynamicFont>(E->self())); } E = E->next(); } diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index a949892086..92bb77bed3 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -50,15 +50,17 @@ class DynamicFontData : public Resource { public: struct CacheID { - int size; - bool mipmaps; - bool filter; - + union { + struct { + uint32_t size : 16; + bool mipmaps : 1; + bool filter : 1; + }; + uint32_t key; + }; bool operator<(CacheID right) const; CacheID() { - size = 16; - mipmaps = false; - filter = false; + key = 0; } }; diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp index 026bcea270..6fc5778dd8 100644 --- a/scene/resources/font.cpp +++ b/scene/resources/font.cpp @@ -596,3 +596,42 @@ BitmapFont::~BitmapFont() { clear(); } + +//////////// + +RES ResourceFormatLoaderBMFont::load(const String &p_path, const String &p_original_path, Error *r_error) { + + if (r_error) + *r_error = ERR_FILE_CANT_OPEN; + + Ref<BitmapFont> font; + font.instance(); + + Error err = font->create_from_fnt(p_path); + + if (err) { + if (r_error) + *r_error = err; + return RES(); + } + + return font; +} + +void ResourceFormatLoaderBMFont::get_recognized_extensions(List<String> *p_extensions) const { + + p_extensions->push_back("fnt"); +} + +bool ResourceFormatLoaderBMFont::handles_type(const String &p_type) const { + + return (p_type == "BitmapFont"); +} + +String ResourceFormatLoaderBMFont::get_resource_type(const String &p_path) const { + + String el = p_path.get_extension().to_lower(); + if (el == "fnt") + return "BitmapFont"; + return ""; +} diff --git a/scene/resources/font.h b/scene/resources/font.h index 3f228ca002..ae08890be3 100644 --- a/scene/resources/font.h +++ b/scene/resources/font.h @@ -159,4 +159,12 @@ public: ~BitmapFont(); }; +class ResourceFormatLoaderBMFont : public ResourceFormatLoader { +public: + virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); + virtual void get_recognized_extensions(List<String> *p_extensions) const; + virtual bool handles_type(const String &p_type) const; + virtual String get_resource_type(const String &p_path) const; +}; + #endif diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index d59390e1b8..949ba12a4c 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -1267,6 +1267,8 @@ void ArrayMesh::_bind_methods() { ClassDB::set_method_flags(get_class_static(), _scs_create("center_geometry"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); ClassDB::bind_method(D_METHOD("regen_normalmaps"), &ArrayMesh::regen_normalmaps); ClassDB::set_method_flags(get_class_static(), _scs_create("regen_normalmaps"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); + ClassDB::bind_method(D_METHOD("lightmap_unwrap"), &ArrayMesh::lightmap_unwrap); + ClassDB::set_method_flags(get_class_static(), _scs_create("lightmap_unwrap"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR); ClassDB::bind_method(D_METHOD("get_faces"), &ArrayMesh::get_faces); ClassDB::bind_method(D_METHOD("generate_triangle_mesh"), &ArrayMesh::generate_triangle_mesh); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index dd8d0e2141..3df9285bb6 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1119,7 +1119,7 @@ void SceneState::set_bundled_scene(const Dictionary &p_dictionary) { uint32_t name_index = r[idx++]; nd.name = name_index & ((1 << NAME_INDEX_BITS) - 1); nd.index = (name_index >> NAME_INDEX_BITS); - nd.index--; //0 is invaild, stored as 1 + nd.index--; //0 is invalid, stored as 1 nd.instance = r[idx++]; nd.properties.resize(r[idx++]); for (int j = 0; j < nd.properties.size(); j++) { @@ -1212,7 +1212,7 @@ Dictionary SceneState::get_bundled_scene() const { rnodes.push_back(nd.owner); rnodes.push_back(nd.type); uint32_t name_index = nd.name; - if (nd.index < (1 << (32 - NAME_INDEX_BITS)) - 1) { //save if less than 16k childs + if (nd.index < (1 << (32 - NAME_INDEX_BITS)) - 1) { //save if less than 16k children name_index |= uint32_t(nd.index + 1) << NAME_INDEX_BITS; //for backwards compatibility, index 0 is no index } rnodes.push_back(name_index); diff --git a/scene/resources/primitive_meshes.h b/scene/resources/primitive_meshes.h index 2b7294141a..1eaa007bd7 100644 --- a/scene/resources/primitive_meshes.h +++ b/scene/resources/primitive_meshes.h @@ -39,7 +39,7 @@ @author Bastiaan Olij <mux213@gmail.com> Base class for all the classes in this file, handles a number of code functions that are shared among all meshes. - This class is set appart that it assumes a single surface is always generated for our mesh. + This class is set apart that it assumes a single surface is always generated for our mesh. */ class PrimitiveMesh : public Mesh { diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index 71a691fe27..91c801c016 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -1312,6 +1312,8 @@ Error ResourceFormatLoaderText::rename_dependencies(const String &p_path, const return ria->rename_dependencies(f, p_path, p_map); } +ResourceFormatLoaderText *ResourceFormatLoaderText::singleton = NULL; + Error ResourceFormatLoaderText::convert_file_to_binary(const String &p_src_path, const String &p_dst_path) { Error err; @@ -1411,7 +1413,7 @@ void ResourceFormatSaverTextInstance::_find_resources(const Variant &p_variant, I = I->next(); } - resource_set.insert(res); //saved after, so the childs it needs are available when loaded + resource_set.insert(res); //saved after, so the children it needs are available when loaded saved_resources.push_back(res); } break; diff --git a/scene/resources/scene_format_text.h b/scene/resources/scene_format_text.h index c014b9bfae..c28ded3d77 100644 --- a/scene/resources/scene_format_text.h +++ b/scene/resources/scene_format_text.h @@ -128,7 +128,9 @@ public: }; class ResourceFormatLoaderText : public ResourceFormatLoader { + public: + static ResourceFormatLoaderText *singleton; virtual Ref<ResourceInteractiveLoader> load_interactive(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const; virtual void get_recognized_extensions(List<String> *p_extensions) const; @@ -138,6 +140,8 @@ public: virtual Error rename_dependencies(const String &p_path, const Map<String, String> &p_map); static Error convert_file_to_binary(const String &p_src_path, const String &p_dst_path); + + ResourceFormatLoaderText() { singleton = this; } }; class ResourceFormatSaverTextInstance { diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index 6811517ead..de75bb3976 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -651,8 +651,8 @@ void StyleBoxFlat::draw(RID p_canvas_item, const Rect2 &p_rect) const { } //adapt borders (prevent weired overlapping/glitchy drawings) - int width = style_rect.size.width; - int height = style_rect.size.height; + int width = MAX(style_rect.size.width, 0); + int height = MAX(style_rect.size.height, 0); int adapted_border[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX }; adapt_values(MARGIN_TOP, MARGIN_BOTTOM, adapted_border, border_width, height, height, height); adapt_values(MARGIN_LEFT, MARGIN_RIGHT, adapted_border, border_width, width, width, width); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 067d123b83..c0f6756fd1 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -76,7 +76,7 @@ void Texture::_bind_methods() { ClassDB::bind_method(D_METHOD("draw_rect_region", "canvas_item", "rect", "src_rect", "modulate", "transpose", "normal_map", "clip_uv"), &Texture::draw_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false), DEFVAL(Variant()), DEFVAL(true)); ClassDB::bind_method(D_METHOD("get_data"), &Texture::get_data); - ADD_PROPERTY(PropertyInfo(Variant::INT, "flags", PROPERTY_HINT_FLAGS, "Mipmaps,Repeat,Filter,Ansiotropic Linear,Convert to Linear,Mirrored Repeat,Video Surface"), "set_flags", "get_flags"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "flags", PROPERTY_HINT_FLAGS, "Mipmaps,Repeat,Filter,Anisotropic Linear,Convert to Linear,Mirrored Repeat,Video Surface"), "set_flags", "get_flags"); BIND_ENUM_CONSTANT(FLAGS_DEFAULT); BIND_ENUM_CONSTANT(FLAG_MIPMAPS); diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 800710ed2a..3138d73caf 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -212,7 +212,7 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { Vector3 v; for (Map<Vector2, int>::Element *E = tile_map[id].autotile_data.priority_map.front(); E; E = E->next()) { if (E->value() > 1) { - //Dont save default value + //Don't save default value v.x = E->key().x; v.y = E->key().y; v.z = E->value(); |