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

Animation Library Editor enable multiselect and tree fold arrow #84088

Closed
Closed
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
171 changes: 91 additions & 80 deletions editor/plugins/animation_library_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void AnimationLibraryEditor::_load_library() {
file_dialog->add_filter("*." + K);
}

file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES);
file_dialog->set_current_file("");
file_dialog->popup_centered_ratio();

Expand Down Expand Up @@ -300,83 +300,6 @@ void AnimationLibraryEditor::_file_popup_selected(int p_id) {
}
void AnimationLibraryEditor::_load_file(String p_path) {
switch (file_dialog_action) {
case FILE_DIALOG_ACTION_OPEN_LIBRARY: {
Ref<AnimationLibrary> al = ResourceLoader::load(p_path);
if (al.is_null()) {
error_dialog->set_text(TTR("Invalid AnimationLibrary file."));
error_dialog->popup_centered();
return;
}

TypedArray<StringName> libs = mixer->call("get_animation_library_list");
for (int i = 0; i < libs.size(); i++) {
const StringName K = libs[i];
Ref<AnimationLibrary> al2 = mixer->call("get_animation_library", K);
if (al2 == al) {
error_dialog->set_text(TTR("This library is already added to the mixer."));
error_dialog->popup_centered();

return;
}
}

String name = AnimationLibrary::validate_library_name(p_path.get_file().get_basename());

int attempt = 1;

while (bool(mixer->call("has_animation_library", name))) {
attempt++;
name = p_path.get_file().get_basename() + " " + itos(attempt);
}

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();

undo_redo->create_action(vformat(TTR("Add Animation Library: %s"), name));
undo_redo->add_do_method(mixer, "add_animation_library", name, al);
undo_redo->add_undo_method(mixer, "remove_animation_library", name);
undo_redo->add_do_method(this, "_update_editor", mixer);
undo_redo->add_undo_method(this, "_update_editor", mixer);
undo_redo->commit_action();
} break;
case FILE_DIALOG_ACTION_OPEN_ANIMATION: {
Ref<Animation> anim = ResourceLoader::load(p_path);
if (anim.is_null()) {
error_dialog->set_text(TTR("Invalid Animation file."));
error_dialog->popup_centered();
return;
}

Ref<AnimationLibrary> al = mixer->call("get_animation_library", adding_animation_to_library);
List<StringName> anims;
al->get_animation_list(&anims);
for (const StringName &K : anims) {
Ref<Animation> a2 = al->get_animation(K);
if (a2 == anim) {
error_dialog->set_text(TTR("This animation is already added to the library."));
error_dialog->popup_centered();
return;
}
}

String name = p_path.get_file().get_basename();

int attempt = 1;

while (al->has_animation(name)) {
attempt++;
name = p_path.get_file().get_basename() + " " + itos(attempt);
}

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();

undo_redo->create_action(vformat(TTR("Load Animation into Library: %s"), name));
undo_redo->add_do_method(al.ptr(), "add_animation", name, anim);
undo_redo->add_undo_method(al.ptr(), "remove_animation", name);
undo_redo->add_do_method(this, "_update_editor", mixer);
undo_redo->add_undo_method(this, "_update_editor", mixer);
undo_redo->commit_action();
} break;

case FILE_DIALOG_ACTION_SAVE_LIBRARY: {
Ref<AnimationLibrary> al = mixer->call("get_animation_library", file_dialog_library);
String prev_path = al->get_path();
Expand Down Expand Up @@ -414,6 +337,93 @@ void AnimationLibraryEditor::_load_file(String p_path) {
undo_redo->commit_action();
}
} break;
default:
break;
}
}

