Skip to content

Commit

Permalink
Initial solution for #162 (can still be improved)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgrenda committed Sep 7, 2023
1 parent a5bef22 commit 32140b4
Showing 1 changed file with 58 additions and 4 deletions.
62 changes: 58 additions & 4 deletions addons/pronto/behaviors/PrototypingUIBehavior.gd
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func _input(event):
is_resizing = false

func _build_panel():
print("Build panel called")

This comment has been minimized.

Copy link
@jgrenda

jgrenda Sep 7, 2023

Author Collaborator

will be removed on next commit

if not get_tree(): # This happens on godot startup
return
_clear_panel()
Expand Down Expand Up @@ -189,6 +190,8 @@ func _clear_panel():
child.queue_free()

func maybe_add_config(node: Node):
if _proccessed_duplicate_node(node):
return false
if is_instance_of(node, CodeBehavior):
if not node.visible: return # Hide values that are hidden in the Editor
vbox.add_child(create_ui_for_code(node))
Expand Down Expand Up @@ -307,14 +310,14 @@ func create_ui_slider_for_value_float(value: ValueBehavior):
var middle_vbox = VBoxContainer.new()
var edit_hbox = HBoxContainer.new()
var lower_hbox = HBoxContainer.new()
var name_vbox = VBoxContainer.new()
name_vbox.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
var name_hbox = HBoxContainer.new()
name_hbox.size_flags_vertical = Control.SIZE_SHRINK_BEGIN

# value name label
var label = Label.new()
label.text = name + ":"
label.vertical_alignment = VERTICAL_ALIGNMENT_TOP
name_vbox.add_child(label)
name_hbox.add_child(label)

# value min label
var label_min = Label.new()
Expand Down Expand Up @@ -379,7 +382,7 @@ func create_ui_slider_for_value_float(value: ValueBehavior):

# adding to node tree
hbox.add_child(_create_spacer())
hbox.add_child(name_vbox)
hbox.add_child(name_hbox)
hbox.add_child(middle_vbox)
hbox.add_child(current_vbox)
hbox.add_child(edit_button)
Expand All @@ -392,6 +395,56 @@ func create_ui_slider_for_value_float(value: ValueBehavior):
container.add_child(edit_hbox)
return container

func _proccessed_duplicate_node(node):
var name = node.name
for entry in vbox.get_children():
var value_label
if is_instance_of(entry, VBoxContainer):
value_label = entry.get_child(0).get_child(1).get_child(0)
if name == value_label.text.substr(0,value_label.text.length()-1):
_update_duplicate_counter(entry)
return true
if is_instance_of(entry, HBoxContainer):
value_label = entry.get_child(1)
if name == value_label.text.substr(0,value_label.text.length()-1):
_update_duplicate_counter(entry)
return true
if is_instance_of(entry, Button):
value_label = entry
if name == value_label.text:
return true
return false

func _update_duplicate_counter(entry):
if is_instance_of(entry, VBoxContainer):
if entry.get_child(0).get_child(1).get_child_count() == 1:
var counter_label = _prepare_counter_label()
entry.get_child(0).get_child(1).add_child(counter_label)
else:
var counter_label = entry.get_child(0).get_child(1).get_child(1)
counter_label.text = str(int(counter_label.text.substr(0,counter_label.text.length()-1)) + 1) + "x"
if is_instance_of(entry, HBoxContainer):
if not is_instance_of(entry.get_child(2), Label):
var counter_label = _prepare_counter_label()
entry.add_child(counter_label)
entry.move_child(counter_label, 2)
else:
var counter_label = entry.get_child(2)
counter_label.text = str(int(counter_label.text.substr(0,counter_label.text.length()-1)) + 1) + "x"
if is_instance_of(entry, CodeEdit):
# todo: think of a smart way to do this
pass

func _prepare_counter_label():
var counter_label = Label.new()
counter_label.vertical_alignment = VERTICAL_ALIGNMENT_TOP
counter_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
var label_settings = LabelSettings.new()
label_settings.font_size = 8
counter_label.label_settings = label_settings
counter_label.text = "2x"
return counter_label

func _build_edit_menu(edit_hbox: HBoxContainer, value: ValueBehavior, \
slider: HSlider, label_min: Label, label_max: Label):
## Value vbox
Expand Down Expand Up @@ -592,3 +645,4 @@ func handles():
"panel_size",
func (coord): return floor(coord).clamp(Vector2(1, 1), Vector2(10000, 10000)))
]

0 comments on commit 32140b4

Please sign in to comment.