From e2971a8fe90125a49f7dffe857a454d1092679e9 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 31 Oct 2024 23:49:58 +0200 Subject: [PATCH] Add UI buttons for confirming and cancelling a transformation Needed especially for users without a keyboard. --- assets/graphics/misc/check_plain.png | Bin 0 -> 176 bytes assets/graphics/misc/check_plain.png.import | 34 ++++++++++ assets/graphics/misc/close.png | Bin 0 -> 153 bytes assets/graphics/misc/close.png.import | 34 ++++++++++ src/Tools/BaseSelectionTool.gd | 21 +++++- src/Tools/BaseSelectionTool.tscn | 69 +++++++++++++++++--- src/UI/Canvas/Canvas.gd | 2 +- src/UI/Canvas/Selection.gd | 14 ++-- 8 files changed, 156 insertions(+), 18 deletions(-) create mode 100644 assets/graphics/misc/check_plain.png create mode 100644 assets/graphics/misc/check_plain.png.import create mode 100644 assets/graphics/misc/close.png create mode 100644 assets/graphics/misc/close.png.import diff --git a/assets/graphics/misc/check_plain.png b/assets/graphics/misc/check_plain.png new file mode 100644 index 0000000000000000000000000000000000000000..a589dba2f5001da7610a08696329785914b984a2 GIT binary patch literal 176 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE-VV{wqX6T`Z5GB1IgEKe855R2ZY zm#u{kC~&x5^!~O#J?N!M4_8O1Q|d>HX8RwmD_3pXDs$9j35(svKDnc1>T?n|7(V3k zZkD@tP%K8)k%d`6TBdc8#DS-#=>`VT+k7L}G#i_A?{(ns-FNd6Yl}m7*#F-Gf5Yxd Xu>~+(bgwG|+REVR>gTe~DWM4fP7geO literal 0 HcmV?d00001 diff --git a/assets/graphics/misc/check_plain.png.import b/assets/graphics/misc/check_plain.png.import new file mode 100644 index 00000000000..9cfa45d0962 --- /dev/null +++ b/assets/graphics/misc/check_plain.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d267xalp3p7ru" +path="res://.godot/imported/check_plain.png-6f37534ee70be1593b3b1be7b4c80f23.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/graphics/misc/check_plain.png" +dest_files=["res://.godot/imported/check_plain.png-6f37534ee70be1593b3b1be7b4c80f23.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/graphics/misc/close.png b/assets/graphics/misc/close.png new file mode 100644 index 0000000000000000000000000000000000000000..65415379199620e1049ffd85e8c0f1dfa7adcd36 GIT binary patch literal 153 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|f<0XvLo9mN zPCCd0ROLMT|NrMPfst4Gs+Oru)LXgg-v$GAhD+1KEs`G@CNQj?Io;+%nosoIg!C;2 z8!oGyN_An2{MsMDwed^uQrA^$Hbo~?C9YJv&=mboMR>}6pz#czu6{1-oD!M void: super._ready() + set_confirm_buttons_visibility() set_spinbox_values() refresh_options() + selection_node.is_moving_content_changed.connect(set_confirm_buttons_visibility) -## Ensure all items are added when we are selecting an option (bad things will happen otherwise) +func set_confirm_buttons_visibility() -> void: + confirm_buttons.visible = selection_node.is_moving_content + + +## Ensure all items are added when we are selecting an option. func refresh_options() -> void: $Modes.clear() $Modes.add_item("Replace selection") @@ -203,6 +210,16 @@ func apply_selection(_position: Vector2i) -> void: _intersect = true +func _on_confirm_button_pressed() -> void: + if selection_node.is_moving_content: + selection_node.transform_content_confirm() + + +func _on_cancel_button_pressed() -> void: + if selection_node.is_moving_content: + selection_node.transform_content_cancel() + + func _on_Modes_item_selected(index: int) -> void: _mode_selected = index save_config() diff --git a/src/Tools/BaseSelectionTool.tscn b/src/Tools/BaseSelectionTool.tscn index a600f1d5ae5..58ed7f3220e 100644 --- a/src/Tools/BaseSelectionTool.tscn +++ b/src/Tools/BaseSelectionTool.tscn @@ -1,34 +1,85 @@ -[gd_scene load_steps=4 format=3 uid="uid://bd62qfjn380wf"] +[gd_scene load_steps=10 format=3 uid="uid://bd62qfjn380wf"] [ext_resource type="PackedScene" uid="uid://ctfgfelg0sho8" path="res://src/Tools/BaseTool.tscn" id="1"] [ext_resource type="Script" path="res://src/Tools/BaseSelectionTool.gd" id="2"] +[ext_resource type="Texture2D" uid="uid://d267xalp3p7ru" path="res://assets/graphics/misc/check_plain.png" id="3_mtv71"] [ext_resource type="PackedScene" path="res://src/UI/Nodes/ValueSliderV2.tscn" id="4"] +[ext_resource type="Texture2D" uid="uid://bnc78807k1xjv" path="res://assets/graphics/misc/close.png" id="4_ad04n"] + +[sub_resource type="InputEventAction" id="InputEventAction_gfv4x"] +action = &"transformation_confirm" + +[sub_resource type="Shortcut" id="Shortcut_5gq73"] +events = [SubResource("InputEventAction_gfv4x")] + +[sub_resource type="InputEventAction" id="InputEventAction_nadbx"] +action = &"transformation_cancel" + +[sub_resource type="Shortcut" id="Shortcut_04tjd"] +events = [SubResource("InputEventAction_nadbx")] [node name="ToolOptions" instance=ExtResource("1")] script = ExtResource("2") -[node name="ModeLabel" type="Label" parent="." index="2"] +[node name="ConfirmButtons" type="HBoxContainer" parent="." index="2"] +layout_mode = 2 + +[node name="ConfirmButton" type="Button" parent="ConfirmButtons" index="0"] +custom_minimum_size = Vector2(0, 26) +layout_mode = 2 +size_flags_horizontal = 3 +mouse_default_cursor_shape = 2 +shortcut = SubResource("Shortcut_5gq73") + +[node name="TextureRect" type="TextureRect" parent="ConfirmButtons/ConfirmButton" index="0" groups=["UIButtons"]] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("3_mtv71") +stretch_mode = 3 + +[node name="CancelButton" type="Button" parent="ConfirmButtons" index="1"] +custom_minimum_size = Vector2(0, 26) +layout_mode = 2 +size_flags_horizontal = 3 +mouse_default_cursor_shape = 2 +shortcut = SubResource("Shortcut_04tjd") + +[node name="TextureRect" type="TextureRect" parent="ConfirmButtons/CancelButton" index="0" groups=["UIButtons"]] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +texture = ExtResource("4_ad04n") +stretch_mode = 3 + +[node name="ModeLabel" type="Label" parent="." index="3"] layout_mode = 2 text = "Mode:" -[node name="Modes" type="OptionButton" parent="." index="3"] +[node name="Modes" type="OptionButton" parent="." index="4"] layout_mode = 2 mouse_default_cursor_shape = 2 -[node name="PositionLabel" type="Label" parent="." index="4"] +[node name="PositionLabel" type="Label" parent="." index="5"] layout_mode = 2 text = "Position:" -[node name="Position" parent="." index="5" instance=ExtResource("4")] +[node name="Position" parent="." index="6" instance=ExtResource("4")] layout_mode = 2 allow_greater = true allow_lesser = true -[node name="SizeLabel" type="Label" parent="." index="6"] +[node name="SizeLabel" type="Label" parent="." index="7"] layout_mode = 2 text = "Size:" -[node name="Size" parent="." index="7" instance=ExtResource("4")] +[node name="Size" parent="." index="8" instance=ExtResource("4")] layout_mode = 2 value = Vector2(1, 1) min_value = Vector2(1, 1) @@ -37,10 +88,12 @@ show_ratio = true prefix_x = "Width:" prefix_y = "Height:" -[node name="Timer" type="Timer" parent="." index="8"] +[node name="Timer" type="Timer" parent="." index="9"] wait_time = 0.2 one_shot = true +[connection signal="pressed" from="ConfirmButtons/ConfirmButton" to="." method="_on_confirm_button_pressed"] +[connection signal="pressed" from="ConfirmButtons/CancelButton" to="." method="_on_cancel_button_pressed"] [connection signal="item_selected" from="Modes" to="." method="_on_Modes_item_selected"] [connection signal="value_changed" from="Position" to="." method="_on_Position_value_changed"] [connection signal="ratio_toggled" from="Size" to="." method="_on_Size_ratio_toggled"] diff --git a/src/UI/Canvas/Canvas.gd b/src/UI/Canvas/Canvas.gd index cae059c7364..f97e3ff15c0 100644 --- a/src/UI/Canvas/Canvas.gd +++ b/src/UI/Canvas/Canvas.gd @@ -17,7 +17,7 @@ var layer_metadata_texture := ImageTexture.new() @onready var tile_mode := $TileMode as Node2D @onready var pixel_grid := $PixelGrid as Node2D @onready var grid := $Grid as Node2D -@onready var selection := $Selection as Node2D +@onready var selection := $Selection as SelectionNode @onready var onion_past := $OnionPast as Node2D @onready var onion_future := $OnionFuture as Node2D @onready var crop_rect := $CropRect as CropRect diff --git a/src/UI/Canvas/Selection.gd b/src/UI/Canvas/Selection.gd index a540054ad54..3110734f5b8 100644 --- a/src/UI/Canvas/Selection.gd +++ b/src/UI/Canvas/Selection.gd @@ -1,5 +1,8 @@ +class_name SelectionNode extends Node2D +signal is_moving_content_changed + enum SelectionOperation { ADD, SUBTRACT, INTERSECT } const KEY_MOVE_ACTION_NAMES: PackedStringArray = [&"ui_up", &"ui_down", &"ui_left", &"ui_right"] const CLIPBOARD_FILE_PATH := "user://clipboard.txt" @@ -7,7 +10,10 @@ const CLIPBOARD_FILE_PATH := "user://clipboard.txt" # flags (additional properties of selection that can be toggled) var flag_tilemode := false -var is_moving_content := false +var is_moving_content := false: + set(value): + is_moving_content = value + is_moving_content_changed.emit() var arrow_key_move := false var is_pasting := false var big_bounding_rectangle := Rect2i(): @@ -100,12 +106,6 @@ func _input(event: InputEvent) -> void: image_current_pixel = canvas.current_pixel if Global.mirror_view: image_current_pixel.x = Global.current_project.size.x - image_current_pixel.x - if is_moving_content: - if Input.is_action_just_pressed("transformation_confirm"): - transform_content_confirm() - elif Input.is_action_just_pressed("transformation_cancel"): - transform_content_cancel() - if not project.layers[project.current_layer].can_layer_get_drawn(): return if event is InputEventKey: