Engine.DialogTransitionerSlide = class
{

    constructor(dialog)
    {
        this.dialog = dialog;
        this.active = false;

        this.TransitionLocation = { "Left":1, "Right":2, "Top":3, "Bottom":4, "Center":5 };
        this.fromSide = this.TransitionLocation.Left;
        this.toSide = this.TransitionLocation.Right;

        this.start = this.TransitionLocation.Left;
        this.target = this.TransitionLocation.Center;
    }


    setTransitionStyle(fromSide, toSide)
    {
        this.fromSide = fromSide;
        this.toSide = toSide;
    }

    transitionOut(finishHide)
    {
        this.start = this.TransitionLocation.Center;
        this.target = this.toSide;
        this.time = 0.5;
        this.transition(finishHide);
    }

    transitionIn(finishSlide)
    {
        this.start = this.fromSide;
        this.target = this.TransitionLocation.Center;
        this.time = 0.5;
        this.transition(finishSlide);
    }

    transition(callback)
    {
        this.active = true;

        if (this.dialog.dialogWidth == 0) this.dialog.dialogWidth = this.dialog.width;
        if (this.dialog.dialogHeight == 0) this.dialog.dialogHeight = this.dialog.height;

        var screenWidth = EngineSettings.screenWidth;
        var screenHeight = EngineSettings.screenHeight;

        var startLoc = new PIXI.Point(0, 0);

        switch (this.start)
        {
            case this.TransitionLocation.Left:
                startLoc.x = -this.dialog.dialogWidth;
                startLoc.y = (screenHeight - this.dialog.dialogHeight) / 2;
                break;
            case this.TransitionLocation.Right:
                startLoc.x = screenWidth;
                startLoc.y = (screenHeight - this.dialog.dialogHeight) / 2;
                break;
            case this.TransitionLocation.Top:
                startLoc.x = (screenWidth - this.dialog.dialogWidth) / 2;
                startLoc.y = -dialog.Height;
                break;
            case this.TransitionLocation.Bottom:
                startLoc.x = (screenWidth - this.dialog.dialogWidth) / 2;
                startLoc.y = screenHeight;
                break;
            case this.TransitionLocation.Center:
                startLoc.x = (screenWidth - this.dialog.dialogWidth) / 2;
                startLoc.y = (screenHeight - this.dialog.dialogHeight) / 2;
                break;
        }

        var endLoc = this.getTargetPosition();

        var tx = new Engine.SimpleTween((v) => { this.dialog.x = v; }, Engine.SimpleTween.quadEaseOut, startLoc.x, endLoc.x, this.time, true);
        var ty = new Engine.SimpleTween((v) => { this.dialog.y = v; }, Engine.SimpleTween.quadEaseOut, startLoc.y, endLoc.y, this.time, true);

        this.dialog.x = startLoc.x;
        this.dialog.y = startLoc.y;

        ty.onFinish = () =>
        {
            this.active = false;
            if (callback != null) callback();
        };
    }

    getTargetPosition()
    {

        var screenWidth = EngineSettings.screenWidth;
        var screenHeight = EngineSettings.screenHeight;

        var endLoc = new PIXI.Point(0, 0);
        switch (this.target)
        {
            case this.TransitionLocation.Left:
                endLoc.x = -this.dialog.dialogWidth;
                endLoc.y = (screenHeight - this.dialog.dialogHeight) / 2;
                break;
            case this.TransitionLocation.Right:
                endLoc.x = screenWidth;
                endLoc.y = (screenHeight - this.dialog.dialogHeight) / 2;
                break;
            case this.TransitionLocation.Top:
                endLoc.x = (screenWidth - this.dialog.dialogWidth) / 2;
                endLoc.y = -this.dialog.dialogHeight;
                break;
            case this.TransitionLocation.Bottom:
                endLoc.x = (screenWidth - this.dialog.dialogWidth) / 2;
                endLoc.y = screenHeight;
                break;
            case this.TransitionLocation.Center:
                endLoc.x = (screenWidth - this.dialog.dialogWidth) / 2;
                endLoc.y = (screenHeight - this.dialog.dialogHeight) / 2;
                break;
        }

        return endLoc;
    }
}