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

Frame tags now work with UndoRedo

This commit is contained in:
OverloadedOrama 2020-04-20 00:09:48 +03:00
parent cb1b741b05
commit 06d19c8e48
3 changed files with 37 additions and 13 deletions

View file

@ -66,18 +66,18 @@ func _on_DeleteFrame_pressed(frame := -1) -> void:
if current_frame > 0 && current_frame == new_canvases.size(): # If it's the last frame if current_frame > 0 && current_frame == new_canvases.size(): # If it's the last frame
current_frame -= 1 current_frame -= 1
var new_animation_tags := Global.animation_tags.duplicate(true)
# Loop through the tags to see if the frame is in one # Loop through the tags to see if the frame is in one
for tag in Global.animation_tags: for tag in new_animation_tags:
if frame + 1 >= tag[2] && frame + 1 <= tag[3]: if frame + 1 >= tag[2] && frame + 1 <= tag[3]:
if tag[3] == tag[2]: # If we're deleting the only frame in the tag if tag[3] == tag[2]: # If we're deleting the only frame in the tag
Global.animation_tags.erase(tag) new_animation_tags.erase(tag)
else: else:
tag[3] -= 1 tag[3] -= 1
elif frame + 1 < tag[2]: elif frame + 1 < tag[2]:
tag[2] -= 1 tag[2] -= 1
tag[3] -= 1 tag[3] -= 1
Global.animation_tags = Global.animation_tags # To execute animation_tags_changed()
Global.undos += 1 Global.undos += 1
Global.undo_redo.create_action("Remove Frame") Global.undo_redo.create_action("Remove Frame")
@ -85,15 +85,18 @@ func _on_DeleteFrame_pressed(frame := -1) -> void:
Global.undo_redo.add_do_property(Global, "canvases", new_canvases) Global.undo_redo.add_do_property(Global, "canvases", new_canvases)
Global.undo_redo.add_do_property(Global, "canvas", new_canvases[current_frame]) Global.undo_redo.add_do_property(Global, "canvas", new_canvases[current_frame])
Global.undo_redo.add_do_property(Global, "current_frame", current_frame) Global.undo_redo.add_do_property(Global, "current_frame", current_frame)
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
for i in range(frame, new_canvases.size()): for i in range(frame, new_canvases.size()):
var c : Canvas = new_canvases[i] var c : Canvas = new_canvases[i]
Global.undo_redo.add_do_property(c, "frame", i) Global.undo_redo.add_do_property(c, "frame", i)
Global.undo_redo.add_undo_property(c, "frame", c.frame) Global.undo_redo.add_undo_property(c, "frame", c.frame)
Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases) Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases)
Global.undo_redo.add_undo_property(Global, "canvas", canvas) Global.undo_redo.add_undo_property(Global, "canvas", canvas)
Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame) Global.undo_redo.add_undo_property(Global, "current_frame", Global.current_frame)
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
Global.undo_redo.add_do_method(Global, "redo", [canvas]) Global.undo_redo.add_do_method(Global, "redo", [canvas])
Global.undo_redo.add_undo_method(Global, "undo", [canvas]) Global.undo_redo.add_undo_method(Global, "undo", [canvas])
@ -120,11 +123,11 @@ func _on_CopyFrame_pressed(frame := -1) -> void:
tex.create_from_image(sprite, 0) tex.create_from_image(sprite, 0)
new_canvas.layers.append([sprite, tex, layer[2]]) new_canvas.layers.append([sprite, tex, layer[2]])
var new_animation_tags := Global.animation_tags.duplicate(true)
# Loop through the tags to see if the frame is in one # Loop through the tags to see if the frame is in one
for tag in Global.animation_tags: for tag in new_animation_tags:
if frame + 1 >= tag[2] && frame + 1 <= tag[3]: if frame + 1 >= tag[2] && frame + 1 <= tag[3]:
tag[3] += 1 tag[3] += 1
Global.animation_tags = Global.animation_tags # To execute animation_tags_changed()
Global.undos += 1 Global.undos += 1
Global.undo_redo.create_action("Add Frame") Global.undo_redo.create_action("Add Frame")
@ -134,6 +137,7 @@ func _on_CopyFrame_pressed(frame := -1) -> void:
Global.undo_redo.add_do_property(Global, "canvases", new_canvases) Global.undo_redo.add_do_property(Global, "canvases", new_canvases)
Global.undo_redo.add_do_property(Global, "canvas", new_canvas) Global.undo_redo.add_do_property(Global, "canvas", new_canvas)
Global.undo_redo.add_do_property(Global, "current_frame", frame + 1) Global.undo_redo.add_do_property(Global, "current_frame", frame + 1)
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
for i in range(Global.layers.size()): for i in range(Global.layers.size()):
for child in Global.layers[i][3].get_children(): for child in Global.layers[i][3].get_children():
Global.undo_redo.add_do_property(child, "pressed", false) Global.undo_redo.add_do_property(child, "pressed", false)
@ -150,6 +154,7 @@ func _on_CopyFrame_pressed(frame := -1) -> void:
Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases) Global.undo_redo.add_undo_property(Global, "canvases", Global.canvases)
Global.undo_redo.add_undo_property(Global, "canvas", Global.canvas) Global.undo_redo.add_undo_property(Global, "canvas", Global.canvas)
Global.undo_redo.add_undo_property(Global, "current_frame", frame) Global.undo_redo.add_undo_property(Global, "current_frame", frame)
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
Global.undo_redo.commit_action() Global.undo_redo.commit_action()

