Fix perform_node_renames handling of AnimationMixers track paths
This commit is contained in:
parent
6afd320984
commit
4f0790a214
1 changed files with 96 additions and 78 deletions
|
@ -55,6 +55,7 @@
|
|||
#include "editor/plugins/script_editor_plugin.h"
|
||||
#include "editor/reparent_dialog.h"
|
||||
#include "editor/shader_create_dialog.h"
|
||||
#include "scene/animation/animation_tree.h"
|
||||
#include "scene/gui/check_box.h"
|
||||
#include "scene/main/window.h"
|
||||
#include "scene/property_utils.h"
|
||||
|
@ -1810,39 +1811,31 @@ void SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath>
|
|||
return;
|
||||
}
|
||||
|
||||
// Renaming node paths used in node properties.
|
||||
List<PropertyInfo> properties;
|
||||
p_base->get_property_list(&properties);
|
||||
|
||||
for (const PropertyInfo &E : properties) {
|
||||
if (!(E.usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR))) {
|
||||
continue;
|
||||
}
|
||||
String propertyname = E.name;
|
||||
Variant old_variant = p_base->get(propertyname);
|
||||
Variant updated_variant = old_variant;
|
||||
if (_check_node_path_recursive(p_base, updated_variant, p_renames)) {
|
||||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
||||
undo_redo->add_do_property(p_base, propertyname, updated_variant);
|
||||
undo_redo->add_undo_property(p_base, propertyname, old_variant);
|
||||
p_base->set(propertyname, updated_variant);
|
||||
}
|
||||
}
|
||||
|
||||
bool autorename_animation_tracks = bool(EDITOR_GET("editors/animation/autorename_animation_tracks"));
|
||||
|
||||
if (autorename_animation_tracks && Object::cast_to<AnimationPlayer>(p_base)) {
|
||||
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_base);
|
||||
AnimationMixer *mixer = Object::cast_to<AnimationMixer>(p_base);
|
||||
if (autorename_animation_tracks && mixer) {
|
||||
// Don't rename if we're an AnimationTree pointing to an AnimationPlayer
|
||||
bool points_to_other_animation_player = false;
|
||||
AnimationTree *at = Object::cast_to<AnimationTree>(mixer);
|
||||
if (at) {
|
||||
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(at->get_node_or_null(at->get_animation_player()));
|
||||
if (ap) {
|
||||
points_to_other_animation_player = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!points_to_other_animation_player) {
|
||||
List<StringName> anims;
|
||||
ap->get_animation_list(&anims);
|
||||
Node *root = ap->get_node(ap->get_root_node());
|
||||
mixer->get_animation_list(&anims);
|
||||
Node *root = mixer->get_node(mixer->get_root_node());
|
||||
|
||||
if (root) {
|
||||
HashMap<Node *, NodePath>::Iterator found_root_path = p_renames->find(root);
|
||||
NodePath new_root_path = found_root_path ? found_root_path->value : root->get_path();
|
||||
if (!new_root_path.is_empty()) { // No renaming if root node is deleted.
|
||||
for (const StringName &E : anims) {
|
||||
Ref<Animation> anim = ap->get_animation(E);
|
||||
Ref<Animation> anim = mixer->get_animation(E);
|
||||
if (!r_rem_anims->has(anim)) {
|
||||
r_rem_anims->insert(anim, HashSet<int>());
|
||||
HashSet<int> &ran = r_rem_anims->find(anim)->value;
|
||||
|
@ -1853,14 +1846,19 @@ void SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath>
|
|||
|
||||
HashSet<int> &ran = r_rem_anims->find(anim)->value;
|
||||
|
||||
if (anim.is_null()) {
|
||||
if (anim.is_null() || EditorNode::get_singleton()->is_resource_read_only(anim)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int tracks_removed = 0;
|
||||
|
||||
for (int i = 0; i < anim->get_track_count(); i++) {
|
||||
if (anim->track_is_imported(i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
NodePath track_np = anim->track_get_path(i);
|
||||
|
||||
Node *n = root->get_node_or_null(track_np);
|
||||
if (!n) {
|
||||
continue;
|
||||
|
@ -1906,6 +1904,26 @@ void SceneTreeDock::perform_node_renames(Node *p_base, HashMap<Node *, NodePath>
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Renaming node paths used in node properties.
|
||||
List<PropertyInfo> properties;
|
||||
p_base->get_property_list(&properties);
|
||||
|
||||
for (const PropertyInfo &E : properties) {
|
||||
if (!(E.usage & (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR))) {
|
||||
continue;
|
||||
}
|
||||
String propertyname = E.name;
|
||||
Variant old_variant = p_base->get(propertyname);
|
||||
Variant updated_variant = old_variant;
|
||||
if (_check_node_path_recursive(p_base, updated_variant, p_renames)) {
|
||||
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
|
||||
undo_redo->add_do_property(p_base, propertyname, updated_variant);
|
||||
undo_redo->add_undo_property(p_base, propertyname, old_variant);
|
||||
p_base->set(propertyname, updated_variant);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < p_base->get_child_count(); i++) {
|
||||
perform_node_renames(p_base->get_child(i), p_renames, r_rem_anims);
|
||||
|
|
Loading…
Reference in a new issue