2021-05-12 22:15:11 +00:00
|
|
|
extends GridContainer
|
2020-05-21 18:30:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2021-08-16 23:56:19 +00:00
|
|
|
# Resize tools panel when window gets resized
|
2022-01-29 22:47:25 +00:00
|
|
|
get_tree().get_root().connect("size_changed", self, "_on_Tools_resized")
|
2021-08-16 23:56:19 +00:00
|
|
|
|
2020-05-21 18:30:40 +00:00
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _input(event: InputEvent) -> void:
|
2021-11-22 19:32:39 +00:00
|
|
|
if not Global.has_focus or not event is InputEventKey:
|
2020-07-09 12:22:17 +00:00
|
|
|
return
|
|
|
|
for action in ["undo", "redo", "redo_secondary"]:
|
|
|
|
if event.is_action_pressed(action):
|
2020-05-21 18:30:40 +00:00
|
|
|
return
|
2021-11-22 19:32:39 +00:00
|
|
|
|
2022-02-21 16:02:02 +00:00
|
|
|
for tool_name in Tools.tools: # Handle tool shortcuts
|
|
|
|
var t: Tools.Tool = Tools.tools[tool_name]
|
|
|
|
if event.is_action_pressed("right_" + t.shortcut + "_tool") and !event.control:
|
2021-11-25 12:48:30 +00:00
|
|
|
# Shortcut for right button (with Alt)
|
2022-02-21 16:02:02 +00:00
|
|
|
Tools.assign_tool(t.name, BUTTON_RIGHT)
|
|
|
|
elif event.is_action_pressed("left_" + t.shortcut + "_tool") and !event.control:
|
2021-11-25 12:48:30 +00:00
|
|
|
# Shortcut for left button
|
2022-02-21 16:02:02 +00:00
|
|
|
Tools.assign_tool(t.name, BUTTON_LEFT)
|
2020-07-09 12:22:17 +00:00
|
|
|
|
|
|
|
|
2021-11-25 12:48:30 +00:00
|
|
|
func _on_Tool_pressed(tool_pressed: BaseButton) -> void:
|
2020-07-09 12:22:17 +00:00
|
|
|
var button := -1
|
|
|
|
button = BUTTON_LEFT if Input.is_action_just_released("left_mouse") else button
|
|
|
|
button = BUTTON_RIGHT if Input.is_action_just_released("right_mouse") else button
|
|
|
|
if button != -1:
|
|
|
|
Tools.assign_tool(tool_pressed.name, button)
|
2021-05-12 22:15:11 +00:00
|
|
|
|
|
|
|
|
2022-01-29 22:47:25 +00:00
|
|
|
func _on_Tools_resized() -> void:
|
|
|
|
var tool_panel_size: Vector2 = get_parent().get_parent().rect_size
|
2022-02-12 22:12:47 +00:00
|
|
|
var column_n = tool_panel_size.x / 28.5
|
|
|
|
if Global.tool_button_size == Global.ButtonSize.BIG:
|
|
|
|
column_n = tool_panel_size.x / 36.5
|
|
|
|
|
|
|
|
if column_n < 1:
|
|
|
|
column_n = 1
|
|
|
|
columns = column_n
|