package edu.smcm.gamedev.butterseal;

import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.Input;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;

/**
 * Contains program logic for the user interface.
 * 
 * This class handles such things as
 *   the pause menu,
 *   the directional pad,
 *   and power selection.
 * 
 * @author Sean
 *
 */
public class BSInterface {
    BSSession session;
    SpriteBatch batch;
    AssetManager assets;
    Map<Rectangle, BSGameStateActor> activeRegions;
    BSPlayer player;
	
    public BSInterface(BSSession session, SpriteBatch batch, AssetManager assets) {
        this.session = session;
        this.batch = batch;
        this.assets = assets;
        this.activeRegions = new HashMap<Rectangle, BSGameStateActor>();
		
        // test active region
        activeRegions.put(new Rectangle().set(0, 0, 100, 100), new BSGameStateActor() {
                @Override
                public void act(BSPlayer player) {
                    // TODO Auto-generated method stub
                    System.out.println("test");
                }
            });
    }
	
    /**
     * Polls the given {@link Input} for valid player interaction
     *   and handles it appropriately. 
     * @param input
     */
    public void poll(Input input) {
        for(Rectangle r : activeRegions.keySet()){
            if (isTouchingInside(input, r)){
                activeRegions.get(r).act(player);
            }
        }
    }
	
    /**
     * 
     * @param input
     * @param region
     * @return true if input is being touched within the given region, false otherwise
     */
    public boolean isTouchingInside(Input input, Rectangle region) {
        int x = input.getX();
        int y = input.getY();
        return region.x < x && x < region.width
            && region.y < y && y < region.height;
    }
	
    /**
     * Draws the interface on the screen.
     */
    public void draw() {
        /* If the game is in session, make the major interface elements.
         * If the game is additionally paused, handle that as well.
         * 
         * If we are not in a game, then draw the title screen.
         */
		
        if (session.isInGame) {
            MakePowerBar();
            MakePowerSelector();
            MakeDirectionalPad();
            MakePauseButton();
            session.state.currentMap.draw();
            if (session.isPaused) {
                MakePauseScreen();
            }
        } else {
            MakeTitleScreen();
        }
    }

    private void MakePowerBar() {
		
    }
	
    private void MakePowerSelector() {
		
    }
	
    private void MakeDirectionalPad() {
		
    }
	
    /**
     * Dims the screen and displays the pause menu
     */
    private void MakePauseButton() {
		
    }
	
    private void MakePauseScreen() {
		
    }
	
    private void MakeTitleScreen() {
        //batch.draw(region, x, y, originX, originY, width, height, scaleX, scaleY, rotation)
    }
}

// Local Variables:
// indent-tabs-mode: nil
// End:

@@ -1317,18 +1317,17 @@
 riately.
- 
 %0A
+
      * @
@@ -1378,24 +1378,54 @@
 ut input) %7B%0A
+        pollKeyboard(input);%0A%0A
         for(
@@ -1584,26 +1584,671 @@
     %7D%0A    %7D%0A
-
 %09%0A
+    /**%0A     * Poll the keyboard for input.%0A     * @param input an input stream to analyze%0A     */%0A    private void pollKeyboard(Input input) %7B%0A        BSDirection toMove;%0A        if(input.isKeyPressed(Input.Keys.RIGHT)) %7B%0A            toMove = BSDirection.EAST;%0A        %7D else if(input.isKeyPressed(Input.Keys.UP)) %7B%0A            toMove = BSDirection.NORTH;%0A        %7D else if(input.isKeyPressed(Input.Keys.LEFT)) %7B%0A            toMove = BSDirection.WEST;%0A        %7D else if(input.isKeyPressed(Input.Keys.DOWN)) %7B%0A            toMove = BSDirection.SOUTH;%0A        %7D else %7B%0A            toMove = null;%0A        %7D%0A        this.player.move(toMove);%0A    %7D%0A%0A
     /**%0A    

Add keyboard interaction to interface