summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/plugins/particles_2d_editor_plugin.cpp9
-rw-r--r--editor/plugins/particles_editor_plugin.cpp9
-rw-r--r--editor/scene_tree_dock.cpp28
-rw-r--r--editor/scene_tree_dock.h2
4 files changed, 19 insertions, 29 deletions
diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp
index 6a674760b7..a944674cbd 100644
--- a/editor/plugins/particles_2d_editor_plugin.cpp
+++ b/editor/plugins/particles_2d_editor_plugin.cpp
@@ -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;
}
diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp
index 7e35e30a89..95828064ac 100644
--- a/editor/plugins/particles_editor_plugin.cpp
+++ b/editor/plugins/particles_editor_plugin.cpp
@@ -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;
}
diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp
index 6c79fad82c..daa7f92dcf 100644
--- a/editor/scene_tree_dock.cpp
+++ b/editor/scene_tree_dock.cpp
@@ -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);
diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h
index ced3f81e2b..653d0a4eca 100644
--- a/editor/scene_tree_dock.h
+++ b/editor/scene_tree_dock.h
@@ -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);