|
@@ -328,6 +328,8 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Color dc = get_theme_color(SNAME("disabled_font_color"), SNAME("Editor"));
|
|
|
|
+
|
|
Ref<Texture2D> remove = get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"));
|
|
Ref<Texture2D> remove = get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"));
|
|
float remove_hpos = limit - hsep - remove->get_width();
|
|
float remove_hpos = limit - hsep - remove->get_width();
|
|
|
|
|
|
@@ -402,7 +404,11 @@ void AnimationBezierTrackEdit::_notification(int p_what) {
|
|
|
|
|
|
float icon_start_height = vofs + rect.size.y / 2;
|
|
float icon_start_height = vofs + rect.size.y / 2;
|
|
Rect2 remove_rect = Rect2(remove_hpos, icon_start_height - remove->get_height() / 2, remove->get_width(), remove->get_height());
|
|
Rect2 remove_rect = Rect2(remove_hpos, icon_start_height - remove->get_height() / 2, remove->get_width(), remove->get_height());
|
|
- draw_texture(remove, remove_rect.position);
|
|
|
|
|
|
+ if (read_only) {
|
|
|
|
+ draw_texture(remove, remove_rect.position, dc);
|
|
|
|
+ } else {
|
|
|
|
+ draw_texture(remove, remove_rect.position);
|
|
|
|
+ }
|
|
|
|
|
|
Rect2 lock_rect = Rect2(lock_hpos, icon_start_height - lock->get_height() / 2, lock->get_width(), lock->get_height());
|
|
Rect2 lock_rect = Rect2(lock_hpos, icon_start_height - lock->get_height() / 2, lock->get_width(), lock->get_height());
|
|
if (locked_tracks.has(current_track)) {
|
|
if (locked_tracks.has(current_track)) {
|
|
@@ -632,8 +638,9 @@ Ref<Animation> AnimationBezierTrackEdit::get_animation() const {
|
|
return animation;
|
|
return animation;
|
|
}
|
|
}
|
|
|
|
|
|
-void AnimationBezierTrackEdit::set_animation_and_track(const Ref<Animation> &p_animation, int p_track) {
|
|
|
|
|
|
+void AnimationBezierTrackEdit::set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only) {
|
|
animation = p_animation;
|
|
animation = p_animation;
|
|
|
|
+ read_only = p_read_only;
|
|
selected_track = p_track;
|
|
selected_track = p_track;
|
|
update();
|
|
update();
|
|
}
|
|
}
|
|
@@ -715,7 +722,7 @@ void AnimationBezierTrackEdit::set_filtered(bool p_filtered) {
|
|
continue; // Skip track due to not selected.
|
|
continue; // Skip track due to not selected.
|
|
}
|
|
}
|
|
|
|
|
|
- set_animation_and_track(animation, i);
|
|
|
|
|
|
+ set_animation_and_track(animation, i, read_only);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -819,12 +826,16 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
|
|
|
|
if (p_event->is_pressed()) {
|
|
if (p_event->is_pressed()) {
|
|
if (ED_GET_SHORTCUT("animation_editor/duplicate_selection")->matches_event(p_event)) {
|
|
if (ED_GET_SHORTCUT("animation_editor/duplicate_selection")->matches_event(p_event)) {
|
|
- duplicate_selection();
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ duplicate_selection();
|
|
|
|
+ }
|
|
accept_event();
|
|
accept_event();
|
|
}
|
|
}
|
|
|
|
|
|
if (ED_GET_SHORTCUT("animation_editor/delete_selection")->matches_event(p_event)) {
|
|
if (ED_GET_SHORTCUT("animation_editor/delete_selection")->matches_event(p_event)) {
|
|
- delete_selection();
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ delete_selection();
|
|
|
|
+ }
|
|
accept_event();
|
|
accept_event();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -917,26 +928,28 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
|
|
if (mb.is_valid() && mb->get_button_index() == MouseButton::RIGHT && mb->is_pressed()) {
|
|
menu_insert_key = mb->get_position();
|
|
menu_insert_key = mb->get_position();
|
|
if (menu_insert_key.x >= limit && menu_insert_key.x <= get_size().width) {
|
|
if (menu_insert_key.x >= limit && menu_insert_key.x <= get_size().width) {
|
|
- Vector2 popup_pos = get_screen_position() + mb->get_position();
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ Vector2 popup_pos = get_screen_position() + mb->get_position();
|
|
|
|
|
|
- menu->clear();
|
|
|
|
- if (!locked_tracks.has(selected_track) || locked_tracks.has(selected_track)) {
|
|
|
|
- menu->add_icon_item(bezier_icon, TTR("Insert Key Here"), MENU_KEY_INSERT);
|
|
|
|
- }
|
|
|
|
- if (selection.size()) {
|
|
|
|
- menu->add_separator();
|
|
|
|
- menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Duplicate Selected Key(s)"), MENU_KEY_DUPLICATE);
|
|
|
|
- menu->add_separator();
|
|
|
|
- menu->add_icon_item(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Delete Selected Key(s)"), MENU_KEY_DELETE);
|
|
|
|
- menu->add_separator();
|
|
|
|
- menu->add_icon_item(get_theme_icon(SNAME("BezierHandlesFree"), SNAME("EditorIcons")), TTR("Make Handles Free"), MENU_KEY_SET_HANDLE_FREE);
|
|
|
|
- menu->add_icon_item(get_theme_icon(SNAME("BezierHandlesBalanced"), SNAME("EditorIcons")), TTR("Make Handles Balanced"), MENU_KEY_SET_HANDLE_BALANCED);
|
|
|
|
- }
|
|
|
|
|
|
+ menu->clear();
|
|
|
|
+ if (!locked_tracks.has(selected_track) || locked_tracks.has(selected_track)) {
|
|
|
|
+ menu->add_icon_item(bezier_icon, TTR("Insert Key Here"), MENU_KEY_INSERT);
|
|
|
|
+ }
|
|
|
|
+ if (selection.size()) {
|
|
|
|
+ menu->add_separator();
|
|
|
|
+ menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Duplicate Selected Key(s)"), MENU_KEY_DUPLICATE);
|
|
|
|
+ menu->add_separator();
|
|
|
|
+ menu->add_icon_item(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Delete Selected Key(s)"), MENU_KEY_DELETE);
|
|
|
|
+ menu->add_separator();
|
|
|
|
+ menu->add_icon_item(get_theme_icon(SNAME("BezierHandlesFree"), SNAME("EditorIcons")), TTR("Make Handles Free"), MENU_KEY_SET_HANDLE_FREE);
|
|
|
|
+ menu->add_icon_item(get_theme_icon(SNAME("BezierHandlesBalanced"), SNAME("EditorIcons")), TTR("Make Handles Balanced"), MENU_KEY_SET_HANDLE_BALANCED);
|
|
|
|
+ }
|
|
|
|
|
|
- if (menu->get_item_count()) {
|
|
|
|
- menu->reset_size();
|
|
|
|
- menu->set_position(popup_pos);
|
|
|
|
- menu->popup();
|
|
|
|
|
|
+ if (menu->get_item_count()) {
|
|
|
|
+ menu->reset_size();
|
|
|
|
+ menu->set_position(popup_pos);
|
|
|
|
+ menu->popup();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -945,7 +958,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
for (const KeyValue<int, Rect2> &E : subtracks) {
|
|
for (const KeyValue<int, Rect2> &E : subtracks) {
|
|
if (E.value.has_point(mb->get_position())) {
|
|
if (E.value.has_point(mb->get_position())) {
|
|
if (!locked_tracks.has(E.key) && !hidden_tracks.has(E.key)) {
|
|
if (!locked_tracks.has(E.key) && !hidden_tracks.has(E.key)) {
|
|
- set_animation_and_track(animation, E.key);
|
|
|
|
|
|
+ set_animation_and_track(animation, E.key, read_only);
|
|
_clear_selection();
|
|
_clear_selection();
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
@@ -958,30 +971,32 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
for (const KeyValue<int, Rect2> &I : track_icons) {
|
|
for (const KeyValue<int, Rect2> &I : track_icons) {
|
|
if (I.value.has_point(mb->get_position())) {
|
|
if (I.value.has_point(mb->get_position())) {
|
|
if (I.key == REMOVE_ICON) {
|
|
if (I.key == REMOVE_ICON) {
|
|
- undo_redo->create_action("Remove Bezier Track");
|
|
|
|
-
|
|
|
|
- undo_redo->add_do_method(this, "_update_locked_tracks_after", track);
|
|
|
|
- undo_redo->add_do_method(this, "_update_hidden_tracks_after", track);
|
|
|
|
-
|
|
|
|
- undo_redo->add_do_method(animation.ptr(), "remove_track", track);
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ undo_redo->create_action("Remove Bezier Track");
|
|
|
|
+
|
|
|
|
+ undo_redo->add_do_method(this, "_update_locked_tracks_after", track);
|
|
|
|
+ undo_redo->add_do_method(this, "_update_hidden_tracks_after", track);
|
|
|
|
+
|
|
|
|
+ undo_redo->add_do_method(animation.ptr(), "remove_track", track);
|
|
|
|
+
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "add_track", Animation::TrackType::TYPE_BEZIER, track);
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "track_set_path", track, animation->track_get_path(track));
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < animation->track_get_key_count(track); ++i) {
|
|
|
|
+ undo_redo->add_undo_method(
|
|
|
|
+ animation.ptr(),
|
|
|
|
+ "bezier_track_insert_key",
|
|
|
|
+ track, animation->track_get_key_time(track, i),
|
|
|
|
+ animation->bezier_track_get_key_value(track, i),
|
|
|
|
+ animation->bezier_track_get_key_in_handle(track, i),
|
|
|
|
+ animation->bezier_track_get_key_out_handle(track, i),
|
|
|
|
+ animation->bezier_track_get_key_handle_mode(track, i));
|
|
|
|
+ }
|
|
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "add_track", Animation::TrackType::TYPE_BEZIER, track);
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "track_set_path", track, animation->track_get_path(track));
|
|
|
|
|
|
+ undo_redo->commit_action();
|
|
|
|
|
|
- for (int i = 0; i < animation->track_get_key_count(track); ++i) {
|
|
|
|
- undo_redo->add_undo_method(
|
|
|
|
- animation.ptr(),
|
|
|
|
- "bezier_track_insert_key",
|
|
|
|
- track, animation->track_get_key_time(track, i),
|
|
|
|
- animation->bezier_track_get_key_value(track, i),
|
|
|
|
- animation->bezier_track_get_key_in_handle(track, i),
|
|
|
|
- animation->bezier_track_get_key_out_handle(track, i),
|
|
|
|
- animation->bezier_track_get_key_handle_mode(track, i));
|
|
|
|
|
|
+ selected_track = CLAMP(selected_track, 0, animation->get_track_count() - 1);
|
|
}
|
|
}
|
|
-
|
|
|
|
- undo_redo->commit_action();
|
|
|
|
-
|
|
|
|
- selected_track = CLAMP(selected_track, 0, animation->get_track_count() - 1);
|
|
|
|
return;
|
|
return;
|
|
} else if (I.key == LOCK_ICON) {
|
|
} else if (I.key == LOCK_ICON) {
|
|
if (locked_tracks.has(track)) {
|
|
if (locked_tracks.has(track)) {
|
|
@@ -991,7 +1006,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
if (selected_track == track) {
|
|
if (selected_track == track) {
|
|
for (int i = 0; i < animation->get_track_count(); ++i) {
|
|
for (int i = 0; i < animation->get_track_count(); ++i) {
|
|
if (!locked_tracks.has(i) && animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) {
|
|
if (!locked_tracks.has(i) && animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) {
|
|
- set_animation_and_track(animation, i);
|
|
|
|
|
|
+ set_animation_and_track(animation, i, read_only);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1007,7 +1022,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
if (selected_track == track) {
|
|
if (selected_track == track) {
|
|
for (int i = 0; i < animation->get_track_count(); ++i) {
|
|
for (int i = 0; i < animation->get_track_count(); ++i) {
|
|
if (!hidden_tracks.has(i) && animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) {
|
|
if (!hidden_tracks.has(i) && animation->track_get_type(i) == Animation::TrackType::TYPE_BEZIER) {
|
|
- set_animation_and_track(animation, i);
|
|
|
|
|
|
+ set_animation_and_track(animation, i, read_only);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1046,7 +1061,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- set_animation_and_track(animation, track);
|
|
|
|
|
|
+ set_animation_and_track(animation, track, read_only);
|
|
solo_track = track;
|
|
solo_track = track;
|
|
}
|
|
}
|
|
update();
|
|
update();
|
|
@@ -1087,7 +1102,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
moving_selection_from_key = pair.second;
|
|
moving_selection_from_key = pair.second;
|
|
moving_selection_from_track = pair.first;
|
|
moving_selection_from_track = pair.first;
|
|
moving_selection_offset = Vector2();
|
|
moving_selection_offset = Vector2();
|
|
- set_animation_and_track(animation, pair.first);
|
|
|
|
|
|
+ set_animation_and_track(animation, pair.first, read_only);
|
|
selection.clear();
|
|
selection.clear();
|
|
selection.insert(pair);
|
|
selection.insert(pair);
|
|
update();
|
|
update();
|
|
@@ -1096,24 +1111,26 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- if (edit_points[i].in_rect.has_point(mb->get_position())) {
|
|
|
|
- moving_handle = -1;
|
|
|
|
- moving_handle_key = edit_points[i].key;
|
|
|
|
- moving_handle_track = edit_points[i].track;
|
|
|
|
- moving_handle_left = animation->bezier_track_get_key_in_handle(edit_points[i].track, edit_points[i].key);
|
|
|
|
- moving_handle_right = animation->bezier_track_get_key_out_handle(edit_points[i].track, edit_points[i].key);
|
|
|
|
- update();
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ if (edit_points[i].in_rect.has_point(mb->get_position())) {
|
|
|
|
+ moving_handle = -1;
|
|
|
|
+ moving_handle_key = edit_points[i].key;
|
|
|
|
+ moving_handle_track = edit_points[i].track;
|
|
|
|
+ moving_handle_left = animation->bezier_track_get_key_in_handle(edit_points[i].track, edit_points[i].key);
|
|
|
|
+ moving_handle_right = animation->bezier_track_get_key_out_handle(edit_points[i].track, edit_points[i].key);
|
|
|
|
+ update();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
|
|
- if (edit_points[i].out_rect.has_point(mb->get_position())) {
|
|
|
|
- moving_handle = 1;
|
|
|
|
- moving_handle_key = edit_points[i].key;
|
|
|
|
- moving_handle_track = edit_points[i].track;
|
|
|
|
- moving_handle_left = animation->bezier_track_get_key_in_handle(edit_points[i].track, edit_points[i].key);
|
|
|
|
- moving_handle_right = animation->bezier_track_get_key_out_handle(edit_points[i].track, edit_points[i].key);
|
|
|
|
- update();
|
|
|
|
- return;
|
|
|
|
|
|
+ if (edit_points[i].out_rect.has_point(mb->get_position())) {
|
|
|
|
+ moving_handle = 1;
|
|
|
|
+ moving_handle_key = edit_points[i].key;
|
|
|
|
+ moving_handle_track = edit_points[i].track;
|
|
|
|
+ moving_handle_left = animation->bezier_track_get_key_in_handle(edit_points[i].track, edit_points[i].key);
|
|
|
|
+ moving_handle_right = animation->bezier_track_get_key_out_handle(edit_points[i].track, edit_points[i].key);
|
|
|
|
+ update();
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1191,7 +1208,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
selection.insert(IntPair(edit_points[i].track, edit_points[i].key));
|
|
selection.insert(IntPair(edit_points[i].track, edit_points[i].key));
|
|
if (!track_set) {
|
|
if (!track_set) {
|
|
track_set = true;
|
|
track_set = true;
|
|
- set_animation_and_track(animation, edit_points[i].track);
|
|
|
|
|
|
+ set_animation_and_track(animation, edit_points[i].track, read_only);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1215,7 +1232,7 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
float track_height = _bezier_h_to_pixel(track_h);
|
|
float track_height = _bezier_h_to_pixel(track_h);
|
|
|
|
|
|
if (abs(mb->get_position().y - track_height) < 10) {
|
|
if (abs(mb->get_position().y - track_height) < 10) {
|
|
- set_animation_and_track(animation, i);
|
|
|
|
|
|
+ set_animation_and_track(animation, i, read_only);
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1229,102 +1246,106 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
}
|
|
}
|
|
|
|
|
|
if (moving_handle != 0 && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
|
if (moving_handle != 0 && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
|
- undo_redo->create_action(TTR("Move Bezier Points"));
|
|
|
|
- undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", selected_track, moving_handle_key, moving_handle_left);
|
|
|
|
- undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", selected_track, moving_handle_key, moving_handle_right);
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", selected_track, moving_handle_key, animation->bezier_track_get_key_in_handle(selected_track, moving_handle_key));
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", selected_track, moving_handle_key, animation->bezier_track_get_key_out_handle(selected_track, moving_handle_key));
|
|
|
|
- undo_redo->commit_action();
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ undo_redo->create_action(TTR("Move Bezier Points"));
|
|
|
|
+ undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", selected_track, moving_handle_key, moving_handle_left);
|
|
|
|
+ undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", selected_track, moving_handle_key, moving_handle_right);
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", selected_track, moving_handle_key, animation->bezier_track_get_key_in_handle(selected_track, moving_handle_key));
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", selected_track, moving_handle_key, animation->bezier_track_get_key_out_handle(selected_track, moving_handle_key));
|
|
|
|
+ undo_redo->commit_action();
|
|
|
|
|
|
- moving_handle = 0;
|
|
|
|
- update();
|
|
|
|
|
|
+ moving_handle = 0;
|
|
|
|
+ update();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
if (moving_selection_attempt && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
|
if (moving_selection_attempt && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
|
|
- if (moving_selection) {
|
|
|
|
- //combit it
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ if (moving_selection) {
|
|
|
|
+ //combit it
|
|
|
|
|
|
- undo_redo->create_action(TTR("Move Bezier Points"));
|
|
|
|
-
|
|
|
|
- List<AnimMoveRestore> to_restore;
|
|
|
|
- // 1-remove the keys
|
|
|
|
- for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
- undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->get().first, E->get().second);
|
|
|
|
- }
|
|
|
|
- // 2- remove overlapped keys
|
|
|
|
- for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
- float newtime = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x);
|
|
|
|
|
|
+ undo_redo->create_action(TTR("Move Bezier Points"));
|
|
|
|
|
|
- int idx = animation->track_find_key(E->get().first, newtime, true);
|
|
|
|
- if (idx == -1) {
|
|
|
|
- continue;
|
|
|
|
|
|
+ List<AnimMoveRestore> to_restore;
|
|
|
|
+ // 1-remove the keys
|
|
|
|
+ for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
+ undo_redo->add_do_method(animation.ptr(), "track_remove_key", E->get().first, E->get().second);
|
|
}
|
|
}
|
|
|
|
+ // 2- remove overlapped keys
|
|
|
|
+ for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
+ float newtime = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x);
|
|
|
|
|
|
- if (selection.has(IntPair(E->get().first, idx))) {
|
|
|
|
- continue; //already in selection, don't save
|
|
|
|
- }
|
|
|
|
|
|
+ int idx = animation->track_find_key(E->get().first, newtime, true);
|
|
|
|
+ if (idx == -1) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
|
|
- undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_time", E->get().first, newtime);
|
|
|
|
- AnimMoveRestore amr;
|
|
|
|
|
|
+ if (selection.has(IntPair(E->get().first, idx))) {
|
|
|
|
+ continue; //already in selection, don't save
|
|
|
|
+ }
|
|
|
|
|
|
- amr.key = animation->track_get_key_value(E->get().first, idx);
|
|
|
|
- amr.track = E->get().first;
|
|
|
|
- amr.time = newtime;
|
|
|
|
|
|
+ undo_redo->add_do_method(animation.ptr(), "track_remove_key_at_time", E->get().first, newtime);
|
|
|
|
+ AnimMoveRestore amr;
|
|
|
|
|
|
- to_restore.push_back(amr);
|
|
|
|
- }
|
|
|
|
|
|
+ amr.key = animation->track_get_key_value(E->get().first, idx);
|
|
|
|
+ amr.track = E->get().first;
|
|
|
|
+ amr.time = newtime;
|
|
|
|
|
|
- // 3-move the keys (re insert them)
|
|
|
|
- for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
- float newpos = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x);
|
|
|
|
- Array key = animation->track_get_key_value(E->get().first, E->get().second);
|
|
|
|
- float h = key[0];
|
|
|
|
- h += moving_selection_offset.y;
|
|
|
|
- key[0] = h;
|
|
|
|
- undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->get().first, newpos, key, 1);
|
|
|
|
- }
|
|
|
|
|
|
+ to_restore.push_back(amr);
|
|
|
|
+ }
|
|
|
|
|
|
- // 4-(undo) remove inserted keys
|
|
|
|
- for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
- float newpos = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x);
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", E->get().first, newpos);
|
|
|
|
- }
|
|
|
|
|
|
+ // 3-move the keys (re insert them)
|
|
|
|
+ for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
+ float newpos = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x);
|
|
|
|
+ Array key = animation->track_get_key_value(E->get().first, E->get().second);
|
|
|
|
+ float h = key[0];
|
|
|
|
+ h += moving_selection_offset.y;
|
|
|
|
+ key[0] = h;
|
|
|
|
+ undo_redo->add_do_method(animation.ptr(), "track_insert_key", E->get().first, newpos, key, 1);
|
|
|
|
+ }
|
|
|
|
|
|
- // 5-(undo) reinsert keys
|
|
|
|
- for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
- float oldpos = animation->track_get_key_time(E->get().first, E->get().second);
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->get().first, oldpos, animation->track_get_key_value(E->get().first, E->get().second), 1);
|
|
|
|
- }
|
|
|
|
|
|
+ // 4-(undo) remove inserted keys
|
|
|
|
+ for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
+ float newpos = editor->snap_time(animation->track_get_key_time(E->get().first, E->get().second) + moving_selection_offset.x);
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "track_remove_key_at_time", E->get().first, newpos);
|
|
|
|
+ }
|
|
|
|
|
|
- // 6-(undo) reinsert overlapped keys
|
|
|
|
- for (const AnimMoveRestore &amr : to_restore) {
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, 1);
|
|
|
|
- }
|
|
|
|
|
|
+ // 5-(undo) reinsert keys
|
|
|
|
+ for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
+ float oldpos = animation->track_get_key_time(E->get().first, E->get().second);
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "track_insert_key", E->get().first, oldpos, animation->track_get_key_value(E->get().first, E->get().second), 1);
|
|
|
|
+ }
|
|
|
|
|
|
- undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
|
|
|
|
- undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
|
|
|
|
+ // 6-(undo) reinsert overlapped keys
|
|
|
|
+ for (const AnimMoveRestore &amr : to_restore) {
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "track_insert_key", amr.track, amr.time, amr.key, 1);
|
|
|
|
+ }
|
|
|
|
|
|
- // 7-reselect
|
|
|
|
|
|
+ undo_redo->add_do_method(this, "_clear_selection_for_anim", animation);
|
|
|
|
+ undo_redo->add_undo_method(this, "_clear_selection_for_anim", animation);
|
|
|
|
|
|
- for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
- float oldpos = animation->track_get_key_time(E->get().first, E->get().second);
|
|
|
|
- float newpos = editor->snap_time(oldpos + moving_selection_offset.x);
|
|
|
|
|
|
+ // 7-reselect
|
|
|
|
|
|
- undo_redo->add_do_method(this, "_select_at_anim", animation, E->get().first, newpos);
|
|
|
|
- undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, oldpos);
|
|
|
|
- }
|
|
|
|
|
|
+ for (SelectionSet::Element *E = selection.back(); E; E = E->prev()) {
|
|
|
|
+ float oldpos = animation->track_get_key_time(E->get().first, E->get().second);
|
|
|
|
+ float newpos = editor->snap_time(oldpos + moving_selection_offset.x);
|
|
|
|
|
|
- undo_redo->commit_action();
|
|
|
|
|
|
+ undo_redo->add_do_method(this, "_select_at_anim", animation, E->get().first, newpos);
|
|
|
|
+ undo_redo->add_undo_method(this, "_select_at_anim", animation, E->get().first, oldpos);
|
|
|
|
+ }
|
|
|
|
|
|
- moving_selection = false;
|
|
|
|
- } else if (select_single_attempt != IntPair(-1, -1)) {
|
|
|
|
- selection.clear();
|
|
|
|
- selection.insert(select_single_attempt);
|
|
|
|
- set_animation_and_track(animation, select_single_attempt.first);
|
|
|
|
- }
|
|
|
|
|
|
+ undo_redo->commit_action();
|
|
|
|
|
|
- moving_selection_attempt = false;
|
|
|
|
- update();
|
|
|
|
|
|
+ moving_selection = false;
|
|
|
|
+ } else if (select_single_attempt != IntPair(-1, -1)) {
|
|
|
|
+ selection.clear();
|
|
|
|
+ selection.insert(select_single_attempt);
|
|
|
|
+ set_animation_and_track(animation, select_single_attempt.first, read_only);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ moving_selection_attempt = false;
|
|
|
|
+ update();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
Ref<InputEventMouseMotion> mm = p_event;
|
|
Ref<InputEventMouseMotion> mm = p_event;
|
|
@@ -1337,7 +1358,9 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll;
|
|
float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll;
|
|
float x = editor->snap_time(((mm->get_position().x - limit) / timeline->get_zoom_scale()) + timeline->get_value());
|
|
float x = editor->snap_time(((mm->get_position().x - limit) / timeline->get_zoom_scale()) + timeline->get_value());
|
|
|
|
|
|
- moving_selection_offset = Vector2(x - animation->track_get_key_time(moving_selection_from_track, moving_selection_from_key), y - animation->bezier_track_get_key_value(moving_selection_from_track, moving_selection_from_key));
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ moving_selection_offset = Vector2(x - animation->track_get_key_time(moving_selection_from_track, moving_selection_from_key), y - animation->bezier_track_get_key_value(moving_selection_from_track, moving_selection_from_key));
|
|
|
|
+ }
|
|
update();
|
|
update();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1399,20 +1422,22 @@ void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) {
|
|
|
|
|
|
bool is_finishing_key_handle_drag = moving_handle != 0 && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT;
|
|
bool is_finishing_key_handle_drag = moving_handle != 0 && mb.is_valid() && !mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT;
|
|
if (is_finishing_key_handle_drag) {
|
|
if (is_finishing_key_handle_drag) {
|
|
- undo_redo->create_action(TTR("Move Bezier Points"));
|
|
|
|
- if (moving_handle == -1) {
|
|
|
|
- double ratio = timeline->get_zoom_scale() * v_zoom;
|
|
|
|
- undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", moving_handle_track, moving_handle_key, moving_handle_left, ratio);
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", moving_handle_track, moving_handle_key, animation->bezier_track_get_key_in_handle(moving_handle_track, moving_handle_key), ratio);
|
|
|
|
- } else if (moving_handle == 1) {
|
|
|
|
- double ratio = timeline->get_zoom_scale() * v_zoom;
|
|
|
|
- undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", moving_handle_track, moving_handle_key, moving_handle_right, ratio);
|
|
|
|
- undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", moving_handle_track, moving_handle_key, animation->bezier_track_get_key_out_handle(moving_handle_track, moving_handle_key), ratio);
|
|
|
|
- }
|
|
|
|
- undo_redo->commit_action();
|
|
|
|
|
|
+ if (!read_only) {
|
|
|
|
+ undo_redo->create_action(TTR("Move Bezier Points"));
|
|
|
|
+ if (moving_handle == -1) {
|
|
|
|
+ double ratio = timeline->get_zoom_scale() * v_zoom;
|
|
|
|
+ undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_in_handle", moving_handle_track, moving_handle_key, moving_handle_left, ratio);
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_in_handle", moving_handle_track, moving_handle_key, animation->bezier_track_get_key_in_handle(moving_handle_track, moving_handle_key), ratio);
|
|
|
|
+ } else if (moving_handle == 1) {
|
|
|
|
+ double ratio = timeline->get_zoom_scale() * v_zoom;
|
|
|
|
+ undo_redo->add_do_method(animation.ptr(), "bezier_track_set_key_out_handle", moving_handle_track, moving_handle_key, moving_handle_right, ratio);
|
|
|
|
+ undo_redo->add_undo_method(animation.ptr(), "bezier_track_set_key_out_handle", moving_handle_track, moving_handle_key, animation->bezier_track_get_key_out_handle(moving_handle_track, moving_handle_key), ratio);
|
|
|
|
+ }
|
|
|
|
+ undo_redo->commit_action();
|
|
|
|
|
|
- moving_handle = 0;
|
|
|
|
- update();
|
|
|
|
|
|
+ moving_handle = 0;
|
|
|
|
+ update();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|