package org.cocos2d.transitions;

import org.cocos2d.CCDirector;
import org.cocos2d.actions.grid.CCStopGrid;
import org.cocos2d.actions.instant.CCCallFunc;
import org.cocos2d.actions.interval.CCIntervalAction;
import org.cocos2d.actions.interval.CCSequence;
import org.cocos2d.actions.tile.CCFadeOutTRTiles;
import org.cocos2d.cocoa.CCGeometry.CCSize;
import org.cocos2d.layers_scenes_transitions_nodes.CCScene;

/**
 * FadeTRTransition.
 * Fade the tiles of the outgoing scene from the left-bottom corner to the top-right corner.
 */
public class CCFadeTRTransition extends CCTransitionScene implements CCTransitionEaseScene{

	public static CCFadeTRTransition transition(float t, CCScene s) {
		return new CCFadeTRTransition(t, s);
	}

	public CCFadeTRTransition(float t, CCScene s) {
		super(t, s);
	}

	// override addScenes, and change the order
	@Override
	public void sceneOrder() {
		inSceneOnTop = false;
	}

	@Override
	public void onEnter() {
		super.onEnter();

		CCSize s = CCDirector.sharedDirector().getWinSizeInPixels();
		float aspect = s.width / s.height;
		int x = (int) (12 * aspect);
		int y = 12;

		CCIntervalAction action  = this.action(CCSize.Make(x,y));

		outScene.runAction(
				CCSequence.actions(
						easeAction(action),
						CCCallFunc.action(this, "finish"),
						CCStopGrid.action()
				)
		);

	}

	protected CCIntervalAction action(CCSize v) {
		return CCFadeOutTRTiles.action(v, duration);
	}

	@Override
	public CCIntervalAction easeAction(CCIntervalAction action) {
		// TODO Auto-generated method stub
		return action;
	}

}
