package {
	import com.greensock.TweenLite;
	import com.netgrind.core.Key;
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.ui.Keyboard;
	import zpp_nape.util.Array2_Float;
	
	/**
	 * ...
	 * @author netgrind
	 */
	public class EndScreen extends Sprite {
		
		public var text:TextField;
		
		public function EndScreen():void {
			super();
			x = 50;
			y =  50;
			graphics.beginFill(0xffffff, .7);
			graphics.drawRect(0, 0, 500, 300);
			graphics.endFill();
			alpha = 0;
			
			text = new TextField();
			text.defaultTextFormat = new TextFormat(null, 16, 0x222222);
			text.width = 500;
			text.height = 300;
			addChild(text);
		}
		
		public function formatTime(time:Number):Number {
			return Math.floor(time * 100) / 100;
		}
		
		public function show(m:Mission):void {
			TweenLite.to(this, .5, { alpha:1 } );
			text.text = "Your time - " + formatTime(m.time) +
			"\nGold time - "+formatTime(m.goalTimes[0])+
			"\nSilver time - "+formatTime(m.goalTimes[1])+
			"\nBronze time - " + formatTime(m.goalTimes[2]) + "\n\n";
			if (m.time < m.goalTimes[0]) text.appendText( "Congratulations, you beat the gold time");
			else if (m.time < m.goalTimes[1]) text.appendText(  "Congratulations, you beat the silver time");
			else if (m.time < m.goalTimes[2]) text.appendText(  "Congratulations, you beat the bronze time");
			else text.appendText(  "You failed to get a medal, better luck next time");
		}
		
		public function hide():void {
			TweenLite.to(this, .5, { alpha:0 } );
		}
		
	}
	
}