package ui
{
	import interf.ISteper;
	import flash.display.BitmapData;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.DisplayObjectContainer;
	import flash.events.MouseEvent;
	import game.Panda;
	import tdh.utils.BitmapInt;
	import tdh.utils.BitmapClip;
	import interf.FpsGame;
	
	public class GameUI extends Object implements ISteper
	{
		
		public function GameUI(goStart:Function)
		{
			super();
			this.score = new BitmapInt(numSrc1);
			this.bamboo = new BitmapInt(numSrc1);
			this.shootsHL = new BitmapClip(shineSrc, -7);
			this.shoots = new BitmapInt(numSrc3);
			this.milkHL = new BitmapClip(shineSrc, -7);
			this.milk = new BitmapInt(numSrc3);
			this.amuletHL = new BitmapClip(shineSrc, -7);
			this.amulet = new BitmapInt(numSrc3);
			this.playArea.addChild(new Bitmap(btnAreaSrc1));
			this.replayArea.addChild(new Bitmap(btnAreaSrc1));
			this.quitArea.addChild(new Bitmap(btnAreaSrc2));
			this.goStartFunc = goStart;
		}
		
		private static var HeaderBmp:Class = GameUI_HeaderBmp;
		
		private static var SPBmp:Class = GameUI_SPBmp;
		
		private static var Num1Bmp:Class = GameUI_Num1Bmp;
		
		public static const numSrc1:BitmapData = new Num1Bmp().bitmapData;
		
		private static var Num2Bmp:Class = GameUI_Num2Bmp;
		
		public static const numSrc2:BitmapData = new Num2Bmp().bitmapData;
		
		private static var Num3Bmp:Class = GameUI_Num3Bmp;
		
		public static const numSrc3:BitmapData = new Num3Bmp().bitmapData;
		
		private static var JumpBtn:Class = GameUI_JumpBtn;
		
		private static var AttackBtn:Class = GameUI_AttackBtn;
		
		private static var FlyBtn:Class = GameUI_FlyBtn;
		
		private static var BtnArea1:Class = GameUI_BtnArea1;
		
		public static const btnAreaSrc1:BitmapData = new BtnArea1().bitmapData;
		
		private static var BtnArea2:Class = GameUI_BtnArea2;
		
		public static const btnAreaSrc2:BitmapData = new BtnArea2().bitmapData;
		
		private static var PauseBmp:Class = GameUI_PauseBmp;
		
		public static const pauseSrc:BitmapData = new PauseBmp().bitmapData;
		
		private static var ItemShineBmp:Class = GameUI_ItemShineBmp;
		
		public static const shineSrc:BitmapData = new ItemShineBmp().bitmapData;
		
		public static const Panel:Class = GameUI_Panel;
		
		private var goStartFunc:Function;
		
		private const header:Bitmap = new HeaderBmp();
		
		private const sp:Bitmap = new SPBmp();
		
		private const jumpBtn:Bitmap = new JumpBtn();
		
		private const attackBtn:Bitmap = new AttackBtn();
		
		private const flyBtn:Bitmap = new FlyBtn();
		
		private const pauseBmp:Bitmap = new PauseBmp();
		
		private const playArea:Sprite = new Sprite();
		
		private const replayArea:Sprite = new Sprite();
		
		private const quitArea:Sprite = new Sprite();
		
		public function showAs(dpoc:DisplayObjectContainer):void
		{
			this.header.x = 21;
			this.header.y = 9;
			dpoc.addChild(this.header);
			this.sp.x = 87;
			this.sp.y = 25;
			dpoc.addChild(this.sp);
			this.score.y = 85;
			this.score.showAs(dpoc);
			this.bamboo.y = 30;
			this.bamboo.showAs(dpoc);
			this.shoots.y = 92;
			this.shoots.showAs(dpoc);
			this.shootsHL.x = 435;
			this.shootsHL.y = 20;
			this.shootsHL.hideAndStop();
			dpoc.addChild(this.shootsHL);
			this.milk.y = 92;
			this.milk.showAs(dpoc);
			this.milkHL.x = 513;
			this.milkHL.y = 20;
			this.milkHL.hideAndStop();
			dpoc.addChild(this.milkHL);
			this.amulet.y = 92;
			this.amulet.showAs(dpoc);
			this.amuletHL.x = 356;
			this.amuletHL.y = 20;
			this.amuletHL.hideAndStop();
			dpoc.addChild(this.amuletHL);
			this.jumpBtn.x = this.flyBtn.x = 50;
			this.jumpBtn.y = this.flyBtn.y = 350;
			dpoc.addChild(this.jumpBtn);
			dpoc.addChild(this.flyBtn);
			this.attackBtn.x = 800 - 88 - 50;
			this.attackBtn.y = 350;
			dpoc.addChild(this.attackBtn);
			this.pauseBmp.visible = false;
			dpoc.addChild(this.pauseBmp);
			this.playArea.x = 222;
			this.playArea.y = 164;
			this.playArea.alpha = 0;
			dpoc.addChild(this.playArea);
			this.replayArea.x = 439;
			this.replayArea.y = 164;
			this.replayArea.alpha = 0;
			dpoc.addChild(this.replayArea);
			this.quitArea.x = 24;
			this.quitArea.y = 393;
			this.quitArea.alpha = 0;
			dpoc.addChild(this.quitArea);
			this.visible = false;
			this.pauseBmp.visible = this.playArea.visible = false;
			this.replayArea.visible = this.quitArea.visible = false;
			this.playArea.addEventListener(MouseEvent.MOUSE_DOWN, this.hl);
			this.replayArea.addEventListener(MouseEvent.MOUSE_DOWN, this.hl);
			this.quitArea.addEventListener(MouseEvent.MOUSE_DOWN, this.hl);
			this.playArea.addEventListener(MouseEvent.MOUSE_UP, this.goplay);
			this.replayArea.addEventListener(MouseEvent.MOUSE_UP, this.replay);
			this.quitArea.addEventListener(MouseEvent.MOUSE_UP, this.quit);
		}
		
		public var panda:Panda;
		
		public var sound1:GameSound;
		
		public var play:Function;
		
		private var spnum:int = 1000;
		
		private var sp_w:int = 233;
		
		private var numBamboo:int;
		
		private var numShoots:int;
		
		private var numMilk:int;
		
		private var numAmulet:int;
		
		public function step():void
		{
			if (this.panda.sp != this.spnum)
			{
				this.spnum = this.panda.sp;
				this.sp.width = this.sp_w * this.spnum / Panda.sp;
			}
			if (this.panda.willFly)
			{
				this.jumpBtn.visible = false;
				this.flyBtn.visible = true;
			}
			else
			{
				this.jumpBtn.visible = true;
				this.flyBtn.visible = false;
			}
			if (this.panda.numBamboo != this.numBamboo)
			{
				this.setBamboo(this.numBamboo = this.panda.numBamboo);
			}
			if (this.panda.numShoots != this.numShoots)
			{
				this.setShoots(this.numShoots = this.panda.numShoots);
			}
			if (this.panda.numMilk != this.numMilk)
			{
				this.setMilk(this.numMilk = this.panda.numMilk);
			}
			if (this.panda.numAmulet != this.numAmulet)
			{
				this.setAmulet(this.numAmulet = this.panda.numAmulet);
			}
			this.setScore(this.panda.runningDistance);
		}
		
		public function startInit(amulet:int, shoots:int, milk:int):void
		{
			this.numAmulet = amulet;
			this.amulet.value = amulet;
			this.amulet.x = 379;
			this.numShoots = shoots;
			this.shoots.value = shoots;
			this.shoots.x = 460;
			this.numMilk = milk;
			this.milk.value = milk;
			this.milk.x = 540;
		}
		
		private var score:BitmapInt;
		
		private function setScore(num:int):void
		{
			this.score.value = num;
			this.score.x = 760 - this.score.width;
		}
		
		private var bamboo:BitmapInt;
		
		private function setBamboo(num:int):void
		{
			this.bamboo.value = num;
			this.bamboo.x = 760 - this.bamboo.width;
		}
		
		private var shootsHL:BitmapClip;
		
		private var shoots:BitmapInt;
		
		private function setShoots(num:int):void
		{
			this.shoots.value = num;
			this.shoots.x = 460;
			this.shootsHL.visible = true;
			this.shootsHL.playOnce(true);
		}
		
		private var milkHL:BitmapClip;
		
		private var milk:BitmapInt;
		
		private function setMilk(num:int):void
		{
			this.milk.value = num;
			this.milk.x = 540;
			this.milkHL.visible = true;
			this.milkHL.playOnce(true);
		}
		
		private var amuletHL:BitmapClip;
		
		private var amulet:BitmapInt;
		
		private function setAmulet(num:int):void
		{
			this.amulet.value = num;
			this.amulet.x = 379;
			this.amuletHL.visible = true;
			this.amuletHL.playOnce(true);
		}
		
		public function set visible(value:Boolean):void
		{
			this.header.visible = this.sp.visible = this.score.visible = value;
			this.bamboo.visible = this.amulet.visible = this.shoots.visible = value;
			this.milk.visible = this.flyBtn.visible = value;
			this.jumpBtn.visible = this.attackBtn.visible = value;
			this.shootsHL.visible = this.milkHL.visible = this.amuletHL.visible = value;
		}
		
		public function get visible():Boolean
		{
			return this.header.visible;
		}
		
		public var engine:FpsGame;
		
		public var welcome:Welcome;
		
		private function pauseDown(e:MouseEvent):void
		{
		}
		
		private function pauseUp(p:* = null):void
		{
		}
		
		public function pause():void
		{
			this.playArea.alpha = this.replayArea.alpha = this.quitArea.alpha = 0;
			this.pauseBmp.visible = this.playArea.visible = true;
			this.replayArea.visible = this.quitArea.visible = true;
		}
		
		private function goplay(e:MouseEvent):void
		{
			this.pauseBmp.visible = this.playArea.visible = false;
			this.replayArea.visible = this.quitArea.visible = false;
			if (this.panda.flying)
			{
				this.sound1.playFlySound();
			}
			this.sound1.playBGSound();
			this.engine.play();
		}
		
		private function replay(e:MouseEvent):void
		{
			this.pauseBmp.visible = this.playArea.visible = false;
			this.replayArea.visible = this.quitArea.visible = false;
			this.engine.stop();
			this.panda.start();
			this.sound1.playBGSound();
			this.engine.start();
		}
		
		private function quit(e:MouseEvent):void
		{
			this.pauseBmp.visible = this.playArea.visible = false;
			this.replayArea.visible = this.quitArea.visible = false;
			this.engine.stop();
			this.goStartFunc();
		}
		
		private function hl(e:MouseEvent):void
		{
			e.target.alpha = 1;
		}
		
		public function a():void
		{
			this.jumpBtn.y = 351;
			this.flyBtn.y = 351;
		}
		
		public function b():void
		{
			this.attackBtn.y = 351;
		}
		
		public function ca():void
		{
			this.jumpBtn.y = 350;
			this.flyBtn.y = 350;
		}
		
		public function cb():void
		{
			this.attackBtn.y = 350;
		}
	}
}
