import BasicObject from "../../Basic/BasicObject"; import BasicView from "../../Basic/BasicView"; import Tool from "../../Tool/Tool"; /**弹窗计数 */ let PopupCount: number = 0; /** * 弹窗组件 - 表现层 */ export default class Popup extends BasicObject { /**视窗 */ private view: BasicView; /**底层遮罩 */ private cover: fgui.GComponent; /**弹窗 */ private window: fgui.GComponent; /**关闭按钮 */ private closeButton: fgui.GComponent; /**关闭方法 */ private closeFunction: Function; constructor (view: BasicView, cover: fgui.GComponent, window: fgui.GComponent, closeButton: fgui.GComponent, closeFunction: Function) { super(); view.node.zIndex += PopupCount; PopupCount++; this.view = view; this.cover = cover; this.window = window; this.closeFunction = closeFunction; this.window.on(cc.Node.EventType.TOUCH_END, () => { }); this.cover.on(cc.Node.EventType.TOUCH_END, () => { this.hide(); }); this.closeButton = closeButton; Tool.Tool2D.Button.addEvent(this.closeButton, { "touchend": () => { this.hide(); } }, this.view.fgui.id); this.window.setScale(0.3, 0.3); } /**显示 */ public show (): void { this.window.setScale(0.3, 0.3); Tool.Tween.tweenTo(this.window, cc.tween(this.window) .to(0.1, {scaleX: 1, scaleY: 1}, cc.easeBackOut()) .start() ); } /**隐藏 */ public hide (): void { Tool.Tween.tweenTo(this.window, cc.tween(this.window) .to(0.1, {scaleX: 0.3, scaleY: 0.3}) .call(() => { this.closeFunction && this.closeFunction(); }) .start() ); } _destroy () { Tool.Tween.destroy(this.window.id); super._destroy(); } }