Allow to add RESET values from existing keys

(cherry picked from commits f77a494d22
and b7d83689e4)
This commit is contained in:
kobewi 2021-12-06 00:45:45 +01:00 committed by Rémi Verschelde
parent dbe9bb85c9
commit 4405daa09b
No known key found for this signature in database
GPG key ID: C3336907360768E1
2 changed files with 63 additions and 1 deletions

View file

@ -2746,6 +2746,12 @@ void AnimationTrackEdit::_gui_input(const Ref<InputEvent> &p_event) {
if (editor->is_selection_active()) {
menu->add_separator();
menu->add_icon_item(get_icon("Duplicate", "EditorIcons"), TTR("Duplicate Key(s)"), MENU_KEY_DUPLICATE);
AnimationPlayer *player = AnimationPlayerEditor::singleton->get_player();
if (!player->has_animation("RESET") || animation != player->get_animation("RESET")) {
menu->add_icon_item(get_icon("Reload", "EditorIcons"), TTR("Add RESET Value(s)"), MENU_KEY_ADD_RESET);
}
menu->add_separator();
menu->add_icon_item(get_icon("Remove", "EditorIcons"), TTR("Delete Key(s)"), MENU_KEY_DELETE);
}
@ -2930,7 +2936,9 @@ void AnimationTrackEdit::_menu_selected(int p_index) {
} break;
case MENU_KEY_DUPLICATE: {
emit_signal("duplicate_request");
} break;
case MENU_KEY_ADD_RESET: {
emit_signal("create_reset_request");
} break;
case MENU_KEY_DELETE: {
emit_signal("delete_request");
@ -2994,6 +3002,7 @@ void AnimationTrackEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("move_selection_cancel"));
ADD_SIGNAL(MethodInfo("duplicate_request"));
ADD_SIGNAL(MethodInfo("create_reset_request"));
ADD_SIGNAL(MethodInfo("duplicate_transpose_request"));
ADD_SIGNAL(MethodInfo("delete_request"));
}
@ -4232,6 +4241,7 @@ void AnimationTrackEditor::_update_tracks() {
track_edit->connect("duplicate_request", this, "_edit_menu_pressed", varray(EDIT_DUPLICATE_SELECTION), CONNECT_DEFERRED);
track_edit->connect("duplicate_transpose_request", this, "_edit_menu_pressed", varray(EDIT_DUPLICATE_TRANSPOSED), CONNECT_DEFERRED);
track_edit->connect("create_reset_request", this, "_edit_menu_pressed", varray(EDIT_ADD_RESET_KEY), CONNECT_DEFERRED);
track_edit->connect("delete_request", this, "_edit_menu_pressed", varray(EDIT_DELETE_SELECTION), CONNECT_DEFERRED);
}
}
@ -5508,6 +5518,55 @@ void AnimationTrackEditor::_edit_menu_pressed(int p_option) {
}
_anim_duplicate_keys(true);
} break;
case EDIT_ADD_RESET_KEY: {
undo_redo->create_action(TTR("Anim Add RESET Keys"));
Ref<Animation> reset = _create_and_get_reset_animation();
int reset_tracks = reset->get_track_count();
Set<int> tracks_added;
for (Map<SelectedKey, KeyInfo>::Element *E = selection.back(); E; E = E->prev()) {
const SelectedKey &sk = E->key();
// Only add one key per track.
if (tracks_added.has(sk.track)) {
continue;
}
tracks_added.insert(sk.track);
int dst_track = -1;
const NodePath &path = animation->track_get_path(sk.track);
for (int i = 0; i < reset->get_track_count(); i++) {
if (reset->track_get_path(i) == path) {
dst_track = i;
break;
}
}
int existing_idx = -1;
if (dst_track == -1) {
// If adding multiple tracks, make sure that correct track is referenced.
dst_track = reset_tracks;
reset_tracks++;
undo_redo->add_do_method(reset.ptr(), "add_track", animation->track_get_type(sk.track));
undo_redo->add_do_method(reset.ptr(), "track_set_path", dst_track, path);
undo_redo->add_undo_method(reset.ptr(), "remove_track", dst_track);
} else {
existing_idx = reset->track_find_key(dst_track, 0, true);
}
undo_redo->add_do_method(reset.ptr(), "track_insert_key", dst_track, 0, animation->track_get_key_value(sk.track, sk.key), animation->track_get_key_transition(sk.track, sk.key));
undo_redo->add_undo_method(reset.ptr(), "track_remove_key_at_time", dst_track, 0);
if (existing_idx != -1) {
undo_redo->add_undo_method(reset.ptr(), "track_insert_key", dst_track, 0, reset->track_get_key_value(dst_track, existing_idx), reset->track_get_key_transition(dst_track, existing_idx));
}
}
undo_redo->commit_action();
} break;
case EDIT_DELETE_SELECTION: {
if (bezier_edit->is_visible()) {
bezier_edit->delete_selection();
@ -5958,6 +6017,7 @@ AnimationTrackEditor::AnimationTrackEditor() {
edit->get_popup()->add_separator();
edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/duplicate_selection", TTR("Duplicate Selection"), KEY_MASK_CMD | KEY_D), EDIT_DUPLICATE_SELECTION);
edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/duplicate_selection_transposed", TTR("Duplicate Transposed"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_D), EDIT_DUPLICATE_TRANSPOSED);
edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/add_reset_value", TTR("Add RESET Value(s)")));
edit->get_popup()->set_item_shortcut_disabled(edit->get_popup()->get_item_index(EDIT_DUPLICATE_SELECTION), true);
edit->get_popup()->set_item_shortcut_disabled(edit->get_popup()->get_item_index(EDIT_DUPLICATE_TRANSPOSED), true);
edit->get_popup()->add_separator();