mirror of
https://gitee.com/dgflash/oops-plugin-framework.git
synced 2026-05-30 18:39:18 +08:00
感谢風舞影天提供的修复oops.gui.openAsync打开同一个 Dialog界面时,出现第一次打开可以正常await到界面node对象,第二次打开同一个界面时,无法等到await返回的node
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: dgflash
|
||||
* @Date: 2021-07-03 16:13:17
|
||||
* @LastEditors: dgflash
|
||||
* @LastEditTime: 2022-09-02 13:39:33
|
||||
* @LastEditTime: 2023-07-24 17:14:57
|
||||
*/
|
||||
|
||||
import { Node } from "cc";
|
||||
@@ -10,20 +10,38 @@ import { UICallbacks, ViewParams } from "./Defines";
|
||||
import { UIConfig } from "./LayerManager";
|
||||
import { LayerPopUp } from "./LayerPopup";
|
||||
|
||||
/** 模式弹窗数据 */
|
||||
type DialogParam = {
|
||||
config: UIConfig;
|
||||
params?: any;
|
||||
callbacks?: UICallbacks;
|
||||
}
|
||||
|
||||
/*
|
||||
* 模式弹窗层,该层的窗口同时只能显示一个,删除以后会自动从队列当中取一个弹窗,直到队列为空
|
||||
*/
|
||||
export class LayerDialog extends LayerPopUp {
|
||||
/** 窗口数据队列 */
|
||||
private queue: Array<ViewParams> = [];
|
||||
/** 窗口参数队列 - 预防同一资源的窗口参数覆盖 */
|
||||
private queue_params: Array<any> = [];
|
||||
/** 窗口调用参数队列 */
|
||||
private params: Array<DialogParam> = [];
|
||||
/** 当前窗口数据 */
|
||||
private current!: ViewParams;
|
||||
|
||||
add(config: UIConfig, params?: any, callbacks?: UICallbacks): string {
|
||||
this.black.enabled = true;
|
||||
|
||||
if (this.current && this.current.valid) {
|
||||
let uuid = this.getUuid(config.prefab);
|
||||
this.params.push({
|
||||
config: config,
|
||||
params: params,
|
||||
callbacks: callbacks,
|
||||
});
|
||||
return uuid;
|
||||
}
|
||||
return this.show(config, params, callbacks);
|
||||
}
|
||||
|
||||
private show(config: UIConfig, params?: any, callbacks?: UICallbacks): string {
|
||||
let prefabPath = config.prefab
|
||||
var uuid = this.getUuid(prefabPath);
|
||||
var viewParams = this.ui_nodes.get(uuid);
|
||||
@@ -31,48 +49,36 @@ export class LayerDialog extends LayerPopUp {
|
||||
viewParams = new ViewParams();
|
||||
viewParams.uuid = this.getUuid(prefabPath);
|
||||
viewParams.prefabPath = prefabPath;
|
||||
viewParams.callbacks = callbacks ?? {};
|
||||
|
||||
var onRemove_Source = viewParams.callbacks.onRemoved;
|
||||
viewParams.callbacks.onRemoved = (node: Node | null, params: any) => {
|
||||
if (onRemove_Source) {
|
||||
onRemove_Source(node, params);
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.next();
|
||||
}, 0);
|
||||
}
|
||||
viewParams.valid = true;
|
||||
this.ui_nodes.set(viewParams.uuid, viewParams);
|
||||
}
|
||||
|
||||
if (this.current && this.current.valid) {
|
||||
this.queue.push(viewParams);
|
||||
this.queue_params.push(params || {});
|
||||
}
|
||||
else {
|
||||
viewParams.params = params || {};
|
||||
this.current = viewParams;
|
||||
this.load(viewParams);
|
||||
}
|
||||
viewParams.callbacks = callbacks ?? {};
|
||||
var onRemove_Source = viewParams.callbacks.onRemoved;
|
||||
viewParams.callbacks.onRemoved = (node: Node | null, params: any) => {
|
||||
if (onRemove_Source) {
|
||||
onRemove_Source(node, params);
|
||||
}
|
||||
setTimeout(() => {
|
||||
this.next();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
viewParams.params = params || {};
|
||||
this.current = viewParams;
|
||||
this.load(viewParams, config.bundle);
|
||||
|
||||
return uuid;
|
||||
}
|
||||
|
||||
protected setBlackDisable() {
|
||||
if (this.queue.length == 0) this.black.enabled = false;
|
||||
if (this.params.length == 0) this.black.enabled = false;
|
||||
}
|
||||
|
||||
private next() {
|
||||
if (this.queue.length > 0) {
|
||||
this.current = this.queue.shift()!;
|
||||
this.current.params = this.queue_params.shift();
|
||||
if (this.current.node) {
|
||||
this.createNode(this.current);
|
||||
}
|
||||
else {
|
||||
this.load(this.current);
|
||||
}
|
||||
if (this.params.length > 0) {
|
||||
let param = this.params.shift()!;
|
||||
this.show(param.config, param.params, param.callbacks);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user