package holo.bolt.states;

import holo.bolt.BoltMain;

import org.newdawn.slick.Font;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.MouseOverArea;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.util.FontUtils;

public class HelpState extends BasicGameState
{
	public static final String[] line = new String[]{"You are an adventurer trapped within an expansive dungeon,", 
		"you have only your crossbow and a single bolt with you.",
		"&Use WASD or the arrow keys to move, right click to shoot.",
		"You must pick the bolt back up before shooting again.",
		"&There are two kinds of enemies in the dungeon, Melee and Ranged.",
		"Melee enemies will walk towards you, they will damage you on contact.",
		"&&&&Ranged enemies will attack you from a distance by shooting projectiles at you.",
		"Ranged enemies also take damage when they are in melee contact with you.",
		"&&&&There are two kinds of interactable tiles, they will give details in-game."};
	
	public Image melee1;
	public Image melee2;

	public Image ranged;

	public Image tile1;
	public Image tile2;
	
	public Image menu;
	public int menuX;
	public int menuY;
	public float menuScale;
	
	public float defaultScale;
	
	public StateBasedGame game;
	public GameContainer container;
	
	public MouseOverArea menuBox;
	@Override
	public void init(GameContainer gc, StateBasedGame game) throws SlickException
	{
		this.game = game;
		container = gc;
		
		defaultScale = gc.getHeight() / 480;
		
		melee1 = new Image("res/MeleeMob1.png");
		melee2 = new Image("res/MeleeMob2.png");
		ranged = new Image("res/RangedMob1.png");
		tile1 = new Image("res/HealingWell.png");
		tile2 = new Image("res/Ladder.png");
		
		menu = new Image("res/Menu.png").getScaledCopy(0.25F);
		menuX = gc.getWidth() - menu.getWidth();
		menuY = gc.getHeight() - menu.getHeight() * 3 / 2;
		menuScale = defaultScale;
		menuBox = new MouseOverArea(gc, menu, menuX - menu.getWidth() / 2, menuY - menu.getHeight() / 2);
	}

	@Override
	public void render(GameContainer gc, StateBasedGame game, Graphics g) throws SlickException
	{
		Font f = gc.getDefaultFont();
		
		int y = 0;
		for(String text : line)
		{
			while(text.charAt(0) == '&')
			{
				y += f.getLineHeight();
				text = text.substring(1);
			}
			FontUtils.drawCenter(f, text, gc.getWidth() / 2 - f.getWidth(text) / 2, y, f.getWidth(text));
			y += f.getLineHeight();
		}
		
		int meleeY = 8 * f.getLineHeight();
		int rangedY = meleeY + 6 * f.getLineHeight();
		int tileY = rangedY + 5 * f.getLineHeight();
		
		melee1.draw(gc.getWidth() / 3, meleeY + f.getLineHeight() * 2);
		melee2.draw(gc.getWidth() * 2 / 3, meleeY);
		
		ranged.draw(gc.getWidth() / 2, rangedY);
		
		tile1.draw(gc.getWidth() / 4, tileY);
		tile2.draw(gc.getWidth() / 2, tileY);
		
		menu.getScaledCopy(menuScale).drawCentered(menuX, menuY);
	}

	@Override
	public void update(GameContainer gc, StateBasedGame game, int delta) throws SlickException
	{
		if(menuBox.isMouseOver())
			menuScale = defaultScale * 1.05F;
		else
			menuScale = defaultScale;
	}

	@Override
	public int getID()
	{
		return BoltMain.HELP_ID;
	}
	
	public void mousePressed(int button, int x, int y) 
	{
		if(button == Input.MOUSE_LEFT_BUTTON)
		{
			if(menuBox.isMouseOver())
				game.enterState(BoltMain.MAIN_MENU_ID);
		}
	}
}
