Skip to content

Commit 1a320e8

Browse files
committed
Added shortcuts for quick buttons bar in add node popup
1 parent c0c36b5 commit 1a320e8

4 files changed

Lines changed: 33 additions & 4 deletions

File tree

material_maker/doc/user_interface_graph_panel.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ button. This menu has a filter field to quickly find the desired node.
6969
The buttons at the top of the node menu can be used to quickly create the most common
7070
nodes. They can be customized by dragging the nodes from the list below into the buttons.
7171

72+
Number row keys(i.e. 1, 2...0) can also be used to activate the corresponding buttons
73+
without opening the node menu.
74+
7275
.. image:: images/node_menu.png
7376
:align: center
7477

material_maker/doc/user_interface_shortcuts.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ Graph Editor
124124
+-------------------------------------------------------+----------------------------------------------------+
125125
| :kbd:`Ctrl/Cmd-Shift-Z` | Redo |
126126
+-------------------------------------------------------+----------------------------------------------------+
127+
| :kbd:`1` :kbd:`2` :kbd:`3` :kbd:`4` :kbd:`5` | Add node from respective quick bar slot in add |
128+
| :kbd:`6` :kbd:`7` :kbd:`8` :kbd:`9` :kbd:`0` | node popup/menu |
129+
+-------------------------------------------------------+----------------------------------------------------+
127130

128131
Nodes
129132
+++++

material_maker/panels/graph_edit/graph_edit.gd

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func process_port_click(pressed : bool):
135135
return
136136

137137

138-
func _input(event: InputEvent) -> void:
138+
func _input(event : InputEvent) -> void:
139139
# Handle node grab
140140
if has_grab:
141141
var selected_nodes := get_selected_nodes()
@@ -156,6 +156,11 @@ func _input(event: InputEvent) -> void:
156156
if get_nodes_under_mouse().is_empty():
157157
node.set_deferred("selected", true)
158158

159+
# Grab graph focus for quick bar shortcuts to work properly
160+
# (i.e. returning to graph after interacting with other panels)
161+
if Rect2(Vector2.ZERO, size).has_point(get_local_mouse_position()):
162+
if event is InputEventKey and event.unicode >= KEY_0 and event.unicode <= KEY_9 and event.pressed:
163+
grab_focus()
159164

160165
func _gui_input(event) -> void:
161166
if (
@@ -299,6 +304,9 @@ func _gui_input(event) -> void:
299304
has_grab = true
300305
KEY_ESCAPE:
301306
has_grab = false
307+
_ when event.unicode >= KEY_0 and event.unicode <= KEY_9:
308+
if get_nodes_under_mouse().is_empty():
309+
quick_bar_shortcuts(event)
302310
match event.get_keycode():
303311
KEY_SHIFT, KEY_CTRL, KEY_ALT:
304312
var found_tip : bool = false
@@ -1833,6 +1841,22 @@ func _get_connection_line(from : Vector2, to : Vector2) -> PackedVector2Array:
18331841
_:
18341842
return points
18351843

1844+
func quick_bar_shortcuts(event : InputEventKey) -> void:
1845+
if not Rect2(Vector2.ZERO, size).has_point(get_local_mouse_position()):
1846+
return
1847+
var key_num : int = event.unicode - KEY_0 - 1
1848+
key_num = 9 if key_num == -1 else key_num
1849+
1850+
var library_manager : Node = get_node("/root/MainWindow/NodeLibraryManager")
1851+
var quick_button_key : String = "quick_button_%d" % [key_num]
1852+
1853+
if mm_globals.config.has_section_key("library", quick_button_key):
1854+
var config : String = mm_globals.config.get_value("library", quick_button_key)
1855+
if config != "":
1856+
var library_item : Dictionary = library_manager.get_item(config)
1857+
if library_item != null:
1858+
do_paste(library_item.item)
1859+
18361860
func colorize_nodes() -> void:
18371861
var nodes : Array[GraphElement]
18381862
for n in get_children():

material_maker/windows/add_node_popup/quick_button.gd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,19 @@ func set_library_item(li : String):
3232
material.set_shader_parameter("tex", ImageTexture.create_from_image(
3333
get_theme_icon("radio_unchecked", "PopupMenu").get_image()))
3434
tooltip_text = "Drag a node from the list to this slot to add it to the quick access."
35+
tooltip_text += "\nSlots can be triggered using number row keys(i.e. 1, 2, 3..0)"
36+
mm_globals.config.set_value("library", "quick_button_%d" % get_index(), li)
3537

3638
func _drop_data(_position, data):
3739
set_library_item(data)
3840
enable()
39-
mm_globals.config.set_value("library", "quick_button_%d" % get_index(), data)
40-
4141

4242
func _on_gui_input(event):
4343
if !disabled and event is InputEventMouseButton:
4444
if event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
4545
emit_signal("object_selected", library_item.item)
4646
if event.pressed and event.button_index == MOUSE_BUTTON_RIGHT:
4747
set_library_item("")
48-
mm_globals.config.set_value("library", "quick_button_%d" % get_index(), "")
4948
disable()
5049

5150
func enable() -> void:

0 commit comments

Comments
 (0)