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

Add a change_cel() method to Project, instead of using a signal

Using a signal to change the cel was not a good idea, because it was not being emitted with the undo/redo system. The signal should also fire *after* the cel changes, and this is what happens in this commit. Should be useful for future features and extensions to check whether a cel has been changed.
This commit is contained in:
Emmanouil Papadeas 2023-01-02 22:09:47 +02:00
parent 40ab13da35
commit 824860a2b5
6 changed files with 52 additions and 55 deletions

View file

@ -549,14 +549,14 @@ func open_image_as_spritesheet_layer(
project.undo_redo.add_do_method(project, "add_frames", frames, frame_indices)
project.undo_redo.add_do_method(project, "add_layers", [layer], [project.layers.size()], [cels])
project.undo_redo.add_do_method(
project, "_cel_changed", new_frames_size - 1, project.layers.size()
project, "change_cel", new_frames_size - 1, project.layers.size()
)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(project, "remove_layers", [project.layers.size()])
project.undo_redo.add_undo_method(project, "remove_frames", frame_indices)
project.undo_redo.add_undo_method(
project, "_cel_changed", project.current_frame, project.current_layer
project, "change_cel", project.current_frame, project.current_layer
)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.commit_action()
@ -576,12 +576,12 @@ func open_image_at_cel(image: Image, layer_index := 0, frame_index := 0) -> void
project.undo_redo.add_undo_property(cel, "image", cel.image)
project.undo_redo.add_do_property(project, "selected_cels", [])
project.undo_redo.add_do_method(project, "_cel_changed", frame_index, layer_index)
project.undo_redo.add_do_method(project, "change_cel", frame_index, layer_index)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_property(project, "selected_cels", [])
project.undo_redo.add_undo_method(
project, "_cel_changed", project.current_frame, project.current_layer
project, "change_cel", project.current_frame, project.current_layer
)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.commit_action()
@ -603,12 +603,12 @@ func open_image_as_new_frame(image: Image, layer_index := 0) -> void:
project.undo_redo.create_action("Add Frame")
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_do_method(project, "add_frames", [frame], [project.frames.size()])
project.undo_redo.add_do_method(project, "_cel_changed", project.frames.size(), layer_index)
project.undo_redo.add_do_method(project, "change_cel", project.frames.size(), layer_index)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_undo_method(project, "remove_frames", [project.frames.size()])
project.undo_redo.add_undo_method(
project, "_cel_changed", project.current_frame, project.current_layer
project, "change_cel", project.current_frame, project.current_layer
)
project.undo_redo.commit_action()
@ -629,11 +629,11 @@ func open_image_as_new_layer(image: Image, file_name: String, frame_index := 0)
cels.append(layer.new_empty_cel())
project.undo_redo.add_do_method(project, "add_layers", [layer], [project.layers.size()], [cels])
project.undo_redo.add_do_method(project, "_cel_changed", frame_index, project.layers.size())
project.undo_redo.add_do_method(project, "change_cel", frame_index, project.layers.size())
project.undo_redo.add_undo_method(project, "remove_layers", [project.layers.size()])
project.undo_redo.add_undo_method(
project, "_cel_changed", project.current_frame, project.current_layer
project, "change_cel", project.current_frame, project.current_layer
)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)

View file

@ -3,8 +3,7 @@ class_name Project
extends Reference
# A class for project properties.
# warning-ignore:unused_signal
signal cel_changed(frame, layer)
signal cel_changed
var name := "" setget _name_changed
var size: Vector2 setget _size_changed
@ -62,7 +61,6 @@ func _init(_frames := [], _name := tr("untitled"), _size := Vector2(64, 64)) ->
size = _size
tiles = Tiles.new(size)
selection_map.create(size.x, size.y, false, Image.FORMAT_LA8)
connect("cel_changed", self, "_cel_changed")
Global.tabs.add_tab(name)
OpenSave.current_save_paths.append("")
@ -468,7 +466,7 @@ func _size_changed(value: Vector2) -> void:
size = value
func _cel_changed(new_frame: int, new_layer := -1) -> void:
func change_cel(new_frame: int, new_layer := -1) -> void:
if new_frame < 0:
new_frame = current_frame
if new_layer < 0:
@ -520,6 +518,7 @@ func _cel_changed(new_frame: int, new_layer := -1) -> void:
Global.layer_opacity_slider.value = cel_opacity * 100
Global.canvas.update()
Global.transparent_checker.update_rect()
emit_signal("cel_changed")
func toggle_frame_buttons() -> void:

