diff --git a/Scripts/Canvas.gd b/Scripts/Canvas.gd index c0f0bd65e..4d4b562aa 100644 --- a/Scripts/Canvas.gd +++ b/Scripts/Canvas.gd @@ -117,7 +117,6 @@ func _process(delta) -> void: if (can_handle || Global.undos == Global.undo_redo.get_version()) && Global.current_frame == frame: if previous_action != "None" && previous_action != "RectSelect": handle_redo("Draw") - print(layers[0][0].data["data"][0]) match current_action: #Handle current tool "Pencil": @@ -242,28 +241,46 @@ func _process(delta) -> void: update_texture(current_layer_index) func handle_undo(action : String) -> void: + var canvases := [] + var animation_timer := $"../../../../../../AnimationTimer" + var layer_index := -1 + if animation_timer.is_stopped(): #if we're not animating, store only the current canvas + canvases = [self] + layer_index = current_layer_index + else: #If we're animating, store all canvases + canvases = Global.canvases Global.undos += 1 - #I'm not sure why I have to unlock it, but... - #...if I don't, it doesn't work properly - layers[current_layer_index][0].unlock() - var data = layers[current_layer_index][0].data - layers[current_layer_index][0].lock() Global.undo_redo.create_action(action) - Global.undo_redo.add_undo_property(layers[current_layer_index][0], "data", data) + for c in canvases: + #I'm not sure why I have to unlock it, but... + #...if I don't, it doesn't work properly + c.layers[c.current_layer_index][0].unlock() + var data = c.layers[c.current_layer_index][0].data + c.layers[c.current_layer_index][0].lock() + Global.undo_redo.add_undo_property(c.layers[c.current_layer_index][0], "data", data) if action == "Rectangle Select": var selected_pixels = Global.selected_pixels.duplicate() Global.undo_redo.add_undo_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon) Global.undo_redo.add_undo_property(Global, "selected_pixels", selected_pixels) - Global.undo_redo.add_undo_method(Global, "undo", self, current_layer_index) + Global.undo_redo.add_undo_method(Global, "undo", canvases, layer_index) func handle_redo(action : String) -> void: if Global.undos < Global.undo_redo.get_version(): return - Global.undo_redo.add_do_property(layers[current_layer_index][0], "data", layers[current_layer_index][0].data) + var canvases := [] + var animation_timer := $"../../../../../../AnimationTimer" + var layer_index := -1 + if animation_timer.is_stopped(): + canvases = [self] + layer_index = current_layer_index + else: + canvases = Global.canvases + for c in canvases: + Global.undo_redo.add_do_property(c.layers[c.current_layer_index][0], "data", c.layers[c.current_layer_index][0].data) if action == "Rectangle Select": Global.undo_redo.add_do_property(Global.selection_rectangle, "polygon", Global.selection_rectangle.polygon) Global.undo_redo.add_do_property(Global, "selected_pixels", Global.selected_pixels) - Global.undo_redo.add_do_method(Global, "redo", self, current_layer_index) + Global.undo_redo.add_do_method(Global, "redo", canvases, layer_index) Global.undo_redo.commit_action() print("Do: ", Global.undo_redo.get_current_action_name()) diff --git a/Scripts/Global.gd b/Scripts/Global.gd index 8ffd73b42..42feb6773 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -162,33 +162,35 @@ func find_node_by_name(root, node_name) -> Node: return found return null -func undo(canvas : Canvas, layer_index : int = -1) -> void: +func undo(canvases : Array, layer_index : int = -1) -> void: undos -= 1 var action_name : String = undo_redo.get_current_action_name() if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale": - if layer_index > -1: - canvas.update_texture(layer_index) - else: - for i in canvas.layers.size(): - canvas.update_texture(i) + for c in canvases: + if layer_index > -1: + c.update_texture(layer_index) + else: + for i in c.layers.size(): + c.update_texture(i) - if action_name == "Scale": - canvas.camera_zoom() + if action_name == "Scale": + c.camera_zoom() print("Undo: ", action_name) -func redo(canvas : Canvas, layer_index : int = -1) -> void: +func redo(canvases : Array, layer_index : int = -1) -> void: if undos < undo_redo.get_version(): #If we did undo and then redo undos = undo_redo.get_version() var action_name : String = undo_redo.get_current_action_name() if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale": - if layer_index > -1: - canvas.update_texture(layer_index) - else: - for i in canvas.layers.size(): - canvas.update_texture(i) + for c in canvases: + if layer_index > -1: + c.update_texture(layer_index) + else: + for i in c.layers.size(): + c.update_texture(i) - if action_name == "Scale": - canvas.camera_zoom() + if action_name == "Scale": + c.camera_zoom() print("Redo: ", action_name) func change_frame() -> void: diff --git a/Scripts/LayerContainer.gd b/Scripts/LayerContainer.gd index d4b5d3ebc..6dbdb20b9 100644 --- a/Scripts/LayerContainer.gd +++ b/Scripts/LayerContainer.gd @@ -6,7 +6,7 @@ var currently_selected := false var visibility_toggled := false func _ready() -> void: - var stylebox = StyleBoxFlat.new() + var stylebox := StyleBoxFlat.new() stylebox.bg_color = Color("3d3b45") add_stylebox_override("panel", stylebox) changed_selection() diff --git a/Scripts/Main.gd b/Scripts/Main.gd index 1953a51e3..3a5ce884c 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -44,7 +44,7 @@ func _ready() -> void: "Show Grid" : KEY_MASK_CTRL + KEY_G } var help_menu_items := { - "About Pixelorama" : 0 + "About Pixelorama" : 0 } var file_menu : PopupMenu = Global.file_menu.get_popup() var edit_menu : PopupMenu = Global.edit_menu.get_popup() @@ -182,8 +182,8 @@ func edit_menu_id_pressed(id : int) -> void: Global.undo_redo.add_undo_property(Global.canvas.layers[j][0], "data", Global.canvas.layers[j][0].data) Global.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size) - Global.undo_redo.add_undo_method(Global, "undo", Global.canvas) - Global.undo_redo.add_do_method(Global, "redo", Global.canvas) + Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas]) + Global.undo_redo.add_do_method(Global, "redo", [Global.canvas]) Global.undo_redo.commit_action() 4: #Clear selection Global.canvas.handle_undo("Rectangle Select") @@ -516,8 +516,8 @@ func _on_ScaleImage_confirmed() -> void: Global.undo_redo.add_undo_property(Global.canvas.layers[i][0], "data", Global.canvas.layers[i][0].data) Global.undo_redo.add_undo_property(Global.canvas, "size", Global.canvas.size) - Global.undo_redo.add_undo_method(Global, "undo", Global.canvas) - Global.undo_redo.add_do_method(Global, "redo", Global.canvas) + Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas]) + Global.undo_redo.add_do_method(Global, "redo", [Global.canvas]) Global.undo_redo.commit_action() func add_layer(is_new := true) -> void: