TableTower/ui/group_layer.gd

38 lines
1.1 KiB
GDScript3
Raw Normal View History

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
# Controls only draw inside their own rect, so cover the whole world.
size = Vector2(BoardView.WORLD_SIZE, BoardView.WORLD_SIZE)
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.
func refit() -> void:
for g in main.data.groups:
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))
if g.fit_to(rects):
var n := main.group_node(g.id)
if n:
n.sync_rect()