diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 5ae38eb..963b9ba 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -209,6 +209,10 @@ func update_variable(old_name: String, new_name: String, new_value: Variant) -> variable_stack[new_name] = new_value +func remove_variable(name: String) -> void: + variable_stack.erase(name) + + ## Group the [param nodes_to_group] into a new deck and return it. ## Returns [code]null[/code] on failure.[br] ## Adds a group node to this deck, and adds group input and output nodes in the group. diff --git a/graph_node_renderer/deck_holder_renderer.gd b/graph_node_renderer/deck_holder_renderer.gd index ce522b5..cfccbe2 100644 --- a/graph_node_renderer/deck_holder_renderer.gd +++ b/graph_node_renderer/deck_holder_renderer.gd @@ -119,6 +119,11 @@ func _ready() -> void: func(old_name: String, new_name: String, new_value: Variant) -> void: get_active_deck().update_variable(old_name, new_name, new_value) ) + + bottom_dock.variable_viewer.top_field_removed.connect( + func(field_name: String) -> void: + get_active_deck().remove_variable(field_name) + ) func _on_tab_container_tab_about_to_change(previous_tab: int) -> void: diff --git a/graph_node_renderer/textures/remove-icon.svg b/graph_node_renderer/textures/remove-icon.svg new file mode 100644 index 0000000..eb8e244 --- /dev/null +++ b/graph_node_renderer/textures/remove-icon.svg @@ -0,0 +1 @@ + diff --git a/graph_node_renderer/textures/remove-icon.svg.import b/graph_node_renderer/textures/remove-icon.svg.import new file mode 100644 index 0000000..d791b97 --- /dev/null +++ b/graph_node_renderer/textures/remove-icon.svg.import @@ -0,0 +1,37 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://cdhco73u4faf8" +path="res://.godot/imported/remove-icon.svg-39dfaea1590f79f30a4d86a2f83a7c3d.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://graph_node_renderer/textures/remove-icon.svg" +dest_files=["res://.godot/imported/remove-icon.svg-39dfaea1590f79f30a4d86a2f83a7c3d.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 +svg/scale=1.0 +editor/scale_with_editor_scale=false +editor/convert_colors_with_editor_theme=false diff --git a/graph_node_renderer/variable_viewer.gd b/graph_node_renderer/variable_viewer.gd index 6811557..d0a0ea2 100644 --- a/graph_node_renderer/variable_viewer.gd +++ b/graph_node_renderer/variable_viewer.gd @@ -3,13 +3,16 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) extends VBoxContainer class_name VariableViewer + +const REMOVE_ICON = preload("res://graph_node_renderer/textures/remove-icon.svg") + @onready var variable_tree: Tree = %VariableTree @onready var types_popup: PopupMenu = %TypesPopup var root: TreeItem - var _old_name: String signal top_field_edited(old_name: String, new_name: String, new_value: Variant) +signal top_field_removed(field_name: String) func _ready() -> void: @@ -74,7 +77,7 @@ func _ready() -> void: # array if item.get_meta(&"indexed", false): - var index := int(new_name) + var index := item.get_index() (container as Array)[index] = new_value # dictionary else: @@ -127,5 +130,34 @@ func add_item(item_name: String, item_value: Variant, parent: TreeItem = root, c for i in (item_value as Array).size(): add_item(str(i), item_value[i], item, item_value, true) item.collapsed = true + item.add_button(2, REMOVE_ICON) return item + + +func _on_variable_tree_button_clicked(item: TreeItem, column: int, id: int, mouse_button_index: int) -> void: + if mouse_button_index != MOUSE_BUTTON_LEFT: + return + + if item.get_meta(&"container", -1) is int: + var key := item.get_text(0) + top_field_removed.emit(key) + item.free() + else: + var container = item.get_meta(&"container") + + # array + if item.get_meta(&"indexed", false): + var index := item.get_index() + var parent := item.get_parent() + (container as Array).remove_at(index) + item.free() + + # go through the array and reset the index strings + for i in (container as Array).size(): + parent.get_child(i).set_text(0, str(i)) + + # dictionary + else: + (container as Dictionary).erase(item.get_text(0)) + item.free() diff --git a/graph_node_renderer/variable_viewer.tscn b/graph_node_renderer/variable_viewer.tscn index 518ecef..e96066f 100644 --- a/graph_node_renderer/variable_viewer.tscn +++ b/graph_node_renderer/variable_viewer.tscn @@ -21,8 +21,11 @@ layout_mode = 2 size_flags_vertical = 3 columns = 3 column_titles_visible = true +allow_rmb_select = true allow_search = false hide_root = true [node name="TypesPopup" type="PopupMenu" parent="."] unique_name_in_owner = true + +[connection signal="button_clicked" from="VariableTree" to="." method="_on_variable_tree_button_clicked"]