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

Use signals to move some code away from Project.change_project()

WIP, more code can be moved
This commit is contained in:
Emmanouil Papadeas 2024-03-22 21:05:00 +02:00
parent dd8145d369
commit 48145b7f61
7 changed files with 29 additions and 30 deletions

View file

@ -584,9 +584,6 @@ var cel_button_scene: PackedScene = load("res://src/UI/Timeline/CelButton.tscn")
@onready var top_menu_container: Panel = control.find_child("TopMenuContainer")
## The label indicating cursor position.
@onready var cursor_position_label: Label = top_menu_container.find_child("CursorPosition")
## The label indicating current frame number.
@onready var current_frame_mark_label: Label = top_menu_container.find_child("CurrentFrameMark")
## The animation timeline. It has the [param AnimationTimeline.gd] script attached.
@onready var animation_timeline: Panel = control.find_child("Animation Timeline")
## The timer used by the animation timeline.

View file

@ -190,10 +190,7 @@ func selection_map_changed() -> void:
func change_project() -> void:
Global.animation_timeline.project_changed()
Global.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
animation_tags = animation_tags
# Change the guides
for guide in Global.canvas.get_children():
if guide is Guide:
@ -206,14 +203,12 @@ func change_project() -> void:
guide.visible = Global.show_y_symmetry_axis and Global.show_guides
else:
guide.visible = false
# Change the project brushes
Brushes.clear_project_brush()
for brush in brushes:
Brushes.add_project_brush(brush)
Global.transparent_checker.update_rect()
Global.animation_timeline.fps_spinbox.value = fps
Global.perspective_editor.update_points()
Global.cursor_position_label.text = "[%s×%s]" % [size.x, size.y]
@ -230,7 +225,7 @@ func change_project() -> void:
else:
Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.SAVE, tr("Save"))
if !was_exported:
if not was_exported:
Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.EXPORT, tr("Export"))
else:
if export_overwrite:
@ -247,12 +242,7 @@ func change_project() -> void:
for j in Tiles.MODE.values():
Global.top_menu_container.tile_mode_submenu.set_item_checked(j, j == tiles.mode)
# Change selection effect & bounding rectangle
Global.canvas.selection.marching_ants_outline.offset = selection_offset
selection_map_changed()
Global.canvas.selection.big_bounding_rectangle = selection_map.get_used_rect()
Global.canvas.selection.big_bounding_rectangle.position += selection_offset
Global.canvas.selection.queue_redraw()
var edit_menu_popup: PopupMenu = Global.top_menu_container.edit_menu
edit_menu_popup.set_item_disabled(Global.EditMenu.NEW_BRUSH, !has_selection)
@ -268,18 +258,6 @@ func change_project() -> void:
if !canvas_references.has(ri) and !ri.is_inside_tree():
Global.canvas.reference_image_container.add_child(ri)
# Tell the reference images that the project changed
Global.reference_panel.project_changed()
var i := 0
for camera in Global.cameras:
camera.rotation = cameras_rotation[i]
camera.zoom = cameras_zoom[i]
camera.offset = cameras_offset[i]
camera.rotation_changed.emit()
camera.zoom_changed.emit()
i += 1
func serialize() -> Dictionary:
var layer_data := []
@ -548,7 +526,6 @@ func change_cel(new_frame: int, new_layer := -1) -> void:
if new_frame != current_frame: # If the frame has changed
current_frame = new_frame
Global.current_frame_mark_label.text = "%s/%s" % [str(current_frame + 1), frames.size()]
if new_layer != current_layer: # If the layer has changed
current_layer = new_layer

View file

@ -43,6 +43,7 @@ var should_tween := true
func _ready() -> void:
Global.project_switched.connect(_project_switched)
if not DisplayServer.is_touchscreen_available():
set_process_input(false)
if index == Cameras.MAIN:
@ -249,6 +250,12 @@ func _has_selection_tool() -> bool:
return false
func _project_switched() -> void:
camera_angle = Global.current_project.cameras_rotation[index]
zoom = Global.current_project.cameras_zoom[index]
offset = Global.current_project.cameras_offset[index]
func _rotate_camera_around_point(degrees: float, point: Vector2) -> void:
var angle := deg_to_rad(degrees)
offset = (offset - point).rotated(angle) + point

