summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
authorMichael Alexsander Silva Dias <michaelalexsander@protonmail.com>2019-05-25 13:01:44 -0300
committerMichael Alexsander Silva Dias <michaelalexsander@protonmail.com>2019-05-27 22:03:26 -0300
commitfad0338beb8e6afa97553985b13ed3a401cd847a (patch)
tree609d3fad97cc4f69023ba9a7c900fc16c551e5a5 /editor
parent25e36f35404c076edb445d0fe595b694db57536d (diff)
Make animation editor change tracks positions instead of swapping them
Diffstat (limited to 'editor')
-rw-r--r--editor/animation_track_editor.cpp66
-rw-r--r--editor/animation_track_editor.h2
2 files changed, 56 insertions, 12 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index 0eec01f2cb..e8490e8729 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -1213,7 +1213,8 @@ void AnimationTrackEdit::_notification(int p_what) {
if (has_focus()) {
Color accent = get_color("accent_color", "Editor");
accent.a *= 0.7;
- draw_rect(Rect2(Point2(), get_size()), accent, false);
+ // Offside so the horizontal sides aren't cutoff.
+ draw_rect(Rect2(Point2(1, 0), get_size() - Size2(1, 0)), accent, false);
}
Ref<Font> font = get_font("font", "Label");
@@ -2185,6 +2186,9 @@ Variant AnimationTrackEdit::get_drag_data(const Point2 &p_point) {
Dictionary drag_data;
drag_data["type"] = "animation_track";
+ String base_path = animation->track_get_path(track);
+ base_path = base_path.get_slice(":", 0); // Remove sub-path.
+ drag_data["group"] = base_path;
drag_data["index"] = track;
ToolButton *tb = memnew(ToolButton);
@@ -2205,8 +2209,18 @@ bool AnimationTrackEdit::can_drop_data(const Point2 &p_point, const Variant &p_d
}
String type = d["type"];
- if (type != "animation_track")
+ if (type != "animation_track") {
return false;
+ }
+
+ // Don't allow moving tracks outside their groups.
+ if (get_editor()->is_grouping_tracks()) {
+ String base_path = animation->track_get_path(track);
+ base_path = base_path.get_slice(":", 0); // Remove sub-path.
+ if (d["group"] != base_path) {
+ return false;
+ }
+ }
if (p_point.y < get_size().height / 2) {
dropping_at = -1;
@@ -2227,8 +2241,18 @@ void AnimationTrackEdit::drop_data(const Point2 &p_point, const Variant &p_data)
}
String type = d["type"];
- if (type != "animation_track")
+ if (type != "animation_track") {
return;
+ }
+
+ // Don't allow moving tracks outside their groups.
+ if (get_editor()->is_grouping_tracks()) {
+ String base_path = animation->track_get_path(track);
+ base_path = base_path.get_slice(":", 0); // Remove sub-path.
+ if (d["group"] != base_path) {
+ return;
+ }
+ }
int from_track = d["index"];
@@ -2683,6 +2707,13 @@ void AnimationTrackEditor::_track_remove_request(int p_track) {
}
}
+void AnimationTrackEditor::_track_grab_focus(int p_track) {
+
+ // Don't steal focus if not working with the track editor.
+ if (Object::cast_to<AnimationTrackEdit>(get_focus_owner()))
+ track_edits[p_track]->grab_focus();
+}
+
void AnimationTrackEditor::set_anim_pos(float p_pos) {
timeline->set_play_position(p_pos);
@@ -3447,7 +3478,7 @@ void AnimationTrackEditor::_update_tracks() {
if (use_grouping) {
String base_path = animation->track_get_path(i);
- base_path = base_path.get_slice(":", 0); // remove subpath
+ base_path = base_path.get_slice(":", 0); // Remove sub-path.
if (!group_sort.has(base_path)) {
AnimationTrackEditGroup *g = memnew(AnimationTrackEditGroup);
@@ -3664,17 +3695,18 @@ void AnimationTrackEditor::_update_length(double p_new_len) {
}
void AnimationTrackEditor::_dropped_track(int p_from_track, int p_to_track) {
- if (p_to_track >= track_edits.size()) {
- p_to_track = track_edits.size() - 1;
- }
-
- if (p_from_track == p_to_track)
+ if (p_from_track == p_to_track || p_from_track == p_to_track - 1) {
return;
+ }
_clear_selection();
undo_redo->create_action(TTR("Rearrange Tracks"));
- undo_redo->add_do_method(animation.ptr(), "track_swap", p_from_track, p_to_track);
- undo_redo->add_undo_method(animation.ptr(), "track_swap", p_to_track, p_from_track);
+ undo_redo->add_do_method(animation.ptr(), "track_move_to", p_from_track, p_to_track);
+ // Take into account that the position of the tracks that come after the one removed will change.
+ int to_track_real = p_to_track > p_from_track ? p_to_track - 1 : p_to_track;
+ undo_redo->add_undo_method(animation.ptr(), "track_move_to", to_track_real, p_to_track > p_from_track ? p_from_track : p_from_track + 1);
+ undo_redo->add_do_method(this, "_track_grab_focus", to_track_real);
+ undo_redo->add_undo_method(this, "_track_grab_focus", p_from_track);
undo_redo->commit_action();
}
@@ -4876,10 +4908,20 @@ void AnimationTrackEditor::_cleanup_animation(Ref<Animation> p_animation) {
}
void AnimationTrackEditor::_view_group_toggle() {
+
_update_tracks();
view_group->set_icon(get_icon(view_group->is_pressed() ? "AnimationTrackList" : "AnimationTrackGroup", "EditorIcons"));
}
+bool AnimationTrackEditor::is_grouping_tracks() {
+
+ if (!view_group) {
+ return false;
+ }
+
+ return !view_group->is_pressed();
+}
+
void AnimationTrackEditor::_selection_changed() {
if (selected_filter->is_pressed()) {
@@ -4926,6 +4968,7 @@ void AnimationTrackEditor::_bind_methods() {
ClassDB::bind_method("_animation_update", &AnimationTrackEditor::_animation_update);
ClassDB::bind_method("_timeline_changed", &AnimationTrackEditor::_timeline_changed);
ClassDB::bind_method("_track_remove_request", &AnimationTrackEditor::_track_remove_request);
+ ClassDB::bind_method("_track_grab_focus", &AnimationTrackEditor::_track_grab_focus);
ClassDB::bind_method("_name_limit_changed", &AnimationTrackEditor::_name_limit_changed);
ClassDB::bind_method("_update_scroll", &AnimationTrackEditor::_update_scroll);
ClassDB::bind_method("_update_tracks", &AnimationTrackEditor::_update_tracks);
@@ -5024,7 +5067,6 @@ AnimationTrackEditor::AnimationTrackEditor() {
scroll->set_enable_v_scroll(true);
track_vbox->add_constant_override("separation", 0);
- //timeline_vbox->add_child(memnew(HSeparator));
HBoxContainer *bottom_hb = memnew(HBoxContainer);
add_child(bottom_hb);
diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h
index a69659642c..c64f663b3b 100644
--- a/editor/animation_track_editor.h
+++ b/editor/animation_track_editor.h
@@ -325,6 +325,7 @@ class AnimationTrackEditor : public VBoxContainer {
void _name_limit_changed();
void _timeline_changed(float p_new_pos, bool p_drag);
void _track_remove_request(int p_track);
+ void _track_grab_focus(int p_track);
UndoRedo *undo_redo;
@@ -513,6 +514,7 @@ public:
float get_moving_selection_offset() const;
bool is_snap_enabled();
float snap_time(float p_value);
+ bool is_grouping_tracks();
MenuButton *get_edit_menu();
AnimationTrackEditor();