From 46e6966e0c6773cd8d5ba06840199023df5ddf52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Wed, 17 Jan 2024 12:45:38 +0300 Subject: [PATCH] add popup for selecting types --- graph_node_renderer/variable_viewer.gd | 24 +++++++++++++++++++++++- graph_node_renderer/variable_viewer.tscn | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/graph_node_renderer/variable_viewer.gd b/graph_node_renderer/variable_viewer.gd index 9ca0ed5..4d80345 100644 --- a/graph_node_renderer/variable_viewer.gd +++ b/graph_node_renderer/variable_viewer.gd @@ -3,10 +3,11 @@ # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) extends VBoxContainer class_name VariableViewer - @onready var variable_tree: Tree = %VariableTree +@onready var types_popup: PopupMenu = %TypesPopup var root: TreeItem + func _ready() -> void: variable_tree.set_column_title(0, "Name") variable_tree.set_column_title(1, "Value") @@ -17,6 +18,26 @@ func _ready() -> void: variable_tree.set_column_expand_ratio(2, 15) root = variable_tree.create_item() rebuild_variable_tree() + + variable_tree.item_activated.connect( + func(): + var column := variable_tree.get_selected_column() + var item := variable_tree.get_selected() + if column < 2: + variable_tree.edit_selected(true) + else: + var pos := get_global_mouse_position() + var r := Rect2i(Vector2i(pos), Vector2i(0, 100)) + + for i in types_popup.get_item_count(): + types_popup.set_item_checked(i, false) + + types_popup.set_item_checked(item.get_metadata(2), true) + types_popup.popup(r) + ) + + for i in DeckType.Types.size(): + types_popup.add_radio_check_item(DeckType.type_str(i)) func rebuild_variable_tree(data: Dictionary = {}) -> void: @@ -42,6 +63,7 @@ func add_item(item_name: String, item_value: Variant, parent: TreeItem = root) - item.set_text(1, str(item_value)) item.set_text(2, DeckType.type_str(type)) + item.set_metadata(2, type) if item_value is Dictionary: for i in item_value: add_item(i, item_value[i], item) diff --git a/graph_node_renderer/variable_viewer.tscn b/graph_node_renderer/variable_viewer.tscn index 64cdad5..518ecef 100644 --- a/graph_node_renderer/variable_viewer.tscn +++ b/graph_node_renderer/variable_viewer.tscn @@ -23,3 +23,6 @@ columns = 3 column_titles_visible = true allow_search = false hide_root = true + +[node name="TypesPopup" type="PopupMenu" parent="."] +unique_name_in_owner = true