Newer
Older
lostmynuts / shared / js / Engine / Dialogs / DialogTransitionerExpand.js
Engine.DialogTransitionerExpand = class
{
	constructor(dialog /*Dialog*/)
	{
        this.active = false;
        this.dialog = dialog;

		this.dontSettle
		this.waiter = new CountWaiter(CountWaiterStatics.CountWaiterMode.WaitForGo);
		this.sx = new Engine.SimpleTween();
		this.sy = new Engine.SimpleTween();
		this.dx = new Engine.SimpleTween();
		this.dy = new Engine.SimpleTween();
		this.popInTime = 0.3;
		this.startX = -1;
		this.startY = -1;
		this.endX = -1;
		this.endY = -1;
		this.enter
	}

	setValues(startX /*float*/, startY /*float*/, endX /*float*/, endY /*float*/, dontSettle /*bool*/)
	{
		if (dontSettle === undefined) dontSettle = false;
		this.dontSettle = dontSettle;
		this.popInTime = dontSettle ? 0.3 : 0.2;
		if (endX != -1)
		{
			this.endX = endX;
			this.endY = endY;
		}
		
		this.startX = startX;
		this.startY = startY;
	}

	transitionOut(finishHide /*Action*/)
	{
		this.enter = false;
		this.transition(() => finishHide());
	}

	transitionIn(finishSlide /*Action*/)
	{
		if (this.startX == -1)
		{
			this.setValues(EngineSettings.screenWidth / 2, EngineSettings.screenHeight / 2, EngineSettings.screenWidth / 2, EngineSettings.screenHeight / 2);
		}
		this.enter = true;
		this.transition(() => finishSlide());
	}

	transition(callback /*Action*/)
	{
		this.active = true;
		
		this.sx.stop();
		this.sy.stop();
		this.dx.stop();
		this.dy.stop();
		
		if (this.enter)
		{
			this.dialog.scale.x = 0;
			this.dialog.scale.y = 0;
		}
		
		if (this.enter)
		{
			this.sx.init((v) => { this.dialog.scale.x = v; }, Engine.SimpleTween.sineWaveIn, 0.0, 1.0, this.popInTime, false);
			this.sy.init((v) => { this.dialog.scale.y = v; }, Engine.SimpleTween.sineWaveIn, 0.0, 1.0, this.popInTime, false);
			this.dx.init((v) => { this.dialog.x = v; }, Engine.SimpleTween.sineWaveIn, this.startX, this.endX, this.popInTime, false);
			this.dy.init((v) => { this.dialog.y = v; }, Engine.SimpleTween.sineWaveIn, this.startY, this.endY, this.popInTime, false);
		}
		else
		{
			this.sx.init((v) => { this.dialog.scale.x = v; }, Engine.SimpleTween.easeLinear, 1.0, 0.0, this.popInTime, false);
			this.sy.init((v) => { this.dialog.scale.y = v; }, Engine.SimpleTween.easeLinear, 1.0, 0.0, this.popInTime, false);
			this.dx.init((v) => { this.dialog.x = v; }, Engine.SimpleTween.easeLinear, this.endX, this.startX, this.popInTime, false);
			this.dy.init((v) => { this.dialog.y = v; }, Engine.SimpleTween.easeLinear, this.endY, this.startY, this.popInTime, false);
		}
		
		this.waiter.init(() => { this.active = false; if (callback != null) callback(); });
		
		this.waiter.waitMany(4);
		this.sx.onFinish = () => { this.waiter.waitDone(); };
		this.sy.onFinish = () => { this.waiter.waitDone(); };
		this.dx.onFinish = () => { this.waiter.waitDone(); };
		this.dy.onFinish = () => { this.waiter.waitDone(); };
		this.waiter.go();
	}

	getTargetPosition()
	{
		return [endX, endY];
	}
}