-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow duplicating entire animations #80380
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -575,6 +575,7 @@ void SpriteFramesEditor::_notification(int p_what) { | |
zoom_reset->set_icon(get_theme_icon(SNAME("ZoomReset"), SNAME("EditorIcons"))); | ||
zoom_in->set_icon(get_theme_icon(SNAME("ZoomMore"), SNAME("EditorIcons"))); | ||
add_anim->set_icon(get_theme_icon(SNAME("New"), SNAME("EditorIcons"))); | ||
duplicate_anim->set_icon(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons"))); | ||
delete_anim->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); | ||
anim_search_box->set_right_icon(get_theme_icon(SNAME("Search"), SNAME("EditorIcons"))); | ||
split_sheet_zoom_out->set_icon(get_theme_icon(SNAME("ZoomLess"), SNAME("EditorIcons"))); | ||
|
@@ -1020,6 +1021,36 @@ void SpriteFramesEditor::_animation_add() { | |
animations->grab_focus(); | ||
} | ||
|
||
void SpriteFramesEditor::_animation_duplicate() { | ||
if (updating) { | ||
return; | ||
} | ||
|
||
if (!frames->has_animation(edited_anim)) { | ||
return; | ||
} | ||
|
||
int counter = 1; | ||
String name = String(edited_anim) + "_" + itos(counter); | ||
while (frames->has_animation(name)) { | ||
counter++; | ||
name = String(edited_anim) + "_" + itos(counter); | ||
} | ||
|
||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); | ||
undo_redo->create_action(TTR("Duplicate Animation"), UndoRedo::MERGE_DISABLE, EditorNode::get_singleton()->get_edited_scene()); | ||
undo_redo->add_do_method(frames.ptr(), "add_animation", name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
undo_redo->add_undo_method(frames.ptr(), "remove_animation", name); | ||
undo_redo->add_do_method(this, "_update_library"); | ||
undo_redo->add_undo_method(this, "_update_library"); | ||
Comment on lines
+1044
to
+1045
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should run after other methods. |
||
undo_redo->add_do_method(frames.ptr(), "duplicate_animation", edited_anim, name); | ||
undo_redo->add_undo_method(frames.ptr(), "remove_animation", name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is called twice. |
||
undo_redo->commit_action(); | ||
|
||
_select_animation(name); | ||
animations->grab_focus(); | ||
} | ||
|
||
void SpriteFramesEditor::_animation_remove() { | ||
if (updating) { | ||
return; | ||
|
@@ -1340,6 +1371,7 @@ void SpriteFramesEditor::edit(Ref<SpriteFrames> p_frames) { | |
_zoom_reset(); | ||
|
||
add_anim->set_disabled(read_only); | ||
duplicate_anim->set_disabled(read_only); | ||
delete_anim->set_disabled(read_only); | ||
anim_speed->set_editable(!read_only); | ||
anim_loop->set_disabled(read_only); | ||
|
@@ -1659,6 +1691,11 @@ SpriteFramesEditor::SpriteFramesEditor() { | |
hbc_animlist->add_child(add_anim); | ||
add_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_add)); | ||
|
||
duplicate_anim = memnew(Button); | ||
duplicate_anim->set_flat(true); | ||
hbc_animlist->add_child(duplicate_anim); | ||
duplicate_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_duplicate)); | ||
|
||
delete_anim = memnew(Button); | ||
delete_anim->set_flat(true); | ||
hbc_animlist->add_child(delete_anim); | ||
|
@@ -1711,6 +1748,8 @@ SpriteFramesEditor::SpriteFramesEditor() { | |
|
||
add_anim->set_shortcut_context(animations); | ||
add_anim->set_shortcut(ED_SHORTCUT("sprite_frames/new_animation", TTR("Add Animation"), KeyModifierMask::CMD_OR_CTRL | Key::N)); | ||
duplicate_anim->set_shortcut_context(animations); | ||
duplicate_anim->set_shortcut(ED_SHORTCUT("sprite_frames/duplicate_animation", TTR("Duplicate Animation"), KeyModifierMask::CMD_OR_CTRL | Key::D)); | ||
delete_anim->set_shortcut_context(animations); | ||
delete_anim->set_shortcut(ED_SHORTCUT("sprite_frames/delete_animation", TTR("Delete Animation"), Key::KEY_DELETE)); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current description is misleading. It sounds like the animation has to already exist, while it doesn't need to.