diff --git a/graph_node_renderer/deck_renderer_graph_edit.gd b/graph_node_renderer/deck_renderer_graph_edit.gd index 8d84fa6..b2577aa 100644 --- a/graph_node_renderer/deck_renderer_graph_edit.gd +++ b/graph_node_renderer/deck_renderer_graph_edit.gd @@ -17,6 +17,9 @@ var add_node_menu: AddNodeMenu ## nodes in [method _on_add_node_menu_node_selected] var popup_position: Vector2 +var rename_popup := RenamePopup.new() +@export var rename_popup_size: Vector2i = Vector2i(200, 0) + ## References the [Deck] that holds all the functional properties of this [DeckRendererGraphEdit] var deck: Deck: set(v): @@ -37,6 +40,11 @@ func _ready() -> void: search_popup_panel.size = search_popup_size add_child(search_popup_panel, false, Node.INTERNAL_MODE_BACK) + rename_popup = RenamePopup.new() + rename_popup.rename_confirmed.connect(_on_rename_popup_rename_confirmed) + rename_popup.close_requested.connect(_on_rename_popup_closed) + add_child(rename_popup, false, Node.INTERNAL_MODE_FRONT) + for t: DeckType.Types in DeckType.CONVERSION_MAP: for out_type: DeckType.Types in DeckType.CONVERSION_MAP[t]: add_valid_connection_type(t, out_type) @@ -185,6 +193,14 @@ func _gui_input(event: InputEvent) -> void: refresh_connections() get_viewport().set_input_as_handled() + if event.is_action_pressed("rename_node") && get_selected_nodes().size() == 1: + var node: DeckNodeRendererGraphNode = get_selected_nodes()[0] + var pos := get_viewport_rect().position + get_global_mouse_position() + rename_popup.popup_on_parent(Rect2i(pos, rename_popup_size)) + rename_popup.le.size.x = rename_popup_size.x + rename_popup.set_text(node.title) + + ## Handles entering groups with action "enter_group". Done here to bypass neighbor ## functionality. func _input(event: InputEvent) -> void: @@ -198,6 +214,17 @@ func _input(event: InputEvent) -> void: group_enter_requested.emit((get_selected_nodes()[0] as DeckNodeRendererGraphNode).node.group_id) get_viewport().set_input_as_handled() + +func _on_rename_popup_rename_confirmed(new_name: String) -> void: + var node: DeckNodeRendererGraphNode = get_selected_nodes()[0] + node.title = new_name + node.node.name = new_name + + +func _on_rename_popup_closed() -> void: + pass + + ## Opens [member search_popup_panel] at the mouse position. Connected to [signal GraphEdit.popup_request] func _on_popup_request(p_popup_position: Vector2) -> void: var p := get_viewport_rect().position + get_global_mouse_position() @@ -280,3 +307,27 @@ func _on_duplicate_nodes_request() -> void: deck.duplicate_nodes(selected_ids) refresh_connections() + + +class RenamePopup extends Popup: + var le := LineEdit.new() + + signal rename_confirmed(new_text: String) + + func _ready() -> void: + add_child(le) + le.placeholder_text = "New Name" + le.text_submitted.connect( + func(new_text: String): + if new_text.is_empty(): + return + + rename_confirmed.emit(new_text) + hide() + ) + + + func set_text(text: String) -> void: + le.text = text + le.select_all() + le.grab_focus() diff --git a/project.godot b/project.godot index 051a5ad..01d38d7 100644 --- a/project.godot +++ b/project.godot @@ -39,6 +39,11 @@ enter_group={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194306,"key_label":0,"unicode":0,"echo":false,"script":null) ] } +rename_node={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194333,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +] +} [rendering]