From 34bc528e978b953b2907906c665ae70c5f5cd744 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 2 Jun 2020 05:14:05 +0300 Subject: [PATCH] Added AnimationTag class Replaces nested Global.animation_tags arrays. Also replaced array.duplicate(true) with looping through the array and creating a new class for each array element, because duplicate(true) does not create new classes, unfortunately, which was causing issues with undo/redo. --- project.godot | 10 ++- src/Autoload/DrawingAlgos.gd | 6 +- src/Autoload/Global.gd | 24 +++--- src/Autoload/OpenSave.gd | 10 +-- src/Classes/AnimationTag.gd | 15 ++++ src/{ => Classes}/Cel.gd | 3 +- src/{ => Classes}/Drawers.gd | 0 src/{ => Classes}/Layer.gd | 3 +- src/UI/Dialogs/ExportDialog.gd | 10 +-- src/UI/Timeline/AnimationTimeline.gd | 73 ++++++++++++------- src/UI/Timeline/AnimationTimeline.tscn | 2 +- src/UI/Timeline/CelButton.gd | 22 +++--- .../{Dialogs => Timeline}/FrameTagDialog.gd | 37 ++++++---- .../{Dialogs => Timeline}/FrameTagDialog.tscn | 2 +- 14 files changed, 134 insertions(+), 83 deletions(-) create mode 100644 src/Classes/AnimationTag.gd rename src/{ => Classes}/Cel.gd (91%) rename src/{ => Classes}/Drawers.gd (100%) rename src/{ => Classes}/Layer.gd (93%) rename src/UI/{Dialogs => Timeline}/FrameTagDialog.gd (78%) rename src/UI/{Dialogs => Timeline}/FrameTagDialog.tscn (98%) diff --git a/project.godot b/project.godot index d04047e3f..97cebc2f2 100644 --- a/project.godot +++ b/project.godot @@ -9,6 +9,11 @@ config_version=4 _global_script_classes=[ { +"base": "Reference", +"class": "AnimationTag", +"language": "GDScript", +"path": "res://src/Classes/AnimationTag.gd" +}, { "base": "Node2D", "class": "Canvas", "language": "GDScript", @@ -17,7 +22,7 @@ _global_script_classes=[ { "base": "Reference", "class": "Cel", "language": "GDScript", -"path": "res://src/Cel.gd" +"path": "res://src/Classes/Cel.gd" }, { "base": "Line2D", "class": "Guide", @@ -27,7 +32,7 @@ _global_script_classes=[ { "base": "Reference", "class": "Layer", "language": "GDScript", -"path": "res://src/Layer.gd" +"path": "res://src/Classes/Layer.gd" }, { "base": "Button", "class": "LayerButton", @@ -45,6 +50,7 @@ _global_script_classes=[ { "path": "res://src/Palette/PaletteColor.gd" } ] _global_script_class_icons={ +"AnimationTag": "", "Canvas": "", "Cel": "", "Guide": "", diff --git a/src/Autoload/DrawingAlgos.gd b/src/Autoload/DrawingAlgos.gd index b51cded9c..ad9332871 100644 --- a/src/Autoload/DrawingAlgos.gd +++ b/src/Autoload/DrawingAlgos.gd @@ -1,9 +1,9 @@ extends Node -const Drawer = preload("res://src/Drawers.gd").Drawer -const SimpleDrawer = preload("res://src/Drawers.gd").SimpleDrawer -const PixelPerfectDrawer = preload("res://src/Drawers.gd").PixelPerfectDrawer +const Drawer = preload("res://src/Classes/Drawers.gd").Drawer +const SimpleDrawer = preload("res://src/Classes/Drawers.gd").SimpleDrawer +const PixelPerfectDrawer = preload("res://src/Classes/Drawers.gd").PixelPerfectDrawer var pixel_perfect_drawer := PixelPerfectDrawer.new() var pixel_perfect_drawer_h_mirror := PixelPerfectDrawer.new() diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index f51d89265..afac91742 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -53,7 +53,7 @@ var right_cursor_tool_texture : ImageTexture var selected_pixels := [] var image_clipboard : Image -var animation_tags := [] setget animation_tags_changed # [Name, Color, From, To] +var animation_tags := [] setget animation_tags_changed var play_only_tags := true var theme_type : int = Theme_Types.DARK @@ -512,9 +512,9 @@ func canvases_changed(value : Array) -> void: animation_timeline.last_frame = canvases.size() - 1 if play_only_tags: for tag in animation_tags: - if current_frame + 1 >= tag[2] && current_frame + 1 <= tag[3]: - animation_timeline.first_frame = tag[2] - 1 - animation_timeline.last_frame = min(canvases.size() - 1, tag[3] - 1) + if current_frame + 1 >= tag.from && current_frame + 1 <= tag.to: + animation_timeline.first_frame = tag.from - 1 + animation_timeline.last_frame = min(canvases.size() - 1, tag.to - 1) func clear_canvases() -> void: @@ -704,13 +704,13 @@ func animation_tags_changed(value : Array) -> void: tag_container.add_child(tag_c) var tag_position := tag_container.get_child_count() - 1 tag_container.move_child(tag_c, tag_position) - tag_c.get_node("Label").text = tag[0] - tag_c.get_node("Label").modulate = tag[1] - tag_c.get_node("Line2D").default_color = tag[1] + tag_c.get_node("Label").text = tag.name + tag_c.get_node("Label").modulate = tag.color + tag_c.get_node("Line2D").default_color = tag.color - tag_c.rect_position.x = (tag[2] - 1) * 39 + tag[2] + tag_c.rect_position.x = (tag.from - 1) * 39 + tag.from - var size : int = tag[3] - tag[2] + var size : int = tag.to - tag.from tag_c.rect_min_size.x = (size + 1) * 39 tag_c.get_node("Line2D").points[2] = Vector2(tag_c.rect_min_size.x, 0) tag_c.get_node("Line2D").points[3] = Vector2(tag_c.rect_min_size.x, 32) @@ -722,9 +722,9 @@ func animation_tags_changed(value : Array) -> void: animation_timeline.last_frame = canvases.size() - 1 if play_only_tags: for tag in animation_tags: - if current_frame + 1 >= tag[2] && current_frame + 1 <= tag[3]: - animation_timeline.first_frame = tag[2] - 1 - animation_timeline.last_frame = min(canvases.size() - 1, tag[3] - 1) + if current_frame + 1 >= tag.from && current_frame + 1 <= tag.to: + animation_timeline.first_frame = tag.from - 1 + animation_timeline.last_frame = min(canvases.size() - 1, tag.to - 1) func update_hint_tooltips() -> void: diff --git a/src/Autoload/OpenSave.gd b/src/Autoload/OpenSave.gd index 51aec6041..3ccb6a729 100644 --- a/src/Autoload/OpenSave.gd +++ b/src/Autoload/OpenSave.gd @@ -158,7 +158,7 @@ func open_pxo_file(path : String, untitled_backup : bool = false) -> void: var tag_color : Color = file.get_var() var tag_from := file.get_8() var tag_to := file.get_8() - Global.animation_tags.append([tag_name, tag_color, tag_from, tag_to]) + Global.animation_tags.append(AnimationTag.new(tag_name, tag_color, tag_from, tag_to)) Global.animation_tags = Global.animation_tags # To execute animation_tags_changed() tag_line = file.get_line() @@ -239,10 +239,10 @@ func save_pxo_file(path : String, autosave : bool) -> void: # Store animation tags for tag in Global.animation_tags: file.store_line(".T/") - file.store_line(tag[0]) # Tag name - file.store_var(tag[1]) # Tag color - file.store_8(tag[2]) # Tag "from", the first frame - file.store_8(tag[3]) # Tag "to", the last frame + file.store_line(tag.name) + file.store_var(tag.color) + file.store_8(tag.from) + file.store_8(tag.to) file.store_line("END_FRAME_TAGS") file.close() diff --git a/src/Classes/AnimationTag.gd b/src/Classes/AnimationTag.gd new file mode 100644 index 000000000..e66c413a1 --- /dev/null +++ b/src/Classes/AnimationTag.gd @@ -0,0 +1,15 @@ +class_name AnimationTag extends Reference +# A class for frame tag properties + + +var name : String +var color : Color +var from : int +var to : int + + +func _init(_name, _color, _from, _to) -> void: + name = _name + color = _color + from = _from + to = _to diff --git a/src/Cel.gd b/src/Classes/Cel.gd similarity index 91% rename from src/Cel.gd rename to src/Classes/Cel.gd index ba0162f63..da1fe80f1 100644 --- a/src/Cel.gd +++ b/src/Classes/Cel.gd @@ -1,5 +1,4 @@ -class_name Cel -extends Reference +class_name Cel extends Reference # A class for cel properties diff --git a/src/Drawers.gd b/src/Classes/Drawers.gd similarity index 100% rename from src/Drawers.gd rename to src/Classes/Drawers.gd diff --git a/src/Layer.gd b/src/Classes/Layer.gd similarity index 93% rename from src/Layer.gd rename to src/Classes/Layer.gd index d5cf9df10..da8d20a3d 100644 --- a/src/Layer.gd +++ b/src/Classes/Layer.gd @@ -1,5 +1,4 @@ -class_name Layer -extends Reference +class_name Layer extends Reference # A class for layer properties diff --git a/src/UI/Dialogs/ExportDialog.gd b/src/UI/Dialogs/ExportDialog.gd index 1ee012584..f8c3117c2 100644 --- a/src/UI/Dialogs/ExportDialog.gd +++ b/src/UI/Dialogs/ExportDialog.gd @@ -147,8 +147,8 @@ func process_spritesheet() -> void: # Range of frames determined by tags var frames := [] if frame_current_tag > 0: - var frame_start = Global.animation_tags[frame_current_tag - 1][2] - var frame_end = Global.animation_tags[frame_current_tag - 1][3] + var frame_start = Global.animation_tags[frame_current_tag - 1].from + var frame_end = Global.animation_tags[frame_current_tag - 1].to frames = Global.canvases.slice(frame_start-1, frame_end-1, 1, true) else: frames = Global.canvases @@ -283,8 +283,8 @@ func get_proccessed_image_animation_tag_and_start_id(processed_image_id : int) - for animation_tag in Global.animation_tags: # Check if processed image is in frame tag and assign frame tag and start id if yes # Then stop - if (processed_image_id + 1) >= animation_tag[2] and (processed_image_id + 1) <= animation_tag[3]: - result_animation_tag_and_start_id = [animation_tag[0], animation_tag[2]] + if (processed_image_id + 1) >= animation_tag.from and (processed_image_id + 1) <= animation_tag.to: + result_animation_tag_and_start_id = [animation_tag.name, animation_tag.from] break return result_animation_tag_and_start_id @@ -454,7 +454,7 @@ func create_frame_tag_list() -> void: # Repopulate list with current tag list for item in Global.animation_tags: - frame_container.add_item(item[0]) + frame_container.add_item(item.name) func store_export_settings() -> void: diff --git a/src/UI/Timeline/AnimationTimeline.gd b/src/UI/Timeline/AnimationTimeline.gd index edc56690a..b20abf4f6 100644 --- a/src/UI/Timeline/AnimationTimeline.gd +++ b/src/UI/Timeline/AnimationTimeline.gd @@ -67,22 +67,33 @@ func _on_DeleteFrame_pressed(frame := -1) -> void: if current_frame > 0 && current_frame == new_canvases.size(): # If it's the last frame current_frame -= 1 - var new_animation_tags := Global.animation_tags.duplicate(true) + var new_animation_tags := Global.animation_tags.duplicate() + # Loop through the tags to create new classes for them, so that they won't be the same + # as Global.animation_tags's classes. Needed for undo/redo to work properly. + for i in new_animation_tags.size(): + new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to) + # Loop through the tags to see if the frame is in one for tag in new_animation_tags: - 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 frame + 1 >= tag.from && frame + 1 <= tag.to: + if tag.from == tag.to: # If we're deleting the only frame in the tag new_animation_tags.erase(tag) else: - tag[3] -= 1 - elif frame + 1 < tag[2]: - tag[2] -= 1 - tag[3] -= 1 + tag.to -= 1 + elif frame + 1 < tag.from: + tag.from -= 1 + tag.to -= 1 # Check if one of the cels of the frame is linked # if they are, unlink them too # this prevents removed cels being kept in linked memory - var new_layers : Array = Global.layers.duplicate(true) + var new_layers : Array = Global.layers.duplicate() + # Loop through the array to create new classes for each element, so that they + # won't be the same as the original array's classes. Needed for undo/redo to work properly. + for i in new_layers.size(): + var new_linked_cels = new_layers[i].linked_cels.duplicate() + new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels) + for layer in new_layers: for linked in layer.linked_cels: if linked == Global.canvases[frame]: @@ -134,11 +145,16 @@ func _on_CopyFrame_pressed(frame := -1) -> void: sprite.lock() new_canvas.layers.append(Cel.new(sprite, layer.opacity)) - var new_animation_tags := Global.animation_tags.duplicate(true) + var new_animation_tags := Global.animation_tags.duplicate() + # Loop through the tags to create new classes for them, so that they won't be the same + # as Global.animation_tags's classes. Needed for undo/redo to work properly. + for i in new_animation_tags.size(): + new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to) + # Loop through the tags to see if the frame is in one for tag in new_animation_tags: - if frame + 1 >= tag[2] && frame + 1 <= tag[3]: - tag[3] += 1 + if frame + 1 >= tag.from && frame + 1 <= tag.to: + tag.to += 1 Global.undos += 1 Global.undo_redo.create_action("Add Frame") @@ -263,9 +279,9 @@ func play_animation(play : bool, forward_dir : bool) -> void: last_frame = Global.canvases.size() - 1 if Global.play_only_tags: for tag in Global.animation_tags: - if Global.current_frame + 1 >= tag[2] && Global.current_frame + 1 <= tag[3]: - first_frame = tag[2] - 1 - last_frame = min(Global.canvases.size() - 1, tag[3] - 1) + if Global.current_frame + 1 >= tag.from && Global.current_frame + 1 <= tag.to: + first_frame = tag.from - 1 + last_frame = min(Global.canvases.size() - 1, tag.to - 1) if first_frame == last_frame: if forward_dir: @@ -400,11 +416,11 @@ func change_layer_order(rate : int) -> void: new_layers[change] = temp Global.undo_redo.create_action("Change Layer Order") for c in Global.canvases: - var new_layers_canvas : Array = c.layers.duplicate() - var temp_canvas = new_layers_canvas[Global.current_layer] - new_layers_canvas[Global.current_layer] = new_layers_canvas[change] - new_layers_canvas[change] = temp_canvas - Global.undo_redo.add_do_property(c, "layers", new_layers_canvas) + var new_canvas_layers : Array = c.layers.duplicate() + var temp_canvas = new_canvas_layers[Global.current_layer] + new_canvas_layers[Global.current_layer] = new_canvas_layers[change] + new_canvas_layers[change] = temp_canvas + Global.undo_redo.add_do_property(c, "layers", new_canvas_layers) Global.undo_redo.add_undo_property(c, "layers", c.layers) Global.undo_redo.add_do_property(Global, "current_layer", change) @@ -418,14 +434,21 @@ func change_layer_order(rate : int) -> void: func _on_MergeDownLayer_pressed() -> void: - var new_layers : Array = Global.layers.duplicate(true) + var new_layers : Array = Global.layers.duplicate() + # Loop through the array to create new classes for each element, so that they + # won't be the same as the original array's classes. Needed for undo/redo to work properly. + for i in new_layers.size(): + var new_linked_cels = new_layers[i].linked_cels.duplicate() + new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels) Global.undos += 1 Global.undo_redo.create_action("Merge Layer") for c in Global.canvases: - var new_layers_canvas : Array = c.layers.duplicate(true) + var new_canvas_layers : Array = c.layers.duplicate() + for i in new_canvas_layers.size(): + new_canvas_layers[i] = Cel.new(new_canvas_layers[i].image, new_canvas_layers[i].opacity) var selected_layer := Image.new() - selected_layer.copy_from(new_layers_canvas[Global.current_layer].image) + selected_layer.copy_from(new_canvas_layers[Global.current_layer].image) selected_layer.lock() if c.layers[Global.current_layer].opacity < 1: # If we have layer transparency @@ -439,15 +462,15 @@ func _on_MergeDownLayer_pressed() -> void: new_layer.copy_from(c.layers[Global.current_layer - 1].image) new_layer.lock() DrawingAlgos.blend_rect(new_layer, selected_layer, Rect2(c.position, c.size), Vector2.ZERO) - new_layers_canvas.remove(Global.current_layer) + new_canvas_layers.remove(Global.current_layer) if !selected_layer.is_invisible() and Global.layers[Global.current_layer - 1].linked_cels.size() > 1 and (c in Global.layers[Global.current_layer - 1].linked_cels): new_layers[Global.current_layer - 1].linked_cels.erase(c) - new_layers_canvas[Global.current_layer - 1].image = new_layer + new_canvas_layers[Global.current_layer - 1].image = new_layer else: Global.undo_redo.add_do_property(c.layers[Global.current_layer - 1].image, "data", new_layer.data) Global.undo_redo.add_undo_property(c.layers[Global.current_layer - 1].image, "data", c.layers[Global.current_layer - 1].image.data) - Global.undo_redo.add_do_property(c, "layers", new_layers_canvas) + Global.undo_redo.add_do_property(c, "layers", new_canvas_layers) Global.undo_redo.add_undo_property(c, "layers", c.layers) new_layers.remove(Global.current_layer) diff --git a/src/UI/Timeline/AnimationTimeline.tscn b/src/UI/Timeline/AnimationTimeline.tscn index e3536993c..3d3f1e63a 100644 --- a/src/UI/Timeline/AnimationTimeline.tscn +++ b/src/UI/Timeline/AnimationTimeline.tscn @@ -22,7 +22,7 @@ [ext_resource path="res://assets/graphics/dark_themes/timeline/onion_skinning_off.png" type="Texture" id=29] [ext_resource path="res://assets/graphics/dark_themes/timeline/expandable.png" type="Texture" id=30] [ext_resource path="res://assets/graphics/dark_themes/timeline/loop.png" type="Texture" id=31] -[ext_resource path="res://src/UI/Dialogs/FrameTagDialog.tscn" type="PackedScene" id=42] +[ext_resource path="res://src/UI/Timeline/FrameTagDialog.tscn" type="PackedScene" id=42] [sub_resource type="StyleBoxFlat" id=1] bg_color = Color( 0.0627451, 0.0627451, 0.0627451, 1 ) diff --git a/src/UI/Timeline/CelButton.gd b/src/UI/Timeline/CelButton.gd index 22c5c65b7..bc75b9fb5 100644 --- a/src/UI/Timeline/CelButton.gd +++ b/src/UI/Timeline/CelButton.gd @@ -55,18 +55,22 @@ func _on_PopupMenu_id_pressed(ID : int) -> void: 4: # Unlink Cel var cel_index : int = Global.layers[layer].linked_cels.find(Global.canvases[frame]) var c = Global.canvases[frame] - var new_layers : Array = Global.layers.duplicate(true) - var new_canvas_layers : Array = c.layers.duplicate(true) + var new_layers : Array = Global.layers.duplicate() + # Loop through the array to create new classes for each element, so that they + # won't be the same as the original array's classes. Needed for undo/redo to work properly. + for i in new_layers.size(): + var new_linked_cels = new_layers[i].linked_cels.duplicate() + new_layers[i] = Layer.new(new_layers[i].name, new_layers[i].visible, new_layers[i].locked, new_layers[i].frame_container, new_layers[i].new_cels_linked, new_linked_cels) + var new_canvas_layers : Array = c.layers.duplicate() + for i in new_canvas_layers.size(): + new_canvas_layers[i] = Cel.new(new_canvas_layers[i].image, new_canvas_layers[i].opacity) if popup_menu.get_item_metadata(4) == "Unlink Cel": new_layers[layer].linked_cels.remove(cel_index) var sprite := Image.new() - sprite.copy_from(Global.canvases[frame].layers[layer][0]) + sprite.copy_from(Global.canvases[frame].layers[layer].image) sprite.lock() - var tex := ImageTexture.new() - tex.create_from_image(sprite, 0) - new_canvas_layers[layer][0] = sprite - new_canvas_layers[layer][1] = tex + new_canvas_layers[layer].image = sprite Global.undo_redo.create_action("Unlink Cel") Global.undo_redo.add_do_property(Global, "layers", new_layers) @@ -84,8 +88,8 @@ func _on_PopupMenu_id_pressed(ID : int) -> void: if new_layers[layer].linked_cels.size() > 1: # If there are already linked cels, set the current cel's image # to the first linked cel's image - new_canvas_layers[layer][0] = new_layers[layer].linked_cels[0].layers[layer][0] - new_canvas_layers[layer][1] = new_layers[layer].linked_cels[0].layers[layer][1] + new_canvas_layers[layer].image = new_layers[layer].linked_cels[0].layers[layer].image + new_canvas_layers[layer].image_texture = new_layers[layer].linked_cels[0].layers[layer].image_texture Global.undo_redo.add_do_property(c, "layers", new_canvas_layers) Global.undo_redo.add_undo_property(c, "layers", c.layers) diff --git a/src/UI/Dialogs/FrameTagDialog.gd b/src/UI/Timeline/FrameTagDialog.gd similarity index 78% rename from src/UI/Dialogs/FrameTagDialog.gd rename to src/UI/Timeline/FrameTagDialog.gd index 331e1b04f..b3be07a6e 100644 --- a/src/UI/Dialogs/FrameTagDialog.gd +++ b/src/UI/Timeline/FrameTagDialog.gd @@ -25,10 +25,10 @@ func _on_FrameTagDialog_about_to_show() -> void: var vbox_cont := VBoxContainer.new() var hbox_cont := HBoxContainer.new() var tag_label := Label.new() - if tag[2] == tag[3]: - tag_label.text = "Tag %s (Frame %s)" % [i + 1, tag[2]] + if tag.from == tag.to: + tag_label.text = "Tag %s (Frame %s)" % [i + 1, tag.from] else: - tag_label.text = "Tag %s (Frames %s-%s)" % [i + 1, tag[2], tag[3]] + tag_label.text = "Tag %s (Frames %s-%s)" % [i + 1, tag.from, tag.to] hbox_cont.add_child(tag_label) var edit_button := Button.new() @@ -39,8 +39,8 @@ func _on_FrameTagDialog_about_to_show() -> void: vbox_cont.add_child(hbox_cont) var name_label := Label.new() - name_label.text = tag[0] - name_label.modulate = tag[1] + name_label.text = tag.name + name_label.modulate = tag.color vbox_cont.add_child(name_label) var hsep := HSeparator.new() @@ -70,10 +70,10 @@ func _on_AddTag_pressed() -> void: func _on_EditButton_pressed(_tag_id : int) -> void: options_dialog.popup_centered() current_tag_id = _tag_id - options_dialog.get_node("GridContainer/NameLineEdit").text = Global.animation_tags[_tag_id][0] - options_dialog.get_node("GridContainer/ColorPickerButton").color = Global.animation_tags[_tag_id][1] - options_dialog.get_node("GridContainer/FromSpinBox").value = Global.animation_tags[_tag_id][2] - options_dialog.get_node("GridContainer/ToSpinBox").value = Global.animation_tags[_tag_id][3] + options_dialog.get_node("GridContainer/NameLineEdit").text = Global.animation_tags[_tag_id].name + options_dialog.get_node("GridContainer/ColorPickerButton").color = Global.animation_tags[_tag_id].color + options_dialog.get_node("GridContainer/FromSpinBox").value = Global.animation_tags[_tag_id].from + options_dialog.get_node("GridContainer/ToSpinBox").value = Global.animation_tags[_tag_id].to if !delete_tag_button: delete_tag_button = options_dialog.add_button("Delete Tag", true, "delete_tag") else: @@ -92,14 +92,19 @@ func _on_TagOptions_confirmed() -> void: if tag_from > tag_to: tag_from = tag_to - var new_animation_tags := Global.animation_tags.duplicate(true) + var new_animation_tags := Global.animation_tags.duplicate() + # Loop through the tags to create new classes for them, so that they won't be the same + # as Global.animation_tags's classes. Needed for undo/redo to work properly. + for i in new_animation_tags.size(): + new_animation_tags[i] = AnimationTag.new(new_animation_tags[i].name, new_animation_tags[i].color, new_animation_tags[i].from, new_animation_tags[i].to) + if current_tag_id == Global.animation_tags.size(): - new_animation_tags.append([tag_name, tag_color, tag_from, tag_to]) + new_animation_tags.append(AnimationTag.new(tag_name, tag_color, tag_from, tag_to)) else: - new_animation_tags[current_tag_id][0] = tag_name - new_animation_tags[current_tag_id][1] = tag_color - new_animation_tags[current_tag_id][2] = tag_from - new_animation_tags[current_tag_id][3] = tag_to + new_animation_tags[current_tag_id].name = tag_name + new_animation_tags[current_tag_id].color = tag_color + new_animation_tags[current_tag_id].from = tag_from + new_animation_tags[current_tag_id].to = tag_to # Handle Undo/Redo Global.undos += 1 @@ -114,7 +119,7 @@ func _on_TagOptions_confirmed() -> void: func _on_TagOptions_custom_action(action : String) -> void: if action == "delete_tag": - var new_animation_tags := Global.animation_tags.duplicate(true) + var new_animation_tags := Global.animation_tags.duplicate() new_animation_tags.remove(current_tag_id) # Handle Undo/Redo Global.undos += 1 diff --git a/src/UI/Dialogs/FrameTagDialog.tscn b/src/UI/Timeline/FrameTagDialog.tscn similarity index 98% rename from src/UI/Dialogs/FrameTagDialog.tscn rename to src/UI/Timeline/FrameTagDialog.tscn index 1531bb738..c50b5bf37 100644 --- a/src/UI/Dialogs/FrameTagDialog.tscn +++ b/src/UI/Timeline/FrameTagDialog.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=3 format=2] -[ext_resource path="res://src/UI/Dialogs/FrameTagDialog.gd" type="Script" id=1] +[ext_resource path="res://src/UI/Timeline/FrameTagDialog.gd" type="Script" id=1] [ext_resource path="res://assets/graphics/dark_themes/timeline/new_frame.png" type="Texture" id=2] [node name="FrameTagDialog" type="AcceptDialog"]