View file

@ -80,6 +80,7 @@ class Gizmo:
func _ready() -> void:
Global.project_switched.connect(_project_switched)
# It's being set to true only when the big_bounding_rectangle has a size larger than 0
set_process_input(false)
Global.camera.zoom_changed.connect(_update_on_zoom)
@ -852,6 +853,13 @@ func clear_selection(use_undo := false) -> void:
commit_undo("Clear Selection", undo_data_tmp)
func _project_switched() -> void:
marching_ants_outline.offset = Global.current_project.selection_offset
big_bounding_rectangle = Global.current_project.selection_map.get_used_rect()
big_bounding_rectangle.position += Global.current_project.selection_offset
queue_redraw()
func _get_preview_image() -> void:
var project := Global.current_project
var blended_image := Image.create(project.size.x, project.size.y, false, Image.FORMAT_RGBA8)

View file

@ -20,13 +20,14 @@ var transform_button_group: ButtonGroup
func _ready() -> void:
Global.project_switched.connect(project_changed)
OpenSave.reference_image_imported.connect(_on_references_changed)
transform_button_group = transform_tools_btns.get_child(0).button_group
transform_button_group.pressed.connect(_on_transform_tool_button_group_pressed)
list_btn_group.pressed.connect(_on_reference_image_button_pressed)
Global.canvas.reference_image_container.reference_image_changed.connect(
_on_reference_image_changed
)
OpenSave.reference_image_imported.connect(_on_references_changed)
# We call this function to update the buttons
_on_references_changed()
_update_ui()
@ -57,7 +58,7 @@ func reorder_reference_image(from: int, to: int, update_reference_index := true)
var project := Global.current_project
project.undo_redo.create_action("Reorder Reference Image")
project.undo_redo.add_do_method(project.reorder_reference_image.bind(from, to))
project.undo_redo.add_do_method(Global.reference_panel._on_references_changed)
project.undo_redo.add_do_method(_on_references_changed)
if update_reference_index:
project.undo_redo.add_do_method(project.set_reference_image_index.bind(to))
else:
@ -67,7 +68,7 @@ func reorder_reference_image(from: int, to: int, update_reference_index := true)
project.undo_redo.add_do_method(_update_ui)
project.undo_redo.add_undo_method(project.reorder_reference_image.bind(to, from))
project.undo_redo.add_undo_method(Global.reference_panel._on_references_changed)
project.undo_redo.add_undo_method(_on_references_changed)
if update_reference_index:
project.undo_redo.add_undo_method(project.set_reference_image_index.bind(from))
else:

View file

@ -1060,6 +1060,7 @@ func _toggle_layer_buttons() -> void:
func project_changed() -> void:
var project := Global.current_project
fps_spinbox.value = project.fps
_toggle_frame_buttons()
_toggle_layer_buttons()
# These must be removed from tree immediately to not mess up the indices of

View file

@ -49,6 +49,7 @@ var about_dialog := Dialog.new("res://src/UI/Dialogs/AboutDialog.tscn")
@onready var panels_submenu := PopupMenu.new()
@onready var layouts_submenu := PopupMenu.new()
@onready var recent_projects_submenu := PopupMenu.new()
@onready var current_frame_mark := $HBoxContainer/CurrentFrameMark as Label
class Dialog:
@ -76,6 +77,8 @@ class Dialog:
func _ready() -> void:
Global.project_switched.connect(_update_current_frame_mark)
Global.cel_switched.connect(_update_current_frame_mark)
_setup_file_menu()
_setup_edit_menu()
_setup_view_menu()
@ -85,6 +88,11 @@ func _ready() -> void:
_setup_help_menu()
func _update_current_frame_mark() -> void:
var project := Global.current_project
current_frame_mark.text = "%s/%s" % [str(project.current_frame + 1), project.frames.size()]
func _setup_file_menu() -> void:
# Order as in FileMenu enum
var file_menu_items := {