void AnimationPlayerEditor::_animation_duplicate() { if (!animation->get_item_count()) return; String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); if (!anim.is_valid()) return; Ref<Animation> new_anim = memnew( Animation ); List<PropertyInfo> plist; anim->get_property_list(&plist); for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { if (E->get().usage&PROPERTY_USAGE_STORAGE) { new_anim->set(E->get().name, anim->get(E->get().name)); } } new_anim->set_path(""); String new_name = current; while(player->has_animation(new_name)) { new_name=new_name+" (copy)"; } undo_redo->create_action(TTR("Duplicate Animation")); undo_redo->add_do_method(player,"add_animation",new_name,new_anim); undo_redo->add_undo_method(player,"remove_animation",new_name); undo_redo->add_do_method(player,"animation_set_next",new_name,player->animation_get_next(current)); undo_redo->add_do_method(this,"_animation_player_changed",player); undo_redo->add_undo_method(this,"_animation_player_changed",player); undo_redo->commit_action(); for(int i=0;i<animation->get_item_count();i++) { if (animation->get_item_text(i)==new_name) { animation->select(i); _animation_selected(i); return; } } }
void AnimationPlayerEditor::_select_anim_by_name(const String& p_anim) { int idx=-1; for(int i=0;i<animation->get_item_count();i++) { if (animation->get_item_text(i)==p_anim) { idx=i; break; } } ERR_FAIL_COND(idx==-1); animation->select(idx); _animation_selected(idx); }
void AnimationPlayerEditor::_update_player() { if (!player) return; updating=true; List<StringName> animlist; player->get_animation_list(&animlist); animation->clear(); nodename->set_text(player->get_name()); stop->set_disabled(animlist.size()==0); play->set_disabled(animlist.size()==0); play_bw->set_disabled(animlist.size()==0); play_bw_from->set_disabled(animlist.size()==0); play_from->set_disabled(animlist.size()==0); autoplay->set_disabled(animlist.size()==0); duplicate_anim->set_disabled(animlist.size()==0); rename_anim->set_disabled(animlist.size()==0); blend_anim->set_disabled(animlist.size()==0); remove_anim->set_disabled(animlist.size()==0); resource_edit_anim->set_disabled(animlist.size()==0); save_anim->set_disabled(animlist.size() == 0); int active_idx=-1; for (List<StringName>::Element *E=animlist.front();E;E=E->next()) { if (player->get_autoplay()==E->get()) animation->add_icon_item(autoplay_icon,E->get()); else animation->add_item(E->get()); if (player->get_current_animation()==E->get()) active_idx=animation->get_item_count()-1; } updating=false; if (active_idx!=-1) { animation->select(active_idx); autoplay->set_pressed(animation->get_item_text(active_idx)==player->get_autoplay()); _animation_selected(active_idx); } else if (animation->get_item_count()>0){ animation->select(0); autoplay->set_pressed(animation->get_item_text(0)==player->get_autoplay()); _animation_selected(0); } //pause->set_pressed(player->is_paused()); if (edit_anim->is_pressed()) { if (animation->get_item_count()) { String current = animation->get_item_text(animation->get_selected()); Ref<Animation> anim = player->get_animation(current); editor->get_animation_editor()->set_animation(anim); Node *root = player->get_node(player->get_root()); if (root) { editor->get_animation_editor()->set_root(root); } } } _update_animation(); }