diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 495f58e54..87a13b59c 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -193,10 +193,6 @@ onready var references_panel: ReferencesPanel = control.find_node("Reference Ima onready var perspective_editor := control.find_node("Perspective Editor") onready var top_menu_container: Panel = control.find_node("TopMenuContainer") -onready var rotation_level_button: Button = control.find_node("RotationLevel") -onready var rotation_level_spinbox: SpinBox = control.find_node("RotationSpinbox") -onready var zoom_level_button: Button = control.find_node("ZoomLevel") -onready var zoom_level_spinbox: SpinBox = control.find_node("ZoomSpinbox") onready var cursor_position_label: Label = control.find_node("CursorPosition") onready var current_frame_mark_label: Label = control.find_node("CurrentFrameMark") diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 0d7a988b3..11f232598 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -257,7 +257,7 @@ func change_project() -> void: ) if camera == Global.camera: - Global.zoom_level_spinbox.min_value = 100.0 / camera.zoom_max.x + camera.set_zoom_max_value() camera.rotation = cameras_rotation[i] camera.zoom = cameras_zoom[i] camera.offset = cameras_offset[i] diff --git a/src/Main.gd b/src/Main.gd index 26b8a74d2..b076c0651 100644 --- a/src/Main.gd +++ b/src/Main.gd @@ -54,11 +54,6 @@ 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 dd0cbd5d3..2010db9cd 100644 --- a/src/UI/Canvas/CameraMovement.gd +++ b/src/UI/Canvas/CameraMovement.gd @@ -8,16 +8,25 @@ enum Cameras { MAIN, SECOND, SMALL } const KEY_MOVE_ACTION_NAMES := ["camera_left", "camera_right", "camera_up", "camera_down"] const CAMERA_SPEED_RATE := 15.0 +export var index := 0 + var zoom_min := Vector2(0.005, 0.005) var zoom_max := Vector2.ONE var viewport_container: ViewportContainer var transparent_checker: ColorRect var mouse_pos := Vector2.ZERO var drag := false -var index := 0 +var rotation_slider: ValueSlider +var zoom_slider: ValueSlider func _ready() -> void: + if index == Cameras.MAIN: + rotation_slider = Global.top_menu_container.get_node("%RotationSlider") + rotation_slider.connect("value_changed", self, "_rotation_value_changed") + zoom_slider = Global.top_menu_container.get_node("%ZoomSlider") + zoom_slider.connect("value_changed", self, "_zoom_value_changed") + set_zoom_max_value() connect("zoom_changed", self, "_zoom_changed") connect("rotation_changed", self, "_rotation_changed") rotating = true @@ -25,67 +34,35 @@ func _ready() -> void: transparent_checker = get_parent().get_node("TransparentChecker") update_transparent_checker_offset() - # signals regarding rotation stats - Global.rotation_level_button.connect("pressed", self, "_rotation_button_pressed") - Global.rotation_level_spinbox.connect("value_changed", self, "_rotation_value_changed") - Global.rotation_level_spinbox.get_child(0).connect( - "focus_exited", self, "_rotation_focus_exited" - ) - # signals regarding zoom stats - Global.zoom_level_button.connect("pressed", self, "_zoom_button_pressed") - Global.zoom_level_spinbox.connect("value_changed", self, "_zoom_value_changed") - Global.zoom_level_spinbox.max_value = 100.0 / zoom_min.x - Global.zoom_level_spinbox.get_child(0).connect("focus_exited", self, "_zoom_focus_exited") +func set_zoom_max_value() -> void: + zoom_slider.max_value = 100.0 / zoom_min.x -func _rotation_button_pressed() -> void: - Global.rotation_level_button.visible = false - Global.rotation_level_spinbox.visible = true - Global.rotation_level_spinbox.editable = true - Global.rotation_level_spinbox.value = str2var( - Global.rotation_level_button.text.replace("°", "") - ) - # Since the actual LineEdit is the first child of SpinBox - Global.rotation_level_spinbox.get_child(0).grab_focus() +func _rotation_value_changed(value: float) -> void: + # Negative makes going up rotate clockwise + var degrees := -value + var difference := degrees - rotation_degrees + var canvas_center: Vector2 = Global.current_project.size / 2 + offset = (offset - canvas_center).rotated(deg2rad(difference)) + canvas_center + rotation_degrees = wrapf(degrees, -180, 180) + emit_signal("rotation_changed") -func _rotation_value_changed(value) -> void: - 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 index == Cameras.MAIN: - # Negative makes going up rotate clockwise - _set_camera_rotation_degrees(-Global.rotation_level_spinbox.value) - Global.rotation_level_button.visible = true - Global.rotation_level_spinbox.visible = false - Global.rotation_level_spinbox.editable = false - - -func _zoom_button_pressed() -> void: - Global.zoom_level_button.visible = false - Global.zoom_level_spinbox.visible = true - Global.zoom_level_spinbox.editable = true - Global.zoom_level_spinbox.value = str2var(Global.zoom_level_button.text.replace("%", "")) - # Since the actual LineEdit is the first child of SpinBox - Global.zoom_level_spinbox.get_child(0).grab_focus() - - -func _zoom_value_changed(value) -> void: - 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 index == Cameras.MAIN: - zoom_camera_percent(Global.zoom_level_spinbox.value) - Global.zoom_level_button.visible = true - Global.zoom_level_spinbox.visible = false - Global.zoom_level_spinbox.editable = false +func _zoom_value_changed(value: float) -> void: + if value <= 0: + value = 1 + var percent := 100.0 / value + var new_zoom := Vector2(percent, percent) + if zoom == new_zoom: + return + if Global.smooth_zoom: + var tween := create_tween().set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_IN) + tween.connect("step_finished", self, "_on_tween_step") + tween.tween_property(self, "zoom", new_zoom, 0.05) + else: + zoom = new_zoom + emit_signal("zoom_changed") func update_transparent_checker_offset() -> void: @@ -155,18 +132,11 @@ func _rotate_camera_around_point(degrees: float, point: Vector2) -> void: emit_signal("rotation_changed") -func _set_camera_rotation_degrees(degrees: float) -> void: - var difference := degrees - rotation_degrees - var canvas_center: Vector2 = Global.current_project.size / 2 - offset = (offset - canvas_center).rotated(deg2rad(difference)) + canvas_center - rotation_degrees = wrapf(degrees, -180, 180) - emit_signal("rotation_changed") - - func _rotation_changed() -> void: 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)) + " °" + var degrees := wrapf(-rotation_degrees, -180, 180) + rotation_slider.value = degrees _update_rulers() @@ -200,22 +170,10 @@ func zoom_camera(dir: int) -> void: emit_signal("zoom_changed") -func zoom_camera_percent(value: float) -> void: - var percent: float = 100.0 / value - var new_zoom = Vector2(percent, percent) - if Global.smooth_zoom: - var tween := create_tween().set_trans(Tween.TRANS_LINEAR).set_ease(Tween.EASE_IN) - tween.connect("step_finished", self, "_on_tween_step") - tween.tween_property(self, "zoom", new_zoom, 0.05) - else: - zoom = new_zoom - emit_signal("zoom_changed") - - func _zoom_changed() -> void: update_transparent_checker_offset() if index == Cameras.MAIN: - Global.zoom_level_button.text = str(round(100 / zoom.x)) + " %" + zoom_slider.value = round(100 / zoom.x) _update_rulers() for guide in Global.current_project.guides: guide.width = zoom.x * 2 diff --git a/src/UI/CanvasPreviewContainer/CanvasPreviewContainer.tscn b/src/UI/CanvasPreviewContainer/CanvasPreviewContainer.tscn index 30c79e86a..03c097bb1 100644 --- a/src/UI/CanvasPreviewContainer/CanvasPreviewContainer.tscn +++ b/src/UI/CanvasPreviewContainer/CanvasPreviewContainer.tscn @@ -94,6 +94,7 @@ offset = Vector2( 32, 32 ) current = true zoom = Vector2( 0.15, 0.15 ) script = ExtResource( 3 ) +index = 2 [node name="Animation" type="HBoxContainer" parent="VBox"] margin_top = 140.0 diff --git a/src/UI/TopMenuContainer/TopMenuContainer.tscn b/src/UI/TopMenuContainer/TopMenuContainer.tscn index d4000c546..ac739d191 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.tscn +++ b/src/UI/TopMenuContainer/TopMenuContainer.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=2 format=2] +[gd_scene load_steps=3 format=2] +[ext_resource path="res://src/UI/Nodes/ValueSlider.gd" type="Script" id=1] [ext_resource path="res://src/UI/TopMenuContainer/TopMenuContainer.gd" type="Script" id=2] [node name="TopMenuContainer" type="Panel"] @@ -77,62 +78,50 @@ margin_left = -65.5 margin_right = 65.5 custom_constants/separation = 20 -[node name="RotationStats" type="CenterContainer" parent="TopLabels"] -margin_right = 60.0 +[node name="RotationSlider" type="TextureProgress" parent="TopLabels"] +unique_name_in_owner = true +margin_right = 70.0 margin_bottom = 28.0 - -[node name="RotationLevel" type="Button" parent="TopLabels/RotationStats"] -margin_top = 4.0 -margin_right = 60.0 -margin_bottom = 24.0 -rect_min_size = Vector2( 60, 0 ) -mouse_filter = 1 +rect_min_size = Vector2( 70, 0 ) mouse_default_cursor_shape = 2 -text = "0 °" -align = 2 - -[node name="RotationSpinbox" type="SpinBox" parent="TopLabels/RotationStats"] -visible = false -margin_left = -7.0 -margin_top = 2.0 -margin_right = 67.0 -margin_bottom = 26.0 -min_value = -1e+07 -max_value = 1e+07 +theme_type_variation = "ValueSlider" +min_value = -180.0 +max_value = 180.0 +step = 0.1 allow_greater = true allow_lesser = true +nine_patch_stretch = true +stretch_margin_left = 3 +stretch_margin_top = 3 +stretch_margin_right = 3 +stretch_margin_bottom = 3 +script = ExtResource( 1 ) suffix = "°" -[node name="ZoomStats" type="CenterContainer" parent="TopLabels"] -margin_left = 80.0 -margin_right = 140.0 +[node name="ZoomSlider" type="TextureProgress" parent="TopLabels"] +unique_name_in_owner = true +margin_left = 90.0 +margin_right = 160.0 margin_bottom = 28.0 - -[node name="ZoomLevel" type="Button" parent="TopLabels/ZoomStats"] -margin_top = 4.0 -margin_right = 60.0 -margin_bottom = 24.0 -rect_min_size = Vector2( 60, 0 ) -mouse_filter = 1 +rect_min_size = Vector2( 70, 0 ) mouse_default_cursor_shape = 2 -text = "781 %" -align = 2 - -[node name="ZoomSpinbox" type="SpinBox" parent="TopLabels/ZoomStats"] -visible = false -margin_left = -7.0 -margin_top = 2.0 -margin_right = 67.0 -margin_bottom = 26.0 -min_value = 100.0 +theme_type_variation = "ValueSlider" +min_value = 50.0 max_value = 2000.0 -value = 100.0 +allow_greater = true +allow_lesser = true +nine_patch_stretch = true +stretch_margin_left = 3 +stretch_margin_top = 3 +stretch_margin_right = 3 +stretch_margin_bottom = 3 +script = ExtResource( 1 ) suffix = "%" [node name="CursorPosition" type="Label" parent="TopLabels"] -margin_left = 160.0 +margin_left = 180.0 margin_top = 7.0 -margin_right = 208.0 +margin_right = 228.0 margin_bottom = 21.0 text = "[64×64]" align = 2 diff --git a/src/UI/UI.tscn b/src/UI/UI.tscn index e8bcb8d0a..0b2fbf447 100644 --- a/src/UI/UI.tscn +++ b/src/UI/UI.tscn @@ -369,6 +369,7 @@ material = SubResource( 3 ) current = true zoom = Vector2( 0.15, 0.15 ) script = ExtResource( 7 ) +index = 1 [node name="Animation Timeline" parent="DockableContainer" instance=ExtResource( 18 )] margin_left = 60.0