mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
add popup for selecting types
This commit is contained in:
parent
7f263b45fb
commit
46e6966e0c
2 changed files with 26 additions and 1 deletions
|
@ -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")
|
||||
|
@ -18,6 +19,26 @@ func _ready() -> void:
|
|||
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:
|
||||
#variable_tree.clear() # godot will raw dog a nullptr later if we clear the whole tree
|
||||
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue