1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-31 07:29:49 +00:00

Just one method for undo/redo in Global.gd

This commit is contained in:
Manolis Papadeas 2021-12-02 02:22:32 +02:00
parent f70efe3076
commit 67ec887ad1
14 changed files with 74 additions and 110 deletions

View file

@ -450,8 +450,8 @@ func general_undo_scale() -> void:
project.undo_redo.add_undo_property( project.undo_redo.add_undo_property(
project.y_symmetry_axis, "points", project.y_symmetry_axis.points project.y_symmetry_axis, "points", project.y_symmetry_axis.points
) )
project.undo_redo.add_undo_method(Global, "undo") project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(Global, "redo") project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.commit_action() project.undo_redo.commit_action()
@ -463,8 +463,8 @@ func general_do_centralize() -> void:
func general_undo_centralize() -> void: func general_undo_centralize() -> void:
var project: Project = Global.current_project var project: Project = Global.current_project
project.undo_redo.add_undo_method(Global, "undo") project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(Global, "redo") project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.commit_action() project.undo_redo.commit_action()

View file

@ -220,22 +220,30 @@ func general_redo(project: Project = current_project) -> void:
notification_label("Redo: %s" % action_name) notification_label("Redo: %s" % action_name)
func undo(_frame_index := -1, _layer_index := -1, project: Project = current_project) -> void: func undo_or_redo(
undo: bool, frame_index := -1, layer_index := -1, project: Project = current_project
) -> void:
if undo:
general_undo(project) general_undo(project)
else:
general_redo(project)
var action_name: String = project.undo_redo.get_current_action_name() var action_name: String = project.undo_redo.get_current_action_name()
if ( if (
action_name == "Draw" action_name
or action_name == "Draw Shape" in [
or action_name == "Rectangle Select" "Draw",
or action_name == "Move Selection" "Draw Shape",
or action_name == "Scale" "Rectangle Select",
or action_name == "Centralize" "Move Selection",
or action_name == "Merge Layer" "Scale",
or action_name == "Link Cel" "Centralize",
or action_name == "Unlink Cel" "Merge Layer",
"Link Cel",
"Unlink Cel"
]
): ):
if _layer_index > -1 and _frame_index > -1: if layer_index > -1 and frame_index > -1:
canvas.update_texture(_layer_index, _frame_index, project) canvas.update_texture(layer_index, frame_index, project)
else: else:
for i in project.frames.size(): for i in project.frames.size():
for j in project.layers.size(): for j in project.layers.size():
@ -250,51 +258,7 @@ func undo(_frame_index := -1, _layer_index := -1, project: Project = current_pro
elif "Frame" in action_name: elif "Frame" in action_name:
# This actually means that frames.size is one, but it hasn't been updated yet # This actually means that frames.size is one, but it hasn't been updated yet
if project.frames.size() == 2: # Stop animating if (undo and project.frames.size() == 2) or project.frames.size() == 1: # Stop animating
play_forward.pressed = false
play_backwards.pressed = false
animation_timer.stop()
elif "Move Cels" == action_name:
project.frames = project.frames # to call frames_changed
canvas.update()
if !project.has_changed:
project.has_changed = true
if project == current_project:
self.window_title = window_title + "(*)"
func redo(_frame_index := -1, _layer_index := -1, project: Project = current_project) -> void:
general_redo(project)
var action_name: String = project.undo_redo.get_current_action_name()
if (
action_name == "Draw"
or action_name == "Draw Shape"
or action_name == "Rectangle Select"
or action_name == "Move Selection"
or action_name == "Scale"
or action_name == "Centralize"
or action_name == "Merge Layer"
or action_name == "Link Cel"
or action_name == "Unlink Cel"
):
if _layer_index > -1 and _frame_index > -1:
canvas.update_texture(_layer_index, _frame_index, project)
else:
for i in project.frames.size():
for j in project.layers.size():
canvas.update_texture(j, i, project)
canvas.selection.update()
if action_name == "Scale":
canvas.camera_zoom()
canvas.grid.update()
canvas.pixel_grid.update()
cursor_position_label.text = "[%s×%s]" % [project.size.x, project.size.y]
elif "Frame" in action_name:
if project.frames.size() == 1: # Stop animating
play_forward.pressed = false play_forward.pressed = false
play_backwards.pressed = false play_backwards.pressed = false
animation_timer.stop() animation_timer.stop()

View file

@ -476,8 +476,8 @@ func open_image_at_frame(image: Image, layer_index := 0, frame_index := 0) -> vo
project.undo_redo.add_undo_property(project, "frames", project.frames) project.undo_redo.add_undo_property(project, "frames", project.frames)
project.undo_redo.add_undo_property(project, "current_frame", project.current_frame) project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
project.undo_redo.add_do_method(Global, "redo") project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo") project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.commit_action() project.undo_redo.commit_action()
@ -500,8 +500,8 @@ func open_image_as_new_frame(image: Image, layer_index := 0) -> void:
project.undos += 1 project.undos += 1
project.undo_redo.create_action("Add Frame") project.undo_redo.create_action("Add Frame")
project.undo_redo.add_do_method(Global, "redo") project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo") project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_property(project, "frames", new_frames) project.undo_redo.add_do_property(project, "frames", new_frames)
project.undo_redo.add_do_property(project, "current_frame", new_frames.size() - 1) project.undo_redo.add_do_property(project, "current_frame", new_frames.size() - 1)
@ -544,8 +544,8 @@ func open_image_as_new_layer(image: Image, file_name: String, frame_index := 0)
project.undo_redo.add_undo_property(project, "layers", project.layers) project.undo_redo.add_undo_property(project, "layers", project.layers)
project.undo_redo.add_undo_property(project, "current_frame", project.current_frame) project.undo_redo.add_undo_property(project, "current_frame", project.current_frame)
project.undo_redo.add_undo_method(Global, "undo") project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(Global, "redo") project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.commit_action() project.undo_redo.commit_action()

View file

@ -100,8 +100,8 @@ func _commit_undo(action: String, undo_data: Dictionary, project: Project) -> vo
project.undo_redo.add_do_property(image, "data", redo_data[image]) project.undo_redo.add_do_property(image, "data", redo_data[image])
for image in undo_data: for image in undo_data:
project.undo_redo.add_undo_property(image, "data", undo_data[image]) project.undo_redo.add_undo_property(image, "data", undo_data[image])
project.undo_redo.add_do_method(Global, "redo", -1, -1, project) project.undo_redo.add_do_method(Global, "undo_or_redo", false, -1, -1, project)
project.undo_redo.add_undo_method(Global, "undo", -1, -1, project) project.undo_redo.add_undo_method(Global, "undo_or_redo", true, -1, -1, project)
project.undo_redo.commit_action() project.undo_redo.commit_action()

View file

@ -257,8 +257,8 @@ func commit_undo(action: String, undo_data: Dictionary) -> void:
image.unlock() image.unlock()
for image in undo_data: for image in undo_data:
project.undo_redo.add_undo_property(image, "data", undo_data[image]) project.undo_redo.add_undo_property(image, "data", undo_data[image])
project.undo_redo.add_do_method(Global, "redo", frame, layer) project.undo_redo.add_do_method(Global, "undo_or_redo", false, frame, layer)
project.undo_redo.add_undo_method(Global, "undo", frame, layer) project.undo_redo.add_undo_method(Global, "undo_or_redo", true, frame, layer)
project.undo_redo.commit_action() project.undo_redo.commit_action()

View file

@ -166,8 +166,8 @@ func commit_undo(action: String) -> void:
image.unlock() image.unlock()
for image in _undo_data: for image in _undo_data:
project.undo_redo.add_undo_property(image, "data", _undo_data[image]) project.undo_redo.add_undo_property(image, "data", _undo_data[image])
project.undo_redo.add_do_method(Global, "redo", frame, layer) project.undo_redo.add_do_method(Global, "undo_or_redo", false, frame, layer)
project.undo_redo.add_undo_method(Global, "undo", frame, layer) project.undo_redo.add_undo_method(Global, "undo_or_redo", true, frame, layer)
project.undo_redo.commit_action() project.undo_redo.commit_action()
_undo_data.clear() _undo_data.clear()

View file

@ -118,8 +118,8 @@ func commit_undo(action: String) -> void:
image.unlock() image.unlock()
for image in _undo_data: for image in _undo_data:
project.undo_redo.add_undo_property(image, "data", _undo_data[image]) project.undo_redo.add_undo_property(image, "data", _undo_data[image])
project.undo_redo.add_do_method(Global, "redo", frame, layer) project.undo_redo.add_do_method(Global, "undo_or_redo", false, frame, layer)
project.undo_redo.add_undo_method(Global, "undo", frame, layer) project.undo_redo.add_undo_method(Global, "undo_or_redo", true, frame, layer)
project.undo_redo.commit_action() project.undo_redo.commit_action()
_undo_data.clear() _undo_data.clear()

View file

@ -600,9 +600,9 @@ func commit_undo(action: String, undo_data_tmp: Dictionary) -> void:
if not image is Image: if not image is Image:
continue continue
project.undo_redo.add_undo_property(image, "data", undo_data_tmp[image]) project.undo_redo.add_undo_property(image, "data", undo_data_tmp[image])
project.undo_redo.add_do_method(Global, "redo") project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_do_method(project, "selection_bitmap_changed") project.undo_redo.add_do_method(project, "selection_bitmap_changed")
project.undo_redo.add_undo_method(Global, "undo") project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_undo_method(project, "selection_bitmap_changed") project.undo_redo.add_undo_method(project, "selection_bitmap_changed")
project.undo_redo.commit_action() project.undo_redo.commit_action()

View file

@ -75,9 +75,9 @@ func _commit_undo(action: String, undo_data: Dictionary, project: Project) -> vo
if not image is Image: if not image is Image:
continue continue
project.undo_redo.add_undo_property(image, "data", undo_data[image]) project.undo_redo.add_undo_property(image, "data", undo_data[image])
project.undo_redo.add_do_method(Global, "redo", -1, -1, project) project.undo_redo.add_do_method(Global, "undo_or_redo", false, -1, -1, project)
project.undo_redo.add_do_method(project, "selection_bitmap_changed") project.undo_redo.add_do_method(project, "selection_bitmap_changed")
project.undo_redo.add_undo_method(Global, "undo", -1, -1, project) project.undo_redo.add_undo_method(Global, "undo_or_redo", true, -1, -1, project)
project.undo_redo.add_undo_method(project, "selection_bitmap_changed") project.undo_redo.add_undo_method(project, "selection_bitmap_changed")
project.undo_redo.commit_action() project.undo_redo.commit_action()

View file

@ -106,8 +106,8 @@ func add_frame() -> void:
project.undos += 1 project.undos += 1
project.undo_redo.create_action("Add Frame") project.undo_redo.create_action("Add Frame")
project.undo_redo.add_do_method(Global, "redo") project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo") project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_property(project, "frames", new_frames) project.undo_redo.add_do_property(project, "frames", new_frames)
project.undo_redo.add_do_property(project, "current_frame", project.current_frame + 1) project.undo_redo.add_do_property(project, "current_frame", project.current_frame + 1)
@ -205,8 +205,8 @@ func delete_frame(frame := -1) -> void:
Global.current_project, "layers", Global.current_project.layers Global.current_project, "layers", Global.current_project.layers
) )
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
@ -268,8 +268,8 @@ func copy_frame(frame := -1) -> void:
Global.current_project.undos += 1 Global.current_project.undos += 1
Global.current_project.undo_redo.create_action("Add Frame") Global.current_project.undo_redo.create_action("Add Frame")
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames) Global.current_project.undo_redo.add_do_property(Global.current_project, "frames", new_frames)
Global.current_project.undo_redo.add_do_property( Global.current_project.undo_redo.add_do_property(
@ -579,8 +579,8 @@ func add_layer(is_new := true) -> void:
Global.current_project, "layers", Global.current_project.layers Global.current_project, "layers", Global.current_project.layers
) )
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
@ -613,8 +613,8 @@ func _on_RemoveLayer_pressed() -> void:
Global.current_project.undo_redo.add_undo_property( Global.current_project.undo_redo.add_undo_property(
Global.current_project, "layers", Global.current_project.layers Global.current_project, "layers", Global.current_project.layers
) )
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
@ -645,8 +645,8 @@ func change_layer_order(rate: int) -> void:
Global.current_project, "current_layer", Global.current_project.current_layer Global.current_project, "current_layer", Global.current_project.current_layer
) )
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
@ -735,8 +735,8 @@ func _on_MergeDownLayer_pressed() -> void:
Global.current_project, "current_layer", Global.current_project.current_layer Global.current_project, "current_layer", Global.current_project.current_layer
) )
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()

View file

@ -143,8 +143,8 @@ func _on_PopupMenu_id_pressed(id: int) -> void:
) )
Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels) Global.current_project.undo_redo.add_undo_property(f, "cels", f.cels)
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
elif popup_menu.get_item_metadata(MenuOptions.LINK) == "Link Cel": elif popup_menu.get_item_metadata(MenuOptions.LINK) == "Link Cel":
@ -164,8 +164,8 @@ func _on_PopupMenu_id_pressed(id: int) -> void:
Global.current_project.undo_redo.add_undo_property( Global.current_project.undo_redo.add_undo_property(
Global.current_project, "layers", Global.current_project.layers Global.current_project, "layers", Global.current_project.layers
) )
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
@ -178,10 +178,10 @@ func delete_cel_contents() -> void:
project.undos += 1 project.undos += 1
project.undo_redo.create_action("Draw") project.undo_redo.create_action("Draw")
project.undo_redo.add_undo_property(image, "data", data) project.undo_redo.add_undo_property(image, "data", data)
project.undo_redo.add_undo_method(Global, "undo", frame, layer, project) project.undo_redo.add_undo_method(Global, "undo_or_redo", true, frame, layer, project)
image.fill(0) image.fill(0)
project.undo_redo.add_do_property(image, "data", image.data) project.undo_redo.add_do_property(image, "data", image.data)
project.undo_redo.add_do_method(Global, "redo", frame, layer, project) project.undo_redo.add_do_method(Global, "undo_or_redo", false, frame, layer, project)
project.undo_redo.commit_action() project.undo_redo.commit_action()
@ -267,6 +267,6 @@ func drop_data(_pos, data) -> void:
Global.current_project.frames[frame], "cels", Global.current_project.frames[frame].cels Global.current_project.frames[frame], "cels", Global.current_project.frames[frame].cels
) )
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()

View file

@ -99,8 +99,8 @@ func change_frame_order(rate: int) -> void:
Global.current_project, "current_frame", Global.current_project.current_frame Global.current_project, "current_frame", Global.current_project.current_frame
) )
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()
@ -150,6 +150,6 @@ func drop_data(_pos, data) -> void:
Global.current_project, "current_frame", Global.current_project.current_frame Global.current_project, "current_frame", Global.current_project.current_frame
) )
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()

View file

@ -34,6 +34,6 @@ func _on_FrameProperties_confirmed():
Global.current_project.frames[frame].duration Global.current_project.frames[frame].duration
) )
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()

View file

@ -169,6 +169,6 @@ func drop_data(_pos, data) -> void:
Global.current_project, "layers", Global.current_project.layers Global.current_project, "layers", Global.current_project.layers
) )
Global.current_project.undo_redo.add_undo_method(Global, "undo") Global.current_project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
Global.current_project.undo_redo.add_do_method(Global, "redo") Global.current_project.undo_redo.add_do_method(Global, "undo_or_redo", false)
Global.current_project.undo_redo.commit_action() Global.current_project.undo_redo.commit_action()