@@ -542,15 +542,7 @@ void AnimationPlayerEditor::_animation_name_edited() {
542
542
String current = animation->get_item_text (animation->get_selected ());
543
543
Ref<Animation> anim = player->get_animation (current);
544
544
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);
554
546
new_anim->set_name (new_name);
555
547
556
548
undo_redo->create_action (TTR (" Duplicate Animation" ));
@@ -1018,6 +1010,23 @@ void AnimationPlayerEditor::_animation_duplicate() {
1018
1010
name->grab_focus ();
1019
1011
}
1020
1012
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
+
1021
1030
void AnimationPlayerEditor::_seek_value_changed (float p_value, bool p_set) {
1022
1031
if (updating || !player || player->is_playing ()) {
1023
1032
return ;
@@ -1114,37 +1123,47 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
1114
1123
case TOOL_NEW_ANIM: {
1115
1124
_animation_new ();
1116
1125
} break ;
1126
+
1117
1127
case TOOL_LOAD_ANIM: {
1118
1128
_animation_load ();
1119
1129
} break ;
1130
+
1120
1131
case TOOL_SAVE_ANIM: {
1121
1132
if (anim.is_valid ()) {
1122
1133
_animation_save (anim);
1123
1134
}
1124
1135
} break ;
1136
+
1125
1137
case TOOL_SAVE_AS_ANIM: {
1126
1138
if (anim.is_valid ()) {
1127
1139
_animation_save_as (anim);
1128
1140
}
1129
1141
} break ;
1142
+
1130
1143
case TOOL_DUPLICATE_ANIM: {
1131
1144
_animation_duplicate ();
1132
1145
} break ;
1146
+
1133
1147
case TOOL_RENAME_ANIM: {
1134
1148
_animation_rename ();
1135
1149
} break ;
1150
+
1136
1151
case TOOL_EDIT_TRANSITIONS: {
1137
1152
_animation_blend ();
1138
1153
} break ;
1154
+
1139
1155
case TOOL_REMOVE_ANIM: {
1140
1156
_animation_remove ();
1141
1157
} break ;
1158
+
1142
1159
case TOOL_COPY_ANIM: {
1143
1160
if (anim.is_valid ()) {
1144
1161
EditorSettings::get_singleton ()->set_resource_clipboard (anim);
1145
1162
}
1146
1163
} break ;
1147
- case TOOL_PASTE_ANIM: {
1164
+
1165
+ case TOOL_PASTE_ANIM:
1166
+ case TOOL_PASTE_ANIM_REF: {
1148
1167
Ref<Animation> anim2 = EditorSettings::get_singleton ()->get_resource_clipboard ();
1149
1168
if (!anim2.is_valid ()) {
1150
1169
error_dialog->set_text (TTR (" No animation resource on clipboard!" ));
@@ -1164,6 +1183,11 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
1164
1183
name = base + " " + itos (idx);
1165
1184
}
1166
1185
1186
+ if (p_option == TOOL_PASTE_ANIM) {
1187
+ anim2 = _animation_clone (anim2);
1188
+ anim2->set_name (name);
1189
+ }
1190
+
1167
1191
undo_redo->create_action (TTR (" Paste Animation" ));
1168
1192
undo_redo->add_do_method (player, " add_animation" , name, anim2);
1169
1193
undo_redo->add_undo_method (player, " remove_animation" , name);
@@ -1173,6 +1197,7 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
1173
1197
1174
1198
_select_anim_by_name (name);
1175
1199
} break ;
1200
+
1176
1201
case TOOL_EDIT_RESOURCE: {
1177
1202
if (anim.is_valid ()) {
1178
1203
editor->edit_resource (anim);
@@ -1606,6 +1631,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay
1606
1631
tool_anim->get_popup ()->add_separator ();
1607
1632
tool_anim->get_popup ()->add_shortcut (ED_SHORTCUT (" animation_player_editor/copy_animation" , TTR (" Copy" )), TOOL_COPY_ANIM);
1608
1633
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);
1609
1635
tool_anim->get_popup ()->add_separator ();
1610
1636
tool_anim->get_popup ()->add_shortcut (ED_SHORTCUT (" animation_player_editor/duplicate_animation" , TTR (" Duplicate..." )), TOOL_DUPLICATE_ANIM);
1611
1637
tool_anim->get_popup ()->add_separator ();
0 commit comments