Files
MusicPlayer/popup_backdrop.gd
T
Sansan 3c7b4e5c9d Split the main window into TopBar and Quiz scenes
The quiz (song, playlist, players, music player and the popups opened from
it) moves into Quiz.tscn and the top panel into TopBar.tscn. The main window
keeps only the top bar, the quiz and the popups opened from the top bar, so
other views can be added next to the quiz later. Every node keeps its place
on screen.

Screenshots of every UI state before and after are pixel-identical, and a
layout test checks each node against a baseline taken before the split.
2026-10-06 10:02:22 +02:00

32 lines
1.2 KiB
GDScript

class_name PopupBackdrop
extends ColorRect
## Dims everything behind an open popup and keeps clicks from reaching the buttons
## under it.
##
## The backdrop sits above the rest of its parent and below the popups it belongs to.
## Popups close themselves when clicked outside, and the backdrop keeps that click from
## reaching the buttons behind them.
var _popups: Array[PopupWindow] = []
## Adds a backdrop to [param parent] and moves [param popups] above it. The backdrop
## shows while any of them is open.
static func add_to(parent: Control, popups: Array[PopupWindow]) -> PopupBackdrop:
var backdrop: PopupBackdrop = PopupBackdrop.new()
backdrop.name = "PopupBackdrop"
backdrop.color = Color(0, 0, 0, 0.55)
backdrop.mouse_filter = Control.MOUSE_FILTER_STOP
backdrop._popups = popups
parent.add_child(backdrop)
backdrop.set_anchors_and_offsets_preset(Control.PRESET_FULL_RECT)
for popup: PopupWindow in popups:
parent.move_child(popup, -1)
popup.visibility_changed.connect(backdrop._update)
backdrop._update()
return backdrop
func _update() -> void:
visible = _popups.any(func(popup: PopupWindow) -> bool: return popup.visible)