WindowManager.ts 2.3 KB

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