diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 679a76460..59ce50487 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -127,6 +127,7 @@ onready var small_preview_viewport : ViewportContainer = canvas_preview_containe onready var camera : Camera2D = main_viewport.find_node("Camera2D") onready var camera2 : Camera2D = control.find_node("Camera2D2") onready var camera_preview : Camera2D = control.find_node("CameraPreview") +onready var cameras = [Global.camera, Global.camera2, Global.camera_preview] onready var horizontal_ruler : BaseButton = control.find_node("HorizontalRuler") onready var vertical_ruler : BaseButton = control.find_node("VerticalRuler") onready var transparent_checker : ColorRect = control.find_node("TransparentChecker") diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 1b175f882..7c132f3f0 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -231,7 +231,7 @@ func change_project() -> void: Global.top_menu_container.edit_menu_button.get_popup().set_item_disabled(6, !has_selection) var i := 0 - for camera in [Global.camera, Global.camera2, Global.camera_preview]: + for camera in Global.cameras: camera.zoom_max = cameras_zoom_max[i] if camera == Global.camera_preview: Global.preview_zoom_slider.disconnect("value_changed", Global.canvas_preview_container, "_on_PreviewZoomSlider_value_changed") diff --git a/src/Main.gd b/src/Main.gd index cc5dd29d2..7efcbb57a 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -1,15 +1,14 @@ extends Control + var opensprite_file_selected := false var redone := false var is_quitting_on_save := false - var tallscreen_is_active = false - var alternate_transparent_background := ColorRect.new() + onready var ui := $MenuAndUI/UI onready var tools_and_canvas : HSplitContainer = $MenuAndUI/UI/ToolsAndCanvas - onready var tallscreen_hsplit_container : HSplitContainer = $MenuAndUI/UI/ToolsAndCanvas/CanvasAndTimeline/TallscreenHSplitContainer onready var bottom_panel : VSplitContainer = tallscreen_hsplit_container.get_node("BottomPanel") onready var right_panel := $MenuAndUI/UI/RightPanel @@ -62,6 +61,11 @@ func _ready() -> void: Global.open_sprites_dialog.current_dir = OS.get_user_data_dir() Global.save_sprites_dialog.current_dir = OS.get_user_data_dir() + var i := 0 + for camera in Global.cameras: + camera.index = i + i += 1 + var zstd_checkbox := CheckBox.new() zstd_checkbox.name = "ZSTDCompression" zstd_checkbox.pressed = true diff --git a/src/UI/Canvas/CameraMovement.gd b/src/UI/Canvas/CameraMovement.gd index 2651254c4..128977097 100644 --- a/src/UI/Canvas/CameraMovement.gd +++ b/src/UI/Canvas/CameraMovement.gd @@ -1,6 +1,8 @@ extends Camera2D +enum Cameras {MAIN, SECOND, SMALL} + const low_speed_move_rate := 150.0 const medium_speed_move_rate := 750.0 const high_speed_move_rate := 3750.0 @@ -12,6 +14,7 @@ var viewport_container : ViewportContainer var transparent_checker : ColorRect var mouse_pos := Vector2.ZERO var drag := false +var index := 0 func _ready() -> void: @@ -44,13 +47,13 @@ func rotation_button_pressed() -> void: func rotation_value_changed(value) -> void: - if name == "Camera2D": + if index == Cameras.MAIN: set_camera_rotation_degrees(-value) # Negative makes going up rotate clockwise func rotation_focus_exited() -> void: if Global.rotation_level_spinbox.value != rotation: #If user pressed enter while editing - if name == "Camera2D": + if index == Cameras.MAIN: set_camera_rotation_degrees(-Global.rotation_level_spinbox.value) # Negative makes going up rotate clockwise Global.rotation_level_button.visible = true Global.rotation_level_spinbox.visible = false @@ -66,13 +69,13 @@ func zoom_button_pressed() -> void: func zoom_value_changed(value) -> void: - if name == "Camera2D": + if index == Cameras.MAIN: zoom_camera_percent(value) func zoom_focus_exited() -> void: if Global.zoom_level_spinbox.value != round(100 / zoom.x): #If user pressed enter while editing - if name == "Camera2D": + if index == Cameras.MAIN: zoom_camera_percent(Global.zoom_level_spinbox.value) Global.zoom_level_button.visible = true Global.zoom_level_spinbox.visible = false @@ -180,38 +183,42 @@ func process_direction_action_released(event: InputEvent) -> void: func _input(event : InputEvent) -> void: + if !Global.can_draw: + drag = false + return mouse_pos = viewport_container.get_local_mouse_position() var viewport_size := viewport_container.rect_size + if !Rect2(Vector2.ZERO, viewport_size).has_point(mouse_pos): + drag = false + return + if event.is_action_pressed("middle_mouse") || event.is_action_pressed("space"): drag = true elif event.is_action_released("middle_mouse") || event.is_action_released("space"): drag = false - - if Global.can_draw && Rect2(Vector2.ZERO, viewport_size).has_point(mouse_pos): - if event.is_action_pressed("zoom_in"): # Wheel Up Event - zoom_camera(-1) - elif event.is_action_pressed("zoom_out"): # Wheel Down Event + elif event.is_action_pressed("zoom_in"): # Wheel Up Event + zoom_camera(-1) + elif event.is_action_pressed("zoom_out"): # Wheel Down Event + zoom_camera(1) + elif event is InputEventMagnifyGesture: # Zoom Gesture on a Laptop touchpad + if event.factor < 1: zoom_camera(1) - elif event is InputEventMagnifyGesture: # Zoom Gesture on a Laptop touchpad - if event.factor < 1: - zoom_camera(1) - else: - zoom_camera(-1) - elif event is InputEventPanGesture: # Pan Gesture on a Latop touchpad - offset = offset + event.delta.rotated(rotation) * zoom * 7 # for moving the canvas - if OS.get_name() == "Android": - return - offset = offset + event.delta * zoom * 7 # for moving the canvas - elif event is InputEventMouseMotion && drag: - offset = offset - event.relative.rotated(rotation) * zoom - update_transparent_checker_offset() - update_rulers() - elif is_action_direction_pressed(event): + else: + zoom_camera(-1) + elif event is InputEventPanGesture and OS.get_name() != "Android": # Pan Gesture on a Latop touchpad + offset = offset + event.delta.rotated(rotation) * zoom * 7 # for moving the canvas + elif event is InputEventMouseMotion && drag: + offset = offset - event.relative.rotated(rotation) * zoom + update_transparent_checker_offset() + update_rulers() + elif event is InputEventKey: + if is_action_direction_pressed(event): process_direction_action_pressed(event) elif is_action_direction_released(event): process_direction_action_released(event) - save_values_to_project() + save_values_to_project() + # Rotate Camera func rotate_camera_around_point(degrees: float, point: Vector2) -> void: @@ -219,6 +226,7 @@ func rotate_camera_around_point(degrees: float, point: Vector2) -> void: rotation_degrees = wrapf(rotation_degrees + degrees, -180, 180) rotation_changed() + func set_camera_rotation_degrees(degrees: float) -> void: var difference := degrees - rotation_degrees var canvas_center := Global.current_project.size / 2 @@ -226,8 +234,9 @@ func set_camera_rotation_degrees(degrees: float) -> void: rotation_degrees = wrapf(degrees, -180, 180) rotation_changed() + func rotation_changed() -> void: - if name == "Camera2D": + if index == Cameras.MAIN: # Negative to make going up in value clockwise, and match the spinbox which does the same Global.rotation_level_button.text = str(wrapi(round(-rotation_degrees), -180, 180)) + " °" update_rulers() @@ -271,7 +280,7 @@ func zoom_camera_percent(value : float) -> void: func zoom_changed() -> void: update_transparent_checker_offset() - if name == "Camera2D": + if index == Cameras.MAIN: Global.zoom_level_button.text = str(round(100 / zoom.x)) + " %" Global.canvas.pixel_grid.update() update_rulers() @@ -280,7 +289,7 @@ func zoom_changed() -> void: Global.canvas.selection.update_on_zoom(zoom.x) - elif name == "CameraPreview": + elif index == Cameras.SMALL: Global.preview_zoom_slider.value = -zoom.x @@ -293,7 +302,6 @@ func _on_tween_step(_object: Object, _key: NodePath, _elapsed: float, _value: Ob zoom_changed() - func zoom_100() -> void: zoom = Vector2.ONE offset = Global.current_project.size / 2 @@ -323,11 +331,11 @@ func fit_to_frame(size : Vector2) -> void: ratio = 0.1 # Set it to a non-zero value just in case # If the ratio is 0, it means that the viewport container is hidden # in that case, use the other viewport to get the ratio - if name == "Camera2D": + if index == Cameras.MAIN: h_ratio = Global.second_viewport.rect_size.x / size.x v_ratio = Global.second_viewport.rect_size.y / size.y ratio = min(h_ratio, v_ratio) - elif name == "Camera2D2": + elif index == Cameras.SECOND: h_ratio = Global.main_viewport.rect_size.x / size.x v_ratio = Global.main_viewport.rect_size.y / size.y ratio = min(h_ratio, v_ratio) @@ -338,18 +346,7 @@ func fit_to_frame(size : Vector2) -> void: func save_values_to_project() -> void: - if name == "Camera2D": - Global.current_project.cameras_rotation[0] = rotation - Global.current_project.cameras_zoom[0] = zoom - Global.current_project.cameras_offset[0] = offset - Global.current_project.cameras_zoom_max[0] = zoom_max - elif name == "Camera2D2": - Global.current_project.cameras_rotation[1] = rotation - Global.current_project.cameras_zoom[1] = zoom - Global.current_project.cameras_offset[1] = offset - Global.current_project.cameras_zoom_max[1] = zoom_max - elif name == "CameraPreview": - Global.current_project.cameras_rotation[2] = rotation - Global.current_project.cameras_zoom[2] = zoom - Global.current_project.cameras_offset[2] = offset - Global.current_project.cameras_zoom_max[2] = zoom_max + Global.current_project.cameras_rotation[index] = rotation + Global.current_project.cameras_zoom[index] = zoom + Global.current_project.cameras_offset[index] = offset + Global.current_project.cameras_zoom_max[index] = zoom_max diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index c63335931..511761030 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -51,7 +51,8 @@ func _draw() -> void: onion_skinning() currently_visible_frame.size = Global.current_project.size current_frame_drawer.update() - tile_mode.update() + if Global.current_project.tile_mode != Global.TileMode.NONE: + tile_mode.update() draw_set_transform(position, rotation, scale) @@ -87,8 +88,8 @@ func camera_zoom() -> void: # Set camera zoom based on the sprite size var bigger_canvas_axis = max(Global.current_project.size.x, Global.current_project.size.y) var zoom_max := Vector2(bigger_canvas_axis, bigger_canvas_axis) * 0.01 - var cameras = [Global.camera, Global.camera2, Global.camera_preview] - for camera in cameras: + + for camera in Global.cameras: if zoom_max > Vector2.ONE: camera.zoom_max = zoom_max else: diff --git a/src/UI/Canvas/Rulers/Guide.gd b/src/UI/Canvas/Rulers/Guide.gd index 99cbf1cba..7fbd1b0eb 100644 --- a/src/UI/Canvas/Rulers/Guide.gd +++ b/src/UI/Canvas/Rulers/Guide.gd @@ -18,6 +18,8 @@ func _ready() -> void: func _input(_event : InputEvent) -> void: + if !visible: + return var tmp_transform = get_canvas_transform().affine_inverse() var tmp_position = Global.main_viewport.get_local_mouse_position() mouse_pos = tmp_transform.basis_xform(tmp_position) + tmp_transform.origin @@ -30,12 +32,12 @@ func _input(_event : InputEvent) -> void: else: point0.x -= width * 3 point1.x += width * 3 - if Global.can_draw and Global.has_focus and point_in_rectangle(mouse_pos, point0, point1) and Input.is_action_just_pressed("left_mouse") and visible: + if Global.can_draw and Global.has_focus and point_in_rectangle(mouse_pos, point0, point1) and Input.is_action_just_pressed("left_mouse"): if !point_in_rectangle(Global.canvas.current_pixel, Vector2.ZERO, project.size): has_focus = true Global.has_focus = false update() - if has_focus and visible: + if has_focus: if Input.is_action_pressed("left_mouse"): if type == Types.HORIZONTAL: var yy = stepify(mouse_pos.y, 0.5) diff --git a/src/UI/Canvas/Rulers/SymmetryGuide.gd b/src/UI/Canvas/Rulers/SymmetryGuide.gd index dcd030a68..13945bace 100644 --- a/src/UI/Canvas/Rulers/SymmetryGuide.gd +++ b/src/UI/Canvas/Rulers/SymmetryGuide.gd @@ -15,6 +15,8 @@ func _ready() -> void: func _input(_event : InputEvent) -> void: + if !visible: + return ._input(_event) if type == Types.HORIZONTAL: project.y_symmetry_point = points[0].y * 2 - 1 diff --git a/src/UI/ToolButtons.gd b/src/UI/ToolButtons.gd index e82047379..eeaa1297d 100644 --- a/src/UI/ToolButtons.gd +++ b/src/UI/ToolButtons.gd @@ -32,11 +32,12 @@ func _ready() -> void: func _input(event : InputEvent) -> void: - if not Global.has_focus: + if not Global.has_focus or not event is InputEventKey: return for action in ["undo", "redo", "redo_secondary"]: if event.is_action_pressed(action): return + for t in tools: # Handle tool shortcuts if event.is_action_pressed("right_" + t[1] + "_tool") and !event.control: # Shortcut for right button (with Alt) Tools.assign_tool(t[0].name, BUTTON_RIGHT)