From 5b6ad923f0b9401b01f13a9f6dc4b6fe8c2d79e9 Mon Sep 17 00:00:00 2001 From: homer666 Date: Mon, 15 Apr 2019 13:33:04 +1000 Subject: [PATCH] AnimationPlayer FPS mode fixes (cherry picked from commit e3b7f9e1ca34e270eb7a7c2ec82b7f7354bb74e5) --- editor/animation_track_editor.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 7eac055b461..87a0cbb1c83 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1022,8 +1022,14 @@ void AnimationTimelineEdit::update_values() { editing = true; if (use_fps && animation->get_step() > 0) { length->set_value(animation->get_length() / animation->get_step()); + length->set_step(1); + length->set_tooltip(TTR("Animation length (frames)")); + time_icon->set_tooltip(TTR("Animation length (frames)")); } else { length->set_value(animation->get_length()); + length->set_step(0.01); + length->set_tooltip(TTR("Animation length (seconds)")); + time_icon->set_tooltip(TTR("Animation length (seconds)")); } loop->set_pressed(animation->has_loop()); editing = false; @@ -1168,7 +1174,7 @@ AnimationTimelineEdit::AnimationTimelineEdit() { len_hb->add_child(expander); time_icon = memnew(TextureRect); time_icon->set_v_size_flags(SIZE_SHRINK_CENTER); - time_icon->set_tooltip(TTR("Animation Length Time (seconds)")); + time_icon->set_tooltip(TTR("Animation length (seconds)")); len_hb->add_child(time_icon); length = memnew(EditorSpinSlider); length->set_min(0.001); @@ -1177,7 +1183,7 @@ AnimationTimelineEdit::AnimationTimelineEdit() { length->set_allow_greater(true); length->set_custom_minimum_size(Vector2(70 * EDSCALE, 0)); length->set_hide_slider(true); - length->set_tooltip(TTR("Animation Length Time (seconds)")); + length->set_tooltip(TTR("Animation length (seconds)")); length->connect("value_changed", this, "_anim_length_changed"); len_hb->add_child(length); loop = memnew(ToolButton); @@ -3857,7 +3863,7 @@ void AnimationTrackEditor::_insert_key_from_track(float p_ofs, int p_track) { ERR_FAIL_INDEX(p_track, animation->get_track_count()); if (snap->is_pressed() && step->get_value() != 0) { - p_ofs = Math::stepify(p_ofs, step->get_value()); + p_ofs = snap_time(p_ofs); } while (animation->track_find_key(p_track, p_ofs, true) != -1) { //make sure insertion point is valid p_ofs += 0.001; @@ -4889,7 +4895,14 @@ void AnimationTrackEditor::_selection_changed() { float AnimationTrackEditor::snap_time(float p_value) { if (snap->is_pressed()) { - p_value = Math::stepify(p_value, step->get_value()); + + double snap_increment; + if (timeline->is_using_fps() && step->get_value() > 0) + snap_increment = 1.0 / step->get_value(); + else + snap_increment = step->get_value(); + + p_value = Math::stepify(p_value, snap_increment); } return p_value;