From 22d52276637164f8929e10b57a3d6cf8a79db69e Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 29 Jun 2016 17:51:10 -0300 Subject: AnimatedSprite and AnimatedSprite 3D adapt the name of the current animation if the one in SpriteFrames is removed/added or renamed. Closes #5152 --- .../editor/plugins/sprite_frames_editor_plugin.cpp | 63 +++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/editor/plugins/sprite_frames_editor_plugin.cpp b/tools/editor/plugins/sprite_frames_editor_plugin.cpp index 4f59287994..e29a0c8d52 100644 --- a/tools/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/tools/editor/plugins/sprite_frames_editor_plugin.cpp @@ -31,7 +31,7 @@ #include "io/resource_loader.h" #include "globals.h" #include "tools/editor/editor_settings.h" - +#include "scene/3d/sprite_3d.h" @@ -355,6 +355,35 @@ void SpriteFramesEditor::_animation_select() { } + +static void _find_anim_sprites(Node* p_node,List *r_nodes,Ref p_sfames) { + + Node *edited = EditorNode::get_singleton()->get_edited_scene(); + if (!edited) + return; + if (p_node!=edited && p_node->get_owner()!=edited) + return; + + { + AnimatedSprite *as = p_node->cast_to(); + if (as && as->get_sprite_frames()==p_sfames) { + r_nodes->push_back(p_node); + } + } + + { + AnimatedSprite3D *as = p_node->cast_to(); + if (as && as->get_sprite_frames()==p_sfames) { + r_nodes->push_back(p_node); + } + } + + for(int i=0;iget_child_count();i++) { + _find_anim_sprites(p_node->get_child(i),r_nodes,p_sfames); + } + +} + void SpriteFramesEditor::_animation_name_edited(){ if (updating) @@ -381,9 +410,24 @@ void SpriteFramesEditor::_animation_name_edited(){ name=new_name+" "+itos(counter); } + List nodes; + _find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(),&nodes,Ref(frames)); + undo_redo->create_action(TTR("Rename Animation")); undo_redo->add_do_method(frames,"rename_animation",edited_anim,name); undo_redo->add_undo_method(frames,"rename_animation",name,edited_anim); + + for(List::Element *E=nodes.front();E;E=E->next()) { + + String current = E->get()->call("get_animation"); + if (current!=edited_anim) + continue; + + undo_redo->add_do_method(E->get(),"set_animation",name); + undo_redo->add_undo_method(E->get(),"set_animation",edited_anim); + + } + undo_redo->add_do_method(this,"_update_library"); undo_redo->add_undo_method(this,"_update_library"); @@ -406,12 +450,28 @@ void SpriteFramesEditor::_animation_add(){ name=new_name+" "+itos(counter); } + List nodes; + _find_anim_sprites(EditorNode::get_singleton()->get_edited_scene(),&nodes,Ref(frames)); + + undo_redo->create_action(TTR("Add Animation")); undo_redo->add_do_method(frames,"add_animation",name); undo_redo->add_undo_method(frames,"remove_animation",name); undo_redo->add_do_method(this,"_update_library"); undo_redo->add_undo_method(this,"_update_library"); + + for(List::Element *E=nodes.front();E;E=E->next()) { + + String current = E->get()->call("get_animation"); + if (frames->has_animation(current)) + continue; + + undo_redo->add_do_method(E->get(),"set_animation",name); + undo_redo->add_undo_method(E->get(),"set_animation",current); + + } + edited_anim=new_name; undo_redo->commit_action(); @@ -426,6 +486,7 @@ void SpriteFramesEditor::_animation_remove(){ if (!frames->has_animation(edited_anim)) return; + undo_redo->create_action(TTR("Remove Animation")); undo_redo->add_do_method(frames,"remove_animation",edited_anim); undo_redo->add_undo_method(frames,"add_animation",edited_anim); -- cgit v1.2.3