From 39afb5e15b5a171f6628d4c3b03b07e4e8e01904 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:27:06 +0300 Subject: [PATCH] Add buttons with menus that move the symmetry guides to the center of the canvas, or the view center --- Translations/Translations.pot | 10 ++- src/UI/GlobalToolOptions/GlobalToolOptions.gd | 22 +++++ .../GlobalToolOptions/GlobalToolOptions.tscn | 89 ++++++++++++++++--- 3 files changed, 107 insertions(+), 14 deletions(-) diff --git a/Translations/Translations.pot b/Translations/Translations.pot index f5933fcb4..18fed9a85 100644 --- a/Translations/Translations.pot +++ b/Translations/Translations.pot @@ -1957,10 +1957,18 @@ msgstr "" msgid "Enable horizontal mirrored drawing" msgstr "" +msgid "Vertical" +msgstr "" + msgid "Enable vertical mirrored drawing" msgstr "" -msgid "Vertical" +#. Found in the global tool options, in the menu that appears next to each mirror button. It affects the position of a symmetry guide. +msgid "Move to canvas center" +msgstr "" + +#. Found in the global tool options, in the menu that appears next to each mirror button. It affects the position of a symmetry guide. +msgid "Move to view center" msgstr "" msgid "Current frame:" diff --git a/src/UI/GlobalToolOptions/GlobalToolOptions.gd b/src/UI/GlobalToolOptions/GlobalToolOptions.gd index e23d1abda..fe7f8f954 100644 --- a/src/UI/GlobalToolOptions/GlobalToolOptions.gd +++ b/src/UI/GlobalToolOptions/GlobalToolOptions.gd @@ -11,6 +11,8 @@ extends PanelContainer func _ready() -> void: Tools.options_reset.connect(reset_options) + %HorizontalMirrorOptions.get_popup().id_pressed.connect(_on_horizontal_mirror_options_id_pressed) + %VerticalMirrorOptions.get_popup().id_pressed.connect(_on_vertical_mirror_options_id_pressed) # Resize tools panel when window gets resized get_tree().get_root().size_changed.connect(_on_resized) horizontal_mirror.button_pressed = Tools.horizontal_mirror @@ -89,3 +91,23 @@ func _on_alpha_lock_toggled(toggled_on: bool) -> void: func _on_Dynamics_pressed() -> void: var pos := dynamics.global_position + Vector2(0, 32) dynamics_panel.popup_on_parent(Rect2(pos, dynamics_panel.size)) + + +func _on_horizontal_mirror_options_id_pressed(id: int) -> void: + var project := Global.current_project + if id == 0: + project.x_symmetry_point = project.size.x - 1 + elif id == 1: + project.x_symmetry_point = Global.camera.camera_screen_center.x * 2 + project.y_symmetry_axis.points[0].x = project.x_symmetry_point / 2 + 0.5 + project.y_symmetry_axis.points[1].x = project.x_symmetry_point / 2 + 0.5 + + +func _on_vertical_mirror_options_id_pressed(id: int) -> void: + var project := Global.current_project + if id == 0: + project.y_symmetry_point = project.size.y - 1 + elif id == 1: + project.y_symmetry_point = Global.camera.camera_screen_center.y * 2 + project.x_symmetry_axis.points[0].y = project.y_symmetry_point / 2 + 0.5 + project.x_symmetry_axis.points[1].y = project.y_symmetry_point / 2 + 0.5 diff --git a/src/UI/GlobalToolOptions/GlobalToolOptions.tscn b/src/UI/GlobalToolOptions/GlobalToolOptions.tscn index f60013ef2..9abe461b1 100644 --- a/src/UI/GlobalToolOptions/GlobalToolOptions.tscn +++ b/src/UI/GlobalToolOptions/GlobalToolOptions.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=24 format=3 uid="uid://wo0hqxkst808"] +[gd_scene load_steps=25 format=3 uid="uid://wo0hqxkst808"] [ext_resource type="Texture2D" uid="uid://cjrokejjsp5dm" path="res://assets/graphics/misc/horizontal_mirror_off.png" id="1"] [ext_resource type="Texture2D" uid="uid://hiduvaa73fr6" path="res://assets/graphics/misc/vertical_mirror_off.png" id="2"] [ext_resource type="Script" path="res://src/UI/GlobalToolOptions/GlobalToolOptions.gd" id="3"] +[ext_resource type="Texture2D" uid="uid://ct8wn8m6x4m54" path="res://assets/graphics/misc/value_arrow.svg" id="3_faalk"] [ext_resource type="Texture2D" uid="uid://22h12g8p3jtd" path="res://assets/graphics/misc/pixel_perfect_off.png" id="4"] [ext_resource type="Script" path="res://src/UI/Nodes/ValueSlider.gd" id="5"] [ext_resource type="Texture2D" uid="uid://j8eywwy082a4" path="res://assets/graphics/misc/alpha_lock_off.png" id="5_jv20x"] @@ -73,7 +74,7 @@ size_flags_vertical = 0 columns = 5 [node name="Horizontal" type="Button" parent="ScrollContainer/CenterContainer/GridContainer" groups=["UIButtons"]] -custom_minimum_size = Vector2(32, 32) +custom_minimum_size = Vector2(44, 32) layout_mode = 2 tooltip_text = "Enable horizontal mirrored drawing" mouse_default_cursor_shape = 2 @@ -81,19 +82,49 @@ toggle_mode = true shortcut = SubResource("Shortcut_eld87") [node name="TextureRect" type="TextureRect" parent="ScrollContainer/CenterContainer/GridContainer/Horizontal"] +layout_mode = 1 +anchors_preset = 4 +anchor_top = 0.5 +anchor_bottom = 0.5 +offset_left = 5.0 +offset_top = -10.0 +offset_right = 25.0 +offset_bottom = 11.0 +grow_vertical = 2 +texture = ExtResource("1") + +[node name="HorizontalMirrorOptions" type="MenuButton" parent="ScrollContainer/CenterContainer/GridContainer/Horizontal"] +unique_name_in_owner = true +custom_minimum_size = Vector2(22, 0) +layout_mode = 1 +anchors_preset = 6 +anchor_left = 1.0 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_left = -22.0 +offset_top = -10.0 +offset_bottom = 10.0 +mouse_default_cursor_shape = 2 +item_count = 2 +popup/item_0/text = "Move to canvas center" +popup/item_1/text = "Move to view center" +popup/item_1/id = 1 + +[node name="TextureRect" type="TextureRect" parent="ScrollContainer/CenterContainer/GridContainer/Horizontal/HorizontalMirrorOptions"] layout_mode = 0 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -10.0 -offset_top = -10.5 -offset_right = 10.0 -offset_bottom = 10.5 -texture = ExtResource("1") +offset_left = -6.0 +offset_top = -6.0 +offset_right = 6.0 +offset_bottom = 6.0 +texture = ExtResource("3_faalk") [node name="Vertical" type="Button" parent="ScrollContainer/CenterContainer/GridContainer" groups=["UIButtons"]] -custom_minimum_size = Vector2(32, 32) +custom_minimum_size = Vector2(44, 32) layout_mode = 2 tooltip_text = "Enable vertical mirrored drawing" mouse_default_cursor_shape = 2 @@ -101,16 +132,48 @@ toggle_mode = true shortcut = SubResource("Shortcut_ai7qc") [node name="TextureRect" type="TextureRect" parent="ScrollContainer/CenterContainer/GridContainer/Vertical"] +layout_mode = 1 +anchors_preset = 4 +anchor_top = 0.5 +anchor_bottom = 0.5 +offset_left = 5.0 +offset_top = -10.0 +offset_right = 25.0 +offset_bottom = 10.0 +grow_vertical = 2 +texture = ExtResource("2") + +[node name="VerticalMirrorOptions" type="MenuButton" parent="ScrollContainer/CenterContainer/GridContainer/Vertical"] +unique_name_in_owner = true +custom_minimum_size = Vector2(22, 0) +layout_mode = 1 +anchors_preset = 6 +anchor_left = 1.0 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_left = -22.0 +offset_top = -10.0 +offset_bottom = 10.0 +grow_horizontal = 0 +grow_vertical = 2 +mouse_default_cursor_shape = 2 +item_count = 2 +popup/item_0/text = "Move to canvas center" +popup/item_1/text = "Move to view center" +popup/item_1/id = 1 + +[node name="TextureRect" type="TextureRect" parent="ScrollContainer/CenterContainer/GridContainer/Vertical/VerticalMirrorOptions"] layout_mode = 0 anchor_left = 0.5 anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 -offset_left = -10.0 -offset_top = -10.0 -offset_right = 10.0 -offset_bottom = 10.0 -texture = ExtResource("2") +offset_left = -6.0 +offset_top = -6.0 +offset_right = 6.0 +offset_bottom = 6.0 +texture = ExtResource("3_faalk") [node name="PixelPerfect" type="Button" parent="ScrollContainer/CenterContainer/GridContainer" groups=["UIButtons"]] custom_minimum_size = Vector2(32, 32)