diff options
Diffstat (limited to 'editor/animation_track_editor.cpp')
-rw-r--r-- | editor/animation_track_editor.cpp | 148 |
1 files changed, 108 insertions, 40 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 43e08ca324..42d5ea120e 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1,3 +1,33 @@ +/*************************************************************************/ +/* animation_track_editor.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + #include "animation_track_editor.h" #include "animation_track_editor_plugins.h" #include "editor/animation_bezier_editor.h" @@ -25,6 +55,7 @@ public: ClassDB::bind_method("_update_obj", &AnimationTrackKeyEdit::_update_obj); ClassDB::bind_method("_key_ofs_changed", &AnimationTrackKeyEdit::_key_ofs_changed); ClassDB::bind_method("_hide_script_from_inspector", &AnimationTrackKeyEdit::_hide_script_from_inspector); + ClassDB::bind_method("get_root_path", &AnimationTrackKeyEdit::get_root_path); } //PopupDialog *ke_dialog; @@ -612,6 +643,10 @@ public: _change_notify(); } + Node *get_root_path() { + return root_path; + } + AnimationTrackKeyEdit() { hidden = true; key_ofs = 0; @@ -624,6 +659,7 @@ public: void AnimationTimelineEdit::_zoom_changed(double) { update(); + play_position->update(); emit_signal("zoom_changed"); } @@ -713,6 +749,7 @@ void AnimationTimelineEdit::_notification(int p_what) { len_hb->set_position(Vector2(get_size().width - get_buttons_width(), 0)); len_hb->set_size(Size2(get_buttons_width(), get_size().height)); } + if (p_what == NOTIFICATION_DRAW) { int key_range = get_size().width - get_buttons_width() - get_name_limit(); @@ -731,29 +768,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); @@ -769,17 +783,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; @@ -805,6 +819,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; @@ -873,9 +910,11 @@ void AnimationTimelineEdit::set_animation(const Ref<Animation> &p_animation) { if (animation.is_valid()) { len_hb->show(); add_track->show(); + play_position->show(); } else { len_hb->hide(); add_track->hide(); + play_position->hide(); } update(); update_values(); @@ -963,7 +1002,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; } @@ -996,7 +1035,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) { @@ -1607,6 +1646,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; @@ -1643,6 +1683,7 @@ void AnimationTrackEdit::set_root(Node *p_root) { } void AnimationTrackEdit::_zoom_changed() { update(); + play_position->update(); } void AnimationTrackEdit::_path_entered(const String &p_text) { @@ -1660,7 +1701,7 @@ void AnimationTrackEdit::_path_entered(const String &p_text) { String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { if (check_rect.has_point(p_pos)) { - return TTR("Toggle this track on/off"); + return TTR("Toggle this track on/off."); } if (path_rect.has_point(p_pos)) { @@ -1668,7 +1709,7 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { } if (update_mode_rect.has_point(p_pos)) { - return TTR("Update Mode (How this property is set)."); + return TTR("Update Mode (How this property is set)"); } if (interp_mode_rect.has_point(p_pos)) { @@ -1676,11 +1717,11 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { } if (loop_mode_rect.has_point(p_pos)) { - return TTR("Loop Wrap Mode (Interpolate end with beginning on loop"); + return TTR("Loop Wrap Mode (Interpolate end with beginning on loop)"); } if (remove_rect.has_point(p_pos)) { - return TTR("Remove this track"); + return TTR("Remove this track."); } if (p_pos.x >= timeline->get_name_limit() && p_pos.x <= (get_size().width - timeline->get_buttons_width())) { @@ -1938,7 +1979,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()) { @@ -2381,6 +2421,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) { @@ -2432,12 +2473,16 @@ void AnimationTrackEditor::set_animation(const Ref<Animation> &p_anim) { if (animation.is_valid()) { animation->connect("changed", this, "_animation_changed"); + hscroll->show(); + edit->set_disabled(false); step->set_block_signals(true); step->set_value(animation->get_step()); step->set_block_signals(false); step->set_read_only(false); snap->set_disabled(false); } else { + hscroll->hide(); + edit->set_disabled(true); step->set_block_signals(true); step->set_value(0); step->set_block_signals(false); @@ -3387,6 +3432,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++) { @@ -3412,11 +3458,11 @@ MenuButton *AnimationTrackEditor::get_edit_menu() { void AnimationTrackEditor::_notification(int p_what) { if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) { - zoom_icon->set_texture(get_icon("Zoom", "EditorIcons")); 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) { @@ -3424,7 +3470,6 @@ void AnimationTrackEditor::_notification(int p_what) { } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - update_keying(); EditorNode::get_singleton()->update_keying(); emit_signal("keying_changed"); @@ -3869,6 +3914,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); @@ -3881,6 +3932,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 } } @@ -4096,7 +4156,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 { @@ -4743,8 +4803,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); @@ -4784,9 +4848,10 @@ AnimationTrackEditor::AnimationTrackEditor() { timeline_vbox->set_custom_minimum_size(Size2(0, 150) * EDSCALE); hscroll = memnew(HScrollBar); - timeline_vbox->add_child(hscroll); hscroll->share(timeline); + hscroll->hide(); hscroll->connect("value_changed", this, "_update_scroll"); + timeline_vbox->add_child(hscroll); timeline->set_hscroll(hscroll); track_vbox = memnew(VBoxContainer); @@ -4796,7 +4861,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(); @@ -4829,6 +4894,7 @@ AnimationTrackEditor::AnimationTrackEditor() { step->set_step(0.01); step->set_hide_slider(true); step->set_custom_minimum_size(Size2(100, 0) * EDSCALE); + step->set_tooltip(TTR("Animation step value.")); bottom_hb->add_child(step); step->connect("value_changed", this, "_update_step"); step->set_read_only(true); @@ -4851,6 +4917,8 @@ AnimationTrackEditor::AnimationTrackEditor() { edit = memnew(MenuButton); edit->set_text(TTR("Edit")); edit->set_flat(false); + edit->set_disabled(true); + edit->set_tooltip(TTR("Animation properties.")); edit->get_popup()->add_item(TTR("Copy Tracks"), EDIT_COPY_TRACKS); edit->get_popup()->add_item(TTR("Paste Tracks"), EDIT_PASTE_TRACKS); edit->get_popup()->add_separator(); |