UNPKG

laya-coreui-es

Version:

laya核心库、ui库es版本,剔除了媒体、TTF等功能。基于 LayaAir-release_2.12.0 修改

163 lines (162 loc) 6.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DialogManager = void 0; const UIConfig_1 = require("./../../UIConfig"); const Const_1 = require("../Const"); const Sprite_1 = require("../display/Sprite"); const Event_1 = require("../events/Event"); const Box_1 = require("./Box"); const Ease_1 = require("../utils/Ease"); const Handler_1 = require("../utils/Handler"); const Tween_1 = require("../utils/Tween"); const IUI_1 = require("./IUI"); const ILaya_1 = require("../../ILaya"); class DialogManager extends Sprite_1.Sprite { constructor() { super(); this.maskLayer = new Sprite_1.Sprite(); this.popupEffect = (dialog) => { dialog.scale(1, 1); dialog._effectTween = Tween_1.Tween.from(dialog, { x: ILaya_1.ILaya.stage.width / 2, y: ILaya_1.ILaya.stage.height / 2, scaleX: 0, scaleY: 0 }, 300, Ease_1.Ease.backOut, Handler_1.Handler.create(this, this.doOpen, [dialog]), 0, false, false); }; this.closeEffect = (dialog) => { dialog._effectTween = Tween_1.Tween.to(dialog, { x: ILaya_1.ILaya.stage.width / 2, y: ILaya_1.ILaya.stage.height / 2, scaleX: 0, scaleY: 0 }, 300, Ease_1.Ease.strongOut, Handler_1.Handler.create(this, this.doClose, [dialog]), 0, false, false); }; this.popupEffectHandler = new Handler_1.Handler(this, this.popupEffect); this.closeEffectHandler = new Handler_1.Handler(this, this.closeEffect); this.mouseEnabled = this.maskLayer.mouseEnabled = true; this.zOrder = 1000; ILaya_1.ILaya.stage.addChild(this); ILaya_1.ILaya.stage.on(Event_1.Event.RESIZE, this, this._onResize); if (UIConfig_1.UIConfig.closeDialogOnSide) this.maskLayer.on("click", this, this._closeOnSide); this._onResize(null); } _closeOnSide() { var dialog = this.getChildAt(this.numChildren - 1); if (dialog instanceof IUI_1.IUI.Dialog) dialog.close("side"); } setLockView(value) { if (!this.lockLayer) { this.lockLayer = new Box_1.Box(); this.lockLayer.mouseEnabled = true; this.lockLayer.size(ILaya_1.ILaya.stage.width, ILaya_1.ILaya.stage.height); } this.lockLayer.removeChildren(); if (value) { value.centerX = value.centerY = 0; this.lockLayer.addChild(value); } } _onResize(e = null) { var width = this.maskLayer.width = ILaya_1.ILaya.stage.width; var height = this.maskLayer.height = ILaya_1.ILaya.stage.height; if (this.lockLayer) this.lockLayer.size(width, height); this.maskLayer.graphics.clear(true); this.maskLayer.graphics.drawRect(0, 0, width, height, UIConfig_1.UIConfig.popupBgColor); this.maskLayer.alpha = UIConfig_1.UIConfig.popupBgAlpha; for (var i = this.numChildren - 1; i > -1; i--) { var item = this.getChildAt(i); if (item.isPopupCenter) this._centerDialog(item); } } _centerDialog(dialog) { dialog.x = Math.round(((ILaya_1.ILaya.stage.width - dialog.width) >> 1) + dialog.pivotX); dialog.y = Math.round(((ILaya_1.ILaya.stage.height - dialog.height) >> 1) + dialog.pivotY); } open(dialog, closeOther = false, showEffect = false) { if (closeOther) this._closeAll(); this._clearDialogEffect(dialog); if (dialog.isPopupCenter) this._centerDialog(dialog); this.addChild(dialog); if (dialog.isModal || this._getBit(Const_1.Const.HAS_ZORDER)) ILaya_1.ILaya.timer.callLater(this, this._checkMask); if (showEffect && dialog.popupEffect != null) dialog.popupEffect.runWith(dialog); else this.doOpen(dialog); this.event(Event_1.Event.OPEN); } _clearDialogEffect(dialog) { if (dialog._effectTween) { Tween_1.Tween.clear(dialog._effectTween); dialog._effectTween = null; } } doOpen(dialog) { dialog.onOpened(dialog._param); } lock(value) { if (this.lockLayer) { if (value) this.addChild(this.lockLayer); else this.lockLayer.removeSelf(); } } close(dialog) { this._clearDialogEffect(dialog); if (dialog.isShowEffect && dialog.closeEffect != null) dialog.closeEffect.runWith([dialog]); else this.doClose(dialog); this.event(Event_1.Event.CLOSE); } doClose(dialog) { dialog.removeSelf(); dialog.isModal && this._checkMask(); dialog.closeHandler && dialog.closeHandler.runWith(dialog.closeType); dialog.onClosed(dialog.closeType); if (dialog.autoDestroyAtClosed) dialog.destroy(); } closeAll() { this._closeAll(); this.event(Event_1.Event.CLOSE); } _closeAll() { for (var i = this.numChildren - 1; i > -1; i--) { var item = this.getChildAt(i); if (item && item.close != null) { this.doClose(item); } } } getDialogsByGroup(group) { var arr = []; for (var i = this.numChildren - 1; i > -1; i--) { var item = this.getChildAt(i); if (item && item.group === group) { arr.push(item); } } return arr; } closeByGroup(group) { var arr = []; for (var i = this.numChildren - 1; i > -1; i--) { var item = this.getChildAt(i); if (item && item.group === group) { item.close(); arr.push(item); } } return arr; } _checkMask() { this.maskLayer.removeSelf(); for (var i = this.numChildren - 1; i > -1; i--) { var dialog = this.getChildAt(i); if (dialog && dialog.isModal) { this.addChildAt(this.maskLayer, i); return; } } } } exports.DialogManager = DialogManager;