You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Add per-scene UndoRedo
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
#include "editor/editor_scale.h"
|
||||
#include "editor/editor_settings.h"
|
||||
#include "editor/editor_toaster.h"
|
||||
#include "editor/editor_undo_redo_manager.h"
|
||||
#include "editor/plugins/animation_player_editor_plugin.h"
|
||||
#include "editor/plugins/script_editor_plugin.h"
|
||||
#include "editor/scene_tree_dock.h"
|
||||
@@ -3988,6 +3989,10 @@ void CanvasItemEditor::_selection_changed() {
|
||||
selected_from_canvas = false;
|
||||
}
|
||||
|
||||
void CanvasItemEditor::set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo) {
|
||||
undo_redo = p_undo_redo;
|
||||
}
|
||||
|
||||
void CanvasItemEditor::edit(CanvasItem *p_canvas_item) {
|
||||
Array selection = editor_selection->get_selected_nodes();
|
||||
if (selection.size() != 1 || Object::cast_to<Node>(selection[0]) != p_canvas_item) {
|
||||
@@ -5419,7 +5424,7 @@ CanvasItemEditor::CanvasItemEditor() {
|
||||
CanvasItemEditor *CanvasItemEditor::singleton = nullptr;
|
||||
|
||||
void CanvasItemEditorPlugin::edit(Object *p_object) {
|
||||
canvas_item_editor->set_undo_redo(&get_undo_redo());
|
||||
canvas_item_editor->set_undo_redo(EditorNode::get_undo_redo());
|
||||
canvas_item_editor->edit(Object::cast_to<CanvasItem>(p_object));
|
||||
}
|
||||
|
||||
@@ -5572,34 +5577,34 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
|
||||
Ref<Texture2D> texture = ResourceCache::get_ref(path);
|
||||
|
||||
if (parent) {
|
||||
editor_data->get_undo_redo().add_do_method(parent, "add_child", child, true);
|
||||
editor_data->get_undo_redo().add_do_method(child, "set_owner", EditorNode::get_singleton()->get_edited_scene());
|
||||
editor_data->get_undo_redo().add_do_reference(child);
|
||||
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", child);
|
||||
editor_data->get_undo_redo()->add_do_method(parent, "add_child", child, true);
|
||||
editor_data->get_undo_redo()->add_do_method(child, "set_owner", EditorNode::get_singleton()->get_edited_scene());
|
||||
editor_data->get_undo_redo()->add_do_reference(child);
|
||||
editor_data->get_undo_redo()->add_undo_method(parent, "remove_child", child);
|
||||
} else { // If no parent is selected, set as root node of the scene.
|
||||
editor_data->get_undo_redo().add_do_method(EditorNode::get_singleton(), "set_edited_scene", child);
|
||||
editor_data->get_undo_redo().add_do_method(child, "set_owner", EditorNode::get_singleton()->get_edited_scene());
|
||||
editor_data->get_undo_redo().add_do_reference(child);
|
||||
editor_data->get_undo_redo().add_undo_method(EditorNode::get_singleton(), "set_edited_scene", (Object *)nullptr);
|
||||
editor_data->get_undo_redo()->add_do_method(EditorNode::get_singleton(), "set_edited_scene", child);
|
||||
editor_data->get_undo_redo()->add_do_method(child, "set_owner", EditorNode::get_singleton()->get_edited_scene());
|
||||
editor_data->get_undo_redo()->add_do_reference(child);
|
||||
editor_data->get_undo_redo()->add_undo_method(EditorNode::get_singleton(), "set_edited_scene", (Object *)nullptr);
|
||||
}
|
||||
|
||||
if (parent) {
|
||||
String new_name = parent->validate_child_name(child);
|
||||
EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton();
|
||||
editor_data->get_undo_redo().add_do_method(ed, "live_debug_create_node", EditorNode::get_singleton()->get_edited_scene()->get_path_to(parent), child->get_class(), new_name);
|
||||
editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(EditorNode::get_singleton()->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
|
||||
editor_data->get_undo_redo()->add_do_method(ed, "live_debug_create_node", EditorNode::get_singleton()->get_edited_scene()->get_path_to(parent), child->get_class(), new_name);
|
||||
editor_data->get_undo_redo()->add_undo_method(ed, "live_debug_remove_node", NodePath(String(EditorNode::get_singleton()->get_edited_scene()->get_path_to(parent)) + "/" + new_name));
|
||||
}
|
||||
|
||||
if (Object::cast_to<TouchScreenButton>(child) || Object::cast_to<TextureButton>(child)) {
|
||||
editor_data->get_undo_redo().add_do_property(child, "texture_normal", texture);
|
||||
editor_data->get_undo_redo()->add_do_property(child, "texture_normal", texture);
|
||||
} else {
|
||||
editor_data->get_undo_redo().add_do_property(child, "texture", texture);
|
||||
editor_data->get_undo_redo()->add_do_property(child, "texture", texture);
|
||||
}
|
||||
|
||||
// make visible for certain node type
|
||||
if (Object::cast_to<Control>(child)) {
|
||||
Size2 texture_size = texture->get_size();
|
||||
editor_data->get_undo_redo().add_do_property(child, "rect_size", texture_size);
|
||||
editor_data->get_undo_redo()->add_do_property(child, "rect_size", texture_size);
|
||||
} else if (Object::cast_to<Polygon2D>(child)) {
|
||||
Size2 texture_size = texture->get_size();
|
||||
Vector<Vector2> list = {
|
||||
@@ -5608,7 +5613,7 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
|
||||
Vector2(texture_size.width, texture_size.height),
|
||||
Vector2(0, texture_size.height)
|
||||
};
|
||||
editor_data->get_undo_redo().add_do_property(child, "polygon", list);
|
||||
editor_data->get_undo_redo()->add_do_property(child, "polygon", list);
|
||||
}
|
||||
|
||||
// Compute the global position
|
||||
@@ -5617,7 +5622,7 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String &
|
||||
|
||||
// there's nothing to be used as source position so snapping will work as absolute if enabled
|
||||
target_position = canvas_item_editor->snap_point(target_position);
|
||||
editor_data->get_undo_redo().add_do_method(child, "set_global_position", target_position);
|
||||
editor_data->get_undo_redo()->add_do_method(child, "set_global_position", target_position);
|
||||
}
|
||||
|
||||
bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, const Point2 &p_point) {
|
||||
@@ -5642,15 +5647,15 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons
|
||||
|
||||
instantiated_scene->set_scene_file_path(ProjectSettings::get_singleton()->localize_path(path));
|
||||
|
||||
editor_data->get_undo_redo().add_do_method(parent, "add_child", instantiated_scene, true);
|
||||
editor_data->get_undo_redo().add_do_method(instantiated_scene, "set_owner", edited_scene);
|
||||
editor_data->get_undo_redo().add_do_reference(instantiated_scene);
|
||||
editor_data->get_undo_redo().add_undo_method(parent, "remove_child", instantiated_scene);
|
||||
editor_data->get_undo_redo()->add_do_method(parent, "add_child", instantiated_scene, true);
|
||||
editor_data->get_undo_redo()->add_do_method(instantiated_scene, "set_owner", edited_scene);
|
||||
editor_data->get_undo_redo()->add_do_reference(instantiated_scene);
|
||||
editor_data->get_undo_redo()->add_undo_method(parent, "remove_child", instantiated_scene);
|
||||
|
||||
String new_name = parent->validate_child_name(instantiated_scene);
|
||||
EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton();
|
||||
editor_data->get_undo_redo().add_do_method(ed, "live_debug_instance_node", edited_scene->get_path_to(parent), path, new_name);
|
||||
editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)) + "/" + new_name));
|
||||
editor_data->get_undo_redo()->add_do_method(ed, "live_debug_instance_node", edited_scene->get_path_to(parent), path, new_name);
|
||||
editor_data->get_undo_redo()->add_undo_method(ed, "live_debug_remove_node", NodePath(String(edited_scene->get_path_to(parent)) + "/" + new_name));
|
||||
|
||||
CanvasItem *instance_ci = Object::cast_to<CanvasItem>(instantiated_scene);
|
||||
if (instance_ci) {
|
||||
@@ -5664,7 +5669,7 @@ bool CanvasItemEditorViewport::_create_instance(Node *parent, String &path, cons
|
||||
// Preserve instance position of the original scene.
|
||||
target_pos += instance_ci->_edit_get_position();
|
||||
|
||||
editor_data->get_undo_redo().add_do_method(instantiated_scene, "set_position", target_pos);
|
||||
editor_data->get_undo_redo()->add_do_method(instantiated_scene, "set_position", target_pos);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -5682,7 +5687,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
|
||||
|
||||
Vector<String> error_files;
|
||||
|
||||
editor_data->get_undo_redo().create_action(TTR("Create Node"));
|
||||
editor_data->get_undo_redo()->create_action(TTR("Create Node"));
|
||||
|
||||
for (int i = 0; i < selected_files.size(); i++) {
|
||||
String path = selected_files[i];
|
||||
@@ -5713,7 +5718,7 @@ void CanvasItemEditorViewport::_perform_drop_data() {
|
||||
}
|
||||
}
|
||||
|
||||
editor_data->get_undo_redo().commit_action();
|
||||
editor_data->get_undo_redo()->commit_action();
|
||||
|
||||
if (error_files.size() > 0) {
|
||||
String files_str;
|
||||
|
||||
Reference in New Issue
Block a user