UNPKG

@senspark/ee

Version:

utility library for cocos creator

150 lines (149 loc) 6.12 kB
"use strict"; 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 (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var assert = require("assert"); var _a = cc._decorator, ccclass = _a.ccclass, disallowMultiple = _a.disallowMultiple, menu = _a.menu; var DialogEventType; (function (DialogEventType) { DialogEventType[DialogEventType["WillShow"] = 0] = "WillShow"; DialogEventType[DialogEventType["DidShow"] = 1] = "DidShow"; DialogEventType[DialogEventType["WillHide"] = 2] = "WillHide"; DialogEventType[DialogEventType["DidHide"] = 3] = "DidHide"; })(DialogEventType = exports.DialogEventType || (exports.DialogEventType = {})); var Dialog = /** @class */ (function (_super) { __extends(Dialog, _super); function Dialog() { var _this = _super.call(this) || this; _this.active = false; _this.actor = new cc.Node(); _this.showingTransitions = []; _this.hidingTransitions = []; _this.eventDictionary = {}; return _this; } Dialog.prototype.onLoad = function () { this.node.addChild(this.actor); }; Dialog.prototype.getContainer = function () { return this.node.parent; }; /** Shows this dialog using the specified dialog manager. */ Dialog.prototype.show = function (manager) { var container = new cc.Node(); container.setContentSize(cc.winSize); container.addChild(this.node); container.addComponent(cc.BlockInputEvents); this.manager = manager; manager.pushDialog(this); }; /** Hides this dialog using the current dialog manager. */ Dialog.prototype.hide = function () { var manager = this.manager; assert(manager !== undefined); if (manager !== undefined) { manager.popDialog(this); } }; /** Attempts to show the specified dialog using the current dialog manager. */ Dialog.prototype.showDialog = function (dialog) { var manager = this.manager; if (manager === undefined) { assert(false, 'The current dialog is not active.'); return; } dialog.show(manager); }; /** Checks whether this dialog is active. */ Dialog.prototype.isActive = function () { return this.active; }; /** Sets this dialog to be active. */ Dialog.prototype.setActive = function (active) { this.active = active; }; /** Adds a will-show event. */ Dialog.prototype.onWillShow = function (event) { return this.addEvent(DialogEventType.WillShow, event); }; /** Adds a did-show event. */ Dialog.prototype.onDidShow = function (event) { return this.addEvent(DialogEventType.DidShow, event); }; /** Adds a will-hide event. */ Dialog.prototype.onWillHide = function (event) { return this.addEvent(DialogEventType.WillHide, event); }; /** Adds a did-hide event. */ Dialog.prototype.onDidHide = function (event) { return this.addEvent(DialogEventType.DidHide, event); }; /** Adds a showing transition. */ Dialog.prototype.addShowingTransition = function (transition) { this.showingTransitions.push(transition); return this; }; /** Adds a hiding transition. */ Dialog.prototype.addHidingTransition = function (transition) { this.hidingTransitions.push(transition); return this; }; Dialog.prototype.playShowingTransition = function (callback) { this.playTransition(this.showingTransitions, callback); }; Dialog.prototype.playHidingTransition = function (callback) { this.playTransition(this.hidingTransitions, callback); }; Dialog.prototype.playTransition = function (actions, callback) { var _this = this; assert(this.actor.getNumberOfRunningActions() === 0); this.actor.stopAllActions(); var transitions = []; actions.forEach(function (action) { return transitions.push.apply(transitions, [ cc.delayTime(0), cc.targetedAction(_this.node, action), ]); }); transitions.push(cc.callFunc(callback)); this.actor.runAction(actions.length === 0 ? cc.callFunc(callback) : cc.sequence(transitions)); }; Dialog.prototype.addEvent = function (type, event) { var events = this.getEvents(type); events.push(event); return this; }; /** Processes all events for the specified event type. */ Dialog.prototype.processEvent = function (type) { var _this = this; var events = this.getEvents(type); events.forEach(function (event) { return event(_this); }); }; Dialog.prototype.getEvents = function (type) { return this.eventDictionary[type] = this.eventDictionary[type] || []; }; Dialog = __decorate([ ccclass, disallowMultiple, menu('ee/Dialog') ], Dialog); return Dialog; }(cc.Component)); exports.Dialog = Dialog;