From 57f3e89f70678a4affb59e869c440b97aabf07f7 Mon Sep 17 00:00:00 2001 From: VirtualBox Date: Sun, 26 Aug 2018 21:11:17 +0200 Subject: [PATCH] Update UndoRedo.xml --- doc/classes/UndoRedo.xml | 37 +++++++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 6 deletions(-) mode change 100644 => 100755 doc/classes/UndoRedo.xml diff --git a/doc/classes/UndoRedo.xml b/doc/classes/UndoRedo.xml old mode 100644 new mode 100755 index b9550c17fb7..0ea5c6e005b --- a/doc/classes/UndoRedo.xml +++ b/doc/classes/UndoRedo.xml @@ -4,8 +4,29 @@ Helper to manage UndoRedo in the editor or custom tools. - Helper to manage UndoRedo in the editor or custom tools. It works by storing calls to functions in both 'do' an 'undo' lists. + Helper to manage UndoRedo in the editor or custom tools. It works by registering methods and property changes inside 'actions'. Common behavior is to create an action, then add do/undo calls to functions or property changes, then committing the action. + Here's an example on how to add an action to Godot editor's own 'undoredo': + [codeblock] + var undoredo = get_undo_redo() # method of EditorPlugin + + func do_something(): + pass # put your code here + + func undo_something(): + pass # put here the code that reverts what's done by "do_something()" + + func _on_MyButton_pressed(): + var node = get_node("MyNode2D") + undoredo.create_action("Move the node") + undoredo.add_do_method(self, "do_something") + undoredo.add_undo_method(self, "undo_something") + undoredo.add_do_property(node, "position", Vector2(100,100)) + undoredo.add_undo_property(node, "position", node.position) + undoredo.commit_action() + [/codeblock] + [method create_action], [method add_do_method], [method add_undo_method], [method add_do_property], [method add_undo_property], and [method commit_action] should be called one after the other, like in the example. Not doing so could lead to crashes. + If you don't need to register a method you can leave [method add_do_method] and [method add_undo_method] out, and so it goes for properties. You can register more than one method/property. @@ -20,6 +41,7 @@ + Register a method that will be called when the action is committed. @@ -32,7 +54,7 @@ - Set a property with a custom value. + Register a property value change for 'do'. @@ -41,7 +63,7 @@ - Add a 'do' reference that will be erased if the 'do' history is lost. This is useful mostly for new nodes created for the 'do' call. Do not use for resources. + Register a reference for 'do' that will be erased if the 'do' history is lost. This is useful mostly for new nodes created for the 'do' call. Do not use for resources. @@ -52,6 +74,7 @@ + Register a method that will be called when the action is undone. @@ -64,7 +87,7 @@ - Undo setting of a property with a custom value. + Register a property value change for 'undo'. @@ -73,7 +96,7 @@ - Add an 'undo' reference that will be erased if the 'undo' history is lost. This is useful mostly for nodes removed with the 'do' call (not the 'undo' call!). + Register a reference for 'undo' that will be erased if the 'undo' history is lost. This is useful mostly for nodes removed with the 'do' call (not the 'undo' call!). @@ -98,7 +121,7 @@ - Create a new action. After this is called, do all your calls to [method add_do_method], [method add_undo_method], [method add_do_property] and [method add_undo_property]. + Create a new action. After this is called, do all your calls to [method add_do_method], [method add_undo_method], [method add_do_property], and [method add_undo_property], then commit the action with [method commit_action]. @@ -120,12 +143,14 @@ + Redo last action. + Undo last action.