mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-30 23:19:49 +00:00
UndoRedo vol 8 - Draw while animating should now work with UndoRedo
This commit is contained in:
parent
8bc0879814
commit
40e0978b3f
|
@ -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
|
||||
Global.undo_redo.create_action(action)
|
||||
for c in canvases:
|
||||
#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)
|
||||
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())
|
||||
|
||||
|
|
|
@ -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":
|
||||
for c in canvases:
|
||||
if layer_index > -1:
|
||||
canvas.update_texture(layer_index)
|
||||
c.update_texture(layer_index)
|
||||
else:
|
||||
for i in canvas.layers.size():
|
||||
canvas.update_texture(i)
|
||||
for i in c.layers.size():
|
||||
c.update_texture(i)
|
||||
|
||||
if action_name == "Scale":
|
||||
canvas.camera_zoom()
|
||||
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":
|
||||
for c in canvases:
|
||||
if layer_index > -1:
|
||||
canvas.update_texture(layer_index)
|
||||
c.update_texture(layer_index)
|
||||
else:
|
||||
for i in canvas.layers.size():
|
||||
canvas.update_texture(i)
|
||||
for i in c.layers.size():
|
||||
c.update_texture(i)
|
||||
|
||||
if action_name == "Scale":
|
||||
canvas.camera_zoom()
|
||||
c.camera_zoom()
|
||||
print("Redo: ", action_name)
|
||||
|
||||
func change_frame() -> void:
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue