From dbe48a468167ccbd2201aa720510bfd59786917c Mon Sep 17 00:00:00 2001 From: OverloadedOrama Date: Tue, 24 Sep 2024 11:59:18 +0300 Subject: [PATCH] Fix issue where sometimes the camera zoom was not being preserved when switching between projects --- src/UI/Canvas/Canvas.gd | 1 - src/UI/Canvas/CanvasCamera.gd | 15 +++++---------- .../CanvasPreviewContainer.gd | 1 - 3 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index 938cf3d40..2f35195e0 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -100,7 +100,6 @@ func _input(event: InputEvent) -> void: func camera_zoom() -> void: for camera in Global.cameras: camera.fit_to_frame(Global.current_project.size) - camera.save_values_to_project() Global.transparent_checker.update_rect() diff --git a/src/UI/Canvas/CanvasCamera.gd b/src/UI/Canvas/CanvasCamera.gd index 89a4b8130..a7cf25800 100644 --- a/src/UI/Canvas/CanvasCamera.gd +++ b/src/UI/Canvas/CanvasCamera.gd @@ -14,18 +14,21 @@ const CAMERA_SPEED_RATE := 15.0 var zoom := Vector2.ONE: set(value): zoom = value + Global.current_project.cameras_zoom[index] = zoom zoom_changed.emit() _update_viewport_transform() var camera_angle := 0.0: set(value): camera_angle = wrapf(value, -PI, PI) camera_angle_degrees = rad_to_deg(camera_angle) + Global.current_project.cameras_rotation[index] = camera_angle rotation_changed.emit() _update_viewport_transform() var camera_angle_degrees := 0.0 var offset := Vector2.ZERO: set(value): offset = value + Global.current_project.cameras_offset[index] = offset offset_changed.emit() _update_viewport_transform() var camera_screen_center := Vector2.ZERO @@ -89,9 +92,7 @@ func _input(event: InputEvent) -> void: else: var dir := Input.get_vector(&"camera_left", &"camera_right", &"camera_up", &"camera_down") if dir != Vector2.ZERO and !_has_selection_tool(): - offset += (dir.rotated(camera_angle) / zoom) * CAMERA_SPEED_RATE - - save_values_to_project() + offset = offset + (dir.rotated(camera_angle) / zoom) * CAMERA_SPEED_RATE func zoom_camera(dir: int) -> void: @@ -181,12 +182,6 @@ func fit_to_frame(size: Vector2) -> void: Global.integer_zoom = !Global.integer_zoom -func save_values_to_project() -> void: - Global.current_project.cameras_rotation[index] = camera_angle - Global.current_project.cameras_zoom[index] = zoom - Global.current_project.cameras_offset[index] = offset - - func update_transparent_checker_offset() -> void: var o := get_global_transform_with_canvas().get_origin() var s := get_global_transform_with_canvas().get_scale() @@ -256,9 +251,9 @@ func _has_selection_tool() -> bool: func _project_switched() -> void: + offset = Global.current_project.cameras_offset[index] 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: diff --git a/src/UI/CanvasPreviewContainer/CanvasPreviewContainer.gd b/src/UI/CanvasPreviewContainer/CanvasPreviewContainer.gd index cf8152770..83f718e79 100644 --- a/src/UI/CanvasPreviewContainer/CanvasPreviewContainer.gd +++ b/src/UI/CanvasPreviewContainer/CanvasPreviewContainer.gd @@ -18,7 +18,6 @@ func _zoom_changed() -> void: func _on_PreviewZoomSlider_value_changed(value: float) -> void: camera.zoom = Vector2(value, value) - camera.save_values_to_project() camera.update_transparent_checker_offset()