package com.andengine.blackdog.chapter3;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.FillResolutionPolicy;
import org.andengine.entity.modifier.ScaleModifier;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.entity.text.Text;
import org.andengine.opengl.font.Font;
import org.andengine.opengl.font.FontFactory;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.vbo.VertexBufferObjectManager;
import org.andengine.ui.activity.SimpleBaseGameActivity;

import android.graphics.Color;
import android.graphics.Typeface;

public class FontSample extends SimpleBaseGameActivity {
	// 카메라 필드를 생성합니다.
	// 가로와 세로 2개의 카메라 변수를 선언했습니다.
	private Camera camera;
	private static final int CAMERA_WIDTH = 800;
	private static final int CAMERA_HEIGHT = 480;

	private Font mFont1;
	private Font mFont2;
	private Font mFont3;
	private Font mFont4;
	private Font mFont5;
	private Font mFont6;
	private Font mFont7;
	
	Text text;
	
	// onCreateEngineOptions() 안에서는 Camera object를 초기화하고, EngineOptions을 생성 합니다.
	// 소스를 보시면 Camera와 EngineOptions을 생성했는데,
	// full screen을 가능하게 했고, landscape orientation을 고정 했습니다.
	// 그리고, FillResolutionPolicy를 정의 했습니다.
	// 엔진은 전체로 해상도를 가득 채울텐데, 가끔 화면에서 어긋날 수 있으므로 주의해야 합니다.
	@Override
	public EngineOptions onCreateEngineOptions() {
		camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
		EngineOptions engineOptions = new EngineOptions(true,
				ScreenOrientation.LANDSCAPE_FIXED, new FillResolutionPolicy(),
				camera);
		return engineOptions;
	}

	@Override
	protected void onCreateResources() {
		
		//기본 폰트의 선언
		this.mFont1 = FontFactory.create(this.getFontManager(),
				this.getTextureManager(), 256, 256,
				Typeface.create(Typeface.DEFAULT, Typeface.BOLD), 32);
		this.mFont1.load();

		FontFactory.setAssetBasePath("font/");
		this.mFont2 = FontFactory.createFromAsset(this.getFontManager(),
				this.getTextureManager(), 512, 512, TextureOptions.BILINEAR,
				this.getAssets(), "Droid.ttf", 28, true, Color.WHITE);
		this.mFont2.load();
		
		this.mFont3 = FontFactory.createFromAsset(this.getFontManager(),
				this.getTextureManager(), 512, 512, TextureOptions.BILINEAR,
				this.getAssets(), "KingdomOfHearts.ttf", 28, true, Color.WHITE);
		this.mFont3.load();
		
		this.mFont4 = FontFactory.createFromAsset(this.getFontManager(),
				this.getTextureManager(), 512, 512, TextureOptions.BILINEAR,
				this.getAssets(), "LCD.ttf", 28, true, Color.WHITE);
		this.mFont4.load();
		
		this.mFont5 = FontFactory.createFromAsset(this.getFontManager(),
				this.getTextureManager(), 512, 512, TextureOptions.BILINEAR,
				this.getAssets(), "NeverwinterNights.ttf", 28, true, Color.WHITE);
		this.mFont5.load();
		
		this.mFont6 = FontFactory.createFromAsset(this.getFontManager(),
				this.getTextureManager(), 512, 512, TextureOptions.BILINEAR,
				this.getAssets(), "UnrealTournament.ttf", 28, true, Color.WHITE);
		this.mFont6.load();
		
		this.mFont7 = FontFactory.createFromAsset(this.getFontManager(),
				this.getTextureManager(), 512, 512, TextureOptions.BILINEAR,
				this.getAssets(), "Plok.ttf", 28, true, Color.WHITE);
		this.mFont7.load();
		
	}

	// onCreateScene()에서는 화면에 관련된 scene object를 초기화 합니다.
	// Scene이란 스프라이트와 같은 새로운 객체를 덧붙일수 있는 객체(Entity)입니다.
	// 배경 화면은 파란색(blue)으로 셋팅 하였습니다.
	@Override
	protected Scene onCreateScene() {
		Scene scene = new Scene();
		scene.setBackground(new Background(0.09804f, 0.6274f, 0.8784f));
		
		final VertexBufferObjectManager vertexBufferObjectManager = this
				.getVertexBufferObjectManager();
		
		String content= "default : Finger Hurdle";
		int y=35;
		
		//기본폰트
		text = new Text(80, y, this.mFont1, content,
				content.length(), vertexBufferObjectManager);
		text.registerEntityModifier(new ScaleModifier(2, 0.0f, 1.0f));
		scene.attachChild(text);
		
		//
		y=y+35;
		content= "Droid.ttf : Finger Hurdle";
		text = new Text(80, y, this.mFont2, content,
				content.length(), vertexBufferObjectManager);
		scene.attachChild(text);
		
		//
		y=y+35;
		content= "KingdomOfHearts.ttf : Finger Hurdle";
		text = new Text(80, y, this.mFont3, content,
				content.length(), vertexBufferObjectManager);
		scene.attachChild(text);
		
		//
		y=y+35;
		content= "LCD.ttf : Finger Hurdle";
		text = new Text(80, y, this.mFont4, content,
				content.length(), vertexBufferObjectManager);
		scene.attachChild(text);
		
		//
		y=y+35;
		content= "LeverwinterNights.ttf : Finger Hurdle";
		text = new Text(80, y, this.mFont5, content,
				content.length(), vertexBufferObjectManager);
		scene.attachChild(text);
		
		//
		y=y+35;
		content= "UnrealTournament.ttf : Finger Hurdle";
		text = new Text(80, y, this.mFont6, content,
				content.length(), vertexBufferObjectManager);
		scene.attachChild(text);
		
		//
		y=y+35;
		content= "Plok.ttf : Finger Hurdle";
		text = new Text(80, y, this.mFont7, content,
				content.length(), vertexBufferObjectManager);
		scene.attachChild(text);
		return scene;
	}
}
