LayerPopup支持多窗口弹出与关闭时,遮罩层自动显示在最上层窗口下方

This commit is contained in:
dgflash
2025-03-12 16:28:19 +08:00
parent 010ba885a1
commit 17b8ba21ba
2 changed files with 29 additions and 19 deletions

View File

@@ -34,7 +34,6 @@ export class LayerDialog extends LayerPopUp {
return;
}
this.black.enabled = true;
this.show(config, params, callbacks);
}

View File

@@ -26,8 +26,20 @@ export class LayerPopUp extends LayerUI {
private init() {
this.layer = Layers.Enum.UI_2D;
this.black = this.addComponent(BlockInputEvents);
this.black.enabled = false;
this.on(Node.EventType.CHILD_ADDED, this.onChildAdded, this);
this.on(Node.EventType.CHILD_REMOVED, this.onChildRemoved, this);
}
private onChildAdded(child: Node) {
if (this.mask) {
this.mask.setSiblingIndex(this.children.length - 2);
}
}
private onChildRemoved(child: Node) {
if (this.mask) {
this.mask.setSiblingIndex(this.children.length - 2);
}
}
protected async showUi(vp: ViewParams): Promise<boolean> {
@@ -78,20 +90,30 @@ export class LayerPopUp extends LayerUI {
/** 启动触摸非窗口区域关闭 */
protected openVacancyRemove(config: UIConfig) {
if (!this.hasEventListener(Node.EventType.TOUCH_END, this.onTouchEnd, this)) {
this.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
}
// 背景半透明遮罩
if (this.mask == null) {
this.mask = ViewUtil.createPrefabNode(Mask);
this.mask.on(Node.EventType.TOUCH_END, this.onTouchEnd, this);
this.black = this.mask.addComponent(BlockInputEvents);
this.black.enabled = false;
}
if (config.mask) {
this.mask.parent = this;
this.mask.setSiblingIndex(0);
}
}
/** 触摸非窗口区域关闭 */
private onTouchEnd(event: EventTouch) {
this.ui_nodes.forEach(vp => {
// 关闭已显示的界面
if (vp.valid && vp.config.vacancy) {
this.remove(vp.config.prefab, vp.config.destroy);
}
});
}
/** 关闭触摸非窗口区域关闭 */
protected closeVacancyRemove() {
let flag = true;
@@ -107,17 +129,6 @@ export class LayerPopUp extends LayerUI {
}
}
private onTouchEnd(event: EventTouch) {
if (event.target === this) {
this.ui_nodes.forEach(vp => {
// 关闭已显示的界面
if (vp.valid && vp.config.vacancy) {
this.remove(vp.config.prefab, vp.config.destroy);
}
});
}
}
clear(isDestroy: boolean) {
super.clear(isDestroy)
this.black.enabled = false;