2021-11-25 12:48:30 +00:00
|
|
|
class_name SelectionTool
|
|
|
|
extends BaseTool
|
2021-04-27 23:57:48 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var undo_data: Dictionary
|
2021-05-02 23:00:07 +00:00
|
|
|
var _move := false
|
|
|
|
var _move_content := true
|
2021-05-03 15:33:51 +00:00
|
|
|
var _start_pos := Vector2.ZERO
|
2021-05-02 23:00:07 +00:00
|
|
|
var _offset := Vector2.ZERO
|
2021-05-17 22:56:55 +00:00
|
|
|
# For tools such as the Polygon selection tool where you have to
|
|
|
|
# click multiple times to create a selection
|
|
|
|
var _ongoing_selection := false
|
2021-05-03 15:33:51 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var _add := false # Shift + Mouse Click
|
|
|
|
var _subtract := false # Ctrl + Mouse Click
|
|
|
|
var _intersect := false # Shift + Ctrl + Mouse Click
|
|
|
|
var _snap_to_grid := false # Mouse Click + Ctrl
|
2021-04-27 23:57:48 +00:00
|
|
|
|
2021-05-11 01:41:30 +00:00
|
|
|
# Used to check if the state of content transformation has been changed
|
|
|
|
# while draw_move() is being called. For example, pressing Enter while still moving content
|
|
|
|
var _content_transformation_check := false
|
2021-04-27 23:57:48 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
onready var selection_node: Node2D = Global.canvas.selection
|
|
|
|
onready var xspinbox: SpinBox = find_node("XSpinBox")
|
|
|
|
onready var yspinbox: SpinBox = find_node("YSpinBox")
|
|
|
|
onready var wspinbox: SpinBox = find_node("WSpinBox")
|
|
|
|
onready var hspinbox: SpinBox = find_node("HSpinBox")
|
|
|
|
onready var timer: Timer = $Timer
|
2021-05-01 00:10:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2021-05-08 21:56:23 +00:00
|
|
|
set_spinbox_values()
|
2021-05-01 00:10:23 +00:00
|
|
|
|
2021-04-27 23:57:48 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _input(event: InputEvent) -> void:
|
2021-05-03 23:45:14 +00:00
|
|
|
if _move:
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
if event.is_action_pressed("transform_snap_grid"):
|
2021-05-03 23:45:14 +00:00
|
|
|
_snap_to_grid = true
|
|
|
|
var grid_size := Vector2(Global.grid_width, Global.grid_height)
|
|
|
|
_offset = _offset.snapped(grid_size)
|
|
|
|
var prev_pos = selection_node.big_bounding_rectangle.position
|
2021-11-25 12:48:30 +00:00
|
|
|
selection_node.big_bounding_rectangle.position = prev_pos.snapped(grid_size)
|
|
|
|
selection_node.marching_ants_outline.offset += (
|
|
|
|
selection_node.big_bounding_rectangle.position
|
|
|
|
- prev_pos
|
|
|
|
)
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
elif event.is_action_released("transform_snap_grid"):
|
2021-05-03 23:45:14 +00:00
|
|
|
_snap_to_grid = false
|
|
|
|
|
|
|
|
|
2021-05-08 21:56:23 +00:00
|
|
|
func set_spinbox_values() -> void:
|
2021-11-25 12:48:30 +00:00
|
|
|
var select_rect: Rect2 = selection_node.big_bounding_rectangle
|
2021-05-08 21:56:23 +00:00
|
|
|
xspinbox.editable = !select_rect.has_no_area()
|
|
|
|
yspinbox.editable = !select_rect.has_no_area()
|
|
|
|
wspinbox.editable = !select_rect.has_no_area()
|
|
|
|
hspinbox.editable = !select_rect.has_no_area()
|
|
|
|
|
|
|
|
xspinbox.value = select_rect.position.x
|
|
|
|
yspinbox.value = select_rect.position.y
|
|
|
|
wspinbox.value = select_rect.size.x
|
|
|
|
hspinbox.value = select_rect.size.y
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func draw_start(position: Vector2) -> void:
|
2021-12-14 23:39:24 +00:00
|
|
|
.draw_start(position)
|
2021-05-07 01:33:28 +00:00
|
|
|
if selection_node.arrow_key_move:
|
|
|
|
return
|
2021-11-25 12:48:30 +00:00
|
|
|
var project: Project = Global.current_project
|
|
|
|
undo_data = selection_node.get_undo_data(false)
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
_intersect = Input.is_action_pressed("selection_intersect", true)
|
|
|
|
_add = Input.is_action_pressed("selection_add", true)
|
|
|
|
_subtract = Input.is_action_pressed("selection_subtract", true)
|
2021-05-03 15:33:51 +00:00
|
|
|
_start_pos = position
|
2021-05-03 00:11:12 +00:00
|
|
|
_offset = position
|
2021-04-27 23:57:48 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var selection_position: Vector2 = selection_node.big_bounding_rectangle.position
|
2021-05-02 23:00:07 +00:00
|
|
|
var offsetted_pos := position
|
|
|
|
if selection_position.x < 0:
|
|
|
|
offsetted_pos.x -= selection_position.x
|
|
|
|
if selection_position.y < 0:
|
|
|
|
offsetted_pos.y -= selection_position.y
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
|
|
|
|
var quick_copy: bool = Input.is_action_pressed("transform_copy_selection_content", true)
|
2021-11-25 12:48:30 +00:00
|
|
|
if (
|
|
|
|
offsetted_pos.x >= 0
|
|
|
|
and offsetted_pos.y >= 0
|
|
|
|
and project.selection_bitmap.get_bit(offsetted_pos)
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
and (!_add and !_subtract and !_intersect or quick_copy)
|
2021-11-25 12:48:30 +00:00
|
|
|
and !_ongoing_selection
|
|
|
|
):
|
2021-08-29 22:22:13 +00:00
|
|
|
if !Global.current_project.layers[Global.current_project.current_layer].can_layer_get_drawn():
|
|
|
|
return
|
2021-05-02 23:00:07 +00:00
|
|
|
# Move current selection
|
|
|
|
_move = true
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
if quick_copy: # Move selection without cutting it from the original position (quick copy)
|
|
|
|
_move_content = true
|
|
|
|
if selection_node.is_moving_content:
|
|
|
|
for image in _get_selected_draw_images():
|
|
|
|
image.blit_rect_mask(
|
|
|
|
selection_node.preview_image,
|
|
|
|
selection_node.preview_image,
|
|
|
|
Rect2(Vector2.ZERO, project.selection_bitmap.get_size()),
|
|
|
|
selection_node.big_bounding_rectangle.position
|
|
|
|
)
|
|
|
|
|
|
|
|
var selected_bitmap_copy = project.selection_bitmap.duplicate()
|
|
|
|
project.move_bitmap_values(selected_bitmap_copy)
|
|
|
|
|
|
|
|
project.selection_bitmap = selected_bitmap_copy
|
|
|
|
selection_node.commit_undo("Move Selection", selection_node.undo_data)
|
|
|
|
selection_node.undo_data = selection_node.get_undo_data(true)
|
2021-07-29 13:03:32 +00:00
|
|
|
else:
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
selection_node.transform_content_start()
|
|
|
|
selection_node.clear_in_selected_cels = false
|
|
|
|
for image in _get_selected_draw_images():
|
|
|
|
image.blit_rect_mask(
|
|
|
|
selection_node.preview_image,
|
|
|
|
selection_node.preview_image,
|
|
|
|
Rect2(Vector2.ZERO, project.selection_bitmap.get_size()),
|
|
|
|
selection_node.big_bounding_rectangle.position
|
|
|
|
)
|
|
|
|
Global.canvas.update_selected_cels_textures()
|
|
|
|
|
|
|
|
elif Input.is_action_pressed("transform_move_selection_only", true): # Doesn't move content
|
|
|
|
selection_node.transform_content_confirm()
|
|
|
|
_move_content = false
|
|
|
|
selection_node.move_borders_start()
|
|
|
|
else: # Move selection and content normally
|
2021-07-29 13:03:32 +00:00
|
|
|
_move_content = true
|
|
|
|
selection_node.transform_content_start()
|
2021-05-03 18:10:49 +00:00
|
|
|
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
else: # No moving
|
2021-05-03 18:10:49 +00:00
|
|
|
selection_node.transform_content_confirm()
|
2021-05-02 23:00:07 +00:00
|
|
|
|
2021-05-11 01:41:30 +00:00
|
|
|
_content_transformation_check = selection_node.is_moving_content
|
|
|
|
|
2021-05-02 23:00:07 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func draw_move(position: Vector2) -> void:
|
2021-12-14 23:39:24 +00:00
|
|
|
.draw_move(position)
|
2021-05-07 01:33:28 +00:00
|
|
|
if selection_node.arrow_key_move:
|
|
|
|
return
|
2021-05-11 01:41:30 +00:00
|
|
|
# This is true if content transformation has been confirmed (pressed Enter for example)
|
|
|
|
# while the content is being moved
|
|
|
|
if _content_transformation_check != selection_node.is_moving_content:
|
|
|
|
return
|
2021-05-02 23:00:07 +00:00
|
|
|
if _move:
|
Implement the Keychain Plugin (#700)
* Start implementing the godot_better_input plugin
* Update ShortcutEdit.gd
* Load & save preset option
* Add some groups and fix action events not being deleted on load
* Add MenuInputAction class for multiple menu accelerators
* Create a proper plugin and a BetterInput autoload
* Update menu accelerators
* Move settings to BetterInput
* Move menu enums to Global, make more MenuInputActions
* Add more menu events
* Add new groups
* Optimize BetterInput _input() method
* Remove a lot of lines of code
* Change some previous events, add ignore actions and a View menu group
* Change update_item_accelerator to update_ui
* Move MenuInputAction initialization to BetterInput.gd
* Update hint tooltips when a shortcut changes
Temporarily comment out some code regarding the configurable modifiers
* Some MenuInputAction variable name changes
* Add handle_input() to InputAction
* Update the shortcuts of buttons
* Fix shortcut selector menu position
* Change plugin name into Keychain
* Fix keyboard input dialog exiting when Enter or Space is being pressed
* Add two more groups
* Make groups folded by default
* Temporarily make tool modifier shortcuts not configurable
A temporary change, they will be made configurable again, with different actions that are currently mapped to the same events, local/independent from each other.
* Add license for Keychain
* Fix issue where a key event would be added in other input types
* Fix bug where the assigned state was not updated when the dialog appeared again
* Update Main.tscn
* Add a disabled line edit in keyboard shortcut selector to grab focus
* Load presets in the Keychain autoload
This way, the input actions get updated from the start, instead of only at the ShortcutEdit scene.
WARNING, this currently causes crashes if the menu items have no shortcut binded to them.
* Move custom settings away from Keychain.gd
To keep it the same as the upstream plugin
* Change menu enum names
* Made action_get_first_key() more general
* Use arrays for menu items instead of dictionaries, fixes crash
* Move moveable panels to Window menu
* Format
* Optimize hint tooltip updating
* Add support for translations in Keychain
* Translation changes
* Made tool modifiers configurable
Needs more testing.
* Made camera arrow key movement configurable & joypad axis support
This commit removes the ability to press Shift and Control+Shift to adjust the camera arrow key movement speed. Instead, the speed depends on the zoom level.
The right joypad analog stick is configured to move the camera by default.
* Rename presets into shortcut profiles, use Resources and let users create their own
* [skip ci] Update addons README
* Update Global.gd
2022-05-16 12:07:51 +00:00
|
|
|
if Input.is_action_pressed("transform_snap_axis"): # Snap to axis
|
2021-05-03 15:33:51 +00:00
|
|
|
var angle := position.angle_to_point(_start_pos)
|
2021-11-25 12:48:30 +00:00
|
|
|
if abs(angle) <= PI / 4 or abs(angle) >= 3 * PI / 4:
|
2021-05-03 15:33:51 +00:00
|
|
|
position.y = _start_pos.y
|
|
|
|
else:
|
|
|
|
position.x = _start_pos.x
|
2021-05-03 23:45:14 +00:00
|
|
|
if _snap_to_grid:
|
|
|
|
position = position.snapped(Vector2(Global.grid_width, Global.grid_height))
|
2021-05-28 14:43:50 +00:00
|
|
|
position += Vector2(Global.grid_offset_x, Global.grid_offset_y)
|
2021-05-03 15:33:51 +00:00
|
|
|
|
2021-05-02 23:00:07 +00:00
|
|
|
if _move_content:
|
2021-05-03 18:10:49 +00:00
|
|
|
selection_node.move_content(position - _offset)
|
2021-05-02 23:00:07 +00:00
|
|
|
else:
|
2021-05-03 18:10:49 +00:00
|
|
|
selection_node.move_borders(position - _offset)
|
2021-05-03 15:33:51 +00:00
|
|
|
|
2021-05-02 23:00:07 +00:00
|
|
|
_offset = position
|
2021-05-03 18:10:49 +00:00
|
|
|
_set_cursor_text(selection_node.big_bounding_rectangle)
|
2021-05-02 23:00:07 +00:00
|
|
|
|
|
|
|
|
2021-12-14 23:39:24 +00:00
|
|
|
func draw_end(position: Vector2) -> void:
|
|
|
|
.draw_end(position)
|
2021-05-07 01:33:28 +00:00
|
|
|
if selection_node.arrow_key_move:
|
|
|
|
return
|
2021-05-11 01:41:30 +00:00
|
|
|
if _content_transformation_check == selection_node.is_moving_content:
|
|
|
|
if _move:
|
|
|
|
selection_node.move_borders_end()
|
|
|
|
else:
|
2021-12-14 23:39:24 +00:00
|
|
|
apply_selection(position)
|
2021-05-02 23:00:07 +00:00
|
|
|
|
|
|
|
_move = false
|
2021-05-03 23:45:14 +00:00
|
|
|
_snap_to_grid = false
|
2021-05-02 23:00:07 +00:00
|
|
|
cursor_text = ""
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func apply_selection(_position: Vector2) -> void:
|
2021-05-02 23:00:07 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _set_cursor_text(rect: Rect2) -> void:
|
2021-05-02 23:00:07 +00:00
|
|
|
cursor_text = "%s, %s" % [rect.position.x, rect.position.y]
|
|
|
|
cursor_text += " -> %s, %s" % [rect.end.x - 1, rect.end.y - 1]
|
|
|
|
cursor_text += " (%s, %s)" % [rect.size.x, rect.size.y]
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_XSpinBox_value_changed(value: float) -> void:
|
|
|
|
var project: Project = Global.current_project
|
2021-05-03 18:10:49 +00:00
|
|
|
if !project.has_selection or selection_node.big_bounding_rectangle.position.x == value:
|
2021-05-01 00:10:23 +00:00
|
|
|
return
|
2021-05-10 21:27:57 +00:00
|
|
|
if timer.is_stopped():
|
2021-11-25 12:48:30 +00:00
|
|
|
undo_data = selection_node.get_undo_data(false)
|
2021-05-10 21:27:57 +00:00
|
|
|
timer.start()
|
2021-05-03 18:10:49 +00:00
|
|
|
selection_node.big_bounding_rectangle.position.x = value
|
2021-05-01 00:10:23 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var selection_bitmap_copy: BitMap = project.selection_bitmap.duplicate()
|
2021-05-01 00:10:23 +00:00
|
|
|
project.move_bitmap_values(selection_bitmap_copy)
|
|
|
|
project.selection_bitmap = selection_bitmap_copy
|
|
|
|
project.selection_bitmap_changed()
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_YSpinBox_value_changed(value: float) -> void:
|
|
|
|
var project: Project = Global.current_project
|
2021-05-03 18:10:49 +00:00
|
|
|
if !project.has_selection or selection_node.big_bounding_rectangle.position.y == value:
|
2021-05-01 00:10:23 +00:00
|
|
|
return
|
2021-05-10 21:27:57 +00:00
|
|
|
if timer.is_stopped():
|
2021-11-25 12:48:30 +00:00
|
|
|
undo_data = selection_node.get_undo_data(false)
|
2021-05-10 21:27:57 +00:00
|
|
|
timer.start()
|
2021-05-03 18:10:49 +00:00
|
|
|
selection_node.big_bounding_rectangle.position.y = value
|
2021-05-01 00:10:23 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var selection_bitmap_copy: BitMap = project.selection_bitmap.duplicate()
|
2021-05-01 00:10:23 +00:00
|
|
|
project.move_bitmap_values(selection_bitmap_copy)
|
|
|
|
project.selection_bitmap = selection_bitmap_copy
|
|
|
|
project.selection_bitmap_changed()
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_WSpinBox_value_changed(value: float) -> void:
|
|
|
|
var project: Project = Global.current_project
|
|
|
|
if (
|
|
|
|
!project.has_selection
|
|
|
|
or selection_node.big_bounding_rectangle.size.x == value
|
|
|
|
or selection_node.big_bounding_rectangle.size.x <= 0
|
|
|
|
):
|
2021-05-01 00:10:23 +00:00
|
|
|
return
|
2021-05-10 21:27:57 +00:00
|
|
|
if timer.is_stopped():
|
2021-11-25 12:48:30 +00:00
|
|
|
undo_data = selection_node.get_undo_data(false)
|
2021-05-10 21:27:57 +00:00
|
|
|
timer.start()
|
2021-05-03 18:10:49 +00:00
|
|
|
selection_node.big_bounding_rectangle.size.x = value
|
2021-05-01 00:10:23 +00:00
|
|
|
resize_selection()
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_HSpinBox_value_changed(value: float) -> void:
|
|
|
|
var project: Project = Global.current_project
|
|
|
|
if (
|
|
|
|
!project.has_selection
|
|
|
|
or selection_node.big_bounding_rectangle.size.y == value
|
|
|
|
or selection_node.big_bounding_rectangle.size.y <= 0
|
|
|
|
):
|
2021-05-01 00:10:23 +00:00
|
|
|
return
|
2021-05-10 21:27:57 +00:00
|
|
|
if timer.is_stopped():
|
2021-11-25 12:48:30 +00:00
|
|
|
undo_data = selection_node.get_undo_data(false)
|
2021-05-10 21:27:57 +00:00
|
|
|
timer.start()
|
2021-05-03 18:10:49 +00:00
|
|
|
selection_node.big_bounding_rectangle.size.y = value
|
2021-05-01 00:10:23 +00:00
|
|
|
resize_selection()
|
2021-04-27 23:57:48 +00:00
|
|
|
|
|
|
|
|
2021-05-01 00:10:23 +00:00
|
|
|
func resize_selection() -> void:
|
2021-11-25 12:48:30 +00:00
|
|
|
var project: Project = Global.current_project
|
|
|
|
var bitmap: BitMap = project.selection_bitmap
|
2021-05-03 18:10:49 +00:00
|
|
|
if selection_node.is_moving_content:
|
2021-05-10 21:27:57 +00:00
|
|
|
bitmap = selection_node.original_bitmap
|
2021-11-25 12:48:30 +00:00
|
|
|
var preview_image: Image = selection_node.preview_image
|
2021-05-03 18:10:49 +00:00
|
|
|
preview_image.copy_from(selection_node.original_preview_image)
|
2021-11-25 12:48:30 +00:00
|
|
|
preview_image.resize(
|
|
|
|
selection_node.big_bounding_rectangle.size.x,
|
|
|
|
selection_node.big_bounding_rectangle.size.y,
|
|
|
|
Image.INTERPOLATE_NEAREST
|
|
|
|
)
|
2021-05-03 18:10:49 +00:00
|
|
|
selection_node.preview_image_texture.create_from_image(preview_image, 0)
|
2021-05-10 21:27:57 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
var selection_bitmap_copy: BitMap = project.selection_bitmap.duplicate()
|
|
|
|
selection_bitmap_copy = project.resize_bitmap_values(
|
|
|
|
bitmap, selection_node.big_bounding_rectangle.size, false, false
|
|
|
|
)
|
2021-05-10 21:27:57 +00:00
|
|
|
project.selection_bitmap = selection_bitmap_copy
|
|
|
|
project.selection_bitmap_changed()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_Timer_timeout() -> void:
|
|
|
|
if !selection_node.is_moving_content:
|
|
|
|
selection_node.commit_undo("Move Selection", undo_data)
|