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

Made Unlink Cel work with UndoRedo

This commit is contained in:
OverloadedOrama 2020-04-21 21:34:45 +03:00
parent 1e4a5cff8e
commit 09d2265056
3 changed files with 20 additions and 7 deletions

View file

@ -54,6 +54,8 @@ func _ready() -> void:
layers.append([sprite, tex, 1])
if self in l[5]:
# If the linked button is pressed, set as the Image & ImageTexture
# to be the same as the first linked cel
var current_layer := layers.size() - 1
layers[current_layer][0] = l[5][0].layers[current_layer][0]
layers[current_layer][1] = l[5][0].layers[current_layer][1]

View file

@ -52,17 +52,28 @@ func _on_PopupMenu_id_pressed(ID : int) -> void:
change_frame_order(1)
4: # Unlink Cel
var cel_index : int = Global.layers[layer][5].find(Global.canvases[frame])
Global.layers[layer][5].remove(cel_index)
_ready()
var c = Global.canvases[frame]
var new_layers := Global.layers.duplicate(true)
var new_canvas_layers : Array = c.layers.duplicate(true)
new_layers[layer][5].remove(cel_index)
var sprite := Image.new()
sprite.copy_from(Global.canvases[frame].layers[layer][0])
sprite.lock()
Global.canvases[frame].layers[layer][0] = sprite
var tex := ImageTexture.new()
tex.create_from_image(sprite, 0)
Global.canvases[frame].layers[layer][1] = tex
Global.canvases[frame].update()
new_canvas_layers[layer][0] = sprite
new_canvas_layers[layer][1] = tex
Global.undo_redo.create_action("Unlink Cel")
Global.undo_redo.add_do_property(Global, "layers", new_layers)
Global.undo_redo.add_do_property(c, "layers", new_canvas_layers)
Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
Global.undo_redo.add_undo_property(c, "layers", c.layers)
Global.undo_redo.add_undo_method(Global, "undo", [Global.canvases[frame]], layer)
Global.undo_redo.add_do_method(Global, "redo", [Global.canvases[frame]], layer)
Global.undo_redo.commit_action()
func change_frame_order(rate : int) -> void:

View file

@ -460,7 +460,7 @@ func general_redo() -> void:
func undo(_canvases : Array, layer_index : int = -1) -> void:
general_undo()
var action_name := undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale" || action_name == "Merge Layer":
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Unlink Cel":
for c in _canvases:
if layer_index > -1:
c.update_texture(layer_index)
@ -493,7 +493,7 @@ func undo(_canvases : Array, layer_index : int = -1) -> void:
func redo(_canvases : Array, layer_index : int = -1) -> void:
general_redo()
var action_name := undo_redo.get_current_action_name()
if action_name == "Draw" || action_name == "Rectangle Select" || action_name == "Scale" || action_name == "Merge Layer":
if action_name == "Draw" or action_name == "Rectangle Select" or action_name == "Scale" or action_name == "Merge Layer" or action_name == "Unlink Cel":
for c in _canvases:
if layer_index > -1:
c.update_texture(layer_index)