summaryrefslogtreecommitdiff
path: root/editor/animation_track_editor.cpp
diff options
context:
space:
mode:
authorkobewi <kobewi4e@gmail.com>2021-12-06 00:45:45 +0100
committerkobewi <kobewi4e@gmail.com>2021-12-06 13:35:54 +0100
commitf77a494d22ed03bd362975a279b4265c1cf41883 (patch)
treec848294b5251a4fcbb48842c7119cdf638b2539a /editor/animation_track_editor.cpp
parent608c9f820349ca13f017ea406c790d90729da837 (diff)
Allow to add RESET values from existing keys
Diffstat (limited to 'editor/animation_track_editor.cpp')
-rw-r--r--editor/animation_track_editor.cpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp
index f36a2099d5..f570d100e7 100644
--- a/editor/animation_track_editor.cpp
+++ b/editor/animation_track_editor.cpp
@@ -2873,6 +2873,12 @@ 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);
}
@@ -3062,6 +3068,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 +3133,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 +4399,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 +5732,54 @@ 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;
+ }
+ }
+
+ 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);
+ }
+
+ int 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);