AddNodePopup improvements

This commit is contained in:
Metin ÇETİN 2020-01-31 03:17:05 +03:00
parent cc6d9c8dde
commit 81a63a84d8
5 changed files with 93 additions and 33 deletions

View File

@ -164,6 +164,7 @@ func update_graph(generators, connections) -> Array:
rv.push_back(node)
for c in connections:
.connect_node("node_"+c.from, c.from_port, "node_"+c.to, c.to_port)
return rv
func new_material() -> void:
@ -372,12 +373,18 @@ 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()):
$AddNodePopup.rect_global_position = get_global_mouse_position()
$AddNodePopup.show()
$"../AddNodePopup".rect_global_position = get_global_mouse_position()
$"../AddNodePopup".show()
if event is InputEventMouseButton:
call_deferred("check_last_selected")
func request_popup(from,from_slot,release_position):
$"../AddNodePopup".rect_global_position = get_global_mouse_position()
$"../AddNodePopup".show()
$"../AddNodePopup".set_quick_connect(from,from_slot)
#$"../AddNodePopup".connect_to
pass
func check_last_selected() -> void:
if last_selected != null and !(is_instance_valid(last_selected) and last_selected.selected):
last_selected = null

View File

@ -1,8 +1,7 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://material_maker/graph_edit.gd" type="Script" id=1]
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=2]
[ext_resource path="res://material_maker/widgets/add_node_popup.tscn" type="PackedScene" id=3]
[sub_resource type="StyleBoxFlat" id=1]
bg_color = Color( 0.6, 0.6, 0.6, 0 )
@ -29,13 +28,15 @@ custom_styles/bg = SubResource( 1 )
right_disconnects = true
use_snap = false
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Timer" type="Timer" parent="."]
wait_time = 0.2
one_shot = true
[node name="GraphUI" type="HBoxContainer" parent="."]
editor/display_folded = true
anchor_left = 1.0
anchor_right = 1.0
margin_left = -262.0
@ -77,9 +78,8 @@ margin_right = 246.0
margin_bottom = 24.0
hint_tooltip = "Show hierarchy"
icon = SubResource( 4 )
[node name="AddNodePopup" parent="." instance=ExtResource( 3 )]
[connection signal="connection_request" from="." to="." method="connect_node"]
[connection signal="connection_to_empty" from="." to="." method="request_popup"]
[connection signal="disconnection_request" from="." to="." method="disconnect_node"]
[connection signal="duplicate_nodes_request" from="." to="." method="duplicate_selected"]
[connection signal="gui_input" from="." to="." method="_on_GraphEdit_gui_input"]

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=2]
[gd_scene load_steps=12 format=2]
[ext_resource path="res://material_maker/main_window.gd" type="Script" id=1]
[ext_resource path="res://material_maker/library.tscn" type="PackedScene" id=2]
@ -6,17 +6,18 @@
[ext_resource path="res://material_maker/preview/preview_3d.tscn" type="PackedScene" id=4]
[ext_resource path="res://material_maker/preview/preview_3d_ui.tscn" type="PackedScene" id=5]
[ext_resource path="res://material_maker/widgets/tabs.gd" type="Script" id=6]
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=7]
[ext_resource path="res://material_maker/node_factory.gd" type="Script" id=8]
[ext_resource path="res://material_maker/widgets/add_node_popup.tscn" type="PackedScene" id=7]
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=8]
[ext_resource path="res://material_maker/node_factory.gd" type="Script" id=9]
[sub_resource type="AtlasTexture" id=1]
flags = 4
atlas = ExtResource( 7 )
atlas = ExtResource( 8 )
region = Rect2( 96, 32, 32, 32 )
[sub_resource type="AtlasTexture" id=2]
flags = 4
atlas = ExtResource( 7 )
atlas = ExtResource( 8 )
region = Rect2( 96, 64, 32, 32 )
[node name="MainWindow" type="Panel"]
@ -152,6 +153,8 @@ margin_bottom = 24.0
tab_align = 0
tab_close_display_policy = 1
[node name="AddNodePopup" parent="VBoxContainer/HBoxContainer/ProjectsPane/Projects" instance=ExtResource( 7 )]
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/HBoxContainer/ProjectsPane"]
anchor_top = 1.0
anchor_bottom = 1.0
@ -191,7 +194,7 @@ margin_bottom = 30.0
size_flags_vertical = 4
[node name="NodeFactory" type="Node" parent="."]
script = ExtResource( 8 )
script = ExtResource( 9 )
[connection signal="need_update" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" to="." method="update_preview_3d"]
[connection signal="environment_selected" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D/Preview3DUI" to="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" method="_on_Environment_item_selected"]
[connection signal="model_selected" from="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D/Preview3DUI" to="VBoxContainer/HBoxContainer/VBoxContainer/Preview/Preview3D" method="_on_Model_item_selected"]

View File

@ -5,6 +5,8 @@ var data = []
onready var itemlist : ItemList = $PanelContainer/VBoxContainer/ItemList
onready var filter_line_edit : LineEdit = $PanelContainer/VBoxContainer/Filter
func get_current_graph():
return get_parent().get_current_tab_control()
func _ready() -> void:
var lib_path = OS.get_executable_path().get_base_dir()+"/library/base.json"
@ -15,37 +17,71 @@ func _ready() -> void:
filter_line_edit.connect("text_changed" ,self,"update_list")
filter_line_edit.connect("text_entered",self,"filter_entered")
itemlist.connect("item_activated",self,"item_activated")
itemlist.connect("item_selected",self,"item_selected")
itemlist.connect("item_activated",self,"item_selected")
update_list()
func filter_entered(filter):
item_activated(0)
item_selected(0)
#print (c.get_metadata(0))
#func get_selected_item_name() -> String:
# return get_item_path(itemlist.get_selected())
func item_activated(index):
func add_node(data):
var node:GraphNode = get_current_graph().create_nodes(data,get_current_graph().offset_from_global_position(get_transform().xform(Vector2(0,0))))[0]
hide()
clear()
# if this node created by dragging to an empty space
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):
#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
quick_connect_node = null
func item_selected(index):
# checks if mouse left | enter pressed. it prevents
# adding nodes just by using arrow keys as it selects the item
if Input.is_mouse_button_pressed(BUTTON_LEFT) || Input.is_key_pressed(KEY_ENTER):
if (index>=itemlist.get_item_count()):
return
if (itemlist.is_item_selectable(index) == false):
item_activated(index+1)
item_selected(index+1)
return
get_parent().create_nodes(data[index],get_parent().offset_from_global_position(get_global_transform().xform(get_local_mouse_position())))
add_node(data[index])
hide()
clear()
pass
func show():
.show()
update_list()
filter_line_edit.grab_focus()
func update_list(filter=""):
var parent_rect = get_parent().get_parent().get_global_rect()
var clipped = parent_rect.clip(get_global_rect())
var offset = (get_rect().size-clipped.size)
rect_position = rect_position - offset
func update_list(filter : String = "") -> void:
clear_list()
data.clear()
for library in libraries:
for obj in library:
if (obj.tree_item.to_lower().find(filter)!=-1 || filter == ""):
if !obj.has("type"):
continue
var show : bool = true
for f in filter.to_lower().split(" ", false):
if f != "" && obj.tree_item.to_lower().find(f) == -1:
show = false
break
if show:
data.append(obj)
itemlist.add_item(obj.tree_item.split("/")[-1],get_preview_texture(obj),obj.has("type"))
itemlist.add_item(obj.tree_item, get_preview_texture(obj))
func get_preview_texture(data : Dictionary) -> ImageTexture:
if data.has("icon") and data.has("library"):
@ -56,6 +92,7 @@ func get_preview_texture(data : Dictionary) -> ImageTexture:
t = ImageTexture.new()
var image : Image = Image.new()
if image.load(image_path) == OK:
image.resize(16, 16)
t.create_from_image(image)
else:
print("Cannot load image "+image_path)
@ -80,17 +117,29 @@ func add_library(file_name : String, filter : String = "") -> bool:
return false
# Quickly connecting when tried to connect to empty
var quick_connect_node:GraphNode
var quick_connect_slot = 0
func set_quick_connect(from,from_slot):
quick_connect_node = get_current_graph().get_node(from)
quick_connect_slot = from_slot
func _input(event):
if event is InputEventMouseButton and event.is_pressed() and event.button_index == BUTTON_LEFT:
if !get_rect().has_point(event.position):
clear()
hide()
func _unhandled_input(event):
if event is InputEventKey and event.scancode == KEY_ESCAPE:
clear()
hide()
func clear():
filter_line_edit.text = ""
update_list()
func _on_itemlist_focus_entered():
# if itemlist received focus and no item is yet selected
# select the first item
if itemlist.get_selected_items().size() == 0:
itemlist.select(0)
pass # Replace with function body.

View File

@ -3,7 +3,6 @@
[ext_resource path="res://material_maker/widgets/add_node_popup.gd" type="Script" id=1]
[node name="AddNodePopup" type="Popup"]
visible = true
margin_right = 228.0
margin_bottom = 319.0
mouse_filter = 1
@ -31,3 +30,5 @@ margin_right = 214.0
margin_bottom = 305.0
size_flags_horizontal = 3
size_flags_vertical = 3
allow_reselect = true
[connection signal="focus_entered" from="PanelContainer/VBoxContainer/ItemList" to="." method="_on_itemlist_focus_entered"]