void AnimationLibraryEditor::_load_files(const Vector<String> &p_paths) {
for (const String &p_path : p_paths) {
switch (file_dialog_action) {
case FILE_DIALOG_ACTION_OPEN_LIBRARY: {
Ref<AnimationLibrary> al = ResourceLoader::load(p_path);
if (al.is_null()) {
error_dialog->set_text(TTR("Invalid AnimationLibrary file."));
error_dialog->popup_centered();
return;
}

TypedArray<StringName> libs = mixer->call("get_animation_library_list");
for (int i = 0; i < libs.size(); i++) {
const StringName K = libs[i];
Ref<AnimationLibrary> al2 = mixer->call("get_animation_library", K);
if (al2 == al) {
error_dialog->set_text(TTR("This library is already added to the mixer."));
error_dialog->popup_centered();

return;
}
}

String name = AnimationLibrary::validate_library_name(p_path.get_file().get_basename());

int attempt = 1;

while (bool(mixer->call("has_animation_library", name))) {
attempt++;
name = p_path.get_file().get_basename() + " " + itos(attempt);
}

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();

undo_redo->create_action(vformat(TTR("Add Animation Library: %s"), name));
undo_redo->add_do_method(mixer, "add_animation_library", name, al);
undo_redo->add_undo_method(mixer, "remove_animation_library", name);
undo_redo->add_do_method(this, "_update_editor", mixer);
undo_redo->add_undo_method(this, "_update_editor", mixer);
undo_redo->commit_action();
} break;
case FILE_DIALOG_ACTION_OPEN_ANIMATION: {
Ref<Animation> anim = ResourceLoader::load(p_path);
if (anim.is_null()) {
error_dialog->set_text(TTR("Invalid Animation file."));
error_dialog->popup_centered();
return;
}

Ref<AnimationLibrary> al = mixer->call("get_animation_library", adding_animation_to_library);
List<StringName> anims;
al->get_animation_list(&anims);
for (const StringName &K : anims) {
Ref<Animation> a2 = al->get_animation(K);
if (a2 == anim) {
error_dialog->set_text(TTR("This animation is already added to the library."));
error_dialog->popup_centered();
return;
}
}

String name = p_path.get_file().get_basename();

int attempt = 1;

while (al->has_animation(name)) {
attempt++;
name = p_path.get_file().get_basename() + " " + itos(attempt);
}

EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();

undo_redo->create_action(vformat(TTR("Load Animation into Library: %s"), name));
undo_redo->add_do_method(al.ptr(), "add_animation", name, anim);
undo_redo->add_undo_method(al.ptr(), "remove_animation", name);
undo_redo->add_do_method(this, "_update_editor", mixer);
undo_redo->add_undo_method(this, "_update_editor", mixer);
undo_redo->commit_action();
} break;
default:
break;
}
}
}

Expand Down Expand Up @@ -505,7 +515,7 @@ void AnimationLibraryEditor::_button_pressed(TreeItem *p_item, int p_column, int
}

file_dialog->set_title(TTR("Load Animation"));
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
file_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES);
file_dialog->set_current_file("");
file_dialog->popup_centered_ratio();

Expand Down Expand Up @@ -742,6 +752,7 @@ AnimationLibraryEditor::AnimationLibraryEditor() {
file_dialog = memnew(EditorFileDialog);
add_child(file_dialog);
file_dialog->connect("file_selected", callable_mp(this, &AnimationLibraryEditor::_load_file));
file_dialog->connect("files_selected", callable_mp(this, &AnimationLibraryEditor::_load_files));

add_library_dialog = memnew(ConfirmationDialog);
VBoxContainer *dialog_vb = memnew(VBoxContainer);
Expand Down Expand Up @@ -777,7 +788,7 @@ AnimationLibraryEditor::AnimationLibraryEditor() {
tree->set_column_custom_minimum_width(1, EDSCALE * 250);
tree->set_column_expand(1, false);
tree->set_hide_root(true);
tree->set_hide_folding(true);
tree->set_hide_folding(false);
tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);

tree->connect("item_edited", callable_mp(this, &AnimationLibraryEditor::_item_renamed));
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/animation_library_editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class AnimationLibraryEditor : public AcceptDialog {
void _add_library_confirm();
void _load_library();
void _load_file(String p_path);
void _load_files(const Vector<String> &p_paths);

void _item_renamed();
void _button_pressed(TreeItem *p_item, int p_column, int p_id, MouseButton p_button);
Expand Down