Skip to content

Commit

Permalink
Merge branch 'master' of github.com:hpi-swa-lab/godot-pronto
Browse files Browse the repository at this point in the history
  • Loading branch information
leogeier committed Aug 23, 2023
2 parents 7684fb0 + 84ac3c8 commit cca7dd2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
4 changes: 2 additions & 2 deletions addons/pronto/behaviors/MoveBehavior.gd
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ signal touched_floor(velocity: float)

@export_category("Rotation")
## Whether the velocity is applied according to the parent's local rotation or in global coordinates.
@export var rotated = false
@export var rotated = true
## Speed at which the parent rotates when asked to.
@export var rotation_speed = 0.0
@export var rotation_speed = 300.0
## Whether to also rotate the velocity vector when the character is rotated. Feels like the parent can drift when disabled.
@export var rotate_velocity = true

Expand Down
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)
2 changes: 0 additions & 2 deletions examples/game_car.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,6 @@ sprite_texture = ExtResource("2_fjkj2")
position = Vector2(61, 47)
script = ExtResource("3_e4ih0")
friction = 2.0
rotated = true
rotation_speed = 300.0
[node name="ControlsBehavior" type="Node2D" parent="car"]
position = Vector2(143, 10)
Expand Down

0 comments on commit cca7dd2

Please sign in to comment.