Files
gplan-2/game/presentation/modal_stack.gd
T

35 lines
1.2 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# VERTICAL SLICE - NOT FOR PRODUCTION
# 实现 GDD:design/ux/interaction-patterns.md(pattern 6 模态 overlay 层级纪律)。
# Date: 2026-09-12(code-review 修复批——自 main.gd 拆出,规范 1.1 状态装配独立成类)
# 模态层级状态机:登记序 = 树序 = z 遮挡序;打开时显式隐藏树序在其上方的可见层、关闭恢复
# (缺陷⑤纪律载体:功能存在 ≠ 功能可达——遮挡关系不得靠树序巧合)。
# 纯逻辑零节点构建——组合根持有本类并喂入 Control;不持久化核心状态。
extends RefCounted
var _list: Array[Control] = [] # 登记序 = z 遮挡序(低 → 高)
var _occluded := {} # modal → 被其隐藏的上方层(关闭恢复)
func register(m: Control) -> void:
_list.append(m)
func open(m: Control) -> void:
var hidden: Array[Control] = []
var idx := _list.find(m)
for i in range(idx + 1, _list.size()):
var higher: Control = _list[i]
if is_instance_valid(higher) and higher.visible:
higher.visible = false
hidden.append(higher)
_occluded[m] = hidden
m.visible = true
func close(m: Control) -> void:
m.visible = false
for h in _occluded.get(m, []):
if is_instance_valid(h):
h.visible = true
_occluded.erase(m)