UIWindow.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.WindData = void 0;
  4. const FairyGUI = CS.FairyGUI;
  5. const FairyEditor = CS.FairyEditor;
  6. const App = FairyEditor.App;
  7. class WindData {
  8. packName;
  9. resName;
  10. url;
  11. constructor(pkg, res) {
  12. this.packName = pkg;
  13. this.resName = res;
  14. this.url = "ui://" + pkg + "/" + res;
  15. }
  16. }
  17. exports.WindData = WindData;
  18. class UIWindow extends CS.FairyGUI.Window {
  19. static mWinds = new Map();
  20. _windData;
  21. constructor(data) {
  22. super();
  23. if (data == null)
  24. return;
  25. this._windData = data;
  26. this.__onInit = () => { this.onInit(); };
  27. this.__onShown = () => { this.onShown(); };
  28. this.__onHide = (() => { this.onHide(); });
  29. }
  30. get windData() {
  31. return this._windData;
  32. }
  33. get url() {
  34. return this._windData.url;
  35. }
  36. static add(wind) {
  37. this.mWinds.set(wind.url, wind);
  38. }
  39. /**查看路径资源是否创建 */
  40. static FindUrl(url) {
  41. if (url == null)
  42. url = "";
  43. return this.mWinds.has(url) ? this.mWinds.get(url) : undefined;
  44. }
  45. /**界面是否正在被展示 */
  46. static isShow(url) {
  47. let wind = this.FindUrl(url);
  48. if (wind == undefined)
  49. return false;
  50. return wind ? wind.isShowing && wind["_inited"] == true : false;
  51. }
  52. /**
  53. * 实例化窗口资源 第一次创建时才会调用
  54. * @returns
  55. */
  56. onInit() {
  57. let self = this;
  58. App.consoleView.Log("创建组件:" + self.url);
  59. let windObj = FairyGUI.UIPackage.CreateObject(self.windData.packName, self.windData.resName);
  60. if (windObj == null) {
  61. App.consoleView.Log("创建窗口失败 url:" + self.url);
  62. return;
  63. }
  64. self.contentPane = windObj;
  65. this.Center();
  66. }
  67. onShown() {
  68. }
  69. onHide() {
  70. }
  71. //#region 界面显示
  72. /**
  73. * 打开面板
  74. * @param id 面板路径
  75. * @param param 需求参数
  76. */
  77. static show(id, param) {
  78. if (this.mWinds.has(id)) {
  79. let wind = this.mWinds.get(id);
  80. wind.data = param;
  81. if (wind.isShowing && wind.contentPane) {
  82. wind.onShown();
  83. }
  84. else {
  85. wind.Show();
  86. }
  87. }
  88. else {
  89. App.consoleView.Log("显示窗口失败没有注册窗口 id:" + id);
  90. }
  91. }
  92. //#endregion
  93. static hide(url, param) {
  94. if (this.mWinds.has(url)) {
  95. let wind = this.mWinds.get(url);
  96. if (wind.isShowing) {
  97. wind.data = param;
  98. wind.Hide();
  99. }
  100. }
  101. else {
  102. App.consoleView.Log("隐藏窗口失败没有注册窗口 id:" + url);
  103. }
  104. }
  105. static delAll(filter) {
  106. let needDel = new Array();
  107. this.mWinds.forEach((v, k) => {
  108. if (filter == null || filter.findIndex(a => a == v.url) == -1) {
  109. needDel.push(v.url);
  110. }
  111. });
  112. for (let i = 0; i < needDel.length; i++) {
  113. this.remove(this.mWinds.get(needDel[i]));
  114. }
  115. }
  116. static remove(wind) {
  117. if (this.mWinds.has(wind.url)) {
  118. this.mWinds.delete(wind.url);
  119. App.consoleView.Log("卸载窗口:" + wind.url);
  120. wind._windData = null;
  121. wind.RemoveFromParent();
  122. wind.contentPane.Dispose();
  123. wind.contentPane = null;
  124. wind.Dispose();
  125. wind = null;
  126. }
  127. }
  128. }
  129. exports.default = UIWindow;