1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-08 12:40:44 +00:00

Refactor to use internal foreign resource checking function.

Create unique duplicates of embedded animations when calling
'Make Unique' on AnimationLibrary.
This commit is contained in:
SaracenOne
2022-09-07 10:17:22 +01:00
parent b8977ca333
commit dc96b2834e
2 changed files with 14 additions and 83 deletions

View File

@@ -198,11 +198,17 @@ void AnimationLibraryEditor::_file_popup_selected(int p_id) {
} break; } break;
case FILE_MENU_MAKE_LIBRARY_UNIQUE: { case FILE_MENU_MAKE_LIBRARY_UNIQUE: {
StringName lib_name = file_dialog_library; StringName lib_name = file_dialog_library;
List<StringName> animation_list;
Ref<AnimationLibrary> ald = al->duplicate(); Ref<AnimationLibrary> ald = memnew(AnimationLibrary);
al->get_animation_list(&animation_list);
// TODO: should probably make all foreign animations assigned to this library for (const StringName &animation_name : animation_list) {
// unique too. Ref<Animation> animation = al->get_animation(animation_name);
if (EditorNode::get_singleton()->is_resource_read_only(animation)) {
animation = animation->duplicate();
}
ald->add_animation(animation_name, animation);
}
Ref<EditorUndoRedoManager> undo_redo = EditorNode::get_singleton()->get_undo_redo(); Ref<EditorUndoRedoManager> undo_redo = EditorNode::get_singleton()->get_undo_redo();
undo_redo->create_action(vformat(TTR("Make Animation Library Unique: %s"), lib_name)); undo_redo->create_action(vformat(TTR("Make Animation Library Unique: %s"), lib_name));

View File

@@ -283,26 +283,7 @@ void AnimationPlayerEditor::_animation_selected(int p_which) {
Ref<Animation> anim = player->get_animation(current); Ref<Animation> anim = player->get_animation(current);
{ {
bool animation_library_is_foreign = false; bool animation_library_is_foreign = EditorNode::get_singleton()->is_resource_read_only(anim);
if (!anim->get_path().is_resource_file()) {
int srpos = anim->get_path().find("::");
if (srpos != -1) {
String base = anim->get_path().substr(0, srpos);
if (ResourceLoader::get_resource_type(base) == "PackedScene") {
if (!get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->get_scene_file_path() != base) {
animation_library_is_foreign = true;
}
} else {
if (FileAccess::exists(base + ".import")) {
animation_library_is_foreign = true;
}
}
}
} else {
if (FileAccess::exists(anim->get_path() + ".import")) {
animation_library_is_foreign = true;
}
}
track_editor->set_animation(anim, animation_library_is_foreign); track_editor->set_animation(anim, animation_library_is_foreign);
Node *root = player->get_node(player->get_root()); Node *root = player->get_node(player->get_root());
@@ -773,26 +754,7 @@ void AnimationPlayerEditor::_animation_edit() {
if (current != String()) { if (current != String()) {
Ref<Animation> anim = player->get_animation(current); Ref<Animation> anim = player->get_animation(current);
bool animation_library_is_foreign = false; bool animation_library_is_foreign = EditorNode::get_singleton()->is_resource_read_only(anim);
if (!anim->get_path().is_resource_file()) {
int srpos = anim->get_path().find("::");
if (srpos != -1) {
String base = anim->get_path().substr(0, srpos);
if (ResourceLoader::get_resource_type(base) == "PackedScene") {
if (!get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->get_scene_file_path() != base) {
animation_library_is_foreign = true;
}
} else {
if (FileAccess::exists(base + ".import")) {
animation_library_is_foreign = true;
}
}
}
} else {
if (FileAccess::exists(anim->get_path() + ".import")) {
animation_library_is_foreign = true;
}
}
track_editor->set_animation(anim, animation_library_is_foreign); track_editor->set_animation(anim, animation_library_is_foreign);
@@ -866,25 +828,7 @@ void AnimationPlayerEditor::_update_player() {
// Check if the global library is foreign since we want to disable options for adding/remove/renaming animations if it is. // Check if the global library is foreign since we want to disable options for adding/remove/renaming animations if it is.
Ref<AnimationLibrary> library = player->get_animation_library(K); Ref<AnimationLibrary> library = player->get_animation_library(K);
if (K == "") { if (K == "") {
if (!library->get_path().is_resource_file()) { foreign_global_anim_lib = EditorNode::get_singleton()->is_resource_read_only(library);
int srpos = library->get_path().find("::");
if (srpos != -1) {
String base = library->get_path().substr(0, srpos);
if (ResourceLoader::get_resource_type(base) == "PackedScene") {
if (!get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->get_scene_file_path() != base) {
foreign_global_anim_lib = true;
}
} else {
if (FileAccess::exists(base + ".import")) {
foreign_global_anim_lib = true;
}
}
}
} else {
if (FileAccess::exists(library->get_path() + ".import")) {
foreign_global_anim_lib = true;
}
}
} }
List<StringName> animlist; List<StringName> animlist;
@@ -950,26 +894,7 @@ void AnimationPlayerEditor::_update_player() {
String current = animation->get_item_text(animation->get_selected()); String current = animation->get_item_text(animation->get_selected());
Ref<Animation> anim = player->get_animation(current); Ref<Animation> anim = player->get_animation(current);
bool animation_library_is_foreign = false; bool animation_library_is_foreign = EditorNode::get_singleton()->is_resource_read_only(anim);
if (!anim->get_path().is_resource_file()) {
int srpos = anim->get_path().find("::");
if (srpos != -1) {
String base = anim->get_path().substr(0, srpos);
if (ResourceLoader::get_resource_type(base) == "PackedScene") {
if (!get_tree()->get_edited_scene_root() || get_tree()->get_edited_scene_root()->get_scene_file_path() != base) {
animation_library_is_foreign = true;
}
} else {
if (FileAccess::exists(base + ".import")) {
animation_library_is_foreign = true;
}
}
}
} else {
if (FileAccess::exists(anim->get_path() + ".import")) {
animation_library_is_foreign = true;
}
}
track_editor->set_animation(anim, animation_library_is_foreign); track_editor->set_animation(anim, animation_library_is_foreign);
Node *root = player->get_node(player->get_root()); Node *root = player->get_node(player->get_root());