From 84ac3c8e66d0ddd96e4ce48d75a8922e42e5d638 Mon Sep 17 00:00:00 2001 From: Tom Beckmann Date: Tue, 22 Aug 2023 19:29:27 +0200 Subject: [PATCH] automatically spawn a PrototypingUI if there are Code or Value behaviors --- .../pronto/behaviors/PrototypingUIBehavior.gd | 15 ++++++++----- addons/pronto/helpers/G.gd | 21 +++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/addons/pronto/behaviors/PrototypingUIBehavior.gd b/addons/pronto/behaviors/PrototypingUIBehavior.gd index 661dd1b2..ca87783e 100644 --- a/addons/pronto/behaviors/PrototypingUIBehavior.gd +++ b/addons/pronto/behaviors/PrototypingUIBehavior.gd @@ -30,10 +30,7 @@ func _ready(): vbox.size_flags_vertical = Control.SIZE_EXPAND_FILL for childNode in self.get_children(): - if is_instance_of(childNode, CodeBehavior): - vbox.add_child(create_ui_for_code(childNode)) - elif is_instance_of(childNode, ValueBehavior): - vbox.add_child(create_ui_for_value(childNode)) + maybe_add_config(childNode) scrollContainer.add_child(vbox) scrollContainer.size_flags_vertical = Control.SIZE_EXPAND_FILL @@ -52,7 +49,15 @@ func _ready(): panel.add_child.call_deferred(outerVbox) # print("Prototype UI generated successfully") - +func maybe_add_config(node: Node): + if is_instance_of(node, CodeBehavior): + vbox.add_child(create_ui_for_code(node)) + return true + elif is_instance_of(node, ValueBehavior): + vbox.add_child(create_ui_for_value(node)) + return true + return false + func create_ui_for_value(value: ValueBehavior): if not value.visible: return # Hide values that are hidden in the Editor if value.selectType == "Float": diff --git a/addons/pronto/helpers/G.gd b/addons/pronto/helpers/G.gd index b10be853..713ec9ca 100644 --- a/addons/pronto/helpers/G.gd +++ b/addons/pronto/helpers/G.gd @@ -41,3 +41,24 @@ func _put(name: String, value: Variant): func _register_store(store: StoreBehavior, prop: String): assert(not prop in _store_update, "Property {0} has already been registered by a store node. Are you spawning the same Store mutliple times?".format([prop])) _store_update[prop] = store + +func _ready(): + if not Engine.is_editor_hint(): + maybe_add_value_user_interface() + +func maybe_add_value_user_interface(): + if not Utils.all_nodes_that(get_tree().root, func (node): return node is PrototypingUIBehavior).is_empty(): + return + + var panel = PanelContainer.new() + panel.size = Vector2(200, 200) + var ui = PrototypingUIBehavior.new() + ui.name = 'Config' + panel.add_child(ui) + + var added_any = [false] + Utils.all_nodes_do(get_tree().root, func (node): + if ui.maybe_add_config(node): + added_any[0] = true) + if added_any[0]: + add_child(panel)