package eco.ui;

import eco.game.*;
import eco.render.Camera;
import eco.render.Render;
import eco.render.RenderUtil;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;

/**
 * This class handles keyboard and mouse input, passing it along to where ever
 * it needs to go
 *
 * @author phil, connor
 */

public class InputManager {

    private static final float moveSpeed = 0.1f;

    public static void update() {
        if (Keyboard.isKeyDown(Keyboard.KEY_R)) {
            Render.camera.yaw -= 0.5f;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_F)) {
            Render.camera.yaw += 0.5f;
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
            Render.camera.moveForward(moveSpeed);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
            Render.camera.moveRight(moveSpeed);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
            Render.camera.moveBack(moveSpeed);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
            Render.camera.moveLeft(moveSpeed);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)) {
            Render.camera.moveDown(moveSpeed);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
            Render.camera.moveUp(moveSpeed);
        }
        while (Keyboard.next()) {
            if (Keyboard.getEventKeyState()) {
                switch (Keyboard.getEventKey()) {
                    case Keyboard.KEY_Q:
                        Render.camera = new Camera(-World.mapsize / 2f
                                * Render.tilesize, -4f, World.mapsize / 2f
                                * Render.tilesize);
                        Log.info("Reset camera to default location");
                        break;
                    case Keyboard.KEY_H:
                    case Keyboard.KEY_GRAVE:
                        IGConsole.consoleLoop();
                        break;
                    case Keyboard.KEY_ESCAPE:
                        Main.paused ^= true;
                        if (Main.paused) {
                            ThreadManager.addJob(new SaveTask());
                        }
                        break;
                    case Keyboard.KEY_F10:
                        RenderUtil.takeScreenshot();
                        break;
                    case Keyboard.KEY_O:
                        Render.overhead ^= true;
                        break;
                }
            }
        }
        while (Mouse.next()) {
            if (Mouse.getEventButton() > -1) {
                if (Mouse.getEventButtonState()) {
                    UIManager.click(Mouse.getX(),
                            Display.getHeight() - Mouse.getY());
                }
            }
        }
    }

    public static void updateMenu() {
        while (Keyboard.next()) {
            if (Keyboard.getEventKeyState()) {
                switch (Keyboard.getEventKey()) {
                    case Keyboard.KEY_GRAVE:
                        IGConsole.consoleLoop();
                        break;
                    case Keyboard.KEY_F10:
                        RenderUtil.takeScreenshot();
                        break;
                }
            }
        }
        while (Mouse.next()) {
            if (Mouse.getEventButton() > -1) {
                if (Mouse.getEventButtonState()) {
                    UIManager.clickMenu(Mouse.getX(), Display.getHeight()
                            - Mouse.getY());
                }
            }
        }
    }

    public static void updatePause() {
        while (Keyboard.next()) {
            if (Keyboard.getEventKeyState()) {
                switch (Keyboard.getEventKey()) {
                    case Keyboard.KEY_F10:
                        RenderUtil.takeScreenshot();
                        break;
                    case Keyboard.KEY_ESCAPE:
                        Main.paused ^= true;
                        break;
                }
            }
        }
        while (Mouse.next()) {
            if (Mouse.getEventButton() > -1) {
                if (Mouse.getEventButtonState()) {
                    UIManager.clickPause(Mouse.getX(), Display.getHeight()
                            - Mouse.getY());
                }
            }
        }
    }

    public static void updateGameOver() {
        while (Keyboard.next()) {
            if (Keyboard.getEventKeyState()) {
                switch (Keyboard.getEventKey()) {
                    case Keyboard.KEY_F10:
                        RenderUtil.takeScreenshot();
                        break;
                }
            }
        }
        while (Mouse.next()) {
            if (Mouse.getEventButton() > -1) {
                if (Mouse.getEventButtonState()) {
                    UIManager.clickGameOver(Mouse.getX(), Display.getHeight()
                            - Mouse.getY());
                }
            }
        }
    }

    public static void updateConsole(){
        while (Keyboard.next()) {
            if (Keyboard.getEventKeyState()) {
                switch (Keyboard.getEventKey()) {
                    case Keyboard.KEY_GRAVE:
                        IGConsole.running = false;
                        break;
                    case Keyboard.KEY_BACK:
                    case Keyboard.KEY_DELETE:
                        if (IGConsole.buffer.length() != 0){
                            IGConsole.buffer = IGConsole.buffer.substring(0, IGConsole.buffer.length() - 1);
                        }
                        break;
                    case Keyboard.KEY_RETURN:
                        IGConsole.logCommand(IGConsole.buffer);
                        Command.onCommand(IGConsole.buffer);
                        IGConsole.buffer = "";
                        break;
                    case Keyboard.KEY_SPACE:
                        IGConsole.buffer += " ";
                        break;
                    case Keyboard.KEY_F10:
                        RenderUtil.takeScreenshot();
                        break;
                    case Keyboard.KEY_UP:
                        IGConsole.adjustCommandOffset(1);
                        break;
                    case Keyboard.KEY_DOWN:
                        IGConsole.adjustCommandOffset(-1);
                        break;
                    default:
                        String value = Keyboard.getKeyName(Keyboard.getEventKey());
                        if (value.length() == 1){
                            IGConsole.buffer += value;
                        }
                        break;
                }
            }
        }

        IGConsole.adjustOffset(Mouse.getDWheel() / 100);
    }

}

@@ -1814,17 +1814,21 @@
 ard.KEY_
-H
+GRAVE
 :%0A      
@@ -1851,37 +1851,35 @@
 se Keyboard.KEY_
-GRAVE
+TAB
 :%0A              
@@ -2990,32 +2990,75 @@
 oard.KEY_GRAVE:%0A
+                    case Keyboard.KEY_TAB:%0A
                 
@@ -5197,32 +5197,75 @@
 oard.KEY_GRAVE:%0A
+                    case Keyboard.KEY_TAB:%0A
                 

Update InputManager.java