From 5d98718c28cfec6e7174f640c191fb114c2fa065 Mon Sep 17 00:00:00 2001 From: Paulb23 Date: Sat, 7 May 2016 17:27:52 +0100 Subject: [PATCH] Fixed animation player auto-queue duplication and undo/redo (cherry picked from commit 488495852bcee4e92038657abd166b83f78f2a2a) --- scene/animation/animation_player.cpp | 3 ++ .../animation_player_editor_plugin.cpp | 32 ++++++++++++++++--- .../plugins/animation_player_editor_plugin.h | 4 +-- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 32958112e58..3cd29695d5c 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -1297,6 +1297,9 @@ void AnimationPlayer::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_animation:Animation","name"),&AnimationPlayer::get_animation); ObjectTypeDB::bind_method(_MD("get_animation_list"),&AnimationPlayer::_get_animation_list); + ObjectTypeDB::bind_method(_MD("animation_set_next", "anim_from", "anim_to"), &AnimationPlayer::animation_set_next); + ObjectTypeDB::bind_method(_MD("animation_get_next", "anim_from"), &AnimationPlayer::animation_get_next); + ObjectTypeDB::bind_method(_MD("set_blend_time","anim_from","anim_to","sec"),&AnimationPlayer::set_blend_time); ObjectTypeDB::bind_method(_MD("get_blend_time","anim_from","anim_to"),&AnimationPlayer::get_blend_time); diff --git a/tools/editor/plugins/animation_player_editor_plugin.cpp b/tools/editor/plugins/animation_player_editor_plugin.cpp index da7c083c5a0..a3057b34300 100644 --- a/tools/editor/plugins/animation_player_editor_plugin.cpp +++ b/tools/editor/plugins/animation_player_editor_plugin.cpp @@ -116,7 +116,7 @@ void AnimationPlayerEditor::_notification(int p_what) { tool_anim->set_icon(get_icon("Tools","EditorIcons")); tool_anim->get_popup()->connect("item_pressed",this,"_animation_tool_menu"); - blend_editor.next->connect("text_changed",this,"_blend_editor_next_changed"); + blend_editor.next->connect("item_selected", this, "_blend_editor_next_changed"); nodename->set_icon(get_icon("AnimationPlayer","EditorIcons")); @@ -536,14 +536,19 @@ void AnimationPlayerEditor::_animation_name_edited() { } -void AnimationPlayerEditor::_blend_editor_next_changed(const String& p_string) { +void AnimationPlayerEditor::_blend_editor_next_changed(const int p_idx) { if (animation->get_item_count()==0) return; String current = animation->get_item_text(animation->get_selected()); - player->animation_set_next(current,p_string); + undo_redo->create_action("Blend Next Changed"); + undo_redo->add_do_method(player,"animation_set_next",current,blend_editor.next->get_item_text(p_idx)); + undo_redo->add_undo_method(player,"animation_set_next",current,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(); } void AnimationPlayerEditor::_animation_blend() { @@ -569,6 +574,11 @@ void AnimationPlayerEditor::_animation_blend() { TreeItem *root = blend_editor.tree->create_item(); updating_blends=true; + int i = 0; + bool anim_found = false; + blend_editor.next->clear(); + blend_editor.next->add_item("", i); + for(List::Element *E=anims.front();E;E=E->next()) { String to=E->get(); @@ -579,9 +589,20 @@ void AnimationPlayerEditor::_animation_blend() { blend->set_cell_mode(1,TreeItem::CELL_MODE_RANGE); blend->set_range_config(1,0,3600,0.001); blend->set_range(1,player->get_blend_time(current,to)); + + i++; + blend_editor.next->add_item(to, i); + if (to == player->animation_get_next(current)) { + blend_editor.next->select(i); + anim_found = true; + } } - blend_editor.next->set_text( player->animation_get_next(current) ); + // make sure we reset it else it becomes out of sync and could contain a deleted animation + if (!anim_found) { + blend_editor.next->select(0); + player->animation_set_next(current, blend_editor.next->get_item_text(0)); + } updating_blends=false; } @@ -913,6 +934,7 @@ void AnimationPlayerEditor::_animation_duplicate() { undo_redo->create_action("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(); @@ -1438,7 +1460,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor) { blend_editor.tree = memnew( Tree ); blend_editor.tree->set_columns(2); blend_vb->add_margin_child("Blend Times: ",blend_editor.tree,true); - blend_editor.next = memnew( LineEdit ); + blend_editor.next = memnew( OptionButton ); blend_vb->add_margin_child("Next (Auto Queue):",blend_editor.next); blend_editor.dialog->set_title("Cross-Animation Blend Times"); updating_blends=false; diff --git a/tools/editor/plugins/animation_player_editor_plugin.h b/tools/editor/plugins/animation_player_editor_plugin.h index 0ad849c2f92..3f3cda25b26 100644 --- a/tools/editor/plugins/animation_player_editor_plugin.h +++ b/tools/editor/plugins/animation_player_editor_plugin.h @@ -103,7 +103,7 @@ class AnimationPlayerEditor : public VBoxContainer { AcceptDialog * dialog; Tree *tree; - LineEdit *next; + OptionButton *next; } blend_editor; @@ -146,7 +146,7 @@ class AnimationPlayerEditor : public VBoxContainer { void _dialog_action(String p_file); void _seek_frame_changed(const String& p_frame); void _seek_value_changed(float p_value); - void _blend_editor_next_changed(const String& p_string); + void _blend_editor_next_changed(const int p_idx); void _list_changed(); void _update_animation();