@mai3/phaser-sdk
Version:
A UI component library based on the Phaser game engine
114 lines (113 loc) • 5.69 kB
JavaScript
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
if (typeof b !== "function" && b !== null)
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import { Container } from './Container';
import { Panel } from './Panel';
var Dialog = /** @class */ (function (_super) {
__extends(Dialog, _super);
function Dialog(scene, config) {
var _this = _super.call(this, scene, __assign(__assign({}, config), { x: 0, y: 0 })) || this;
_this._childComponents = [];
_this._handlePointerDown = function (_, _localX, _localY, event) {
event.stopPropagation();
};
_this.Type = 'Dialog';
_this.scene = scene;
_this._initDialog(config);
return _this;
}
Dialog.prototype._initDialog = function (config) {
this._config = config;
this._createRoot();
this._positionDialog();
this.updateConfig(this._config);
this.setScrollFactor(this._config.isScrollFactor ? 0 : 1);
};
Dialog.prototype._createRoot = function () {
var _a, _b, _c, _d, _e, _f;
var _g = this._config, _h = _g.width, width = _h === void 0 ? 0 : _h, _j = _g.height, height = _j === void 0 ? 0 : _j, _k = _g.texture, texture = _k === void 0 ? '' : _k, frame = _g.frame, _l = _g.leftWidth, leftWidth = _l === void 0 ? 0 : _l, _m = _g.rightWidth, rightWidth = _m === void 0 ? 0 : _m, _o = _g.topHeight, topHeight = _o === void 0 ? 0 : _o, _p = _g.bottomHeight, bottomHeight = _p === void 0 ? 0 : _p, _q = _g.radius, radius = _q === void 0 ? 0 : _q, _r = _g.borderWidth, borderWidth = _r === void 0 ? 0 : _r, _s = _g.borderColor, borderColor = _s === void 0 ? 0 : _s;
this._root = new Panel(this.scene, { x: 0, y: 0, width: width, height: height, texture: texture, frame: frame, leftWidth: leftWidth, rightWidth: rightWidth, topHeight: topHeight, bottomHeight: bottomHeight, radius: radius, borderWidth: borderWidth, borderColor: borderColor });
this._root.setName("root");
this._root.drawBackground();
this.addAt(this._root, 1);
if (((_a = this._config) === null || _a === void 0 ? void 0 : _a.isShowCloseButton) && ((_b = this._config) === null || _b === void 0 ? void 0 : _b.closeButtonConfig)) {
var closeBtnConfig = this._config.closeButtonConfig;
closeBtnConfig.x = (_c = closeBtnConfig.x) !== null && _c !== void 0 ? _c : (((_d = this._config.width) !== null && _d !== void 0 ? _d : 0) - ((_e = closeBtnConfig.width) !== null && _e !== void 0 ? _e : 0) - 30);
closeBtnConfig.y = (_f = closeBtnConfig.y) !== null && _f !== void 0 ? _f : 30;
var child = this.scene.getChild(closeBtnConfig);
this._root.addChild(child);
this._childComponents.push(child);
}
};
Dialog.prototype._positionDialog = function () {
var _a, _b;
var _c = this._config, _d = _c.width, width = _d === void 0 ? 0 : _d, _e = _c.height, height = _e === void 0 ? 0 : _e;
var rootX = (this.scene.scale.width - width) / 2;
var rootY = (this.scene.scale.height - height) / 2;
this.setPosition(rootX, rootY);
this.setDepth((_b = (_a = this._config) === null || _a === void 0 ? void 0 : _a.depth) !== null && _b !== void 0 ? _b : 99999);
this.RefreshBounds();
};
Dialog.prototype.addItems = function (childConfigs) {
var _this = this;
childConfigs.forEach(function (childConfig) {
var child = _this.scene.getChild(childConfig);
_this._root.addChild(child);
_this._childComponents.push(child);
});
};
Dialog.prototype.reDraw = function (config) {
if (this._root) {
this._root.destroy(true);
this._root = undefined;
}
this._initDialog(config);
};
Dialog.prototype.show = function () {
this.setVisible(true);
};
Dialog.prototype.hide = function () {
this.setVisible(false);
};
Dialog.prototype.close = function () {
this.destroy();
};
Dialog.prototype.destroy = function (fromScene) {
var _a, _b;
this._childComponents.forEach(function (child) {
child.destroy(true);
});
this._childComponents = [];
(_a = this._root) === null || _a === void 0 ? void 0 : _a.removeAll(true);
this.getAll().forEach(function (obj) { return obj.destroy(true); });
(_b = this._root) === null || _b === void 0 ? void 0 : _b.destroy(fromScene);
this._root = undefined;
this._config = undefined;
_super.prototype.destroy.call(this, fromScene);
};
return Dialog;
}(Container));
export { Dialog };