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

Changing layer order works again

Started using a setter method for Global.current_layer
This commit is contained in:
OverloadedOrama 2020-03-01 00:57:47 +02:00
parent 18356d4408
commit 4e31c1ed4b
4 changed files with 50 additions and 63 deletions

View file

@ -154,8 +154,6 @@ func add_layer(is_new := true) -> void:
Global.undos += 1 Global.undos += 1
Global.undo_redo.create_action("Add Layer") 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: for c in Global.canvases:
var new_layer := Image.new() 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_do_property(c, "layers", new_canvas_layers)
Global.undo_redo.add_undo_property(c, "layers", c.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, "current_layer", Global.current_layer)
Global.undo_redo.add_undo_property(Global, "layers", Global.layers) Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
@ -187,7 +187,6 @@ func _on_RemoveLayer_pressed() -> void:
Global.undos += 1 Global.undos += 1
Global.undo_redo.create_action("Remove Layer") 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, "current_layer", Global.current_layer - 1)
Global.undo_redo.add_do_property(Global, "layers", new_layers)
for c in Global.canvases: for c in Global.canvases:
var new_canvas_layers : Array = c.layers.duplicate() 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_do_property(c, "layers", new_canvas_layers)
Global.undo_redo.add_undo_property(c, "layers", c.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, "current_layer", Global.current_layer)
Global.undo_redo.add_undo_property(Global, "layers", Global.layers) Global.undo_redo.add_undo_property(Global, "layers", Global.layers)
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas]) Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])
@ -202,17 +202,25 @@ func _on_RemoveLayer_pressed() -> void:
Global.undo_redo.commit_action() Global.undo_redo.commit_action()
func change_layer_order(rate : int) -> void: 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 new_layers : Array = Global.layers.duplicate()
var temp = new_layers[Global.canvas.current_layer_index] var temp = new_layers[Global.current_layer]
new_layers[Global.canvas.current_layer_index] = new_layers[change] new_layers[Global.current_layer] = new_layers[change]
new_layers[change] = temp new_layers[change] = temp
Global.undo_redo.create_action("Change Layer Order") Global.undo_redo.create_action("Change Layer Order")
Global.undo_redo.add_do_property(Global.canvas, "layers", new_layers) for c in Global.canvases:
Global.undo_redo.add_do_property(Global.canvas, "current_layer_index", change) var new_layers_canvas : Array = c.layers.duplicate()
Global.undo_redo.add_undo_property(Global.canvas, "layers", Global.canvas.layers) var temp_canvas = new_layers_canvas[Global.current_layer]
Global.undo_redo.add_undo_property(Global.canvas, "current_layer_index", Global.canvas.current_layer_index) 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_undo_method(Global, "undo", [Global.canvas])
Global.undo_redo.add_do_method(Global, "redo", [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: func _on_MergeDownLayer_pressed() -> void:
var new_layers : Array = Global.canvas.layers.duplicate() var new_layers : Array = Global.canvas.layers.duplicate()
new_layers.remove(Global.canvas.current_layer_index) new_layers.remove(Global.current_layer)
var selected_layer = Global.canvas.layers[Global.canvas.current_layer_index][0] var selected_layer = Global.canvas.layers[Global.current_layer][0]
if Global.canvas.layers[Global.canvas.current_layer_index][4] < 1: # If we have layer transparency if Global.canvas.layers[Global.current_layer][2] < 1: # If we have layer transparency
for xx in selected_layer.get_size().x: for xx in selected_layer.get_size().x:
for yy in selected_layer.get_size().y: for yy in selected_layer.get_size().y:
var pixel_color : Color = selected_layer.get_pixel(xx, yy) 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)) selected_layer.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
var new_layer := Image.new() 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() new_layer.lock()
Global.canvas.blend_rect(new_layer, selected_layer, Rect2(Global.canvas.position, Global.canvas.size), Vector2.ZERO) 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.undos += 1
Global.undo_redo.create_action("Merge Layer") 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", 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.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_undo_method(Global, "undo", [Global.canvas])
Global.undo_redo.add_do_method(Global, "redo", [Global.canvas]) Global.undo_redo.add_do_method(Global, "redo", [Global.canvas])

View file

@ -51,7 +51,7 @@ func _ready() -> void:
var tex := ImageTexture.new() var tex := ImageTexture.new()
tex.create_from_image(sprite, 0) tex.create_from_image(sprite, 0)
# Store [Image, ImageTexture, Layer Name, Opacity] # Store [Image, ImageTexture, Opacity]
layers.append([sprite, tex, 1]) layers.append([sprite, tex, 1])
var frame_button = load("res://Prefabs/FrameButton.tscn").instance() var frame_button = load("res://Prefabs/FrameButton.tscn").instance()

View file

@ -15,7 +15,7 @@ var saved := true # Checks if the user has saved
# Canvas related stuff # Canvas related stuff
var layers := [] setget layers_changed var layers := [] setget layers_changed
var current_frame := 0 setget frame_changed var current_frame := 0 setget frame_changed
var current_layer := 0 var current_layer := 0 setget layer_changed
# warning-ignore:unused_class_variable # warning-ignore:unused_class_variable
var can_draw := false var can_draw := false
# warning-ignore:unused_class_variable # warning-ignore:unused_class_variable
@ -410,13 +410,6 @@ func undo(_canvases : Array, layer_index : int = -1) -> void:
if action_name == "Scale": if action_name == "Scale":
c.camera_zoom() 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": if action_name == "Add Frame":
canvas_parent.remove_child(_canvases[0]) canvas_parent.remove_child(_canvases[0])
frames_container.remove_child(_canvases[0].frame_button) 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": if action_name == "Scale":
c.camera_zoom() 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": if action_name == "Add Frame":
canvas_parent.add_child(_canvases[0]) canvas_parent.add_child(_canvases[0])
@ -551,6 +509,7 @@ func layers_changed(value : Array) -> void:
frame_button.frame = j frame_button.frame = j
frame_button.layer = i frame_button.layer = i
frame_button.pressed = true frame_button.pressed = true
frame_button.get_child(0).texture = Global.canvases[j].layers[i][1]
layers[i][2].add_child(frame_button) 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.pressed = true
#canvas.frame_button.get_node("FrameID").add_color_override("font_color", Color("#3c5d75")) #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: func create_brush_button(brush_img : Image, brush_type := Brush_Types.CUSTOM, hint_tooltip := "") -> void:
var brush_container var brush_container
var brush_button = load("res://Prefabs/BrushButton.tscn").instance() var brush_button = load("res://Prefabs/BrushButton.tscn").instance()

View file

@ -47,7 +47,6 @@ func changed_selection() -> void:
var parent := get_parent() var parent := get_parent()
for child in parent.get_children(): for child in parent.get_children():
if child is Button: if child is Button:
#print(child.name)
child.label.visible = true child.label.visible = true
child.line_edit.visible = false child.line_edit.visible = false
child.line_edit.editable = false child.line_edit.editable = false