View file

@ -160,8 +160,8 @@ func add_frame() -> void:
project.undo_redo.add_undo_method(project, "remove_frames", [frame_add_index])
project.undo_redo.add_do_property(project, "animation_tags", new_animation_tags)
project.undo_redo.add_undo_property(project, "animation_tags", project.animation_tags)
project.undo_redo.add_do_method(project, "_cel_changed", project.current_frame + 1)
project.undo_redo.add_undo_method(project, "_cel_changed", project.current_frame)
project.undo_redo.add_do_method(project, "change_cel", project.current_frame + 1)
project.undo_redo.add_undo_method(project, "change_cel", project.current_frame)
project.undo_redo.commit_action()
@ -225,8 +225,8 @@ func delete_frames(indices := []) -> void:
project.undo_redo.add_undo_method(project, "add_frames", frames, indices)
project.undo_redo.add_do_property(project, "animation_tags", new_animation_tags)
project.undo_redo.add_undo_property(project, "animation_tags", project.animation_tags)
project.undo_redo.add_do_method(project, "_cel_changed", current_frame)
project.undo_redo.add_undo_method(project, "_cel_changed", project.current_frame)
project.undo_redo.add_do_method(project, "change_cel", current_frame)
project.undo_redo.add_undo_method(project, "change_cel", project.current_frame)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.commit_action()
@ -301,8 +301,8 @@ func copy_frames(indices := []) -> void:
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(project, "add_frames", copied_frames, copied_indices)
project.undo_redo.add_undo_method(project, "remove_frames", copied_indices)
project.undo_redo.add_do_method(project, "_cel_changed", indices[-1] + 1)
project.undo_redo.add_undo_method(project, "_cel_changed", indices[-1])
project.undo_redo.add_do_method(project, "change_cel", indices[-1] + 1)
project.undo_redo.add_undo_method(project, "change_cel", indices[-1])
project.undo_redo.add_do_property(project, "animation_tags", new_animation_tags)
project.undo_redo.add_undo_property(project, "animation_tags", project.animation_tags)
project.undo_redo.commit_action()
@ -396,7 +396,7 @@ func _on_AnimationTimer_timeout() -> void:
if animation_forward:
if project.current_frame < last_frame:
project.selected_cels.clear()
project.emit_signal("cel_changed", project.current_frame + 1, -1)
project.change_cel(project.current_frame + 1, -1)
Global.animation_timer.wait_time = (
project.frames[project.current_frame].duration
* (1 / fps)
@ -411,7 +411,7 @@ func _on_AnimationTimer_timeout() -> void:
is_animation_running = false
1: # Cycle loop
project.selected_cels.clear()
project.emit_signal("cel_changed", first_frame, -1)
project.change_cel(first_frame, -1)
Global.animation_timer.wait_time = (
project.frames[project.current_frame].duration
* (1 / fps)
@ -424,7 +424,7 @@ func _on_AnimationTimer_timeout() -> void:
else:
if project.current_frame > first_frame:
project.selected_cels.clear()
project.emit_signal("cel_changed", project.current_frame - 1, -1)
project.change_cel(project.current_frame - 1, -1)
Global.animation_timer.wait_time = (
project.frames[project.current_frame].duration
* (1 / fps)
@ -439,7 +439,7 @@ func _on_AnimationTimer_timeout() -> void:
is_animation_running = false
1: # Cycle loop
project.selected_cels.clear()
project.emit_signal("cel_changed", last_frame, -1)
project.change_cel(last_frame, -1)
Global.animation_timer.wait_time = (
project.frames[project.current_frame].duration
* (1 / fps)
@ -501,7 +501,7 @@ func _on_NextFrame_pressed() -> void:
Global.canvas.selection.transform_content_confirm()
project.selected_cels.clear()
if project.current_frame < project.frames.size() - 1:
project.emit_signal("cel_changed", project.current_frame + 1, -1)
project.change_cel(project.current_frame + 1, -1)
func _on_PreviousFrame_pressed() -> void:
@ -509,19 +509,19 @@ func _on_PreviousFrame_pressed() -> void:
Global.canvas.selection.transform_content_confirm()
project.selected_cels.clear()
if project.current_frame > 0:
project.emit_signal("cel_changed", project.current_frame - 1, -1)
project.change_cel(project.current_frame - 1, -1)
func _on_LastFrame_pressed() -> void:
Global.canvas.selection.transform_content_confirm()
Global.current_project.selected_cels.clear()
Global.current_project.emit_signal("cel_changed", Global.current_project.frames.size() - 1, -1)
Global.current_project.change_cel(Global.current_project.frames.size() - 1, -1)
func _on_FirstFrame_pressed() -> void:
Global.canvas.selection.transform_content_confirm()
Global.current_project.selected_cels.clear()
Global.current_project.emit_signal("cel_changed", 0, -1)
Global.current_project.change_cel(0, -1)
func _on_FPSValue_value_changed(value: float) -> void:
@ -591,8 +591,8 @@ func add_layer(type: int) -> void:
project.undo_redo.create_action("Add Layer")
project.undo_redo.add_do_method(project, "add_layers", [l], [new_layer_idx], [cels])
project.undo_redo.add_undo_method(project, "remove_layers", [new_layer_idx])
project.undo_redo.add_do_method(project, "_cel_changed", -1, new_layer_idx)
project.undo_redo.add_undo_method(project, "_cel_changed", -1, project.current_layer)
project.undo_redo.add_do_method(project, "change_cel", -1, new_layer_idx)
project.undo_redo.add_undo_method(project, "change_cel", -1, project.current_layer)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.commit_action()
@ -651,9 +651,9 @@ func _on_CloneLayer_pressed() -> void:
project.undo_redo.add_do_method(project, "add_layers", clones, indices, cels)
project.undo_redo.add_undo_method(project, "remove_layers", indices)
project.undo_redo.add_do_method(
project, "_cel_changed", -1, project.current_layer + clones.size()
project, "change_cel", -1, project.current_layer + clones.size()
)
project.undo_redo.add_undo_method(project, "_cel_changed", -1, project.current_layer)
project.undo_redo.add_undo_method(project, "change_cel", -1, project.current_layer)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.commit_action()
@ -680,8 +680,8 @@ func _on_RemoveLayer_pressed() -> void:
project.undo_redo.create_action("Remove Layer")
project.undo_redo.add_do_method(project, "remove_layers", indices)
project.undo_redo.add_undo_method(project, "add_layers", layers, indices, cels)
project.undo_redo.add_do_method(project, "_cel_changed", -1, max(indices[0] - 1, 0))
project.undo_redo.add_undo_method(project, "_cel_changed", -1, project.current_layer)
project.undo_redo.add_do_method(project, "change_cel", -1, max(indices[0] - 1, 0))
project.undo_redo.add_undo_method(project, "change_cel", -1, project.current_layer)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.commit_action()
@ -737,8 +737,8 @@ func change_layer_order(up: bool) -> void:
project.undo_redo.add_undo_method(
project, "move_layers", to_indices, from_indices, from_parents
)
project.undo_redo.add_do_method(project, "_cel_changed", -1, to_index + child_count)
project.undo_redo.add_undo_method(project, "_cel_changed", -1, project.current_layer)
project.undo_redo.add_do_method(project, "change_cel", -1, to_index + child_count)
project.undo_redo.add_undo_method(project, "change_cel", -1, project.current_layer)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.commit_action()
@ -797,8 +797,8 @@ func _on_MergeDownLayer_pressed() -> void:
project.undo_redo.add_undo_method(
project, "add_layers", [top_layer], [top_layer.index], [top_cels]
)
project.undo_redo.add_do_method(project, "_cel_changed", -1, bottom_layer.index)
project.undo_redo.add_undo_method(project, "_cel_changed", -1, top_layer.index)
project.undo_redo.add_do_method(project, "change_cel", -1, bottom_layer.index)
project.undo_redo.add_undo_method(project, "change_cel", -1, top_layer.index)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.commit_action()

View file

@ -78,11 +78,9 @@ func _on_CelButton_pressed() -> void:
project.selected_cels.append(frame_layer)
if change_cel:
project.emit_signal("cel_changed", frame, layer)
project.change_cel(frame, layer)
else:
project.emit_signal(
"cel_changed", project.selected_cels[0][0], project.selected_cels[0][1]
)
project.change_cel(project.selected_cels[0][0], project.selected_cels[0][1])
release_focus()
elif Input.is_action_just_released("right_mouse"):
@ -264,9 +262,9 @@ func drop_data(_pos, data) -> void:
project.undo_redo.add_do_method(project, "move_cel", drop_frame, to_frame, layer)
project.undo_redo.add_undo_method(project, "move_cel", to_frame, drop_frame, layer)
project.undo_redo.add_do_method(project, "_cel_changed", frame, layer)
project.undo_redo.add_do_method(project, "change_cel", frame, layer)
project.undo_redo.add_undo_method(
project, "_cel_changed", project.current_frame, project.current_layer
project, "change_cel", project.current_frame, project.current_layer
)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)

View file

@ -46,7 +46,7 @@ func _button_pressed() -> void:
if !Global.current_project.selected_cels.has(frame_layer):
Global.current_project.selected_cels.append(frame_layer)
Global.current_project.emit_signal("cel_changed", frame, -1)
Global.current_project.change_cel(frame, -1)
elif Input.is_action_just_released("right_mouse"):
if Global.current_project.frames.size() == 1:
@ -94,11 +94,11 @@ func change_frame_order(rate: int) -> void:
project.undo_redo.add_undo_method(project, "move_frame", change, frame)
if project.current_frame == frame:
project.undo_redo.add_do_method(project, "_cel_changed", change)
project.undo_redo.add_do_method(project, "change_cel", change)
else:
project.undo_redo.add_do_method(project, "_cel_changed", project.current_frame)
project.undo_redo.add_do_method(project, "change_cel", project.current_frame)
project.undo_redo.add_undo_method(project, "_cel_changed", project.current_frame)
project.undo_redo.add_undo_method(project, "change_cel", project.current_frame)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.commit_action()
@ -155,10 +155,10 @@ func drop_data(_pos, data) -> void:
project.undo_redo.add_undo_method(project, "move_frame", to_frame, drop_frame)
if project.current_frame == drop_frame:
project.undo_redo.add_do_method(project, "_cel_changed", frame)
project.undo_redo.add_do_method(project, "change_cel", frame)
else:
project.undo_redo.add_do_method(project, "_cel_changed", project.current_frame)
project.undo_redo.add_undo_method(project, "_cel_changed", project.current_frame)
project.undo_redo.add_do_method(project, "change_cel", project.current_frame)
project.undo_redo.add_undo_method(project, "change_cel", project.current_frame)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.commit_action()

View file

@ -119,13 +119,13 @@ func _on_LayerContainer_gui_input(event: InputEvent) -> void:
var frame_layer := [i, j]
if !project.selected_cels.has(frame_layer):
project.selected_cels.append(frame_layer)
project.emit_signal("cel_changed", -1, layer)
project.change_cel(-1, layer)
elif Input.is_action_pressed("ctrl"):
for i in range(0, project.frames.size()):
var frame_layer := [i, layer]
if !project.selected_cels.has(frame_layer):
project.selected_cels.append(frame_layer)
project.emit_signal("cel_changed", -1, layer)
project.change_cel(-1, layer)
else: # If the button is pressed without Shift or Control
_select_current_layer()
@ -181,7 +181,7 @@ func _select_current_layer() -> void:
if !Global.current_project.selected_cels.has(frame_layer):
Global.current_project.selected_cels.append(frame_layer)
Global.current_project.emit_signal("cel_changed", -1, layer)
Global.current_project.change_cel(-1, layer)
func get_drag_data(_position) -> Array:
@ -339,10 +339,10 @@ func drop_data(_pos, data) -> void:
project, "move_layers", drop_to_indices, drop_from_indices, drop_from_parents
)
if project.current_layer == drop_layer:
project.undo_redo.add_do_method(project, "_cel_changed", -1, layer)
project.undo_redo.add_do_method(project, "change_cel", -1, layer)
else:
project.undo_redo.add_do_method(project, "_cel_changed", -1, project.current_layer)
project.undo_redo.add_undo_method(project, "_cel_changed", -1, project.current_layer)
project.undo_redo.add_do_method(project, "change_cel", -1, project.current_layer)
project.undo_redo.add_undo_method(project, "change_cel", -1, project.current_layer)
project.undo_redo.add_undo_method(Global, "undo_or_redo", true)
project.undo_redo.add_do_method(Global, "undo_or_redo", false)
project.undo_redo.commit_action()