38743699-eec6-40be-9af0-5c74a66a18da.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. "use strict";
  2. cc._RF.push(module, '38743aZ7sZAvprwXHSmahja', 'BaseView');
  3. // lightMVC/core/base/BaseView.ts
  4. "use strict";
  5. var __extends = (this && this.__extends) || (function () {
  6. var extendStatics = function (d, b) {
  7. extendStatics = Object.setPrototypeOf ||
  8. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  9. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  10. return extendStatics(d, b);
  11. };
  12. return function (d, b) {
  13. extendStatics(d, b);
  14. function __() { this.constructor = d; }
  15. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  16. };
  17. })();
  18. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  19. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  20. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  21. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  22. return c > 3 && r && Object.defineProperty(target, key, r), r;
  23. };
  24. Object.defineProperty(exports, "__esModule", { value: true });
  25. exports.BaseView = void 0;
  26. /**
  27. * 视图基类
  28. */
  29. var ViewEvent_1 = require("./ViewEvent");
  30. var ViewManager_1 = require("../manager/ViewManager");
  31. var UIUtils_1 = require("../../util/UIUtils");
  32. var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
  33. var BaseView = /** @class */ (function (_super) {
  34. __extends(BaseView, _super);
  35. function BaseView() {
  36. return _super !== null && _super.apply(this, arguments) || this;
  37. }
  38. BaseView.prototype.__init__ = function () {
  39. this.__event__ = new ViewEvent_1.default();
  40. this.ui = UIUtils_1.default.seekAllSubView(this.node);
  41. this.init();
  42. };
  43. /**
  44. * view 创建时会被调用,子类可以重写.
  45. */
  46. BaseView.prototype.init = function () {
  47. };
  48. /**
  49. * 发送UI事件
  50. * @param {string} event 事件名称
  51. * @param {Object} body 事件参数
  52. */
  53. BaseView.prototype.sendEvent = function (event, body) {
  54. this.__event__.emit(event, body);
  55. };
  56. /**
  57. * 绑定UI事件
  58. * @param {string} name 事件名称
  59. * @param {(body: any)=>void} cb 事件回调
  60. * @param {BaseMediator} target 事件回调绑定对象
  61. * @private 私有函数,不得调用。
  62. */
  63. BaseView.prototype.__bindEvent__ = function (name, cb, target) {
  64. this.__event__.on(name, cb, target);
  65. };
  66. /**
  67. * 关闭当前的界面
  68. */
  69. BaseView.prototype.closeView = function () {
  70. var bgname = "blackBg" + this.node.name;
  71. if (this.node.parent && this.node.parent.getChildByName(bgname))
  72. this.node.parent.getChildByName(bgname).destroy();
  73. ViewManager_1.ViewManager.getInstance().__closeView__(this);
  74. this.__onClose__();
  75. };
  76. /**
  77. * 关闭所有弹出的界面
  78. */
  79. BaseView.prototype.closeAllPopView = function () {
  80. ViewManager_1.ViewManager.getInstance().__closeAllPopView__();
  81. };
  82. BaseView.prototype.__onClose__ = function () {
  83. this.__event__.destroy();
  84. this.onClose();
  85. this.node.destroy();
  86. };
  87. /**
  88. * 当界面被关闭时会被调用,子类可以重写该方法。
  89. * @override
  90. */
  91. BaseView.prototype.onClose = function () {
  92. };
  93. /**
  94. * 子类覆盖,返回UI的prefab路径
  95. * 路径第一个目录为子包名称如:aa/bb/ccc;aa为子包名 bb/ccc为子包内的prefab路径;
  96. * 如果放在resources的prefab;则路径去掉子包名/bb/ccc
  97. * @return {string}
  98. */
  99. BaseView.path = function () {
  100. return "";
  101. };
  102. /**
  103. * 注册mediator
  104. */
  105. BaseView.prototype.registerMediator = function (mediator, view, data) {
  106. var viewMediator = new mediator();
  107. viewMediator["__init__"]();
  108. viewMediator.view = view;
  109. viewMediator.view.__init__();
  110. viewMediator.init(data);
  111. };
  112. BaseView = __decorate([
  113. ccclass
  114. ], BaseView);
  115. return BaseView;
  116. }(cc.Component));
  117. exports.BaseView = BaseView;
  118. cc._RF.pop();