diff --git a/Scripts/AnimationTimeline.gd b/Scripts/AnimationTimeline.gd index caa0f80a6..cf3a8ba02 100644 --- a/Scripts/AnimationTimeline.gd +++ b/Scripts/AnimationTimeline.gd @@ -154,8 +154,6 @@ func add_layer(is_new := true) -> void: Global.undos += 1 Global.undo_redo.create_action("Add Layer") - Global.undo_redo.add_do_property(Global, "current_layer", Global.current_layer + 1) - Global.undo_redo.add_do_property(Global, "layers", new_layers) for c in Global.canvases: var new_layer := Image.new() @@ -174,6 +172,8 @@ func add_layer(is_new := true) -> void: 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", Global.current_layer + 1) + Global.undo_redo.add_do_property(Global, "layers", new_layers) Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer) Global.undo_redo.add_undo_property(Global, "layers", Global.layers) @@ -187,7 +187,6 @@ func _on_RemoveLayer_pressed() -> void: Global.undos += 1 Global.undo_redo.create_action("Remove Layer") Global.undo_redo.add_do_property(Global, "current_layer", Global.current_layer - 1) - Global.undo_redo.add_do_property(Global, "layers", new_layers) for c in Global.canvases: var new_canvas_layers : Array = c.layers.duplicate() @@ -195,6 +194,7 @@ func _on_RemoveLayer_pressed() -> void: 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, "layers", new_layers) Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer) Global.undo_redo.add_undo_property(Global, "layers", Global.layers) Global.undo_redo.add_do_method(Global, "redo", [Global.canvas]) @@ -202,17 +202,25 @@ func _on_RemoveLayer_pressed() -> void: Global.undo_redo.commit_action() func change_layer_order(rate : int) -> void: - var change = Global.canvas.current_layer_index + rate + var change = Global.current_layer + rate - var new_layers : Array = Global.canvas.layers.duplicate() - var temp = new_layers[Global.canvas.current_layer_index] - new_layers[Global.canvas.current_layer_index] = new_layers[change] + var new_layers : Array = Global.layers.duplicate() + var temp = new_layers[Global.current_layer] + new_layers[Global.current_layer] = new_layers[change] new_layers[change] = temp Global.undo_redo.create_action("Change Layer Order") - Global.undo_redo.add_do_property(Global.canvas, "layers", new_layers) - Global.undo_redo.add_do_property(Global.canvas, "current_layer_index", change) - Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers) - Global.undo_redo.add_undo_property(Global.canvas, "current_layer_index", Global.canvas.current_layer_index) + 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) + Global.undo_redo.add_undo_property(c, "layers", c.layers) + + Global.undo_redo.add_do_property(Global, "current_layer", change) + Global.undo_redo.add_do_property(Global, "layers", new_layers) + Global.undo_redo.add_undo_property(Global, "layers", Global.layers) + Global.undo_redo.add_undo_property(Global, "current_layer", Global.current_layer) Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas]) Global.undo_redo.add_do_method(Global, "redo", [Global.canvas]) @@ -220,17 +228,17 @@ func change_layer_order(rate : int) -> void: func _on_MergeDownLayer_pressed() -> void: var new_layers : Array = Global.canvas.layers.duplicate() - new_layers.remove(Global.canvas.current_layer_index) - var selected_layer = Global.canvas.layers[Global.canvas.current_layer_index][0] - if Global.canvas.layers[Global.canvas.current_layer_index][4] < 1: # If we have layer transparency + new_layers.remove(Global.current_layer) + var selected_layer = Global.canvas.layers[Global.current_layer][0] + if Global.canvas.layers[Global.current_layer][2] < 1: # If we have layer transparency for xx in selected_layer.get_size().x: for yy in selected_layer.get_size().y: var pixel_color : Color = selected_layer.get_pixel(xx, yy) - var alpha : float = pixel_color.a * Global.canvas.layers[Global.canvas.current_layer_index][4] + var alpha : float = pixel_color.a * Global.canvas.layers[Global.current_layer][4] selected_layer.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha)) var new_layer := Image.new() - new_layer.copy_from(Global.canvas.layers[Global.canvas.current_layer_index - 1][0]) + new_layer.copy_from(Global.canvas.layers[Global.current_layer - 1][0]) new_layer.lock() Global.canvas.blend_rect(new_layer, selected_layer, Rect2(Global.canvas.position, Global.canvas.size), Vector2.ZERO) @@ -238,9 +246,9 @@ func _on_MergeDownLayer_pressed() -> void: Global.undos += 1 Global.undo_redo.create_action("Merge Layer") Global.undo_redo.add_do_property(Global.canvas, "layers", new_layers) - Global.undo_redo.add_do_property(Global.canvas.layers[Global.canvas.current_layer_index - 1][0], "data", new_layer.data) + Global.undo_redo.add_do_property(Global.canvas.layers[Global.current_layer - 1][0], "data", new_layer.data) Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers) - Global.undo_redo.add_undo_property(Global.canvas.layers[Global.canvas.current_layer_index - 1][0], "data", Global.canvas.layers[Global.canvas.current_layer_index - 1][0].data) + Global.undo_redo.add_undo_property(Global.canvas.layers[Global.current_layer - 1][0], "data", Global.canvas.layers[Global.current_layer - 1][0].data) Global.undo_redo.add_undo_method(Global, "undo", [Global.canvas]) Global.undo_redo.add_do_method(Global, "redo", [Global.canvas]) diff --git a/Scripts/Canvas.gd b/Scripts/Canvas.gd index 1dd79d455..f8c2c797f 100644 --- a/Scripts/Canvas.gd +++ b/Scripts/Canvas.gd @@ -51,7 +51,7 @@ func _ready() -> void: var tex := ImageTexture.new() tex.create_from_image(sprite, 0) - # Store [Image, ImageTexture, Layer Name, Opacity] + # Store [Image, ImageTexture, Opacity] layers.append([sprite, tex, 1]) var frame_button = load("res://Prefabs/FrameButton.tscn").instance() diff --git a/Scripts/Global.gd b/Scripts/Global.gd index 829598390..ec92a695d 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -15,7 +15,7 @@ var saved := true # Checks if the user has saved # Canvas related stuff var layers := [] setget layers_changed var current_frame := 0 setget frame_changed -var current_layer := 0 +var current_layer := 0 setget layer_changed # warning-ignore:unused_class_variable var can_draw := false # warning-ignore:unused_class_variable @@ -410,13 +410,6 @@ func undo(_canvases : Array, layer_index : int = -1) -> void: if action_name == "Scale": c.camera_zoom() -# if "Layer" in action_name: -# var current_layer_index : int = _canvases[0].current_layer_index -# _canvases[0].generate_layer_panels() -# if action_name == "Change Layer Order": -# _canvases[0].current_layer_index = current_layer_index -# _canvases[0].get_layer_container(current_layer_index).changed_selection() - if action_name == "Add Frame": canvas_parent.remove_child(_canvases[0]) frames_container.remove_child(_canvases[0].frame_button) @@ -455,41 +448,6 @@ func redo(_canvases : Array, layer_index : int = -1) -> void: if action_name == "Scale": c.camera_zoom() -# if action_name == "Add Layer": -# var layer_container = load("res://Prefabs/LayerContainer.tscn").instance() -# layers[current_layer][0] = tr("Layer") + " %s" % current_layer -# layer_container.i = current_layer -# layer_container.get_child(0).get_child(1).text = layers[current_layer][0] -# layer_container.get_child(0).get_child(2).text = layers[current_layer][0] -# layers_container.add_child(layer_container) -# layers_container.move_child(layer_container, 0) -# -# frames_container.add_child(layers[current_layer][2]) -# frames_container.move_child(layers[current_layer][2], 0) -# for i in range(canvases.size()): -# var frame_button = load("res://Prefabs/FrameButton.tscn").instance() -# frame_button.frame = i -# frame_button.layer = current_layer -# frame_button.pressed = true -# -# layers[current_layer][2].add_child(frame_button) -# -# remove_layer_button.disabled = false -# remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND -# -# if action_name == "Remove Layer": -# var layer_container_child_index = (layers_container.get_child_count() - 1) - layer_index -# layers_container.remove_child(layers_container.get_child(layer_container_child_index)) -# print(layer_index, layers[layer_index][2]) -# frames_container.remove_child(layers[layer_index][2]) -# if layers.size() == 2: # Actually 1, but it hasn't been updated yet -# remove_layer_button.disabled = true -# remove_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN - -# if action_name == "Change Layer Order": -# var current_layer_index : int = _canvases[0].current_layer_index -# _canvases[0].current_layer_index = current_layer_index -# _canvases[0].get_layer_container(current_layer_index).changed_selection() if action_name == "Add Frame": canvas_parent.add_child(_canvases[0]) @@ -551,6 +509,7 @@ func layers_changed(value : Array) -> void: frame_button.frame = j frame_button.layer = i frame_button.pressed = true + frame_button.get_child(0).texture = Global.canvases[j].layers[i][1] layers[i][2].add_child(frame_button) @@ -583,6 +542,27 @@ func frame_changed(value : int) -> void: #canvas.frame_button.pressed = true #canvas.frame_button.get_node("FrameID").add_color_override("font_color", Color("#3c5d75")) +func layer_changed(value : int) -> void: + current_layer = value + layer_opacity_slider.value = canvas.layers[current_layer][2] * 100 + layer_opacity_spinbox.value = canvas.layers[current_layer][2] * 100 + if current_layer < layers.size() - 1: + move_up_layer_button.disabled = false + move_up_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + else: + move_up_layer_button.disabled = true + move_up_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN + + if current_layer > 0: + move_down_layer_button.disabled = false + move_down_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + merge_down_layer_button.disabled = false + merge_down_layer_button.mouse_default_cursor_shape = Control.CURSOR_POINTING_HAND + else: + move_down_layer_button.disabled = true + move_down_layer_button.mouse_default_cursor_shape = Control.CURSOR_FORBIDDEN + merge_down_layer_button.disabled = true + func create_brush_button(brush_img : Image, brush_type := Brush_Types.CUSTOM, hint_tooltip := "") -> void: var brush_container var brush_button = load("res://Prefabs/BrushButton.tscn").instance() diff --git a/Scripts/LayerContainer.gd b/Scripts/LayerContainer.gd index d1e5cf197..b78cab5cd 100644 --- a/Scripts/LayerContainer.gd +++ b/Scripts/LayerContainer.gd @@ -47,7 +47,6 @@ func changed_selection() -> void: var parent := get_parent() for child in parent.get_children(): if child is Button: - #print(child.name) child.label.visible = true child.line_edit.visible = false child.line_edit.editable = false