Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid popping up dialogs excessively in the Animation editor #84208

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 29 additions & 46 deletions editor/plugins/animation_player_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,26 +653,23 @@ void AnimationPlayerEditor::_blend_editor_next_changed(const int p_idx) {
undo_redo->commit_action();
}

void AnimationPlayerEditor::_animation_blend() {
if (updating_blends) {
void AnimationPlayerEditor::_edit_animation_blend() {
if (updating_blends || !animation->has_selectable_items()) {
return;
}

blend_editor.tree->clear();
blend_editor.dialog->popup_centered(Size2(400, 400) * EDSCALE);
_update_animation_blend();
}

if (!animation->has_selectable_items()) {
void AnimationPlayerEditor::_update_animation_blend() {
if (updating_blends || !animation->has_selectable_items()) {
return;
}

String current = animation->get_item_text(animation->get_selected());

blend_editor.dialog->popup_centered(Size2(400, 400) * EDSCALE);
blend_editor.tree->clear();

blend_editor.tree->set_hide_root(true);
blend_editor.tree->set_column_expand_ratio(0, 10);
blend_editor.tree->set_column_clip_content(0, true);
blend_editor.tree->set_column_expand_ratio(1, 3);
blend_editor.tree->set_column_clip_content(1, true);
String current = animation->get_item_text(animation->get_selected());

List<StringName> anims;
player->get_animation_list(&anims);
Expand Down Expand Up @@ -711,21 +708,17 @@ void AnimationPlayerEditor::_animation_blend() {
}

void AnimationPlayerEditor::_blend_edited() {
if (updating_blends) {
return;
}

if (!animation->has_selectable_items()) {
if (updating_blends || !animation->has_selectable_items()) {
return;
}

String current = animation->get_item_text(animation->get_selected());

TreeItem *selected = blend_editor.tree->get_edited();
if (!selected) {
return;
}

String current = animation->get_item_text(animation->get_selected());

updating_blends = true;
String to = selected->get_text(0);
float blend_time = selected->get_range(1);
Expand Down Expand Up @@ -1277,9 +1270,11 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set, bool

void AnimationPlayerEditor::_animation_player_changed(Object *p_pl) {
_update_player();

if (blend_editor.dialog->is_visible()) {
_animation_blend(); // Update.
_update_animation_blend(); // Update.
}

if (library_editor->is_visible()) {
library_editor->update_tree();
}
Expand Down Expand Up @@ -1366,7 +1361,7 @@ void AnimationPlayerEditor::_animation_tool_menu(int p_option) {
_animation_rename();
} break;
case TOOL_EDIT_TRANSITIONS: {
_animation_blend();
_edit_animation_blend();
} break;
case TOOL_REMOVE_ANIM: {
_animation_remove();
Expand Down Expand Up @@ -1802,17 +1797,8 @@ bool AnimationPlayerEditor::_validate_tracks(const Ref<Animation> p_anim) {
}

void AnimationPlayerEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_animation_new"), &AnimationPlayerEditor::_animation_new);
ClassDB::bind_method(D_METHOD("_animation_rename"), &AnimationPlayerEditor::_animation_rename);
ClassDB::bind_method(D_METHOD("_animation_remove"), &AnimationPlayerEditor::_animation_remove);
ClassDB::bind_method(D_METHOD("_animation_blend"), &AnimationPlayerEditor::_animation_blend);
ClassDB::bind_method(D_METHOD("_animation_edit"), &AnimationPlayerEditor::_animation_edit);
ClassDB::bind_method(D_METHOD("_animation_resource_edit"), &AnimationPlayerEditor::_animation_resource_edit);
// Needed for UndoRedo.
ClassDB::bind_method(D_METHOD("_animation_player_changed"), &AnimationPlayerEditor::_animation_player_changed);
ClassDB::bind_method(D_METHOD("_animation_libraries_updated"), &AnimationPlayerEditor::_animation_libraries_updated);
ClassDB::bind_method(D_METHOD("_list_changed"), &AnimationPlayerEditor::_list_changed);
ClassDB::bind_method(D_METHOD("_animation_duplicate"), &AnimationPlayerEditor::_animation_duplicate);

ClassDB::bind_method(D_METHOD("_start_onion_skinning"), &AnimationPlayerEditor::_start_onion_skinning);
ClassDB::bind_method(D_METHOD("_stop_onion_skinning"), &AnimationPlayerEditor::_stop_onion_skinning);

Expand All @@ -1833,11 +1819,8 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plug
plugin = p_plugin;
singleton = this;

updating = false;

set_focus_mode(FOCUS_ALL);

player = nullptr;
set_process_shortcut_input(true);

HBoxContainer *hb = memnew(HBoxContainer);
add_child(hb);
Expand Down Expand Up @@ -1921,7 +1904,6 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plug
hb->add_child(memnew(VSeparator));

track_editor = memnew(AnimationTrackEditor);

hb->add_child(track_editor->get_edit_menu());

hb->add_child(memnew(VSeparator));
Expand Down Expand Up @@ -1992,21 +1974,27 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plug
name_dialog->connect(SNAME("confirmed"), callable_mp(this, &AnimationPlayerEditor::_animation_name_edited));

blend_editor.dialog = memnew(AcceptDialog);
add_child(blend_editor.dialog);
blend_editor.dialog->set_title(TTR("Cross-Animation Blend Times"));
blend_editor.dialog->set_ok_button_text(TTR("Close"));
blend_editor.dialog->set_hide_on_ok(true);
add_child(blend_editor.dialog);

VBoxContainer *blend_vb = memnew(VBoxContainer);
blend_editor.dialog->add_child(blend_vb);

blend_editor.tree = memnew(Tree);
blend_editor.tree->set_hide_root(true);
blend_editor.tree->set_columns(2);
blend_editor.tree->set_column_expand_ratio(0, 10);
blend_editor.tree->set_column_clip_content(0, true);
blend_editor.tree->set_column_expand_ratio(1, 3);
blend_editor.tree->set_column_clip_content(1, true);
blend_vb->add_margin_child(TTR("Blend Times:"), blend_editor.tree, true);
blend_editor.tree->connect(SNAME("item_edited"), callable_mp(this, &AnimationPlayerEditor::_blend_edited));

blend_editor.next = memnew(OptionButton);
blend_editor.next->set_auto_translate(false);
blend_vb->add_margin_child(TTR("Next (Auto Queue):"), blend_editor.next);
blend_editor.dialog->set_title(TTR("Cross-Animation Blend Times"));
updating_blends = false;

blend_editor.tree->connect(SNAME("item_edited"), callable_mp(this, &AnimationPlayerEditor::_blend_edited));

autoplay->connect(SNAME("pressed"), callable_mp(this, &AnimationPlayerEditor::_autoplay_pressed));
autoplay->set_toggle_mode(true);
Expand All @@ -2021,11 +2009,6 @@ AnimationPlayerEditor::AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plug
frame->connect(SNAME("value_changed"), callable_mp(this, &AnimationPlayerEditor::_seek_value_changed).bind(true, false));
scale->connect(SNAME("text_submitted"), callable_mp(this, &AnimationPlayerEditor::_scale_changed));

last_active = false;
timeline_position = 0;

set_process_shortcut_input(true);

add_child(track_editor);
track_editor->set_v_size_flags(SIZE_EXPAND_FILL);
track_editor->connect(SNAME("timeline_changed"), callable_mp(this, &AnimationPlayerEditor::_animation_key_editor_seek));
Expand Down
13 changes: 8 additions & 5 deletions editor/plugins/animation_player_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ class AnimationPlayerEditor : public VBoxContainer {
Ref<Texture2D> autoplay_icon;
Ref<Texture2D> reset_icon;
Ref<ImageTexture> autoplay_reset_icon;
bool last_active;
float timeline_position;

bool last_active = false;
float timeline_position = 0;

EditorFileDialog *file = nullptr;
ConfirmationDialog *delete_dialog = nullptr;
Expand All @@ -130,8 +131,8 @@ class AnimationPlayerEditor : public VBoxContainer {
ConfirmationDialog *error_dialog = nullptr;
int name_dialog_op = TOOL_NEW_ANIM;

bool updating;
bool updating_blends;
bool updating = false;
bool updating_blends = false;

AnimationTrackEditor *track_editor = nullptr;
static AnimationPlayerEditor *singleton;
Expand Down Expand Up @@ -190,7 +191,6 @@ class AnimationPlayerEditor : public VBoxContainer {

void _animation_remove();
void _animation_remove_confirmed();
void _animation_blend();
void _animation_edit();
void _animation_duplicate();
Ref<Animation> _animation_clone(const Ref<Animation> p_anim);
Expand All @@ -199,6 +199,9 @@ class AnimationPlayerEditor : public VBoxContainer {
void _seek_value_changed(float p_value, bool p_set = false, bool p_timeline_only = false);
void _blend_editor_next_changed(const int p_idx);

void _edit_animation_blend();
void _update_animation_blend();

void _list_changed();
void _current_animation_changed(const String &p_name);
void _update_animation();
Expand Down
Loading