add ability to remove variables in variable viewer

This commit is contained in:
Lera Elvoé 2024-01-18 11:01:51 +03:00
parent bcdba9818c
commit b2439d9209
No known key found for this signature in database
6 changed files with 84 additions and 2 deletions

View file

@ -209,6 +209,10 @@ func update_variable(old_name: String, new_name: String, new_value: Variant) ->
variable_stack[new_name] = new_value 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. ## Group the [param nodes_to_group] into a new deck and return it.
## Returns [code]null[/code] on failure.[br] ## Returns [code]null[/code] on failure.[br]
## Adds a group node to this deck, and adds group input and output nodes in the group. ## Adds a group node to this deck, and adds group input and output nodes in the group.

View file

@ -119,6 +119,11 @@ func _ready() -> void:
func(old_name: String, new_name: String, new_value: Variant) -> void: func(old_name: String, new_name: String, new_value: Variant) -> void:
get_active_deck().update_variable(old_name, new_name, new_value) 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: func _on_tab_container_tab_about_to_change(previous_tab: int) -> void:

View file

@ -0,0 +1 @@
<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m5 1v1h-4v2h14v-2h-4v-1zm-3 4v8a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2v-8zm1 2h2v6h-2zm4 0h2v6h-2zm4 0h2v6h-2z" fill="#e0e0e0"/></svg>

After

Width:  |  Height:  |  Size: 218 B

View file

@ -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

View file

@ -3,13 +3,16 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
extends VBoxContainer extends VBoxContainer
class_name VariableViewer class_name VariableViewer
const REMOVE_ICON = preload("res://graph_node_renderer/textures/remove-icon.svg")
@onready var variable_tree: Tree = %VariableTree @onready var variable_tree: Tree = %VariableTree
@onready var types_popup: PopupMenu = %TypesPopup @onready var types_popup: PopupMenu = %TypesPopup
var root: TreeItem var root: TreeItem
var _old_name: String var _old_name: String
signal top_field_edited(old_name: String, new_name: String, new_value: Variant) signal top_field_edited(old_name: String, new_name: String, new_value: Variant)
signal top_field_removed(field_name: String)
func _ready() -> void: func _ready() -> void:
@ -74,7 +77,7 @@ func _ready() -> void:
# array # array
if item.get_meta(&"indexed", false): if item.get_meta(&"indexed", false):
var index := int(new_name) var index := item.get_index()
(container as Array)[index] = new_value (container as Array)[index] = new_value
# dictionary # dictionary
else: 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(): for i in (item_value as Array).size():
add_item(str(i), item_value[i], item, item_value, true) add_item(str(i), item_value[i], item, item_value, true)
item.collapsed = true item.collapsed = true
item.add_button(2, REMOVE_ICON)
return item 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()

View file

@ -21,8 +21,11 @@ layout_mode = 2
size_flags_vertical = 3 size_flags_vertical = 3
columns = 3 columns = 3
column_titles_visible = true column_titles_visible = true
allow_rmb_select = true
allow_search = false allow_search = false
hide_root = true hide_root = true
[node name="TypesPopup" type="PopupMenu" parent="."] [node name="TypesPopup" type="PopupMenu" parent="."]
unique_name_in_owner = true unique_name_in_owner = true
[connection signal="button_clicked" from="VariableTree" to="." method="_on_variable_tree_button_clicked"]