Allow to add RESET values from existing keys
This commit is contained in:
parent
608c9f8203
commit
f77a494d22
2 changed files with 62 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -140,6 +140,7 @@ class AnimationTrackEdit : public Control {
|
|||
MENU_LOOP_CLAMP,
|
||||
MENU_KEY_INSERT,
|
||||
MENU_KEY_DUPLICATE,
|
||||
MENU_KEY_ADD_RESET,
|
||||
MENU_KEY_DELETE
|
||||
};
|
||||
AnimationTimelineEdit *timeline;
|
||||
|
@ -500,6 +501,7 @@ public:
|
|||
EDIT_SCALE_CONFIRM,
|
||||
EDIT_DUPLICATE_SELECTION,
|
||||
EDIT_DUPLICATE_TRANSPOSED,
|
||||
EDIT_ADD_RESET_KEY,
|
||||
EDIT_DELETE_SELECTION,
|
||||
EDIT_GOTO_NEXT_STEP,
|
||||
EDIT_GOTO_PREV_STEP,
|
||||
|
|
Loading…
Reference in a new issue