View file

@ -88,21 +88,39 @@ func _on_TagOptions_confirmed() -> void:
if tag_from > tag_to: if tag_from > tag_to:
tag_from = tag_to tag_from = tag_to
var new_animation_tags := Global.animation_tags.duplicate(true)
if current_tag_id == Global.animation_tags.size(): if current_tag_id == Global.animation_tags.size():
Global.animation_tags.append([tag_name, tag_color, tag_from, tag_to]) new_animation_tags.append([tag_name, tag_color, tag_from, tag_to])
Global.animation_tags = Global.animation_tags # To execute animation_tags_changed()
else: else:
Global.animation_tags[current_tag_id][0] = tag_name new_animation_tags[current_tag_id][0] = tag_name
Global.animation_tags[current_tag_id][1] = tag_color new_animation_tags[current_tag_id][1] = tag_color
Global.animation_tags[current_tag_id][2] = tag_from new_animation_tags[current_tag_id][2] = tag_from
Global.animation_tags[current_tag_id][3] = tag_to new_animation_tags[current_tag_id][3] = tag_to
# Handle Undo/Redo
Global.undos += 1
Global.undo_redo.create_action("Modify Frame Tag")
Global.undo_redo.add_do_method(Global, "general_redo")
Global.undo_redo.add_undo_method(Global, "general_undo")
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
Global.undo_redo.commit_action()
_on_FrameTagDialog_about_to_show() _on_FrameTagDialog_about_to_show()
func _on_TagOptions_custom_action(action : String) -> void: func _on_TagOptions_custom_action(action : String) -> void:
if action == "delete_tag": if action == "delete_tag":
Global.animation_tags.remove(current_tag_id) var new_animation_tags := Global.animation_tags.duplicate(true)
Global.animation_tags = Global.animation_tags # To execute animation_tags_changed() new_animation_tags.remove(current_tag_id)
# Handle Undo/Redo
Global.undos += 1
Global.undo_redo.create_action("Delete Frame Tag")
Global.undo_redo.add_do_method(Global, "general_redo")
Global.undo_redo.add_undo_method(Global, "general_undo")
Global.undo_redo.add_do_property(Global, "animation_tags", new_animation_tags)
Global.undo_redo.add_undo_property(Global, "animation_tags", Global.animation_tags)
Global.undo_redo.commit_action()
options_dialog.hide() options_dialog.hide()
_on_FrameTagDialog_about_to_show() _on_FrameTagDialog_about_to_show()

View file

@ -431,6 +431,7 @@ func find_node_by_name(root, node_name) -> Node:
return found return found
return null return null
func notification_label(text : String) -> void: func notification_label(text : String) -> void:
var notification : Label = load("res://Prefabs/NotificationLabel.tscn").instance() var notification : Label = load("res://Prefabs/NotificationLabel.tscn").instance()
notification.text = tr(text) notification.text = tr(text)