Skip to content
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

[AnimatedSprite] Implement duplicate animations #57949

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* 3942
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has to be removed :)

39 changes: 38 additions & 1 deletion editor/plugins/sprite_frames_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,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")));
new_anim->set_icon(get_theme_icon(SNAME("New"), SNAME("EditorIcons")));
duplicate_anim->set_icon(get_theme_icon(SNAME("Duplicate"), SNAME("EditorIcons")));
remove_anim->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons")));
split_sheet_zoom_out->set_icon(get_theme_icon(SNAME("ZoomLess"), SNAME("EditorIcons")));
split_sheet_zoom_reset->set_icon(get_theme_icon(SNAME("ZoomReset"), SNAME("EditorIcons")));
Expand Down Expand Up @@ -662,13 +663,43 @@ void SpriteFramesEditor::_animation_add() {
undo_redo->add_do_method(E, "set_animation", name);
undo_redo->add_undo_method(E, "set_animation", current);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These trailing spaces have to be removed.

edited_anim = name;

undo_redo->commit_action();
animations->grab_focus();
}

void SpriteFramesEditor::_animation_duplicate() {
if ( !frames->has_animation(edited_anim) ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( !frames->has_animation(edited_anim) ) {
if (!frames->has_animation(edited_anim)) {

I wonder why CI did not detect this :(

print_line("Current animation has no frames");
return;
}

StringName anim_to_duplicate = edited_anim;
int duplicate_frame_count = frames->get_frame_count(anim_to_duplicate);
String new_name = String(edited_anim); //Get the animation name to duplicate, cant use the anim_to_duplicate since its a StringName and cannot be modified
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For comments, it's prefered to start with // (with an empty space following //) and end with a period. Serveral other comments need to be fixed too.


_animation_add();

for (int i = 0; i < duplicate_frame_count; i++) {
frames->add_frame(edited_anim, frames->get_frame(anim_to_duplicate, i));
}

//Rename the duplicated animation
int counter = 1;
while(frames->has_animation(new_name + "_" + itos(counter))) {
counter++;
}
new_name = new_name + "_" + itos(counter);
frames->rename_animation(edited_anim,new_name);
Comment on lines +690 to +695
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is inconsistent with how _animation_add() handles name conflicts. It uses "Existing Name N" while this uses "Existing Name_N". I think they should be unified.

Also, there should be a space between while and (. More style issues can be found by running clang-format, see Code Style Guide.


//Update the UI
edited_anim = new_name;
_update_library();
animations->grab_focus();
}

void SpriteFramesEditor::_animation_remove() {
if (updating) {
return;
Expand Down Expand Up @@ -1036,6 +1067,12 @@ SpriteFramesEditor::SpriteFramesEditor() {
hbc_animlist->add_child(new_anim);
new_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_add));

duplicate_anim = memnew(Button);
duplicate_anim->set_flat(true);
duplicate_anim->set_tooltip(TTR("Duplicate Animation"));
hbc_animlist->add_child(duplicate_anim);
duplicate_anim->connect("pressed", callable_mp(this, &SpriteFramesEditor::_animation_duplicate));

remove_anim = memnew(Button);
remove_anim->set_flat(true);
remove_anim->set_tooltip(TTR("Remove Animation"));
Expand Down
2 changes: 2 additions & 0 deletions editor/plugins/sprite_frames_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class SpriteFramesEditor : public HSplitContainer {

Button *new_anim;
Button *remove_anim;
Button *duplicate_anim;

Tree *animations;
SpinBox *anim_speed;
Expand Down Expand Up @@ -113,6 +114,7 @@ class SpriteFramesEditor : public HSplitContainer {
void _animation_select();
void _animation_name_edited();
void _animation_add();
void _animation_duplicate();
void _animation_remove();
void _animation_remove_confirmed();
void _animation_loop_changed();
Expand Down