diff options
Diffstat (limited to 'editor/animation_track_editor.cpp')
| -rw-r--r-- | editor/animation_track_editor.cpp | 99 |
1 files changed, 65 insertions, 34 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index adc9821d8a..02d667031a 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -624,6 +624,7 @@ public: void AnimationTimelineEdit::_zoom_changed(double) { update(); + play_position->update(); emit_signal("zoom_changed"); } @@ -643,6 +644,8 @@ void AnimationTimelineEdit::_anim_length_changed(double p_new_len) { if (editing) return; + p_new_len = MAX(0.001, p_new_len); + editing = true; *block_animation_update_ptr = true; undo_redo->create_action("Change animation length"); @@ -729,29 +732,6 @@ void AnimationTimelineEdit::_notification(int p_what) { if (l <= 0) l = 0.001; //avoid crashor - int end_px = (l - get_value()) * scale; - int begin_px = -get_value() * scale; - Color notimecol = get_color("dark_color_2", "Editor"); - Color timecolor = color; - timecolor.a = 0.2; - Color linecolor = color; - linecolor.a = 0.2; - - { - - draw_rect(Rect2(Point2(get_name_limit(), 0), Point2(zoomw - 1, h)), notimecol); - - if (begin_px < zoomw && end_px > 0) { - - if (begin_px < 0) - begin_px = 0; - if (end_px > zoomw) - end_px = zoomw; - - draw_rect(Rect2(Point2(get_name_limit() + begin_px, 0), Point2(end_px - begin_px - 1, h)), timecolor); - } - } - Ref<Texture> hsize_icon = get_icon("Hsize", "EditorIcons"); hsize_rect = Rect2(get_name_limit() - hsize_icon->get_width() - 2 * EDSCALE, (get_size().height - hsize_icon->get_height()) / 2, hsize_icon->get_width(), hsize_icon->get_height()); draw_texture(hsize_icon, hsize_rect.position); @@ -767,17 +747,17 @@ void AnimationTimelineEdit::_notification(int p_what) { if (animation->track_get_key_count(i) > 0) { float beg = animation->track_get_key_time(i, 0); - if (animation->track_get_type(i) == Animation::TYPE_BEZIER) { + /*if (animation->track_get_type(i) == Animation::TYPE_BEZIER) { beg += animation->bezier_track_get_key_in_handle(i, 0).x; - } + }* not worth it since they have no use */ if (beg < time_min) time_min = beg; float end = animation->track_get_key_time(i, animation->track_get_key_count(i) - 1); - if (animation->track_get_type(i) == Animation::TYPE_BEZIER) { + /*if (animation->track_get_type(i) == Animation::TYPE_BEZIER) { end += animation->bezier_track_get_key_out_handle(i, animation->track_get_key_count(i) - 1).x; - } + } not worth it since they have no use */ if (end > time_max) time_max = end; @@ -803,6 +783,29 @@ void AnimationTimelineEdit::_notification(int p_what) { set_page(zoomw / scale); + int end_px = (l - get_value()) * scale; + int begin_px = -get_value() * scale; + Color notimecol = get_color("dark_color_2", "Editor"); + Color timecolor = color; + timecolor.a = 0.2; + Color linecolor = color; + linecolor.a = 0.2; + + { + + draw_rect(Rect2(Point2(get_name_limit(), 0), Point2(zoomw - 1, h)), notimecol); + + if (begin_px < zoomw && end_px > 0) { + + if (begin_px < 0) + begin_px = 0; + if (end_px > zoomw) + end_px = zoomw; + + draw_rect(Rect2(Point2(get_name_limit() + begin_px, 0), Point2(end_px - begin_px - 1, h)), timecolor); + } + } + Color color_time_sec = color; Color color_time_dec = color; color_time_dec.a *= 0.5; @@ -961,7 +964,7 @@ void AnimationTimelineEdit::_gui_input(const Ref<InputEvent> &p_event) { if (!panning_timeline && mb->get_button_index() == BUTTON_LEFT) { int x = mb->get_position().x - get_name_limit(); - float ofs = x / get_zoom_scale(); + float ofs = x / get_zoom_scale() + get_value(); emit_signal("timeline_changed", ofs, false); dragging_timeline = true; } @@ -994,7 +997,7 @@ void AnimationTimelineEdit::_gui_input(const Ref<InputEvent> &p_event) { } if (dragging_timeline) { int x = mm->get_position().x - get_name_limit(); - float ofs = x / get_zoom_scale(); + float ofs = x / get_zoom_scale() + get_value(); emit_signal("timeline_changed", ofs, false); } if (panning_timeline) { @@ -1059,7 +1062,7 @@ AnimationTimelineEdit::AnimationTimelineEdit() { time_icon->set_tooltip(TTR("Animation Length Time (seconds)")); len_hb->add_child(time_icon); length = memnew(EditorSpinSlider); - length->set_min(0); + length->set_min(0.001); length->set_max(3600); length->set_step(0.01); length->set_allow_greater(true); @@ -1605,6 +1608,7 @@ void AnimationTrackEdit::set_undo_redo(UndoRedo *p_undo_redo) { void AnimationTrackEdit::set_timeline(AnimationTimelineEdit *p_timeline) { timeline = p_timeline; timeline->connect("zoom_changed", this, "_zoom_changed"); + timeline->connect("name_limit_changed", this, "_zoom_changed"); } void AnimationTrackEdit::set_editor(AnimationTrackEditor *p_editor) { editor = p_editor; @@ -1641,6 +1645,7 @@ void AnimationTrackEdit::set_root(Node *p_root) { } void AnimationTrackEdit::_zoom_changed() { update(); + play_position->update(); } void AnimationTrackEdit::_path_entered(const String &p_text) { @@ -1936,7 +1941,6 @@ void AnimationTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { offset = offset * scale + limit; rect.position.x += offset; - print_line("rect: " + rect + " pos: " + pos); if (rect.has_point(pos)) { if (is_key_selectable_by_distance()) { @@ -2379,6 +2383,7 @@ Size2 AnimationTrackEditGroup::get_minimum_size() const { void AnimationTrackEditGroup::set_timeline(AnimationTimelineEdit *p_timeline) { timeline = p_timeline; timeline->connect("zoom_changed", this, "_zoom_changed"); + timeline->connect("name_limit_changed", this, "_zoom_changed"); } void AnimationTrackEditGroup::set_root(Node *p_root) { @@ -3385,6 +3390,7 @@ void AnimationTrackEditor::_update_tracks() { void AnimationTrackEditor::_animation_changed() { + timeline->update(); timeline->update_values(); if (block_animation_update) { for (int i = 0; i < track_edits.size(); i++) { @@ -3415,6 +3421,7 @@ void AnimationTrackEditor::_notification(int p_what) { snap->set_icon(get_icon("Snap", "EditorIcons")); view_group->set_icon(get_icon(view_group->is_pressed() ? "AnimationTrackList" : "AnimationTrackGroup", "EditorIcons")); selected_filter->set_icon(get_icon("AnimationFilter", "EditorIcons")); + main_panel->add_style_override("panel", get_stylebox("bg", "Tree")); } if (p_what == NOTIFICATION_READY) { @@ -3533,6 +3540,11 @@ void AnimationTrackEditor::_new_track_node_selected(NodePath p_path) { return; } + if (node == AnimationPlayerEditor::singleton->get_player()) { + EditorNode::get_singleton()->show_warning(TTR("An animation player can't animate itself, only other players.")); + return; + } + undo_redo->create_action("Add Track"); undo_redo->add_do_method(animation.ptr(), "add_track", adding_track_type); undo_redo->add_do_method(animation.ptr(), "track_set_path", animation->get_track_count(), path_to); @@ -3862,6 +3874,12 @@ struct _AnimMoveRestore { void AnimationTrackEditor::_clear_key_edit() { if (key_edit) { + +#if 0 + // going back seems like the most comfortable thing to do, but it results + // in weird behaviors and crashes, because going back to animation editor + // triggers the editor setting up again itself + bool go_back = false; if (EditorNode::get_singleton()->get_inspector()->get_edited_object() == key_edit) { EditorNode::get_singleton()->push_item(NULL); @@ -3874,6 +3892,15 @@ void AnimationTrackEditor::_clear_key_edit() { if (go_back) { EditorNode::get_singleton()->get_inspector_dock()->go_back(); } +#else + //if key edit is the object being inspected, remove it first + if (EditorNode::get_singleton()->get_inspector()->get_edited_object() == key_edit) { + EditorNode::get_singleton()->push_item(NULL); + } + //then actually delete it + memdelete(key_edit); + key_edit = NULL; +#endif } } @@ -4089,7 +4116,7 @@ void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) { track_edits[i]->append_to_selection(local_rect); } - if (_get_track_selected() == -1) { //minimal hack to make shortcuts work + if (_get_track_selected() == -1 && track_edits.size() > 0) { //minimal hack to make shortcuts work track_edits[track_edits.size() - 1]->grab_focus(); } } else { @@ -4736,8 +4763,12 @@ AnimationTrackEditor::AnimationTrackEditor() { block_animation_update = false; undo_redo = EditorNode::get_singleton()->get_undo_redo(); + + main_panel = memnew(PanelContainer); + add_child(main_panel); + main_panel->set_v_size_flags(SIZE_EXPAND_FILL); HBoxContainer *timeline_scroll = memnew(HBoxContainer); - add_child(timeline_scroll); + main_panel->add_child(timeline_scroll); timeline_scroll->set_v_size_flags(SIZE_EXPAND_FILL); VBoxContainer *timeline_vbox = memnew(VBoxContainer); @@ -4789,7 +4820,7 @@ AnimationTrackEditor::AnimationTrackEditor() { scroll->set_enable_v_scroll(true); track_vbox->add_constant_override("separation", 0); - timeline_vbox->add_child(memnew(HSeparator)); + //timeline_vbox->add_child(memnew(HSeparator)); HBoxContainer *bottom_hb = memnew(HBoxContainer); add_child(bottom_hb); bottom_hb->add_spacer(); |