Skip to content

Commit

Permalink
Updated popup menu to show only useful nodes when connecting
Browse files Browse the repository at this point in the history
  • Loading branch information
RodZill4 committed Mar 14, 2020
1 parent 64eeaa1 commit e6cbb02
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 14 deletions.
4 changes: 2 additions & 2 deletions material_maker/graph_edit.gd
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ func set_last_selected(node) -> void:
func _on_GraphEdit_gui_input(event) -> void:
if event.is_action_pressed("ui_library_popup") && get_rect().has_point(get_local_mouse_position()):
node_popup.rect_global_position = get_global_mouse_position()
node_popup.show()
node_popup.show_popup()
if event is InputEventMouseButton:
call_deferred("check_last_selected")

Expand All @@ -408,7 +408,7 @@ func request_popup(from, from_slot, release_position) -> void:
else:
# Request the popup
node_popup.rect_global_position = get_global_mouse_position()
node_popup.show()
node_popup.show_popup(mm_io_types.types[node.generator.get_output_defs()[from_slot].type].slot_type)
node_popup.set_quick_connect(from, from_slot)

func check_last_selected() -> void:
Expand Down
2 changes: 1 addition & 1 deletion material_maker/nodes/ios.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ func set_generator(g) -> void:
generator.connect("parameter_changed", self, "on_parameter_changed")
update_node()

func on_parameter_changed(p, v) -> void:
func on_parameter_changed(p, _v) -> void:
if p == "__update_all__":
call_deferred("update_node")

Expand Down
1 change: 0 additions & 1 deletion material_maker/nodes/remote.gd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var links = {}
onready var grid = $Controls

func add_control(text, control) -> void:
var index = grid.get_child_count() / 4
var label = preload("res://material_maker/widgets/linked_widgets/editable_label.tscn").instance()
label.set_text(text)
label.connect("label_changed", self, "on_label_changed", [ control.name ])
Expand Down
42 changes: 33 additions & 9 deletions material_maker/widgets/add_node_popup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var libraries = []
var data = []
onready var itemlist : ItemList = $PanelContainer/VBoxContainer/ItemList
onready var filter_line_edit : LineEdit = $PanelContainer/VBoxContainer/Filter
var quick_connect : int = -1
var insert_position : Vector2

func get_current_graph():
Expand All @@ -14,10 +15,10 @@ func _ready() -> void:
if !add_library(lib_path):
add_library("res://material_maker/library/base.json")
add_library("user://library/user.json")
filter_line_edit.connect("text_changed" ,self,"update_list")
filter_line_edit.connect("text_entered",self,"filter_entered")
itemlist.connect("item_selected",self,"item_selected")
itemlist.connect("item_activated",self,"item_selected")
filter_line_edit.connect("text_changed", self, "update_list")
filter_line_edit.connect("text_entered", self, "filter_entered")
itemlist.connect("item_selected", self, "item_selected")
itemlist.connect("item_activated", self, "item_selected")
update_list()

func filter_entered(filter) -> void:
Expand All @@ -29,10 +30,10 @@ func add_node(data) -> void:
if quick_connect_node != null:
var type = quick_connect_node.get_connection_output_type(quick_connect_slot)
for new_slot in node.get_connection_input_count():
if type == node.get_connection_input_type(new_slot):
#if type == node.get_connection_input_type(new_slot):
#connect the first two slots with the same type
get_current_graph().connect_node(quick_connect_node.name, quick_connect_slot, node.name, new_slot)
break
get_current_graph().connect_node(quick_connect_node.name, quick_connect_slot, node.name, new_slot)
break
quick_connect_node = null
hide()

Expand All @@ -59,8 +60,9 @@ func hide() -> void:

clear()

func show() -> void:
.show()
func show_popup(qc : int = -1) -> void:
show()
quick_connect = qc
update_list()
filter_line_edit.grab_focus()
var parent_rect = get_parent().get_parent().get_global_rect()
Expand All @@ -76,6 +78,28 @@ func update_list(filter : String = "") -> void:
for obj in library:
if !obj.has("type"):
continue
if quick_connect != -1:
var ref_obj = obj
if mm_loader.predefined_generators.has(obj.type):
ref_obj = mm_loader.predefined_generators[obj.type]
if ref_obj.has("shader_model"):
if ! ref_obj.shader_model.has("inputs") or ref_obj.shader_model.inputs.empty():
continue
elif mm_io_types.types[ref_obj.shader_model.inputs[0].type].slot_type != quick_connect:
continue
elif ref_obj.has("nodes"):
var input_ports = []
for n in ref_obj.nodes:
if n.name == "gen_inputs":
if input_ports.has("ports"):
input_ports = n.ports
break
if input_ports.empty() or mm_io_types.types[input_ports[0].type].slot_type != quick_connect:
continue
elif ref_obj.type == "comment" or ref_obj.type == "image" or ref_obj.type == "remote":
continue
elif (ref_obj.type == "convolution" or ref_obj.type == "debug" or ref_obj.type == "buffer" or ref_obj.type == "export" ) and quick_connect != 0:
continue
var show : bool = true
for f in filter.to_lower().split(" ", false):
if f != "" && obj.tree_item.to_lower().find(f) == -1:
Expand Down
2 changes: 1 addition & 1 deletion material_maker/widgets/add_node_popup.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource path="res://material_maker/widgets/add_node_popup.gd" type="Script" id=1]

[node name="AddNodePopup" type="Popup"]
margin_right = 228.0
margin_right = 275.0
margin_bottom = 319.0
mouse_filter = 1
script = ExtResource( 1 )
Expand Down

0 comments on commit e6cbb02

Please sign in to comment.