Use SceneTreeDock to replace particles node properly, fixes #24162

This commit is contained in:
Juan Linietsky 2019-01-14 13:41:54 -03:00
parent ed9b230744
commit 6f884cc884
4 changed files with 19 additions and 29 deletions

View file

@ -85,8 +85,6 @@ void Particles2DEditorPlugin::_menu_callback(int p_idx) {
} break;
case MENU_OPTION_CONVERT_TO_CPU_PARTICLES: {
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
CPUParticles2D *cpu_particles = memnew(CPUParticles2D);
cpu_particles->convert_from_particles(particles);
cpu_particles->set_name(particles->get_name());
@ -94,12 +92,7 @@ void Particles2DEditorPlugin::_menu_callback(int p_idx) {
cpu_particles->set_visible(particles->is_visible());
cpu_particles->set_pause_mode(particles->get_pause_mode());
undo_redo->create_action("Replace Particles by CPUParticles");
undo_redo->add_do_method(particles, "replace_by", cpu_particles);
undo_redo->add_undo_method(cpu_particles, "replace_by", particles);
undo_redo->add_do_reference(cpu_particles);
undo_redo->add_undo_reference(particles);
undo_redo->commit_action();
EditorNode::get_singleton()->get_scene_tree_dock()->replace_node(particles, cpu_particles, false);
} break;
}

View file

@ -305,8 +305,6 @@ void ParticlesEditor::_menu_option(int p_option) {
} break;
case MENU_OPTION_CONVERT_TO_CPU_PARTICLES: {
UndoRedo *undo_redo = EditorNode::get_singleton()->get_undo_redo();
CPUParticles *cpu_particles = memnew(CPUParticles);
cpu_particles->convert_from_particles(node);
cpu_particles->set_name(node->get_name());
@ -314,12 +312,7 @@ void ParticlesEditor::_menu_option(int p_option) {
cpu_particles->set_visible(node->is_visible());
cpu_particles->set_pause_mode(node->get_pause_mode());
undo_redo->create_action("Replace Particles by CPUParticles");
undo_redo->add_do_method(node, "replace_by", cpu_particles);
undo_redo->add_undo_method(cpu_particles, "replace_by", node);
undo_redo->add_do_reference(cpu_particles);
undo_redo->add_undo_reference(node);
undo_redo->commit_action();
EditorNode::get_singleton()->get_scene_tree_dock()->replace_node(node, cpu_particles, false);
} break;
}

View file

@ -1737,24 +1737,28 @@ void SceneTreeDock::_create() {
}
}
void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node) {
void SceneTreeDock::replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties) {
Node *n = p_node;
Node *newnode = p_by_node;
Node *default_oldnode = Object::cast_to<Node>(ClassDB::instance(n->get_class()));
List<PropertyInfo> pinfo;
n->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
continue;
if (E->get().name == "__meta__")
continue;
if (default_oldnode->get(E->get().name) != n->get(E->get().name)) {
newnode->set(E->get().name, n->get(E->get().name));
if (p_keep_properties) {
Node *default_oldnode = Object::cast_to<Node>(ClassDB::instance(n->get_class()));
List<PropertyInfo> pinfo;
n->get_property_list(&pinfo);
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
if (!(E->get().usage & PROPERTY_USAGE_STORAGE))
continue;
if (E->get().name == "__meta__")
continue;
if (default_oldnode->get(E->get().name) != n->get(E->get().name)) {
newnode->set(E->get().name, n->get(E->get().name));
}
}
memdelete(default_oldnode);
}
memdelete(default_oldnode);
editor->push_item(NULL);

View file

@ -238,7 +238,7 @@ public:
void show_tab_buttons();
void hide_tab_buttons();
void replace_node(Node *p_node, Node *p_by_node);
void replace_node(Node *p_node, Node *p_by_node, bool p_keep_properties = true);
void open_script_dialog(Node *p_for_node);