UI improvements

This commit is contained in:
2026-06-14 10:19:31 -05:00
parent 8ffde98fdd
commit 0cf1f92eaa
16 changed files with 263 additions and 114 deletions
+9 -41
View File
@@ -1,48 +1,16 @@
class_name ModalBackdrop extends ColorRect
# Tracks which overlays are currently open. Each entry must be a direct sibling
# (child of the same parent). The backdrop repositions itself in the scene tree
# to sit immediately below whichever open overlay has the highest tree index,
# so only one backdrop is ever visible regardless of how many overlays are open.
var _openOverlays:Array[Control] = []
func _ready() -> void:
visible = false
mouse_filter = MOUSE_FILTER_IGNORE
UI.FOCUS_STACK.activeLayerChanged.connect(_onActiveLayerChanged)
func register(overlay:Control) -> void:
assert(overlay.get_parent() == get_parent(), "ModalBackdrop: overlay must be a sibling")
assert(overlay.has_signal("opened") and overlay.has_signal("closed"),
"ModalBackdrop: overlay must have opened/closed signals")
overlay.connect("opened", func(): _onOpened(overlay))
overlay.connect("closed", func(): _onClosed(overlay))
func _onOpened(overlay:Control) -> void:
if overlay not in _openOverlays:
_openOverlays.append(overlay)
_reposition()
func _onClosed(overlay:Control) -> void:
_openOverlays.erase(overlay)
_reposition()
func _reposition() -> void:
if _openOverlays.is_empty():
func _onActiveLayerChanged(layer:ClosableMenu) -> void:
if layer == null or layer.get_parent() != get_parent():
visible = false
return
visible = true
var top := _topOverlay()
var topIdx := top.get_index()
var myIdx := get_index()
if myIdx == topIdx - 1:
return
if myIdx < topIdx:
get_parent().move_child(self, topIdx - 1)
mouse_filter = MOUSE_FILTER_IGNORE
z_index = 0
else:
get_parent().move_child(self, topIdx)
func _topOverlay() -> Control:
var top:Control = _openOverlays[0]
for overlay in _openOverlays:
if overlay.get_index() > top.get_index():
top = overlay
return top
visible = true
mouse_filter = MOUSE_FILTER_STOP
z_index = layer.z_index - 5