'''
extends Node
var popup_window: Panel
func _ready():
popup_window = Panel.new()
add_child(popup_window)
popup_window.visible = false
popup_window.z_index = 10 # Ensure it's on top
# Create a stylebox for the panel's background
var stylebox = StyleBoxFlat.new()
stylebox.bg_color = Color(0.1, 0.1, 0.1, 0.5) # Set background color (e.g., dark gray with some transparency)
popup_window.add_theme_stylebox_override("panel", stylebox)
# Add the vertical container for the Area2D nodes
var vbox = VBoxContainer.new()
popup_window.add_child(vbox)
var rawComponents: Array[CollisionPolygon2D] = []
var folder_path = "res://objects/"
var dir = DirAccess.open(folder_path)
if dir != null:
dir.list_dir_begin()
var file_name = dir.get_next()
while file_name != "":
if !dir.current_is_dir() and (file_name.ends_with(".tscn") or file_name.ends_with(".res")):
var file_path = folder_path + file_name
var resource = load(file_path)
if resource:
var collision_polygon
if resource is PackedScene:
collision_polygon = resource.instantiate()
else:
collision_polygon = resource
if collision_polygon is CollisionPolygon2D:
rawComponents.append(collision_polygon)
print("Added CollisionPolygon2D from: ", file_path)
else:
print("Not a CollisionPolygon2D: ", file_path)
else:
print("Failed to load: ", file_path)
file_name = dir.get_next()
dir.list_dir_end()
print("Number of elements in rawComponents: ", len(rawComponents))
for component in rawComponents:
var area = Area2D.new()
area.add_child(component)
area.scale *= 0.25
area.rotation_degrees += 90
# Create a Control node to wrap the Area2D
var container = Control.new()
# Set a minimum size for the Control container
var polygon_size = calculate_polygon_size(component)
container.custom_minimum_size = polygon_size
print("container size =", container.custom_minimum_size)
# Add the Area2D to the Control container
container.add_child(area)
# Add the Control container to the VBoxContainer
vbox.add_child(container)
# Force update the VBoxContainer's layout
vbox.queue_sort()
# Set the size of the popup window to match the VBoxContainer
popup_window.custom_minimum_size = vbox.get_combined_minimum_size()
func calculate_polygon_size(polygon: CollisionPolygon2D) -> Vector2:
if polygon.polygon.size() == 0:
return Vector2.ZERO
var min_x = polygon.polygon[0].x
var max_x = polygon.polygon[0].x
var min_y = polygon.polygon[0].y
var max_y = polygon.polygon[0].y
for point in polygon.polygon:
min_x = min(min_x, point.x)
max_x = max(max_x, point.x)
min_y = min(min_y, point.y)
max_y = max(max_y, point.y)
return Vector2(max_y - min_y, max_x - min_x) / 4
func show_popup(target_position: Vector2):
if popup_window == null:
print("Error: popup_window is not initialized")
return
var window_size = popup_window.custom_minimum_size
var popup_position = target_position - Vector2(0, window_size.y / 2)
popup_window.position = popup_position
popup_window.visible = true
func hide_popup():
if popup_window != null:
popup_window.visible = false
func _on_area_mouse_entered(area):
print("Mouse entered: ", area)
show_popup(area.global_position)
func _on_area_mouse_exited(area):
print("Mouse exited: ", area)
hide_popup()
'''
My understanding is that Control nodes as children of VBoxContainers should automatically space vertically. This is not happening. The “containers” are overlapping. I’m trying to create a visual list of collisionPolygon2d’s that will eventually be selectable from a window that pops up when I roll over a “hard point” which is an Area2D with a collision shape/sprite/script. Any help or criticism would be appreciated.