Newer
Older
lostmynuts / shared / js / Engine / Dialogs / LoadingTextBox.js
Engine.LoadingTextBox = class extends Engine.Dialog
{
    constructor(parentClip)
    {
        super(parentClip);

        this.background = new Engine.Drawable("BGStandard");
        
        this.text = new Engine.DrawableText();

        this.loadingCircle = new Engine.Drawable("LoadingCircle");
        this.boxWidth = 270;
        this.boxHeight = 90;

        this.dialogWidth = this.boxWidth;
        this.dialogHeight = this.boxHeight;

        this.name = "LoadingBox";
        this.background.setNineRect();
        this.background.width = this.boxWidth;
        this.background.height = this.boxHeight;

        this.initialTransparent = false;
        this.alwaysTransparent = false;
        this.delayTimer = new Engine.SimpleTimer();

        this.addChild(this.background);
        this.addChild(this.text);
        this.addChild(this.loadingCircle);

    }

    showAfterDelay()
    {
        if (this.parent == null) return;

        this.blockerInfo = new Engine.DialogBlockerInfo();
        if (this.alwaysTransparent)
        {
            this.blockerInfo.color = 0x000000;
            this.blockerInfo.alpha = 0;
        }
        Engine.DialogManagerInstance.updateBlockers();

        this.background.alpha = 1;
        this.addChild(this.text);
        this.addChild(this.loadingCircle);
    }

    show(message, delay, initialTransparent, alwaysTransparent)
    {
        if (delay === undefined) delay = 0;
        if (initialTransparent === undefined) initialTransparent = false;
        if (alwaysTransparent === undefined) alwaysTransparent = false;

        Debug.Log("Showing - " + message);
        this.initialTransparent = initialTransparent;
        this.alwaysTransparent = alwaysTransparent;
        if (delay != 0)
        {
            this.background.alpha = 0;
            this.removeChild(this.text);
            this.removeChild(this.loadingCircle);
            this.blockerInfo = null;

            if (this.delayTimer.active) this.delayTimer.stop();
            this.delayTimer.start(delay, () => { this.showAfterDelay(); });

            if (initialTransparent)
            {
                this.blockerInfo = new Engine.DialogBlockerInfo();
                this.blockerInfo.color = 0x000000;
                this.blockerInfo.alpha = 0;
            }
        }
        else
        {
            this.background.alpha = 1;
            this.addChild(this.text);
            this.addChild(this.loadingCircle);
            if (!this.active)
            {
                this.blockerInfo = new Engine.DialogBlockerInfo();
                if (alwaysTransparent)
                {
                    this.blockerInfo.color = 0x000000;
                    this.blockerInfo.alpha = 0;
                }
            }
        }

        this.active = true;

        this.parentClip.addChild(this);

        var loadingWidth = this.loadingCircle.width;
        this.loadingCircle.y = this.boxHeight / 2;
        this.loadingCircle.x = loadingWidth;
        this.loadingCircle.gotoAndPlay(0);

        this.text.setText(message);
        this.text.x = Math.floor(loadingWidth + ((this.boxWidth - loadingWidth) - this.text.width) / 2);
        this.text.y = Math.floor((this.boxHeight - this.text.height) / 2);

        this.dt.transitionIn();
    }

    hide(instant)
    {
        super.hide(this.delayTimer.active);
        this.delayTimer.stop();
    }

}