mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-31 07:29:49 +00:00
Move even more code away from Project.change_project()
Making Pixelorama more modular by relying more on signals
This commit is contained in:
parent
48145b7f61
commit
acce1dda2e
|
@ -191,72 +191,19 @@ func selection_map_changed() -> void:
|
||||||
func change_project() -> void:
|
func change_project() -> void:
|
||||||
Global.animation_timeline.project_changed()
|
Global.animation_timeline.project_changed()
|
||||||
animation_tags = animation_tags
|
animation_tags = animation_tags
|
||||||
# Change the guides
|
|
||||||
for guide in Global.canvas.get_children():
|
|
||||||
if guide is Guide:
|
|
||||||
if guide in guides:
|
|
||||||
guide.visible = Global.show_guides
|
|
||||||
if guide is SymmetryGuide:
|
|
||||||
if guide.type == Guide.Types.HORIZONTAL:
|
|
||||||
guide.visible = Global.show_x_symmetry_axis and Global.show_guides
|
|
||||||
else:
|
|
||||||
guide.visible = Global.show_y_symmetry_axis and Global.show_guides
|
|
||||||
else:
|
|
||||||
guide.visible = false
|
|
||||||
# Change the project brushes
|
# Change the project brushes
|
||||||
Brushes.clear_project_brush()
|
Brushes.clear_project_brush()
|
||||||
for brush in brushes:
|
for brush in brushes:
|
||||||
Brushes.add_project_brush(brush)
|
Brushes.add_project_brush(brush)
|
||||||
|
|
||||||
Global.transparent_checker.update_rect()
|
Global.transparent_checker.update_rect()
|
||||||
Global.perspective_editor.update_points()
|
|
||||||
Global.cursor_position_label.text = "[%s×%s]" % [size.x, size.y]
|
Global.cursor_position_label.text = "[%s×%s]" % [size.x, size.y]
|
||||||
|
|
||||||
Global.main_window.title = "%s - Pixelorama %s" % [name, Global.current_version]
|
Global.main_window.title = "%s - Pixelorama %s" % [name, Global.current_version]
|
||||||
if has_changed:
|
if has_changed:
|
||||||
Global.main_window.title = Global.main_window.title + "(*)"
|
Global.main_window.title = Global.main_window.title + "(*)"
|
||||||
|
|
||||||
if export_directory_path != "":
|
if export_directory_path != "":
|
||||||
Global.open_sprites_dialog.current_path = export_directory_path
|
Global.open_sprites_dialog.current_path = export_directory_path
|
||||||
Global.save_sprites_dialog.current_path = export_directory_path
|
Global.save_sprites_dialog.current_path = export_directory_path
|
||||||
Global.top_menu_container.file_menu.set_item_text(
|
|
||||||
Global.FileMenu.SAVE, tr("Save") + " %s" % file_name
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.SAVE, tr("Save"))
|
|
||||||
|
|
||||||
if not was_exported:
|
|
||||||
Global.top_menu_container.file_menu.set_item_text(Global.FileMenu.EXPORT, tr("Export"))
|
|
||||||
else:
|
|
||||||
if export_overwrite:
|
|
||||||
Global.top_menu_container.file_menu.set_item_text(
|
|
||||||
Global.FileMenu.EXPORT,
|
|
||||||
tr("Overwrite") + " %s" % (file_name + Export.file_format_string(file_format))
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
Global.top_menu_container.file_menu.set_item_text(
|
|
||||||
Global.FileMenu.EXPORT,
|
|
||||||
tr("Export") + " %s" % (file_name + Export.file_format_string(file_format))
|
|
||||||
)
|
|
||||||
|
|
||||||
for j in Tiles.MODE.values():
|
|
||||||
Global.top_menu_container.tile_mode_submenu.set_item_checked(j, j == tiles.mode)
|
|
||||||
|
|
||||||
selection_map_changed()
|
selection_map_changed()
|
||||||
var edit_menu_popup: PopupMenu = Global.top_menu_container.edit_menu
|
|
||||||
edit_menu_popup.set_item_disabled(Global.EditMenu.NEW_BRUSH, !has_selection)
|
|
||||||
|
|
||||||
# We loop through all the reference image nodes and the ones that are not apart
|
|
||||||
# of the current project we remove from the tree
|
|
||||||
# They will still be in memory though
|
|
||||||
for ri: ReferenceImage in Global.canvas.reference_image_container.get_children():
|
|
||||||
if !reference_images.has(ri):
|
|
||||||
Global.canvas.reference_image_container.remove_child(ri)
|
|
||||||
# Now we loop through this projects reference images and add them back to the tree
|
|
||||||
var canvas_references := Global.canvas.reference_image_container.get_children()
|
|
||||||
for ri: ReferenceImage in reference_images:
|
|
||||||
if !canvas_references.has(ri) and !ri.is_inside_tree():
|
|
||||||
Global.canvas.reference_image_container.add_child(ri)
|
|
||||||
|
|
||||||
|
|
||||||
func serialize() -> Dictionary:
|
func serialize() -> Dictionary:
|
||||||
|
|
|
@ -13,6 +13,7 @@ var project := Global.current_project
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
Global.project_switched.connect(_project_switched)
|
||||||
width = 2.0 / Global.camera.zoom.x
|
width = 2.0 / Global.camera.zoom.x
|
||||||
default_color = Global.guide_color
|
default_color = Global.guide_color
|
||||||
project.guides.append(self)
|
project.guides.append(self)
|
||||||
|
@ -208,6 +209,18 @@ func set_color(color: Color) -> void:
|
||||||
default_color = color
|
default_color = color
|
||||||
|
|
||||||
|
|
||||||
|
func _project_switched() -> void:
|
||||||
|
if self in Global.current_project.guides:
|
||||||
|
visible = Global.show_guides
|
||||||
|
if self is SymmetryGuide:
|
||||||
|
if type == Types.HORIZONTAL:
|
||||||
|
visible = Global.show_x_symmetry_axis and Global.show_guides
|
||||||
|
else:
|
||||||
|
visible = Global.show_y_symmetry_axis and Global.show_guides
|
||||||
|
else:
|
||||||
|
visible = false
|
||||||
|
|
||||||
|
|
||||||
func _outside_canvas() -> bool:
|
func _outside_canvas() -> bool:
|
||||||
if type == Types.HORIZONTAL:
|
if type == Types.HORIZONTAL:
|
||||||
return points[0].y < 0 || points[0].y > project.size.y
|
return points[0].y < 0 || points[0].y > project.size.y
|
||||||
|
|
|
@ -8,6 +8,10 @@ var tracker_disabled := false
|
||||||
@onready var vanishing_point_container = $"%VanishingPointContainer"
|
@onready var vanishing_point_container = $"%VanishingPointContainer"
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
Global.project_switched.connect(_update_points)
|
||||||
|
|
||||||
|
|
||||||
func _on_AddPoint_pressed() -> void:
|
func _on_AddPoint_pressed() -> void:
|
||||||
do_pool.clear() # Reset (clears Redo history of vanishing points)
|
do_pool.clear() # Reset (clears Redo history of vanishing points)
|
||||||
var project := Global.current_project
|
var project := Global.current_project
|
||||||
|
@ -18,12 +22,12 @@ func _on_AddPoint_pressed() -> void:
|
||||||
project.undo_redo.commit_action()
|
project.undo_redo.commit_action()
|
||||||
|
|
||||||
|
|
||||||
func _on_TrackerLines_toggled(button_pressed: bool):
|
func _on_TrackerLines_toggled(button_pressed: bool) -> void:
|
||||||
for point in vanishing_point_container.get_children():
|
for point in vanishing_point_container.get_children():
|
||||||
tracker_disabled = !button_pressed
|
tracker_disabled = !button_pressed
|
||||||
|
|
||||||
|
|
||||||
func add_vanishing_point(is_redo := false):
|
func add_vanishing_point(is_redo := false) -> void:
|
||||||
var vanishing_point := vanishing_point_res.instantiate()
|
var vanishing_point := vanishing_point_res.instantiate()
|
||||||
vanishing_point_container.add_child(vanishing_point)
|
vanishing_point_container.add_child(vanishing_point)
|
||||||
if is_redo and !do_pool.is_empty():
|
if is_redo and !do_pool.is_empty():
|
||||||
|
@ -34,14 +38,14 @@ func add_vanishing_point(is_redo := false):
|
||||||
vanishing_point.initiate()
|
vanishing_point.initiate()
|
||||||
|
|
||||||
|
|
||||||
func undo_add_vanishing_point():
|
func undo_add_vanishing_point() -> void:
|
||||||
var point = vanishing_point_container.get_child(vanishing_point_container.get_child_count() - 1)
|
var point = vanishing_point_container.get_child(vanishing_point_container.get_child_count() - 1)
|
||||||
point.queue_free()
|
point.queue_free()
|
||||||
do_pool.append(point.serialize())
|
do_pool.append(point.serialize())
|
||||||
point.update_data_to_project(true)
|
point.update_data_to_project(true)
|
||||||
|
|
||||||
|
|
||||||
func delete_point(idx: int):
|
func delete_point(idx: int) -> void:
|
||||||
var project := Global.current_project
|
var project := Global.current_project
|
||||||
project.undos += 1
|
project.undos += 1
|
||||||
project.undo_redo.create_action("Delete Vanishing Point")
|
project.undo_redo.create_action("Delete Vanishing Point")
|
||||||
|
@ -50,20 +54,20 @@ func delete_point(idx: int):
|
||||||
project.undo_redo.commit_action()
|
project.undo_redo.commit_action()
|
||||||
|
|
||||||
|
|
||||||
func do_delete_point(idx: int):
|
func do_delete_point(idx: int) -> void:
|
||||||
var point = vanishing_point_container.get_child(idx)
|
var point = vanishing_point_container.get_child(idx)
|
||||||
delete_pool.append(point.serialize())
|
delete_pool.append(point.serialize())
|
||||||
point.queue_free()
|
point.queue_free()
|
||||||
point.update_data_to_project(true)
|
point.update_data_to_project(true)
|
||||||
|
|
||||||
|
|
||||||
func undo_delete_point(idx: int):
|
func undo_delete_point(idx: int) -> void:
|
||||||
var point = delete_pool.pop_back()
|
var point = delete_pool.pop_back()
|
||||||
Global.current_project.vanishing_points.insert(idx, point)
|
Global.current_project.vanishing_points.insert(idx, point)
|
||||||
update_points()
|
_update_points()
|
||||||
|
|
||||||
|
|
||||||
func update_points():
|
func _update_points() -> void:
|
||||||
# Delete old vanishing points
|
# Delete old vanishing points
|
||||||
for c in vanishing_point_container.get_children():
|
for c in vanishing_point_container.get_children():
|
||||||
c.queue_free()
|
c.queue_free()
|
||||||
|
|
|
@ -5,9 +5,7 @@ extends Sprite2D
|
||||||
signal properties_changed
|
signal properties_changed
|
||||||
|
|
||||||
var project := Global.current_project
|
var project := Global.current_project
|
||||||
|
|
||||||
var shader := preload("res://src/Shaders/ReferenceImageShader.gdshader")
|
var shader := preload("res://src/Shaders/ReferenceImageShader.gdshader")
|
||||||
|
|
||||||
var image_path := ""
|
var image_path := ""
|
||||||
var filter := false:
|
var filter := false:
|
||||||
set(value):
|
set(value):
|
||||||
|
@ -33,8 +31,11 @@ var color_clamping := 0.0:
|
||||||
if material:
|
if material:
|
||||||
get_material().set_shader_parameter("clamping", value)
|
get_material().set_shader_parameter("clamping", value)
|
||||||
|
|
||||||
|
@onready var parent := get_parent()
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
Global.project_switched.connect(_project_switched)
|
||||||
project.reference_images.append(self)
|
project.reference_images.append(self)
|
||||||
# Make this show behind parent because we want to use _draw() to draw over it
|
# Make this show behind parent because we want to use _draw() to draw over it
|
||||||
show_behind_parent = true
|
show_behind_parent = true
|
||||||
|
@ -131,3 +132,14 @@ func create_from_image(image: Image) -> void:
|
||||||
var itex := ImageTexture.create_from_image(image)
|
var itex := ImageTexture.create_from_image(image)
|
||||||
texture = itex
|
texture = itex
|
||||||
position_reset()
|
position_reset()
|
||||||
|
|
||||||
|
|
||||||
|
func _project_switched() -> void:
|
||||||
|
# Remove from the tree if it doesn't belong to the current project.
|
||||||
|
# It will still be in memory though.
|
||||||
|
if Global.current_project.reference_images.has(self):
|
||||||
|
if not is_inside_tree():
|
||||||
|
parent.add_child(self)
|
||||||
|
else:
|
||||||
|
if is_inside_tree():
|
||||||
|
parent.remove_child(self)
|
||||||
|
|
|
@ -77,7 +77,7 @@ class Dialog:
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
Global.project_switched.connect(_update_current_frame_mark)
|
Global.project_switched.connect(_project_switched)
|
||||||
Global.cel_switched.connect(_update_current_frame_mark)
|
Global.cel_switched.connect(_update_current_frame_mark)
|
||||||
_setup_file_menu()
|
_setup_file_menu()
|
||||||
_setup_edit_menu()
|
_setup_edit_menu()
|
||||||
|
@ -88,6 +88,27 @@ func _ready() -> void:
|
||||||
_setup_help_menu()
|
_setup_help_menu()
|
||||||
|
|
||||||
|
|
||||||
|
func _project_switched() -> void:
|
||||||
|
var project := Global.current_project
|
||||||
|
edit_menu.set_item_disabled(Global.EditMenu.NEW_BRUSH, not project.has_selection)
|
||||||
|
if project.export_directory_path.is_empty():
|
||||||
|
file_menu.set_item_text(Global.FileMenu.SAVE, tr("Save"))
|
||||||
|
else:
|
||||||
|
file_menu.set_item_text(Global.FileMenu.SAVE, tr("Save") + " %s" % project.file_name)
|
||||||
|
if project.was_exported:
|
||||||
|
var f_name := " %s" % (project.file_name + Export.file_format_string(project.file_format))
|
||||||
|
if project.export_overwrite:
|
||||||
|
file_menu.set_item_text(Global.FileMenu.EXPORT, tr("Overwrite") + f_name)
|
||||||
|
else:
|
||||||
|
file_menu.set_item_text(Global.FileMenu.EXPORT, tr("Export") + f_name)
|
||||||
|
else:
|
||||||
|
file_menu.set_item_text(Global.FileMenu.EXPORT, tr("Export"))
|
||||||
|
for j in Tiles.MODE.values():
|
||||||
|
tile_mode_submenu.set_item_checked(j, j == project.tiles.mode)
|
||||||
|
|
||||||
|
_update_current_frame_mark()
|
||||||
|
|
||||||
|
|
||||||
func _update_current_frame_mark() -> void:
|
func _update_current_frame_mark() -> void:
|
||||||
var project := Global.current_project
|
var project := Global.current_project
|
||||||
current_frame_mark.text = "%s/%s" % [str(project.current_frame + 1), project.frames.size()]
|
current_frame_mark.text = "%s/%s" % [str(project.current_frame + 1), project.frames.size()]
|
||||||
|
|
Loading…
Reference in a new issue