WindowManager.ts 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { find, Label, Node } from "cc";
  2. import { ui_window, WindowSystem } from "./WindowSystem";
  3. import { Window } from "./Window";
  4. import { WindowOpenMode } from "./WindowOpenMode";
  5. /**
  6. * 窗口管理器
  7. * 实际管理在窗口系统,这里仅仅作为API调用
  8. * @author 袁浩
  9. */
  10. export class WindowManager {
  11. private static get windowSystem(): WindowSystem {
  12. var windowSystemNode = find("Canvas/WindowSystem");
  13. if (!windowSystemNode) {//如果没有窗口系统节点则创建一个
  14. var windowSystemNode = new Node("WindowSystem");
  15. windowSystem = windowSystemNode.addComponent(WindowSystem);
  16. }
  17. var windowSystem = windowSystemNode.getComponent(WindowSystem) || windowSystemNode.addComponent(WindowSystem);
  18. return windowSystem;
  19. }
  20. /**
  21. * 最近打开的窗口
  22. */
  23. public static get currentWindow(): Window {
  24. return this.windowSystem ? this.windowSystem.currentWindow : null;
  25. }
  26. /**
  27. * 打开窗口
  28. * @param prefabPath 预制体路径
  29. * @param openMode 窗口打开模式
  30. * @param params 给窗口传递的参数
  31. * @returns
  32. */
  33. public static async open(prefabPath: string, openMode: WindowOpenMode, ...params) {
  34. return this.windowSystem && this.windowSystem.open(prefabPath, openMode, params);
  35. }
  36. /**
  37. * 关闭窗口
  38. * @param type 指定窗口类型,如果不传则关闭最近打开的窗口
  39. */
  40. public static close(type: ui_window | Window | Node = null): void {
  41. this.windowSystem && this.windowSystem.close(type);
  42. }
  43. /**
  44. * 关闭指定路径的窗口
  45. * @param path 路径,例:Canvas/XXWindow
  46. */
  47. public static closeByPath(path: string): void {
  48. this.windowSystem && this.windowSystem.closeByPath(path);
  49. }
  50. /**
  51. * 关闭所有窗口
  52. */
  53. public static closeAll() {
  54. this.windowSystem && this.windowSystem.closeAll();
  55. }
  56. /**
  57. * 显示小提示
  58. * @param message
  59. */
  60. public static showTips(message: string, prefabPath: string = "Prefabs/Tips") {
  61. this.windowSystem && this.windowSystem.showTips(message, prefabPath);
  62. }
  63. public static getWindowList(): Window[] {
  64. return this.windowSystem && this.windowSystem.windowList;
  65. }
  66. }