bbcc9005-d8c8-4ef2-8b8f-ddeea4b1088e.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. "use strict";
  2. cc._RF.push(module, 'bbcc9AF2MhO8ouP3e6ksQiO', 'UIPage');
  3. // scripts/Framework/UIPage.ts
  4. "use strict";
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. var Utils_1 = require("../../common-plugin/Scripts/Utils");
  7. var CocosZ_1 = require("./CocosZ");
  8. var UIMgr_1 = require("./UIMgr");
  9. var UIPage = /** @class */ (function () {
  10. function UIPage(pageName) {
  11. var _this = this;
  12. this._page = null;
  13. this._pageName = "";
  14. /** 页面状态 */
  15. this._isOpen = false;
  16. var prefab = CocosZ_1.cocosz.resMgr.getRes(pageName, cc.Prefab);
  17. if (prefab) {
  18. var node = cc.instantiate(prefab);
  19. if (node) {
  20. this._page = node;
  21. this._pageName = pageName;
  22. node.active = false;
  23. node.position = cc.Vec3.ZERO;
  24. this._isOpen = false;
  25. this.getUIRoot().addChild(node);
  26. node.group = 'ui';
  27. }
  28. }
  29. else {
  30. CocosZ_1.cocosz.resMgr.loadAndCacheRes("UI/" + pageName, cc.Prefab, null, function (err, res) {
  31. if (res) {
  32. var node = cc.instantiate(res);
  33. if (node) {
  34. _this._page = node;
  35. _this._pageName = pageName;
  36. node.active = false;
  37. node.position = cc.Vec3.ZERO;
  38. _this._isOpen = false;
  39. _this.getUIRoot().addChild(node);
  40. node.group = 'ui';
  41. _this.onLoad();
  42. _this.open();
  43. }
  44. }
  45. else {
  46. cc.error("Prefab " + pageName + " is not found!");
  47. }
  48. });
  49. }
  50. }
  51. UIPage.prototype.open = function () {
  52. if (this.isValid()) {
  53. if (!this._isOpen) {
  54. // 恢复开关
  55. UIMgr_1.default.canOpen = true;
  56. // 打开界面
  57. this._isOpen = true;
  58. this._page.active = true;
  59. this.onOpen();
  60. // 插屏
  61. var serverValue = CocosZ_1.cocosz.getConfigByKey("isInterstitial_" + this._pageName);
  62. if (serverValue) {
  63. // 每次都弹
  64. if (serverValue === "true") {
  65. CocosZ_1.cocosz.isShowAd && Utils_1.utils.adManager.ShowInterstitial();
  66. }
  67. // 几次弹一次
  68. else if ((Number.isInteger(serverValue) && serverValue > 0)) {
  69. if (!UIPage.interstitialCount[this._pageName]) {
  70. UIPage.interstitialCount[this._pageName] = 0;
  71. }
  72. if (++UIPage.interstitialCount[this._pageName] % serverValue === 0) {
  73. CocosZ_1.cocosz.isShowAd && Utils_1.utils.adManager.ShowInterstitial();
  74. }
  75. }
  76. }
  77. }
  78. }
  79. else {
  80. cc.log("Page is not found!");
  81. }
  82. };
  83. UIPage.prototype.close = function () {
  84. if (this._isOpen) {
  85. this._isOpen = false;
  86. this.onClose();
  87. }
  88. if (this.isValid()) {
  89. this._page.active = false;
  90. this.destroy();
  91. }
  92. // 资源销毁
  93. if ("UILoadingPage" === this._pageName) {
  94. CocosZ_1.cocosz.resMgr.releaseSingleRes(this._pageName, cc.Prefab);
  95. }
  96. };
  97. UIPage.prototype.destroy = function () {
  98. if (this._isOpen) {
  99. this._isOpen = false;
  100. }
  101. this.onDestroy();
  102. // 销毁界面
  103. if (this.isValid()) {
  104. this._page.destroy();
  105. }
  106. };
  107. UIPage.prototype.getUIRoot = function () {
  108. return cc.find("Canvas");
  109. };
  110. UIPage.prototype.isValid = function () {
  111. return this._page && cc.isValid(this._page);
  112. };
  113. UIPage.prototype.isOpen = function () {
  114. return this.isValid() && this._isOpen;
  115. };
  116. /**
  117. * 子类扩展:页面初始化时调用,注意不是引擎周期函数,此时引擎周期函数还没有调用
  118. */
  119. UIPage.prototype.onLoad = function () {
  120. };
  121. /**
  122. * 子类扩展:页面展示时调用
  123. */
  124. UIPage.prototype.onOpen = function () { };
  125. /**
  126. * 子类扩展:页面关闭时调用
  127. */
  128. UIPage.prototype.onClose = function () { };
  129. /**
  130. * 子类扩展:页面销毁时调用
  131. */
  132. UIPage.prototype.onDestroy = function () { };
  133. /** 记录页面插屏次数 */
  134. UIPage.interstitialCount = {};
  135. return UIPage;
  136. }());
  137. exports.default = UIPage;
  138. cc._RF.pop();