Skip to content

Commit

Permalink
Adds ability to swap tools (Shift + x as an initial shortcut) (#1173)
Browse files Browse the repository at this point in the history
* Use Shift + x as a shortcut to swap tools

* rename it to swap tools, instead of switch tools
  • Loading branch information
Variable-ind authored Feb 7, 2025
1 parent 0dca8ab commit 6411d20
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ right_pan_tool={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":true,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":77,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
]
}
swap_tools={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":88,"physical_keycode":0,"key_label":0,"unicode":88,"location":0,"echo":false,"script":null)
]
}
show_pixel_grid={
"deadzone": 0.5,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"command_or_control_autoremap":true,"alt_pressed":false,"shift_pressed":false,"pressed":false,"keycode":72,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
Expand Down
1 change: 1 addition & 0 deletions src/Autoload/Global.gd
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ func _initialize_keychain() -> void:
&"brush_size_increment": Keychain.InputAction.new("", "Buttons"),
&"brush_size_decrement": Keychain.InputAction.new("", "Buttons"),
&"change_tool_mode": Keychain.InputAction.new("", "Tool modifiers", false),
&"swap_tools": Keychain.InputAction.new("", "Tool modifiers", false),
&"draw_create_line": Keychain.InputAction.new("", "Draw tools", false),
&"draw_snap_angle": Keychain.InputAction.new("", "Draw tools", false),
&"draw_color_picker": Keychain.InputAction.new("Quick color picker", "Draw tools", false),
Expand Down
26 changes: 26 additions & 0 deletions src/Autoload/Tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,32 @@ func swap_color() -> void:
assign_color(left, MOUSE_BUTTON_RIGHT, false)


func swap_tools() -> void:
if MOUSE_BUTTON_LEFT and MOUSE_BUTTON_RIGHT in _slots.keys():
var left_slot: Slot = _slots[MOUSE_BUTTON_LEFT]
var right_slot: Slot = _slots[MOUSE_BUTTON_RIGHT]
if left_slot.tool_node:
if (
left_slot.tool_node.has_method("get_config")
and right_slot.tool_node.has_method("get_config")
and left_slot.tool_node.has_method("set_config")
and right_slot.tool_node.has_method("set_config")
and left_slot.tool_node.has_method("update_config")
and right_slot.tool_node.has_method("update_config")
):
var left_name := left_slot.tool_node.name
var right_name := right_slot.tool_node.name
var left_config: Dictionary = left_slot.tool_node.get_config()
var right_config: Dictionary = right_slot.tool_node.get_config()
# Now interchange tools
assign_tool(left_name, MOUSE_BUTTON_RIGHT)
assign_tool(right_name, MOUSE_BUTTON_LEFT)
_slots[MOUSE_BUTTON_LEFT].tool_node.set_config(right_config)
_slots[MOUSE_BUTTON_RIGHT].tool_node.set_config(left_config)
_slots[MOUSE_BUTTON_LEFT].tool_node.update_config()
_slots[MOUSE_BUTTON_RIGHT].tool_node.update_config()


func assign_color(color: Color, button: int, change_alpha := true, index: int = -1) -> void:
var c: Color = _slots[button].color
# This was requested by Issue #54 on GitHub
Expand Down
3 changes: 3 additions & 0 deletions src/UI/ToolsPanel/ToolButtons.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed(action):
return

if event.is_action_pressed("swap_tools"):
Tools.swap_tools()

for tool_name in Tools.tools: # Handle tool shortcuts
if not get_node(tool_name).visible:
continue
Expand Down

0 comments on commit 6411d20

Please sign in to comment.