Skip to content

Commit

Permalink
automatically spawn a PrototypingUI if there are Code or Value behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
tom95 committed Aug 22, 2023
1 parent 1111456 commit 84ac3c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
15 changes: 10 additions & 5 deletions addons/pronto/behaviors/PrototypingUIBehavior.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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":
Expand Down
21 changes: 21 additions & 0 deletions addons/pronto/helpers/G.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 84ac3c8

Please sign in to comment.