Skip to content

Commit c8cd638

Browse files
authored
Merge pull request #60226 from timothyqiu/anim-ref
[3.x] Add option to paste animation as duplicate
2 parents 79bcfb8 + 4e0547a commit c8cd638

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

editor/plugins/animation_player_editor_plugin.cpp

+36-10
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,7 @@ void AnimationPlayerEditor::_animation_name_edited() {
542542
String current = animation->get_item_text(animation->get_selected());
543543
Ref<Animation> anim = player->get_animation(current);
544544

545-
Ref<Animation> new_anim = Ref<Animation>(memnew(Animation));
546-
List<PropertyInfo> plist;
547-
anim->get_property_list(&plist);
548-
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
549-
if (E->get().usage & PROPERTY_USAGE_STORAGE) {
550-
new_anim->set(E->get().name, anim->get(E->get().name));
551-
}
552-
}
553-
new_anim->set_path("");
545+
Ref<Animation> new_anim = _animation_clone(anim);
554546
new_anim->set_name(new_name);
555547

556548
undo_redo->create_action(TTR("Duplicate Animation"));
@@ -1018,6 +1010,23 @@ void AnimationPlayerEditor::_animation_duplicate() {
10181010
name->grab_focus();
10191011
}
10201012

1013+
Ref<Animation> AnimationPlayerEditor::_animation_clone(const Ref<Animation> p_anim) {
1014+
Ref<Animation> new_anim = memnew(Animation);
1015+
1016+
List<PropertyInfo> plist;
1017+
p_anim->get_property_list(&plist);
1018+
for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
1019+
const PropertyInfo &property = E->get();
1020+
if (property.usage & PROPERTY_USAGE_STORAGE) {
1021+
new_anim->set(property.name, p_anim->get(property.name));
1022+
}
1023+
}
1024+
1025+
new_anim->set_path("");
1026+
1027+
return new_anim;
1028+
}
1029+
10211030
void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) {
10221031
if (updating || !player || player->is_playing()) {
10231032
return;
@@ -1114,37 +1123,47 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
11141123
case TOOL_NEW_ANIM: {
11151124
_animation_new();
11161125
} break;
1126+
11171127
case TOOL_LOAD_ANIM: {
11181128
_animation_load();
11191129
} break;
1130+
11201131
case TOOL_SAVE_ANIM: {
11211132
if (anim.is_valid()) {
11221133
_animation_save(anim);
11231134
}
11241135
} break;
1136+
11251137
case TOOL_SAVE_AS_ANIM: {
11261138
if (anim.is_valid()) {
11271139
_animation_save_as(anim);
11281140
}
11291141
} break;
1142+
11301143
case TOOL_DUPLICATE_ANIM: {
11311144
_animation_duplicate();
11321145
} break;
1146+
11331147
case TOOL_RENAME_ANIM: {
11341148
_animation_rename();
11351149
} break;
1150+
11361151
case TOOL_EDIT_TRANSITIONS: {
11371152
_animation_blend();
11381153
} break;
1154+
11391155
case TOOL_REMOVE_ANIM: {
11401156
_animation_remove();
11411157
} break;
1158+
11421159
case TOOL_COPY_ANIM: {
11431160
if (anim.is_valid()) {
11441161
EditorSettings::get_singleton()->set_resource_clipboard(anim);
11451162
}
11461163
} break;
1147-
case TOOL_PASTE_ANIM: {
1164+
1165+
case TOOL_PASTE_ANIM:
1166+
case TOOL_PASTE_ANIM_REF: {
11481167
Ref<Animation> anim2 = EditorSettings::get_singleton()->get_resource_clipboard();
11491168
if (!anim2.is_valid()) {
11501169
error_dialog->set_text(TTR("No animation resource on clipboard!"));
@@ -1164,6 +1183,11 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
11641183
name = base + " " + itos(idx);
11651184
}
11661185

1186+
if (p_option == TOOL_PASTE_ANIM) {
1187+
anim2 = _animation_clone(anim2);
1188+
anim2->set_name(name);
1189+
}
1190+
11671191
undo_redo->create_action(TTR("Paste Animation"));
11681192
undo_redo->add_do_method(player, "add_animation", name, anim2);
11691193
undo_redo->add_undo_method(player, "remove_animation", name);
@@ -1173,6 +1197,7 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
11731197

11741198
_select_anim_by_name(name);
11751199
} break;
1200+
11761201
case TOOL_EDIT_RESOURCE: {
11771202
if (anim.is_valid()) {
11781203
editor->edit_resource(anim);
@@ -1606,6 +1631,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay
16061631
tool_anim->get_popup()->add_separator();
16071632
tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/copy_animation", TTR("Copy")), TOOL_COPY_ANIM);
16081633
tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/paste_animation", TTR("Paste")), TOOL_PASTE_ANIM);
1634+
tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/paste_animation_as_reference", TTR("Paste As Reference")), TOOL_PASTE_ANIM_REF);
16091635
tool_anim->get_popup()->add_separator();
16101636
tool_anim->get_popup()->add_shortcut(ED_SHORTCUT("animation_player_editor/duplicate_animation", TTR("Duplicate...")), TOOL_DUPLICATE_ANIM);
16111637
tool_anim->get_popup()->add_separator();

editor/plugins/animation_player_editor_plugin.h

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class AnimationPlayerEditor : public VBoxContainer {
6060
TOOL_REMOVE_ANIM,
6161
TOOL_COPY_ANIM,
6262
TOOL_PASTE_ANIM,
63+
TOOL_PASTE_ANIM_REF,
6364
TOOL_EDIT_RESOURCE
6465
};
6566

@@ -184,6 +185,7 @@ class AnimationPlayerEditor : public VBoxContainer {
184185
void _animation_blend();
185186
void _animation_edit();
186187
void _animation_duplicate();
188+
Ref<Animation> _animation_clone(const Ref<Animation> p_anim);
187189
void _animation_resource_edit();
188190
void _scale_changed(const String &p_scale);
189191
void _dialog_action(String p_file);

0 commit comments

Comments
 (0)