44 lines
1.4 KiB
GDScript
44 lines
1.4 KiB
GDScript
class_name GroupLayer
|
|
extends Control
|
|
## Holds the frames of expanded groups, behind the pipes and the cards, and
|
|
## keeps each frame fitted around its member cards. A group whose member is
|
|
## being dragged is frozen, so the card can be dragged out of the frame.
|
|
|
|
var main: Main
|
|
## Group ids that don't refit right now (a member is being dragged).
|
|
var frozen: Dictionary = {}
|
|
|
|
|
|
func _init() -> void:
|
|
mouse_filter = MOUSE_FILTER_IGNORE
|
|
BoardView.cover_world(self)
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
if main == null or main.data == null:
|
|
return
|
|
refit()
|
|
|
|
|
|
## Fits every expanded, unfrozen group's frame around its visible members and
|
|
## inner groups, innermost first so outer frames fit the inner ones' new size.
|
|
func refit() -> void:
|
|
var order := main.data.groups.duplicate()
|
|
if order.size() > 1:
|
|
order.sort_custom(func(a: TableGroup, b: TableGroup) -> bool: return main.data.depth_of(a) > main.data.depth_of(b))
|
|
for g: TableGroup in order:
|
|
if g.collapsed or frozen.has(g.id):
|
|
continue
|
|
var rects: Array = []
|
|
for tid in g.members:
|
|
var c := main.card_for(tid)
|
|
if c and c.visible and c.size.x > 0.0:
|
|
rects.append(Rect2(c.position, c.size))
|
|
for inner in main.data.child_groups(g.id):
|
|
var n := main.group_node(inner.id)
|
|
if n and n.visible:
|
|
rects.append(Rect2(n.position, n.size) if inner.collapsed else inner.rect())
|
|
if g.fit_to(rects):
|
|
var n := main.group_node(g.id)
|
|
if n:
|
|
n.sync_rect()
|