diff --git a/material_maker/graph_edit.gd b/material_maker/graph_edit.gd index 456569a..6138fbd 100644 --- a/material_maker/graph_edit.gd +++ b/material_maker/graph_edit.gd @@ -385,9 +385,18 @@ func _on_GraphEdit_gui_input(event) -> void: call_deferred("check_last_selected") func request_popup(from, from_slot, release_position) -> void: - node_popup.rect_global_position = get_global_mouse_position() - node_popup.show() - node_popup.set_quick_connect(from, from_slot) + # Check if the connector was actually dragged + var node : GraphNode = get_node(from) + var node_transform : Transform2D = node.get_global_transform() + var output_position = node_transform.xform(node.get_connection_output_position(from_slot)/node_transform.get_scale()) + if (get_global_mouse_position()-output_position).length() < 20: + # Tell the node its connector was clicked + node.on_clicked_output(from_slot) + else: + # Request the popup + node_popup.rect_global_position = get_global_mouse_position() + node_popup.show() + node_popup.set_quick_connect(from, from_slot) func check_last_selected() -> void: if last_selected != null and !(is_instance_valid(last_selected) and last_selected.selected): diff --git a/material_maker/icons/icons.svg b/material_maker/icons/icons.svg index a43e0c6..ab74fb5 100644 --- a/material_maker/icons/icons.svg +++ b/material_maker/icons/icons.svg @@ -55,9 +55,9 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="10.114758" - inkscape:cx="100.19195" - inkscape:cy="20.027892" + inkscape:zoom="40.459032" + inkscape:cx="12.31719" + inkscape:cy="41.781829" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" @@ -593,5 +593,17 @@ style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1.15158939px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" d="m 114.33714,336.4547 v 5.90037 z m 8.55274,0 v 5.90037 z m -17.10352,0.12943 v 5.90037 z" id="path920" /> + diff --git a/material_maker/icons/output_preview.tres b/material_maker/icons/output_preview.tres new file mode 100644 index 0000000..348fb74 --- /dev/null +++ b/material_maker/icons/output_preview.tres @@ -0,0 +1,8 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=2] + +[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=1] + +[resource] +flags = 4 +atlas = ExtResource( 1 ) +region = Rect2( 0, 80, 16, 16 ) diff --git a/material_maker/nodes/generic.gd b/material_maker/nodes/generic.gd index 2a2d7ae..76c1975 100644 --- a/material_maker/nodes/generic.gd +++ b/material_maker/nodes/generic.gd @@ -11,6 +11,17 @@ var preview_position : int var preview_size : int var preview_timer : Timer = null +func _draw() -> void: + ._draw() + if preview_index >= 0: + var conn_pos = get_connection_output_position(preview_index) + if preview_index > 0: + conn_pos.y += 1 + print(conn_pos) + conn_pos /= get_global_transform().get_scale() + print(conn_pos) + draw_texture(preload("res://material_maker/icons/output_preview.tres"), conn_pos-Vector2(8, 8)) + func set_generator(g) -> void: .set_generator(g) generator.connect("parameter_changed", self, "on_parameter_changed") @@ -262,23 +273,8 @@ func update_node() -> void: hsizer.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL add_child(hsizer) hsizer = get_child(i) - var has_filler = false - for c in hsizer.get_children(): - if c.size_flags_horizontal & SIZE_EXPAND != 0: - has_filler = true - break - if !has_filler: - var empty_control : Control = Control.new() - empty_control.size_flags_horizontal = SIZE_EXPAND | SIZE_FILL - hsizer.add_child(empty_control) - var button = preload("res://material_maker/widgets/preview_button.tscn").instance() - button.size_flags_horizontal = SIZE_SHRINK_END - button.size_flags_vertical = SIZE_SHRINK_CENTER - if i == preview_index: - button.pressed = true - hsizer.add_child(button) - button.connect("toggled", self, "on_preview_button", [ i ]) - button_width = button.rect_size.x + if hsizer.get_child_count() == 0: + hsizer.rect_min_size.y = 16 if !outputs.empty(): for i in range(output_count, get_child_count()): var hsizer : HBoxContainer = get_child(i) @@ -352,34 +348,22 @@ func do_save_generator(file_name : String) -> void: file.close() mm_loader.update_predefined_generators() -func update_preview_buttons(index : int) -> void: - for i in range(output_count): - if i != index: - var line = get_child(i) - line.get_child(line.get_child_count()-1).pressed = false - -var processing_button = false - -func on_preview_button(pressed : bool, index : int) -> void: - if processing_button: - return - processing_button = true - if pressed: +func on_clicked_output(index : int) -> void: + if preview_index == index: + preview_index = -1 + preview.visible = false + remove_child(preview) + rect_size = Vector2(0, 0) + else: preview_index = index var width if preview.visible: - update_preview_buttons(index) update_preview() else: var status = update_preview(get_child(0).rect_size.x) while status is GDScriptFunctionState: status = yield(status, "completed") - else: - preview_index = -1 - preview.visible = false - remove_child(preview) - rect_size = Vector2(0, 0) - processing_button = false + update() func update_preview(size : int = 0) -> void: if preview_index == -1: