diff options
Diffstat (limited to 'editor/animation_track_editor.cpp')
-rw-r--r-- | editor/animation_track_editor.cpp | 77 |
1 files changed, 69 insertions, 8 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 6fce55f8e3..0c2754ba74 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -39,6 +39,7 @@ #include "editor_scale.h" #include "scene/animation/animation_player.h" #include "scene/main/window.h" +#include "scene/scene_string_names.h" #include "servers/audio/audio_stream.h" class AnimationTrackKeyEdit : public Object { @@ -2872,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(); @@ -3061,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: { @@ -3123,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")); } @@ -3240,7 +3250,7 @@ void AnimationTrackEditGroup::set_type_and_name(const Ref<Texture2D> &p_type, co node_name = p_name; node = p_node; update(); - minimum_size_changed(); + update_minimum_size(); } Size2 AnimationTrackEditGroup::get_minimum_size() const { @@ -3505,7 +3515,7 @@ void AnimationTrackEditor::make_insert_queue() { void AnimationTrackEditor::commit_insert_queue() { bool reset_allowed = true; AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player(); - if (player->has_animation("RESET") && player->get_animation("RESET") == animation) { + if (player->has_animation(SceneStringNames::get_singleton()->RESET) && player->get_animation(SceneStringNames::get_singleton()->RESET) == animation) { // Avoid messing with the reset animation itself. reset_allowed = false; } else { @@ -3925,15 +3935,15 @@ void AnimationTrackEditor::insert_value_key(const String &p_property, const Vari Ref<Animation> AnimationTrackEditor::_create_and_get_reset_animation() { AnimationPlayer *player = AnimationPlayerEditor::get_singleton()->get_player(); - if (player->has_animation("RESET")) { - return player->get_animation("RESET"); + if (player->has_animation(SceneStringNames::get_singleton()->RESET)) { + return player->get_animation(SceneStringNames::get_singleton()->RESET); } else { Ref<Animation> reset_anim; reset_anim.instantiate(); reset_anim->set_length(ANIM_MIN_LENGTH); - undo_redo->add_do_method(player, "add_animation", "RESET", reset_anim); + undo_redo->add_do_method(player, "add_animation", SceneStringNames::get_singleton()->RESET, reset_anim); undo_redo->add_do_method(AnimationPlayerEditor::get_singleton(), "_animation_player_changed", player); - undo_redo->add_undo_method(player, "remove_animation", "RESET"); + undo_redo->add_undo_method(player, "remove_animation", SceneStringNames::get_singleton()->RESET); undo_redo->add_undo_method(AnimationPlayerEditor::get_singleton(), "_animation_player_changed", player); return reset_anim; } @@ -4388,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); } } @@ -5720,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(); @@ -6144,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); |