diff options
Diffstat (limited to 'editor/animation_track_editor.cpp')
-rw-r--r-- | editor/animation_track_editor.cpp | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index eacfeb06fd..0c2754ba74 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -2873,13 +2873,18 @@ void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) { if (editor->is_selection_active()) { menu->add_separator(); menu->add_icon_item(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")), TTR("Duplicate Key(s)"), MENU_KEY_DUPLICATE); + + AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player(); + if (!player->has_animation(SceneStringNames::get_singleton()->RESET) || animation != player->get_animation(SceneStringNames::get_singleton()->RESET)) { + menu->add_icon_item(get_theme_icon(SNAME("Reload"), SNAME("EditorIcons")), TTR("Add RESET Value(s)"), MENU_KEY_ADD_RESET); + } + menu->add_separator(); menu->add_icon_item(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")), TTR("Delete Key(s)"), MENU_KEY_DELETE); } menu->set_as_minsize(); - Vector2 popup_pos = get_screen_transform().xform(get_local_mouse_position()); - menu->set_position(popup_pos); + menu->set_position(get_screen_position() + get_local_mouse_position()); menu->popup(); insert_at_pos = offset + timeline->get_value(); @@ -3062,6 +3067,9 @@ void AnimationTrackEdit::_menu_selected(int p_index) { } break; case MENU_KEY_DUPLICATE: { emit_signal(SNAME("duplicate_request")); + } break; + case MENU_KEY_ADD_RESET: { + emit_signal(SNAME("create_reset_request")); } break; case MENU_KEY_DELETE: { @@ -3124,6 +3132,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")); } @@ -4389,6 +4398,7 @@ void AnimationTrackEditor::_update_tracks() { track_edit->connect("duplicate_request", callable_mp(this, &AnimationTrackEditor::_edit_menu_pressed), varray(EDIT_DUPLICATE_SELECTION), CONNECT_DEFERRED); track_edit->connect("duplicate_transpose_request", callable_mp(this, &AnimationTrackEditor::_edit_menu_pressed), varray(EDIT_DUPLICATE_TRANSPOSED), CONNECT_DEFERRED); + track_edit->connect("create_reset_request", callable_mp(this, &AnimationTrackEditor::_edit_menu_pressed), varray(EDIT_ADD_RESET_KEY), CONNECT_DEFERRED); track_edit->connect("delete_request", callable_mp(this, &AnimationTrackEditor::_edit_menu_pressed), varray(EDIT_DELETE_SELECTION), CONNECT_DEFERRED); } } @@ -5721,6 +5731,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 (const KeyValue<SelectedKey, KeyInfo> &E : selection) { + 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(); @@ -6145,6 +6204,7 @@ AnimationTrackEditor::AnimationTrackEditor() { edit->get_popup()->add_separator(); edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/duplicate_selection", TTR("Duplicate Selection"), KeyModifierMask::CMD | Key::D), EDIT_DUPLICATE_SELECTION); edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/duplicate_selection_transposed", TTR("Duplicate Transposed"), KeyModifierMask::SHIFT | KeyModifierMask::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()->add_separator(); edit->get_popup()->add_shortcut(ED_SHORTCUT("animation_editor/delete_selection", TTR("Delete Selection"), Key::KEY_DELETE), EDIT_DELETE_SELECTION); |