mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-09-03 04:03:46 +08:00
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
import type { Node } from 'cc';
|
||
import { LayerPopUp } from './LayerPopup';
|
||
import type { UIParam, UIState } from './LayerUIElement';
|
||
import type { UIConfig } from './UIConfig';
|
||
|
||
/** 模式弹窗数据 */
|
||
type DialogParam = {
|
||
/** 弹窗唯一编号 */
|
||
uiid: string;
|
||
/** 窗口配置 */
|
||
config: UIConfig;
|
||
/** 窗口附加参数 */
|
||
params?: UIParam;
|
||
}
|
||
|
||
/*
|
||
* 模式弹窗层,该层的窗口同时只能显示一个,删除以后会自动从队列当中取一个弹窗,直到队列为空
|
||
*/
|
||
export class LayerDialog extends LayerPopUp {
|
||
/** 窗口调用参数队列 */
|
||
private params: Array<DialogParam> = [];
|
||
/** 当前打开的界面 */
|
||
private current: Node = null!;
|
||
|
||
/**
|
||
* 添加模式窗口
|
||
* 1. 同时添加多个模式窗口时,第一个之后的窗口会先队列起来,在第一个关闭后在加载与显示第二个;同时方法返回节点保持只返回当前显示的界面节点
|
||
*/
|
||
add(uiid: string, config: UIConfig, params?: UIParam): Promise<Node> {
|
||
return new Promise<Node>(async (resolve, reject) => {
|
||
// 控制同一时间只能显示一个模式窗口
|
||
if (this.ui_nodes.size > 0) {
|
||
this.params.push({ uiid: uiid, config: config, params: params });
|
||
resolve(this.current);
|
||
}
|
||
else {
|
||
this.current = await this.showDialog(uiid, config, params);
|
||
resolve(this.current);
|
||
}
|
||
});
|
||
}
|
||
|
||
/** 显示模式弹窗 */
|
||
private showDialog(uiid: string, config: UIConfig, param?: UIParam): Promise<Node> {
|
||
return new Promise<Node>(async (resolve, reject) => {
|
||
const state = this.initUIConfig(uiid, config, param);
|
||
const node = await this.load(state);
|
||
resolve(node);
|
||
});
|
||
}
|
||
|
||
protected closeUi(state: UIState) {
|
||
super.closeUi(state);
|
||
// 使用 Promise 微任务代替 setTimeout,性能更好且更可靠
|
||
Promise.resolve().then(() => this.next());
|
||
}
|
||
|
||
protected closeBlack() {
|
||
if (this.params.length == 0) {
|
||
super.closeBlack();
|
||
}
|
||
}
|
||
|
||
private next() {
|
||
if (this.params.length > 0) {
|
||
const param = this.params.shift()!;
|
||
this.showDialog(param.uiid, param.config, param.params);
|
||
}
|
||
}
|
||
}
|