import { find, Label, Node } from "cc"; import { ui_window, WindowSystem } from "./WindowSystem"; import { Window } from "./Window"; import { WindowOpenMode } from "./WindowOpenMode"; /** * 窗口管理器 * 实际管理在窗口系统,这里仅仅作为API调用 * @author 袁浩 */ export class WindowManager { private static get windowSystem(): WindowSystem { var windowSystemNode = find("Canvas/WindowSystem"); if (!windowSystemNode) {//如果没有窗口系统节点则创建一个 var windowSystemNode = new Node("WindowSystem"); windowSystem = windowSystemNode.addComponent(WindowSystem); } var windowSystem = windowSystemNode.getComponent(WindowSystem) || windowSystemNode.addComponent(WindowSystem); return windowSystem; } /** * 最近打开的窗口 */ public static get currentWindow(): Window { return this.windowSystem ? this.windowSystem.currentWindow : null; } /** * 打开窗口 * @param prefabPath 预制体路径 * @param openMode 窗口打开模式 * @param params 给窗口传递的参数 * @returns */ public static async open(prefabPath: string, openMode: WindowOpenMode, ...params) { return this.windowSystem && this.windowSystem.open(prefabPath, openMode, params); } /** * 关闭窗口 * @param type 指定窗口类型,如果不传则关闭最近打开的窗口 */ public static close(type: ui_window | Window | Node = null): void { this.windowSystem && this.windowSystem.close(type); } /** * 关闭指定路径的窗口 * @param path 路径,例:Canvas/XXWindow */ public static closeByPath(path: string): void { this.windowSystem && this.windowSystem.closeByPath(path); } /** * 关闭所有窗口 */ public static closeAll() { this.windowSystem && this.windowSystem.closeAll(); } /** * 显示小提示 * @param message */ public static showTips(message: string, prefabPath: string = "Prefabs/Tips") { this.windowSystem && this.windowSystem.showTips(message, prefabPath); } public static getWindowList(): Window[] { return this.windowSystem && this.windowSystem.windowList; } }