mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-02-20 12:33:14 +00:00
Support tools that don't have shortcuts
Might be useful for Extensions that add tools and for the future where we allow users more freedom with shortcut binding, including unbinding shortcuts.
This commit is contained in:
parent
77f598d969
commit
63a9f2485c
2 changed files with 30 additions and 11 deletions
|
@ -109,16 +109,30 @@ class Tool:
|
|||
scene = load("res://src/%s/%s.tscn" % [subdir, name])
|
||||
|
||||
func generate_hint_tooltip() -> String:
|
||||
var left_shortcut: String = InputMap.get_action_list("left_" + shortcut + "_tool")[0].as_text()
|
||||
var right_shortcut: String = InputMap.get_action_list("right_" + shortcut + "_tool")[0].as_text()
|
||||
var hint := display_name
|
||||
hint += "\n\n%s for left mouse button\n%s for right mouse button"
|
||||
var shortcuts := []
|
||||
var left_text := ""
|
||||
var right_text := ""
|
||||
if InputMap.has_action("left_" + shortcut + "_tool"):
|
||||
var left_shortcut: String = InputMap.get_action_list("left_" + shortcut + "_tool")[0].as_text()
|
||||
shortcuts.append(left_shortcut)
|
||||
left_text = "\n%s for left mouse button"
|
||||
if InputMap.has_action("right_" + shortcut + "_tool"):
|
||||
var right_shortcut: String = InputMap.get_action_list("right_" + shortcut + "_tool")[0].as_text()
|
||||
shortcuts.append(right_shortcut)
|
||||
right_text = "\n%s for right mouse button"
|
||||
|
||||
if !shortcuts.empty():
|
||||
hint += "\n" + left_text + right_text
|
||||
|
||||
if !extra_hint.empty():
|
||||
hint += "\n\n" + extra_hint
|
||||
|
||||
var shortcuts := [left_shortcut, right_shortcut]
|
||||
shortcuts.append_array(extra_shortcuts)
|
||||
hint = tr(hint) % shortcuts
|
||||
if shortcuts.empty():
|
||||
hint = tr(hint)
|
||||
else:
|
||||
hint = tr(hint) % shortcuts
|
||||
return hint
|
||||
|
||||
|
||||
|
@ -187,6 +201,7 @@ func add_tool_button(t: Tool) -> void:
|
|||
var tool_button: BaseButton = _tool_button_scene.instance()
|
||||
tool_button.name = t.name
|
||||
tool_button.get_node("ToolIcon").texture = t.icon
|
||||
tool_button.hint_tooltip = t.generate_hint_tooltip()
|
||||
t.button_node = tool_button
|
||||
_tool_buttons.add_child(tool_button)
|
||||
tool_button.connect("pressed", _tool_buttons, "_on_Tool_pressed", [tool_button])
|
||||
|
|
|
@ -15,12 +15,16 @@ func _input(event: InputEvent) -> void:
|
|||
|
||||
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:
|
||||
# Shortcut for right button (with Alt)
|
||||
Tools.assign_tool(t.name, BUTTON_RIGHT)
|
||||
elif event.is_action_pressed("left_" + t.shortcut + "_tool") and !event.control:
|
||||
# Shortcut for left button
|
||||
Tools.assign_tool(t.name, BUTTON_LEFT)
|
||||
if InputMap.has_action("right_" + t.shortcut + "_tool"):
|
||||
if event.is_action_pressed("right_" + t.shortcut + "_tool") and !event.control:
|
||||
# Shortcut for right button (with Alt)
|
||||
Tools.assign_tool(t.name, BUTTON_RIGHT)
|
||||
return
|
||||
if InputMap.has_action("left_" + t.shortcut + "_tool"):
|
||||
if event.is_action_pressed("left_" + t.shortcut + "_tool") and !event.control:
|
||||
# Shortcut for left button
|
||||
Tools.assign_tool(t.name, BUTTON_LEFT)
|
||||
return
|
||||
|
||||
|
||||
func _on_Tool_pressed(tool_pressed: BaseButton) -> void:
|
||||
|
|
Loading…
Add table
Reference in a new issue