From 251cc4b8edbbf0b9f72526ba03f086669912d29a Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Thu, 24 Oct 2024 17:21:28 +0200 Subject: [PATCH 1/5] Library Panel: Improve scroll to section This makes it so the section is at the top of the library. --- material_maker/panels/library/library.gd | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/material_maker/panels/library/library.gd b/material_maker/panels/library/library.gd index 9fd6df739..b4cf08710 100644 --- a/material_maker/panels/library/library.gd +++ b/material_maker/panels/library/library.gd @@ -218,7 +218,10 @@ func _on_Section_Button_pressed(category : String) -> void: if item.get_text(0) == category: item.select(0) item.collapsed = false - tree.ensure_cursor_is_visible() + for node in tree.get_children(true): + if node is VScrollBar: + node.value = tree.get_item_area_rect(item).position.y + break break func _on_Section_Button_event(event : InputEvent, category : String) -> void: From 5bbe7f58a54dea5479d69edacf8d38837b034230 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Thu, 24 Oct 2024 17:33:13 +0200 Subject: [PATCH 2/5] Improve look/size of AddNode popup --- material_maker/theme/classic.tres | 6 +++++- material_maker/theme/default dark.tres | 6 +++++- material_maker/windows/add_node_popup/add_node_popup.tscn | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/material_maker/theme/classic.tres b/material_maker/theme/classic.tres index 37193941f..4528db9b2 100644 --- a/material_maker/theme/classic.tres +++ b/material_maker/theme/classic.tres @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=62 format=3 uid="uid://42cileyfwaca"] +[gd_resource type="Theme" load_steps=63 format=3 uid="uid://42cileyfwaca"] [ext_resource type="FontFile" uid="uid://dgkwr5jydtk6p" path="res://material_maker/theme/font_rubik/Rubik-VariableFont_wght.ttf" id="1_l05jd"] [ext_resource type="Texture2D" uid="uid://c74jqqhkapvx0" path="res://material_maker/theme/dark/graphnode_close.png" id="19"] @@ -200,6 +200,8 @@ border_width_right = 1 border_width_bottom = 1 border_color = Color(1, 0.560784, 0.560784, 1) +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_p6o2d"] + [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dyhk7"] content_margin_left = 10.0 content_margin_top = 2.0 @@ -581,6 +583,8 @@ LineEdit/styles/read_only = SubResource("StyleBoxFlat_k7e83") MM_AddNodePanel/base_type = &"PanelContainer" MM_AddNodePanel/styles/panel = SubResource("StyleBoxFlat_f0kci") MM_AddNodePanelList/base_type = &"ItemList" +MM_AddNodePanelList/font_sizes/font_size = 14 +MM_AddNodePanelList/styles/focus = SubResource("StyleBoxEmpty_p6o2d") MM_FilterLineEdit/base_type = &"LineEdit" MM_FilterLineEdit/styles/focus = SubResource("StyleBoxFlat_dyhk7") MM_FilterLineEdit/styles/normal = SubResource("StyleBoxFlat_e8p1m") diff --git a/material_maker/theme/default dark.tres b/material_maker/theme/default dark.tres index e0012cd10..352f4f6b4 100644 --- a/material_maker/theme/default dark.tres +++ b/material_maker/theme/default dark.tres @@ -1,4 +1,4 @@ -[gd_resource type="Theme" load_steps=59 format=3 uid="uid://b628lwfk6ig2c"] +[gd_resource type="Theme" load_steps=60 format=3 uid="uid://b628lwfk6ig2c"] [ext_resource type="FontFile" uid="uid://dgkwr5jydtk6p" path="res://material_maker/theme/font_rubik/Rubik-VariableFont_wght.ttf" id="1_5tfb1"] [ext_resource type="Texture2D" uid="uid://c74jqqhkapvx0" path="res://material_maker/theme/dark/graphnode_close.png" id="2_qksaj"] @@ -197,6 +197,8 @@ border_width_right = 1 border_width_bottom = 1 border_color = Color(0.359069, 0.359069, 0.359069, 1) +[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_l61r7"] + [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_dyhk7"] content_margin_left = 10.0 content_margin_top = 2.0 @@ -591,6 +593,8 @@ LineEdit/styles/read_only = SubResource("StyleBoxFlat_k7e83") MM_AddNodePanel/base_type = &"PanelContainer" MM_AddNodePanel/styles/panel = SubResource("StyleBoxFlat_f0kci") MM_AddNodePanelList/base_type = &"ItemList" +MM_AddNodePanelList/font_sizes/font_size = 14 +MM_AddNodePanelList/styles/focus = SubResource("StyleBoxEmpty_l61r7") MM_FilterLineEdit/base_type = &"LineEdit" MM_FilterLineEdit/styles/focus = SubResource("StyleBoxFlat_dyhk7") MM_FilterLineEdit/styles/normal = SubResource("StyleBoxFlat_mv8c7") diff --git a/material_maker/windows/add_node_popup/add_node_popup.tscn b/material_maker/windows/add_node_popup/add_node_popup.tscn index 8c4f0b11a..eacecb62e 100644 --- a/material_maker/windows/add_node_popup/add_node_popup.tscn +++ b/material_maker/windows/add_node_popup/add_node_popup.tscn @@ -99,7 +99,7 @@ shader_parameter/tex = ExtResource("3") [node name="AddNodePopup" type="Popup"] transparent_bg = true -size = Vector2i(252, 400) +size = Vector2i(350, 400) visible = true transparent = true script = ExtResource("1") From fe8328398c8c3d0a6b1375d6f341d48afc608674 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Thu, 24 Oct 2024 17:34:51 +0200 Subject: [PATCH 3/5] Improve sorting and naming of options in the AddNode popup This is done by assigning a "result_quality" score to each item based on how it matched. In the Add Node Panel this is used to sort the results. E.g. results that START with the filter are rated higher then those that just contain it. --- .../tools/library_manager/library.gd | 44 ++++++++++++++++++- .../tools/library_manager/library_manager.gd | 22 ++++++---- .../windows/add_node_popup/add_node_popup.gd | 30 ++++++++----- 3 files changed, 73 insertions(+), 23 deletions(-) diff --git a/material_maker/tools/library_manager/library.gd b/material_maker/tools/library_manager/library.gd index 3427c3ee9..7bcf0cf8f 100644 --- a/material_maker/tools/library_manager/library.gd +++ b/material_maker/tools/library_manager/library.gd @@ -63,14 +63,54 @@ func get_item(lib_name : String): return { name=i.tree_item, item=i, icon=library_icons[i.tree_item] } return null +## Returns the items of this library that match the filter. +## Also assigns each returned item a score of how well it matched. func get_items(filter : String, disabled_sections : Array, aliased_items : Array) -> Array: var array : Array = [] + filter = filter.to_lower().strip_edges() for i in library_items: - if filter == "" or i.tree_item.to_lower().find(filter) != -1 or aliased_items.find(i.tree_item) != -1: + var include := true + var result_quality := 1.0 + if filter: + include = false + if i.display_name.to_lower().begins_with(filter) or " "+filter in i.display_name.to_lower(): + include = true + + if not include: + include = true + result_quality = 0.8 + for word in filter.split(" "): + if not word in i.display_name.to_lower(): + include = false + + if (not include) and i.has("name"): + include = true + result_quality = 0.8 + for word in filter.split(" "): + if not word in i.name.to_lower(): + include = false + + if not include: + result_quality = 0.6 + for alias_dict in aliased_items: + for key in alias_dict: + if key == i.tree_item and filter in alias_dict[key]: + if alias_dict[key].begins_with(filter) or ","+filter in alias_dict[key]: + result_quality = 0.9 + include = true + + if not include: + include = true + result_quality = 0.4 + for word in filter.split(" "): + if not word in i.tree_item.to_lower(): + include = false + + if include: var slash_pos = i.tree_item.find("/") var section_name = i.tree_item.left(slash_pos) if slash_pos != -1 else i.tree_item if disabled_sections.find(section_name) == -1: - array.push_back({ name=i.tree_item, item=i, icon=library_icons[i.tree_item] }) + array.push_back({ name=i.tree_item, item=i, icon=library_icons[i.tree_item], quality=result_quality}) return array func generate_node_sections(node_sections : Dictionary) -> void: diff --git a/material_maker/tools/library_manager/library_manager.gd b/material_maker/tools/library_manager/library_manager.gd index 8591c16e8..f88ba0078 100644 --- a/material_maker/tools/library_manager/library_manager.gd +++ b/material_maker/tools/library_manager/library_manager.gd @@ -92,24 +92,22 @@ func get_item(item_name : String): return item return null -func get_items(filter : String, sorted = false) -> Array: - var array : Array = [] - var aliased_items = [] - for al in [ base_item_aliases, user_item_aliases ]: - for a in al.keys(): - if al[a].find(filter) != -1 and aliased_items.find(a) == -1: - aliased_items.push_back(a) +func get_items(filter : String, sorted := false) -> Array: + var array: Array = [] + var aliased_items := [base_item_aliases, user_item_aliases] + for li in get_child_count(): var l = get_child(li) if disabled_libraries.find(l.library_path) == -1: for i in l.get_items(filter, disabled_sections, aliased_items): i.library_index = li array.push_back(i) + if sorted: - var sorted_array : Array = [] + var sorted_array: Array = [] for i in array: var u1 = item_usage[i.name] if item_usage.has(i.name) else 0 - var inserted = false + var inserted := false for p in sorted_array.size(): var i2 = sorted_array[p] var u2 = item_usage[i2.name] if item_usage.has(i2.name) else 0 @@ -120,8 +118,14 @@ func get_items(filter : String, sorted = false) -> Array: if !inserted: sorted_array.push_back(i) array = sorted_array + var idx := 0 + for item in array: + item["idx"] = idx + idx += 1 + return array + func save_library_list() -> void: var library_list = [] for i in range(2, get_child_count()): diff --git a/material_maker/windows/add_node_popup/add_node_popup.gd b/material_maker/windows/add_node_popup/add_node_popup.gd index a8e7fd41c..c272c52cf 100644 --- a/material_maker/windows/add_node_popup/add_node_popup.gd +++ b/material_maker/windows/add_node_popup/add_node_popup.gd @@ -81,7 +81,7 @@ func show_popup(node_name : String = "", slot : int = -1, slot_type : int = -1, b.enable() if filter.text != "": filter.text = "" - update_list(filter.text) + update_list(filter.text) filter.grab_focus() @@ -163,7 +163,9 @@ func update_list(filter_text : String = "") -> void: %List.clear() var idx := 0 - for i in library_manager.get_items(filter_text, true): + var items: Array = library_manager.get_items(filter_text, true) + items.sort_custom(func(a,b): return a.idx < b.idx if a.quality == b.quality else a.quality > b.quality) + for i in items: var obj = i.item if not obj.has("type"): continue @@ -172,14 +174,18 @@ func update_list(filter_text : String = "") -> void: var section = obj.tree_item.get_slice("/", 0) var color : Color = get_node("/root/MainWindow/NodeLibraryManager").get_section_color(section) color = color.lerp(get_theme_color("font_color", "Label"), 0.5) - - %List.add_item(obj.display_name, i.icon) + #print(i) + var _name = obj.display_name + _name = obj.tree_item# + "("+str(i.quality)+")" + " ("+str(i.idx)+")" + #if obj.has("shortdesc") + + %List.add_item(_name, i.icon) %List.set_item_custom_fg_color(idx, color) %List.set_item_metadata(idx, i) %List.set_item_tooltip_enabled(idx, false) idx += 1 - + %List.select(0) %List.ensure_current_is_visible() @@ -192,14 +198,19 @@ func _unhandled_input(event) -> void: func _on_filter_gui_input(event: InputEvent) -> void: if event.is_action("ui_down"): %List.grab_focus() - %List.select(1) + %List.select(0) func _on_list_gui_input(event: InputEvent) -> void: if event.is_action("ui_up"): if not %List.item_count or %List.is_selected(0): %Filter.grab_focus() - + + if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT and not event.pressed: + var idx: int = %List.get_item_at_position(%List.get_local_mouse_position(), true) + if idx != -1: + _on_list_item_activated(idx) + func get_list_drag_data(m_position): var data = %List.get_item_metadata(%List.get_item_at_position(m_position)) @@ -210,11 +221,6 @@ func get_list_drag_data(m_position): return data.item.tree_item - -func _on_list_item_clicked(index: int, at_position:= Vector2(), mouse_button_index:= 0) -> void: - pass - - func _on_list_item_activated(index: int) -> void: var data = %List.get_item_metadata(index) add_node(data.item) From 8b94250d071bf4be78444d581137ca1c982429c1 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Sun, 27 Oct 2024 18:55:46 +0100 Subject: [PATCH 4/5] Improve QuickAccess buttons - changes the "Empty Slot" icon - Adds a tooltip explaining how to add nodes to the quick access - allows removing quick access items with right-click - changes the default quick access nodes (some were broken) --- .../add_node_popup/add_node_popup.tscn | 20 ++++++++++--------- .../windows/add_node_popup/quick_button.gd | 11 ++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/material_maker/windows/add_node_popup/add_node_popup.tscn b/material_maker/windows/add_node_popup/add_node_popup.tscn index eacecb62e..945761594 100644 --- a/material_maker/windows/add_node_popup/add_node_popup.tscn +++ b/material_maker/windows/add_node_popup/add_node_popup.tscn @@ -124,55 +124,56 @@ size_flags_horizontal = 3 material = SubResource("ShaderMaterial_88qrb") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Miscellaneous/Reroute" +default_library_item = "Simple/Uniform/Greyscale" [node name="Button2" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_wwply") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Simple/Shape3D" +default_library_item = "Filter/Colorize" [node name="Button3" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_h5yl4") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Noise/FBM" +default_library_item = "Filter/Blend" [node name="Button4" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_xysbp") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Filter/Colorize" +default_library_item = "Transform" [node name="Button5" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_2fcwt") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Transform3D" +default_library_item = "Filter/Math" [node name="Button6" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_l7flh") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Transform3D/Tiler" [node name="Button7" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_s5pxd") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Filter/Blend" [node name="Button8" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_irmk8") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Filter/Math" [node name="Button9" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_nyf2o") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Filter/Normal map" + +[node name="Button10" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] +material = SubResource("ShaderMaterial_nyf2o") +layout_mode = 2 +size_flags_horizontal = 6 [node name="Filter" type="LineEdit" parent="PanelContainer/VBoxContainer"] unique_name_in_owner = true @@ -197,6 +198,7 @@ fixed_icon_size = Vector2i(18, 18) [connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button7" to="." method="add_node"] [connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button8" to="." method="add_node"] [connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button9" to="." method="add_node"] +[connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button10" to="." method="add_node"] [connection signal="gui_input" from="PanelContainer/VBoxContainer/Filter" to="." method="_on_filter_gui_input"] [connection signal="gui_input" from="PanelContainer/VBoxContainer/List" to="." method="_on_list_gui_input"] [connection signal="item_activated" from="PanelContainer/VBoxContainer/List" to="." method="_on_list_item_activated"] diff --git a/material_maker/windows/add_node_popup/quick_button.gd b/material_maker/windows/add_node_popup/quick_button.gd index 56a9d33ac..aca6fa61e 100644 --- a/material_maker/windows/add_node_popup/quick_button.gd +++ b/material_maker/windows/add_node_popup/quick_button.gd @@ -18,23 +18,34 @@ func _ready(): default_library_item = mm_globals.config.get_value("library", "quick_button_%d" % get_index()) set_library_item(default_library_item) + func _can_drop_data(_position, _data): return true + func set_library_item(li : String): library_item = library_manager.get_item(li) if library_item != null: material.set_shader_parameter("tex", library_item.icon) tooltip_text = library_item.item.tree_item + else: + material.set_shader_parameter("tex", get_theme_icon("radio_unchecked", "PopupMenu")) + tooltip_text = "Drag a node from the list to this slot to add it to the quick access." func _drop_data(_position, data): set_library_item(data) + enable() mm_globals.config.set_value("library", "quick_button_%d" % get_index(), data) + func _on_gui_input(event): if !disabled and event is InputEventMouseButton: if event.pressed and event.button_index == MOUSE_BUTTON_LEFT: emit_signal("object_selected", library_item.item) + if event.pressed and event.button_index == MOUSE_BUTTON_RIGHT: + set_library_item("") + mm_globals.config.set_value("library", "quick_button_%d" % get_index(), "") + disable() func enable() -> void: disabled = false From 724dadc433a222c002ca5df47dd858b5e5eedc06 Mon Sep 17 00:00:00 2001 From: Jowan-Spooner Date: Mon, 2 Dec 2024 20:51:30 +0100 Subject: [PATCH 5/5] Add more quick-access buttons --- .../add_node_popup/add_node_popup.tscn | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/material_maker/windows/add_node_popup/add_node_popup.tscn b/material_maker/windows/add_node_popup/add_node_popup.tscn index 9ff837ffb..496948e8a 100644 --- a/material_maker/windows/add_node_popup/add_node_popup.tscn +++ b/material_maker/windows/add_node_popup/add_node_popup.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=18 format=3 uid="uid://clw8sb0p8webl"] +[gd_scene load_steps=19 format=3 uid="uid://clw8sb0p8webl"] [ext_resource type="Script" path="res://material_maker/windows/add_node_popup/add_node_popup.gd" id="1"] [ext_resource type="PackedScene" uid="uid://cjcxjmoki7j0n" path="res://material_maker/windows/add_node_popup/quick_button.tscn" id="2"] @@ -104,9 +104,16 @@ shader_parameter/disabled = false shader_parameter/brightness = 0.8 shader_parameter/tex = SubResource("PlaceholderTexture2D_buqpn") +[sub_resource type="ShaderMaterial" id="ShaderMaterial_7i7iy"] +resource_local_to_scene = true +shader = SubResource("11") +shader_parameter/disabled = false +shader_parameter/brightness = 0.8 +shader_parameter/tex = SubResource("PlaceholderTexture2D_buqpn") + [node name="AddNodePopup" type="Popup"] transparent_bg = true -size = Vector2i(350, 400) +size = Vector2i(360, 400) visible = true transparent = true script = ExtResource("1") @@ -143,13 +150,13 @@ default_library_item = "Simple/Shape" material = SubResource("ShaderMaterial_h5yl4") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Filter/Blend" +default_library_item = "Noise/FBM" [node name="Button4" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_xysbp") layout_mode = 2 size_flags_horizontal = 6 -default_library_item = "Transform" +default_library_item = "Filter/Colorize" [node name="Button5" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_2fcwt") @@ -167,11 +174,13 @@ default_library_item = "Transform/Tiler" material = SubResource("ShaderMaterial_s5pxd") layout_mode = 2 size_flags_horizontal = 6 +default_library_item = "Filter/Blend" [node name="Button8" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_irmk8") layout_mode = 2 size_flags_horizontal = 6 +default_library_item = "Filter/Math" [node name="Button9" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] material = SubResource("ShaderMaterial_nyf2o") @@ -179,7 +188,17 @@ layout_mode = 2 size_flags_horizontal = 6 [node name="Button10" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] -material = SubResource("ShaderMaterial_nyf2o") +material = SubResource("ShaderMaterial_7i7iy") +layout_mode = 2 +size_flags_horizontal = 6 + +[node name="Button11" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] +material = SubResource("ShaderMaterial_7i7iy") +layout_mode = 2 +size_flags_horizontal = 6 + +[node name="Button12" parent="PanelContainer/VBoxContainer/Buttons" instance=ExtResource("2")] +material = SubResource("ShaderMaterial_7i7iy") layout_mode = 2 size_flags_horizontal = 6 @@ -207,6 +226,8 @@ fixed_icon_size = Vector2i(18, 18) [connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button8" to="." method="add_node"] [connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button9" to="." method="add_node"] [connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button10" to="." method="add_node"] +[connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button11" to="." method="add_node"] +[connection signal="object_selected" from="PanelContainer/VBoxContainer/Buttons/Button12" to="." method="add_node"] [connection signal="gui_input" from="PanelContainer/VBoxContainer/Filter" to="." method="_on_filter_gui_input"] [connection signal="gui_input" from="PanelContainer/VBoxContainer/List" to="." method="_on_list_gui_input"] [connection signal="item_activated" from="PanelContainer/VBoxContainer/List" to="." method="_on_list_item_activated"]