Skip to content

Commit

Permalink
Merge pull request #714 from Jowan-Spooner/better-add-node-panel2
Browse files Browse the repository at this point in the history
Add Node Popup Improvements
  • Loading branch information
RodZill4 authored Dec 3, 2024
2 parents 346d251 + 724dadc commit e13b650
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 30 deletions.
5 changes: 4 additions & 1 deletion material_maker/panels/library/library.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion material_maker/theme/classic.tres
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -584,6 +586,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")
Expand Down
6 changes: 5 additions & 1 deletion material_maker/theme/default dark.tres
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
44 changes: 42 additions & 2 deletions material_maker/tools/library_manager/library.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 13 additions & 9 deletions material_maker/tools/library_manager/library_manager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,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
Expand All @@ -121,8 +119,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()):
Expand Down
30 changes: 18 additions & 12 deletions material_maker/windows/add_node_popup/add_node_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -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))
Expand All @@ -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)
Expand Down
32 changes: 28 additions & 4 deletions material_maker/windows/add_node_popup/add_node_popup.tscn
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down Expand Up @@ -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(252, 400)
size = Vector2i(360, 400)
visible = true
transparent = true
script = ExtResource("1")
Expand All @@ -131,7 +138,7 @@ 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")
Expand Down Expand Up @@ -179,7 +186,21 @@ default_library_item = "Filter/Math"
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_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

[node name="Filter" type="LineEdit" parent="PanelContainer/VBoxContainer"]
unique_name_in_owner = true
Expand All @@ -204,6 +225,9 @@ 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="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"]
Expand Down
11 changes: 11 additions & 0 deletions material_maker/windows/add_node_popup/quick_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e13b650

Please sign in to comment.