Create the node where the mouse pointer was when showing the node popup

+ added missing return types
+ fixed random seed icons
This commit is contained in:
RodZill4 2020-02-01 08:35:00 +01:00
parent b04937bf83
commit 3333def3d2
4 changed files with 36 additions and 46 deletions

View File

@ -12,6 +12,8 @@ var generator = null
var last_selected = null
onready var node_popup = $"../AddNodePopup"
onready var timer : Timer = $Timer
onready var subgraph_ui : HBoxContainer = $GraphUI/SubGraphUI
@ -373,17 +375,15 @@ 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()
node_popup.rect_global_position = get_global_mouse_position()
node_popup.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 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)
func check_last_selected() -> void:
if last_selected != null and !(is_instance_valid(last_selected) and last_selected.selected):

View File

@ -1,9 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[sub_resource type="StreamTexture" id=1]
flags = 4
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=1]
[resource]
flags = 4
atlas = SubResource( 1 )
atlas = ExtResource( 1 )
region = Rect2( 80, 32, 16, 16 )

View File

@ -1,9 +1,8 @@
[gd_resource type="AtlasTexture" load_steps=2 format=2]
[sub_resource type="StreamTexture" id=1]
flags = 4
[ext_resource path="res://material_maker/icons/icons.svg" type="Texture" id=1]
[resource]
flags = 4
atlas = SubResource( 1 )
atlas = ExtResource( 1 )
region = Rect2( 64, 32, 16, 16 )

View File

@ -4,45 +4,40 @@ var libraries = []
var data = []
onready var itemlist : ItemList = $PanelContainer/VBoxContainer/ItemList
onready var filter_line_edit : LineEdit = $PanelContainer/VBoxContainer/Filter
var insert_position : Vector2
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"
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")
update_list()
func filter_entered(filter):
func filter_entered(filter) -> void:
item_selected(0)
#print (c.get_metadata(0))
#func get_selected_item_name() -> String:
# return get_item_path(itemlist.get_selected())
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]
func add_node(data) -> void:
var node : GraphNode = get_current_graph().create_nodes(data, get_current_graph().offset_from_global_position(insert_position))[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)
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):
func item_selected(index) -> void:
# 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):
@ -55,18 +50,16 @@ func item_selected(index):
hide()
clear()
pass
func show():
func show() -> void:
.show()
update_list()
filter_line_edit.grab_focus()
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)
insert_position = rect_position
rect_position = rect_position - offset
func update_list(filter : String = "") -> void:
clear_list()
data.clear()
@ -98,12 +91,11 @@ func get_preview_texture(data : Dictionary) -> ImageTexture:
print("Cannot load image "+image_path)
return t
return null
func clear_list():
itemlist.clear()
func add_library(file_name : String, filter : String = "") -> bool:
func clear_list() -> void:
itemlist.clear()
func add_library(file_name : String, filter : String = "") -> bool:
var file = File.new()
if file.open(file_name, File.READ) != OK:
return false
@ -116,30 +108,30 @@ func add_library(file_name : String, filter : String = "") -> bool:
return true
return false
# Quickly connecting when tried to connect to empty
var quick_connect_node:GraphNode
var quick_connect_node : GraphNode
var quick_connect_slot = 0
func set_quick_connect(from,from_slot):
func set_quick_connect(from, from_slot) -> void:
quick_connect_node = get_current_graph().get_node(from)
quick_connect_slot = from_slot
func _input(event):
func _input(event) -> void:
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):
func _unhandled_input(event) -> void:
if event is InputEventKey and event.scancode == KEY_ESCAPE:
clear()
hide()
func clear():
func clear() -> void:
filter_line_edit.text = ""
func _on_itemlist_focus_entered():
func _on_itemlist_focus_entered() -> void:
# 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.