2020-07-09 12:22:17 +00:00
|
|
|
|
extends Node
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
signal color_changed(color, button)
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var pen_pressure := 1.0
|
2022-02-17 14:07:03 +00:00
|
|
|
|
var horizontal_mirror := false
|
|
|
|
|
var vertical_mirror := false
|
2022-02-28 17:24:14 +00:00
|
|
|
|
var pixel_perfect := false
|
2021-11-25 12:48:30 +00:00
|
|
|
|
|
2022-02-21 16:02:02 +00:00
|
|
|
|
var tools := {
|
|
|
|
|
"RectSelect":
|
2022-02-22 00:58:52 +00:00
|
|
|
|
Tool.new(
|
2022-02-22 22:10:16 +00:00
|
|
|
|
"RectSelect",
|
|
|
|
|
"Rectangular Selection",
|
|
|
|
|
"rectangle_select",
|
|
|
|
|
preload("res://src/Tools/SelectionTools/RectSelect.tscn")
|
2022-02-22 00:58:52 +00:00
|
|
|
|
),
|
2022-02-21 16:02:02 +00:00
|
|
|
|
"EllipseSelect":
|
2022-02-22 00:58:52 +00:00
|
|
|
|
Tool.new(
|
2022-02-22 22:10:16 +00:00
|
|
|
|
"EllipseSelect",
|
|
|
|
|
"Elliptical Selection",
|
|
|
|
|
"ellipse_select",
|
|
|
|
|
preload("res://src/Tools/SelectionTools/EllipseSelect.tscn")
|
2022-02-22 00:58:52 +00:00
|
|
|
|
),
|
2022-02-21 16:02:02 +00:00
|
|
|
|
"PolygonSelect":
|
|
|
|
|
Tool.new(
|
|
|
|
|
"PolygonSelect",
|
|
|
|
|
"Polygonal Selection",
|
|
|
|
|
"polygon_select",
|
2022-02-22 22:10:16 +00:00
|
|
|
|
preload("res://src/Tools/SelectionTools/PolygonSelect.tscn"),
|
|
|
|
|
"Double-click to connect the last point to the starting point"
|
2022-02-21 16:02:02 +00:00
|
|
|
|
),
|
|
|
|
|
"ColorSelect":
|
2022-02-22 22:10:16 +00:00
|
|
|
|
Tool.new(
|
|
|
|
|
"ColorSelect",
|
|
|
|
|
"Select By Color",
|
|
|
|
|
"color_select",
|
|
|
|
|
preload("res://src/Tools/SelectionTools/ColorSelect.tscn")
|
|
|
|
|
),
|
|
|
|
|
"MagicWand":
|
|
|
|
|
Tool.new(
|
|
|
|
|
"MagicWand",
|
|
|
|
|
"Magic Wand",
|
|
|
|
|
"magic_wand",
|
|
|
|
|
preload("res://src/Tools/SelectionTools/MagicWand.tscn")
|
|
|
|
|
),
|
|
|
|
|
"Lasso":
|
|
|
|
|
Tool.new(
|
|
|
|
|
"Lasso",
|
|
|
|
|
"Lasso / Free Select Tool",
|
|
|
|
|
"lasso",
|
|
|
|
|
preload("res://src/Tools/SelectionTools/Lasso.tscn")
|
|
|
|
|
),
|
|
|
|
|
"Move": Tool.new("Move", "Move", "move", preload("res://src/Tools/Move.tscn")),
|
|
|
|
|
"Zoom": Tool.new("Zoom", "Zoom", "zoom", preload("res://src/Tools/Zoom.tscn")),
|
|
|
|
|
"Pan": Tool.new("Pan", "Pan", "pan", preload("res://src/Tools/Pan.tscn")),
|
2022-02-21 16:02:02 +00:00
|
|
|
|
"ColorPicker":
|
|
|
|
|
Tool.new(
|
2022-02-22 22:10:16 +00:00
|
|
|
|
"ColorPicker",
|
|
|
|
|
"Color Picker",
|
|
|
|
|
"colorpicker",
|
|
|
|
|
preload("res://src/Tools/ColorPicker.tscn"),
|
|
|
|
|
"Select a color from a pixel of the sprite"
|
2022-02-21 16:02:02 +00:00
|
|
|
|
),
|
2022-02-22 22:10:16 +00:00
|
|
|
|
"Pencil":
|
|
|
|
|
Tool.new(
|
|
|
|
|
"Pencil",
|
|
|
|
|
"Pencil",
|
|
|
|
|
"pencil",
|
|
|
|
|
preload("res://src/Tools/Pencil.tscn"),
|
|
|
|
|
"Hold %s to make a line",
|
2022-05-16 16:46:26 +00:00
|
|
|
|
["draw_create_line"]
|
2022-02-22 22:10:16 +00:00
|
|
|
|
),
|
|
|
|
|
"Eraser":
|
|
|
|
|
Tool.new(
|
|
|
|
|
"Eraser",
|
|
|
|
|
"Eraser",
|
|
|
|
|
"eraser",
|
|
|
|
|
preload("res://src/Tools/Eraser.tscn"),
|
|
|
|
|
"Hold %s to make a line",
|
2022-05-16 16:46:26 +00:00
|
|
|
|
["draw_create_line"]
|
2022-02-22 22:10:16 +00:00
|
|
|
|
),
|
|
|
|
|
"Bucket": Tool.new("Bucket", "Bucket", "fill", preload("res://src/Tools/Bucket.tscn")),
|
|
|
|
|
"Shading":
|
|
|
|
|
Tool.new("Shading", "Shading Tool", "shading", preload("res://src/Tools/Shading.tscn")),
|
2022-02-21 16:02:02 +00:00
|
|
|
|
"LineTool":
|
|
|
|
|
Tool.new(
|
|
|
|
|
"LineTool",
|
|
|
|
|
"Line Tool",
|
|
|
|
|
"linetool",
|
2022-02-22 22:10:16 +00:00
|
|
|
|
preload("res://src/Tools/LineTool.tscn"),
|
2022-02-21 16:02:02 +00:00
|
|
|
|
"""Hold %s to snap the angle of the line
|
|
|
|
|
Hold %s to center the shape on the click origin
|
|
|
|
|
Hold %s to displace the shape's origin""",
|
2022-05-16 16:46:26 +00:00
|
|
|
|
["shape_perfect", "shape_center", "shape_displace"]
|
2022-02-21 16:02:02 +00:00
|
|
|
|
),
|
|
|
|
|
"RectangleTool":
|
|
|
|
|
Tool.new(
|
|
|
|
|
"RectangleTool",
|
|
|
|
|
"Rectangle Tool",
|
|
|
|
|
"rectangletool",
|
2022-02-22 22:10:16 +00:00
|
|
|
|
preload("res://src/Tools/RectangleTool.tscn"),
|
2022-02-21 16:02:02 +00:00
|
|
|
|
"""Hold %s to create a 1:1 shape
|
|
|
|
|
Hold %s to center the shape on the click origin
|
|
|
|
|
Hold %s to displace the shape's origin""",
|
2022-05-16 16:46:26 +00:00
|
|
|
|
["shape_perfect", "shape_center", "shape_displace"]
|
2022-02-21 16:02:02 +00:00
|
|
|
|
),
|
|
|
|
|
"EllipseTool":
|
|
|
|
|
Tool.new(
|
|
|
|
|
"EllipseTool",
|
|
|
|
|
"Ellipse Tool",
|
|
|
|
|
"ellipsetool",
|
2022-02-22 22:10:16 +00:00
|
|
|
|
preload("res://src/Tools/EllipseTool.tscn"),
|
2022-02-21 16:02:02 +00:00
|
|
|
|
"""Hold %s to create a 1:1 shape
|
|
|
|
|
Hold %s to center the shape on the click origin
|
|
|
|
|
Hold %s to displace the shape's origin""",
|
2022-05-16 16:46:26 +00:00
|
|
|
|
["shape_perfect", "shape_center", "shape_displace"]
|
2022-02-21 16:02:02 +00:00
|
|
|
|
),
|
2021-11-25 12:48:30 +00:00
|
|
|
|
}
|
2022-02-21 16:02:02 +00:00
|
|
|
|
|
|
|
|
|
var _tool_button_scene: PackedScene = preload("res://src/Tools/ToolButton.tscn")
|
|
|
|
|
var _slots := {}
|
|
|
|
|
var _panels := {}
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var _tool_buttons: Node
|
|
|
|
|
var _active_button := -1
|
|
|
|
|
var _last_position := Vector2.INF
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
|
2022-02-21 16:02:02 +00:00
|
|
|
|
class Tool:
|
|
|
|
|
var name := ""
|
|
|
|
|
var display_name := ""
|
|
|
|
|
var scene: PackedScene
|
|
|
|
|
var icon: Texture
|
2022-02-22 22:10:16 +00:00
|
|
|
|
var cursor_icon: Texture
|
2022-02-21 16:02:02 +00:00
|
|
|
|
var shortcut := ""
|
|
|
|
|
var extra_hint := ""
|
|
|
|
|
var extra_shortcuts := [] # Array of String(s)
|
|
|
|
|
var button_node: BaseButton
|
|
|
|
|
|
|
|
|
|
func _init(
|
|
|
|
|
_name: String,
|
|
|
|
|
_display_name: String,
|
|
|
|
|
_shortcut: String,
|
2022-02-22 22:10:16 +00:00
|
|
|
|
_scene: PackedScene,
|
2022-02-21 16:02:02 +00:00
|
|
|
|
_extra_hint := "",
|
2022-02-22 22:10:16 +00:00
|
|
|
|
_extra_shortucts := []
|
2022-02-21 16:02:02 +00:00
|
|
|
|
) -> void:
|
|
|
|
|
name = _name
|
|
|
|
|
display_name = _display_name
|
|
|
|
|
shortcut = _shortcut
|
2022-02-22 22:10:16 +00:00
|
|
|
|
scene = _scene
|
2022-02-21 16:02:02 +00:00
|
|
|
|
extra_hint = _extra_hint
|
|
|
|
|
extra_shortcuts = _extra_shortucts
|
|
|
|
|
icon = load("res://assets/graphics/tools/%s.png" % name.to_lower())
|
2022-02-22 22:10:16 +00:00
|
|
|
|
cursor_icon = load("res://assets/graphics/tools/cursors/%s.png" % name.to_lower())
|
2022-02-21 16:02:02 +00:00
|
|
|
|
|
|
|
|
|
func generate_hint_tooltip() -> String:
|
|
|
|
|
var hint := display_name
|
2022-02-22 21:38:47 +00:00
|
|
|
|
var shortcuts := []
|
|
|
|
|
var left_text := ""
|
|
|
|
|
var right_text := ""
|
|
|
|
|
if InputMap.has_action("left_" + shortcut + "_tool"):
|
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 left_list := InputMap.get_action_list("left_" + shortcut + "_tool")
|
|
|
|
|
if left_list.size() > 0:
|
|
|
|
|
var left_shortcut: String = left_list[0].as_text()
|
|
|
|
|
shortcuts.append(left_shortcut)
|
|
|
|
|
left_text = "\n%s for left mouse button"
|
2022-02-22 21:38:47 +00:00
|
|
|
|
if InputMap.has_action("right_" + shortcut + "_tool"):
|
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 right_list := InputMap.get_action_list("right_" + shortcut + "_tool")
|
|
|
|
|
if right_list.size() > 0:
|
|
|
|
|
var right_shortcut: String = right_list[0].as_text()
|
|
|
|
|
shortcuts.append(right_shortcut)
|
|
|
|
|
right_text = "\n%s for right mouse button"
|
2022-02-22 21:38:47 +00:00
|
|
|
|
|
|
|
|
|
if !shortcuts.empty():
|
|
|
|
|
hint += "\n" + left_text + right_text
|
|
|
|
|
|
2022-02-21 16:02:02 +00:00
|
|
|
|
if !extra_hint.empty():
|
|
|
|
|
hint += "\n\n" + extra_hint
|
|
|
|
|
|
2022-05-16 16:46:26 +00:00
|
|
|
|
var extra_shortcuts_mapped := []
|
|
|
|
|
for event in extra_shortcuts:
|
|
|
|
|
var key: InputEventKey = Keychain.action_get_first_key(event)
|
|
|
|
|
var key_string := "None"
|
|
|
|
|
if key:
|
|
|
|
|
key_string = OS.get_scancode_string(key.get_scancode_with_modifiers())
|
|
|
|
|
extra_shortcuts_mapped.append(key_string)
|
|
|
|
|
|
|
|
|
|
shortcuts.append_array(extra_shortcuts_mapped)
|
2022-04-27 12:03:39 +00:00
|
|
|
|
|
2022-02-22 21:38:47 +00:00
|
|
|
|
if shortcuts.empty():
|
|
|
|
|
hint = tr(hint)
|
|
|
|
|
else:
|
|
|
|
|
hint = tr(hint) % shortcuts
|
2022-02-21 16:02:02 +00:00
|
|
|
|
return hint
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
class Slot:
|
|
|
|
|
var name: String
|
|
|
|
|
var kname: String
|
|
|
|
|
var tool_node: Node = null
|
|
|
|
|
var button: int
|
|
|
|
|
var color: Color
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func _init(slot_name: String) -> void:
|
2020-07-09 12:22:17 +00:00
|
|
|
|
name = slot_name
|
|
|
|
|
kname = name.replace(" ", "_").to_lower()
|
|
|
|
|
|
|
|
|
|
|
2020-10-23 17:18:39 +00:00
|
|
|
|
func _ready() -> void:
|
2021-06-26 11:01:07 +00:00
|
|
|
|
_tool_buttons = Global.control.find_node("ToolButtons")
|
2022-02-21 16:02:02 +00:00
|
|
|
|
for t in tools:
|
|
|
|
|
add_tool_button(tools[t])
|
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 tool_shortcut: String = Tools.tools[t].shortcut
|
|
|
|
|
var left_tool_shortcut := "left_%s_tool" % tool_shortcut
|
|
|
|
|
var right_tool_shortcut := "right_%s_tool" % tool_shortcut
|
|
|
|
|
Keychain.actions[left_tool_shortcut] = Keychain.InputAction.new("", "Left")
|
|
|
|
|
Keychain.actions[right_tool_shortcut] = Keychain.InputAction.new("", "Right")
|
|
|
|
|
|
2020-07-09 12:22:17 +00:00
|
|
|
|
_slots[BUTTON_LEFT] = Slot.new("Left tool")
|
|
|
|
|
_slots[BUTTON_RIGHT] = Slot.new("Right tool")
|
2021-08-16 23:56:19 +00:00
|
|
|
|
_panels[BUTTON_LEFT] = Global.control.find_node("LeftPanelContainer", true, false)
|
|
|
|
|
_panels[BUTTON_RIGHT] = Global.control.find_node("RightPanelContainer", true, false)
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var tool_name: String = Global.config_cache.get_value(
|
|
|
|
|
_slots[BUTTON_LEFT].kname, "tool", "Pencil"
|
|
|
|
|
)
|
2022-02-21 16:02:02 +00:00
|
|
|
|
if not tool_name in tools:
|
2021-11-17 17:59:14 +00:00
|
|
|
|
tool_name = "Pencil"
|
|
|
|
|
set_tool(tool_name, BUTTON_LEFT)
|
|
|
|
|
tool_name = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "tool", "Eraser")
|
2022-02-21 16:02:02 +00:00
|
|
|
|
if not tool_name in tools:
|
2021-11-17 17:59:14 +00:00
|
|
|
|
tool_name = "Eraser"
|
|
|
|
|
set_tool(tool_name, BUTTON_RIGHT)
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
update_tool_buttons()
|
|
|
|
|
update_tool_cursors()
|
|
|
|
|
|
2022-02-17 14:07:03 +00:00
|
|
|
|
horizontal_mirror = Global.config_cache.get_value("preferences", "horizontal_mirror", false)
|
|
|
|
|
vertical_mirror = Global.config_cache.get_value("preferences", "vertical_mirror", false)
|
2022-02-28 17:24:14 +00:00
|
|
|
|
pixel_perfect = Global.config_cache.get_value("preferences", "pixel_perfect", false)
|
2022-02-17 14:07:03 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
# Yield is necessary for the color picker nodes to update their color values
|
|
|
|
|
yield(get_tree(), "idle_frame")
|
|
|
|
|
var color_value: Color = Global.config_cache.get_value(
|
|
|
|
|
_slots[BUTTON_LEFT].kname, "color", Color.black
|
|
|
|
|
)
|
2021-11-17 17:59:14 +00:00
|
|
|
|
assign_color(color_value, BUTTON_LEFT, false)
|
|
|
|
|
color_value = Global.config_cache.get_value(_slots[BUTTON_RIGHT].kname, "color", Color.white)
|
|
|
|
|
assign_color(color_value, BUTTON_RIGHT, false)
|
|
|
|
|
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
2022-02-21 16:02:02 +00:00
|
|
|
|
func add_tool_button(t: Tool) -> void:
|
|
|
|
|
var tool_button: BaseButton = _tool_button_scene.instance()
|
|
|
|
|
tool_button.name = t.name
|
2022-07-07 23:54:31 +00:00
|
|
|
|
tool_button.get_node("BackgroundLeft").modulate = Global.left_tool_color
|
|
|
|
|
tool_button.get_node("BackgroundRight").modulate = Global.right_tool_color
|
2022-02-21 16:02:02 +00:00
|
|
|
|
tool_button.get_node("ToolIcon").texture = t.icon
|
2022-02-22 21:38:47 +00:00
|
|
|
|
tool_button.hint_tooltip = t.generate_hint_tooltip()
|
2022-02-21 16:02:02 +00:00
|
|
|
|
t.button_node = tool_button
|
|
|
|
|
_tool_buttons.add_child(tool_button)
|
|
|
|
|
tool_button.connect("pressed", _tool_buttons, "_on_Tool_pressed", [tool_button])
|
|
|
|
|
|
|
|
|
|
|
2022-02-22 00:58:52 +00:00
|
|
|
|
func remove_tool(t: Tool) -> void:
|
|
|
|
|
t.button_node.queue_free()
|
|
|
|
|
tools.erase(t.name)
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func set_tool(name: String, button: int) -> void:
|
2020-07-09 12:22:17 +00:00
|
|
|
|
var slot = _slots[button]
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var panel: Node = _panels[button]
|
2022-02-21 16:02:02 +00:00
|
|
|
|
var node: Node = tools[name].scene.instance()
|
2022-02-11 01:16:33 +00:00
|
|
|
|
if button == BUTTON_LEFT: # As guides are only moved with left mouse
|
|
|
|
|
if name == "Pan": # tool you want to give more access at guides
|
|
|
|
|
Global.move_guides_on_canvas = true
|
|
|
|
|
else:
|
|
|
|
|
Global.move_guides_on_canvas = false
|
2020-07-09 12:22:17 +00:00
|
|
|
|
node.name = name
|
|
|
|
|
node.tool_slot = slot
|
|
|
|
|
slot.tool_node = node
|
|
|
|
|
slot.button = button
|
|
|
|
|
panel.add_child(slot.tool_node)
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func assign_tool(name: String, button: int) -> void:
|
2020-07-09 12:22:17 +00:00
|
|
|
|
var slot = _slots[button]
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var panel: Node = _panels[button]
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
if slot.tool_node != null:
|
|
|
|
|
if slot.tool_node.name == name:
|
|
|
|
|
return
|
|
|
|
|
panel.remove_child(slot.tool_node)
|
|
|
|
|
slot.tool_node.queue_free()
|
|
|
|
|
|
|
|
|
|
set_tool(name, button)
|
|
|
|
|
update_tool_buttons()
|
|
|
|
|
update_tool_cursors()
|
|
|
|
|
Global.config_cache.set_value(slot.kname, "tool", name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func default_color() -> void:
|
|
|
|
|
assign_color(Color.black, BUTTON_LEFT)
|
|
|
|
|
assign_color(Color.white, BUTTON_RIGHT)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func swap_color() -> void:
|
|
|
|
|
var left = _slots[BUTTON_LEFT].color
|
|
|
|
|
var right = _slots[BUTTON_RIGHT].color
|
2020-10-23 17:18:39 +00:00
|
|
|
|
assign_color(right, BUTTON_LEFT, false)
|
|
|
|
|
assign_color(left, BUTTON_RIGHT, false)
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func assign_color(color: Color, button: int, change_alpha := true) -> void:
|
|
|
|
|
var c: Color = _slots[button].color
|
2020-10-23 17:18:39 +00:00
|
|
|
|
# This was requested by Issue #54 on GitHub
|
|
|
|
|
if color.a == 0 and change_alpha:
|
2020-07-09 12:22:17 +00:00
|
|
|
|
if color.r != c.r or color.g != c.g or color.b != c.b:
|
|
|
|
|
color.a = 1
|
|
|
|
|
_slots[button].color = color
|
|
|
|
|
Global.config_cache.set_value(_slots[button].kname, "color", color)
|
|
|
|
|
emit_signal("color_changed", color, button)
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func get_assigned_color(button: int) -> Color:
|
2020-07-09 12:22:17 +00:00
|
|
|
|
return _slots[button].color
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func set_button_size(button_size: int) -> void:
|
2021-06-13 23:14:31 +00:00
|
|
|
|
if button_size == Global.ButtonSize.SMALL:
|
|
|
|
|
for t in _tool_buttons.get_children():
|
|
|
|
|
t.rect_min_size = Vector2(24, 24)
|
|
|
|
|
t.get_node("BackgroundLeft").rect_size.x = 12
|
|
|
|
|
t.get_node("BackgroundRight").rect_size.x = 12
|
|
|
|
|
t.get_node("BackgroundRight").rect_position = Vector2(24, 24)
|
|
|
|
|
else:
|
|
|
|
|
for t in _tool_buttons.get_children():
|
|
|
|
|
t.rect_min_size = Vector2(32, 32)
|
|
|
|
|
t.get_node("BackgroundLeft").rect_size.x = 16
|
|
|
|
|
t.get_node("BackgroundRight").rect_size.x = 16
|
|
|
|
|
t.get_node("BackgroundRight").rect_position = Vector2(32, 32)
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 12:22:17 +00:00
|
|
|
|
func update_tool_buttons() -> void:
|
|
|
|
|
for child in _tool_buttons.get_children():
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var left_background: NinePatchRect = child.get_node("BackgroundLeft")
|
|
|
|
|
var right_background: NinePatchRect = child.get_node("BackgroundRight")
|
2021-06-13 23:14:31 +00:00
|
|
|
|
left_background.visible = _slots[BUTTON_LEFT].tool_node.name == child.name
|
|
|
|
|
right_background.visible = _slots[BUTTON_RIGHT].tool_node.name == child.name
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
|
2022-02-21 16:02:02 +00:00
|
|
|
|
func update_hint_tooltips() -> void:
|
|
|
|
|
for tool_name in tools:
|
|
|
|
|
var t: Tool = tools[tool_name]
|
|
|
|
|
t.button_node.hint_tooltip = t.generate_hint_tooltip()
|
|
|
|
|
|
|
|
|
|
|
2020-07-09 12:22:17 +00:00
|
|
|
|
func update_tool_cursors() -> void:
|
2022-02-22 22:10:16 +00:00
|
|
|
|
var left_tool: Tool = tools[_slots[BUTTON_LEFT].tool_node.name]
|
|
|
|
|
Global.left_cursor.texture = left_tool.cursor_icon
|
|
|
|
|
var right_tool: Tool = tools[_slots[BUTTON_RIGHT].tool_node.name]
|
|
|
|
|
Global.right_cursor.texture = right_tool.cursor_icon
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func draw_indicator() -> void:
|
|
|
|
|
if Global.right_square_indicator_visible:
|
2022-07-07 23:49:40 +00:00
|
|
|
|
_slots[BUTTON_RIGHT].tool_node.draw_indicator(false)
|
|
|
|
|
if Global.left_square_indicator_visible:
|
|
|
|
|
_slots[BUTTON_LEFT].tool_node.draw_indicator(true)
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
|
2021-03-30 17:07:13 +00:00
|
|
|
|
func draw_preview() -> void:
|
|
|
|
|
_slots[BUTTON_LEFT].tool_node.draw_preview()
|
|
|
|
|
_slots[BUTTON_RIGHT].tool_node.draw_preview()
|
|
|
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
func handle_draw(position: Vector2, event: InputEvent) -> void:
|
2020-07-09 12:22:17 +00:00
|
|
|
|
if not (Global.can_draw and Global.has_focus):
|
|
|
|
|
return
|
|
|
|
|
|
2021-03-29 20:00:09 +00:00
|
|
|
|
var draw_pos := position
|
|
|
|
|
if Global.mirror_view:
|
|
|
|
|
draw_pos.x = Global.current_project.size.x - position.x - 1
|
|
|
|
|
|
2022-05-16 22:25:50 +00:00
|
|
|
|
if event.is_action_pressed("activate_left_tool") and _active_button == -1:
|
|
|
|
|
_active_button = BUTTON_LEFT
|
|
|
|
|
_slots[_active_button].tool_node.draw_start(draw_pos)
|
|
|
|
|
elif event.is_action_released("activate_left_tool") and _active_button == BUTTON_LEFT:
|
|
|
|
|
_slots[_active_button].tool_node.draw_end(draw_pos)
|
|
|
|
|
_active_button = -1
|
|
|
|
|
elif event.is_action("activate_right_tool") and _active_button == -1:
|
|
|
|
|
_active_button = BUTTON_RIGHT
|
|
|
|
|
_slots[_active_button].tool_node.draw_start(draw_pos)
|
|
|
|
|
elif event.is_action_released("activate_right_tool") and _active_button == BUTTON_RIGHT:
|
|
|
|
|
_slots[_active_button].tool_node.draw_end(draw_pos)
|
|
|
|
|
_active_button = -1
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
if event is InputEventMouseMotion:
|
2021-01-26 14:34:25 +00:00
|
|
|
|
pen_pressure = event.pressure
|
|
|
|
|
if Global.pressure_sensitivity_mode == Global.PressureSensitivity.NONE:
|
|
|
|
|
pen_pressure = 1.0
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
|
if not position.is_equal_approx(_last_position):
|
|
|
|
|
_last_position = position
|
|
|
|
|
_slots[BUTTON_LEFT].tool_node.cursor_move(position)
|
|
|
|
|
_slots[BUTTON_RIGHT].tool_node.cursor_move(position)
|
|
|
|
|
if _active_button != -1:
|
2021-03-29 20:00:09 +00:00
|
|
|
|
_slots[_active_button].tool_node.draw_move(draw_pos)
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
|
var project: Project = Global.current_project
|
2020-07-09 12:22:17 +00:00
|
|
|
|
var text := "[%s×%s]" % [project.size.x, project.size.y]
|
|
|
|
|
if Global.has_focus:
|
|
|
|
|
text += " %s, %s" % [position.x, position.y]
|
|
|
|
|
if not _slots[BUTTON_LEFT].tool_node.cursor_text.empty():
|
|
|
|
|
text += " %s" % _slots[BUTTON_LEFT].tool_node.cursor_text
|
|
|
|
|
if not _slots[BUTTON_RIGHT].tool_node.cursor_text.empty():
|
|
|
|
|
text += " %s" % _slots[BUTTON_RIGHT].tool_node.cursor_text
|
|
|
|
|
Global.cursor_position_label.text = text
|