/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package transientlibs.preui.gdx.game;
import com.badlogic.gdx.Application.ApplicationType;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import transientlibs.slick2d.util.Log;
import transientlibs.maps.units.GenericUnit;
import transientlibs.maps.units.Unit;
import transientlibs.maps.units.GDXUnit;
import transientlibs.objects.general.ModeList;
import transientlibs.objects.general.ModeSelector;
import transientlibs.objects.primitives.Char;
/**
*
* @author kibertoad
*/
public class TransientInput implements InputProcessor {
public ModeSelector modeSelector;
public ModeList modeList;
public boolean isMouseClicked = false;
public boolean processedMouseClick = false;
public boolean processedRMBClick = false;
public boolean pressedAnyKey;
public float storedDelta = 0.1f;
public Unit player;
public static final int UP = 0;
public static final int DOWN = 1;
public static final int LEFT = 2;
public static final int RIGHT = 3;
public static final int JUMP = 4;
public static final int SHOOT = 5;
public static final int ESCAPE = 6;
public static final int FULLSCREEN = 7;
public static final int QUIT = 8;
public static final int BACKSPACE = 9;
public static final int SHIFT = 10;
public static final int ENTER = 11;
public static final int DELETE = 12;
public static final int SPACE = 13;
public static final char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
public static final char[] numberlist = "0123456789".toCharArray();
public Char lastPressedLetter = new Char(' ', true);
public Char lastPressedNumber = new Char(' ', true);
public boolean[] numbers = new boolean[10];
public boolean RMBClicked = false;
public boolean[] letters = new boolean[26];
public boolean[] oldLetters = new boolean[26];
public boolean[] buttons = new boolean[64];
public boolean[] oldButtons = new boolean[64];
public boolean processedKeypress = false;
public static final int fullScreenSizeX = 1680;
public static final int fullScreenSizeY = 1050;
public void processExternal(TransientInput setInput) {
}
public TransientInput() {
modeList = new ModeList();
modeSelector = new ModeSelector(modeList);
modeList.add("map");
modeList.add("combat");
modeList.add("generic");
modeSelector.switchMode("generic");
}
public void process() {
if (isPressed(TransientInput.FULLSCREEN)) {
//if (buttons[TransientInput.FULLSCREEN]) {
//killCount++;
//if (Gdx.graphics.isFullscreen()) {
Gdx.graphics.setDisplayMode(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), !(Gdx.graphics.isFullscreen()));
//} else {
//Gdx.graphics.setDisplayMode(fullScreenSizeX, fullScreenSizeY, !(Gdx.graphics.isFullscreen()));
//}
Log.info("FULLSCREEN");
processedKeypress = true;
//if (killCount >= 3){
// System.exit(0);
//}
}
//if (isPressed(TransientInput.QUIT)) {
//if (buttons[TransientInput.QUIT]) {
if (isPressed(TransientInput.QUIT)) {
//killCount++;
processedKeypress = true;
exitGame();
//if (killCount >= 3){
// System.exit(0);
//}
}
}
public Char consumePressedLetter() {
if (!lastPressedLetter.isNull) {
lastPressedLetter.isNull = true;
return lastPressedLetter;
} else {
return null;
}
}
public Char consumePressedNumber() {
if (!lastPressedNumber.isNull) {
lastPressedNumber.isNull = true;
return lastPressedNumber;
} else {
return null;
}
}
public void set(int key, boolean down) {
pressedAnyKey = false;
//Log.info("SET: " + key);
int button = -1;
//if ((key == Keys.DPAD_UP) || (key == Keys.W)) {
if (key == Keys.UP) {
button = UP;
}
//if ((key == Keys.DPAD_LEFT) || (key == Keys.A)) {
if (key == Keys.LEFT) {
button = LEFT;
}
//if ((key == Keys.DPAD_DOWN) || (key == Keys.S)) {
if (key == Keys.DOWN) {
button = DOWN;
}
//if ((key == Keys.DPAD_RIGHT) || (key == Keys.D)) {
if (key == Keys.RIGHT) {
button = RIGHT;
}
if ((key == Keys.F12)) {
button = FULLSCREEN;
}
if (key == Keys.ESCAPE || key == Keys.MENU) {
button = ESCAPE;
}
if (key == Keys.F10) {
button = QUIT;
}
if (key == Keys.BACKSPACE) {
button = BACKSPACE;
}
if (key == Keys.ENTER) {
button = ENTER;
}
if (key == Keys.FORWARD_DEL) {
button = DELETE;
}
if (key == Keys.SPACE) {
button = SPACE;
}
if ((key == Keys.SHIFT_LEFT) || (key == Keys.SHIFT_RIGHT)) {
button = SHIFT;
}
if ((key >= 29) && (key <= 54)) {
letters[key - 29] = down;
lastPressedLetter.value = alphabet[key - 29];
lastPressedLetter.isNull = !down;
}
if ((key >= 7) && (key <= 16)) {
numbers[key - 7] = down;
lastPressedNumber.value = numberlist[key - 7];
lastPressedNumber.isNull = !down;
}
if (button >= 0) {
buttons[button] = down;
pressedAnyKey = down; //= true before
}
}
public void tick() {
System.arraycopy(buttons, 0, oldButtons, 0, buttons.length);
System.arraycopy(letters, 0, oldLetters, 0, letters.length);
//pressedAnyKey = false;
}
/**
* Use this only for preset game keys like Quit
*/
public boolean isPressed(int theKey) {
return (!oldButtons[theKey] && buttons[theKey]);
}
public boolean isRepeteadlyPressed(int theKey) {
return (buttons[theKey]);
//return (!oldButtons[theKey] && buttons[theKey]);
}
public void releaseAllKeys() {
for (int i = 0; i < buttons.length; i++) {
if (i == UP || i == DOWN) {
continue;
}
buttons[i] = false;
}
for (int i = 0; i < numbers.length; i++) {
numbers[i] = false;
}
for (int i = 0; i < letters.length; i++) {
letters[i] = false;
}
pressedAnyKey = false;
lastPressedLetter.isNull = true;
lastPressedNumber.isNull = true;
RMBClicked = false;
}
@Override
public boolean keyDown(int keycode) {
set(keycode, true);
return false;
}
@Override
public boolean keyUp(int keycode) {
set(keycode, false);
return false;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDown(int x, int y, int pointer, int button) {
return false;
}
@Override
public boolean touchUp(int x, int y, int pointer, int button) {
/*
x = (int) (x / (float) Gdx.graphics.getWidth() * 320);
if (x > 160 - 32 && x < 160) {
set(Keys.DPAD_UP, !buttons[UP]);
if (buttons[UP]) {
buttons[DOWN] = false;
}
}
if (x > 160 && x < 160 + 32) {
set(Keys.DPAD_DOWN, !buttons[DOWN]);
if (buttons[DOWN]) {
buttons[UP] = false;
}
}
System.out.println("buttons: " + buttons[UP] + ", " + buttons[DOWN]);
return false;
*/
return false;
}
@Override
public boolean touchDragged(int x, int y, int pointer) {
return false;
}
@Override
public boolean mouseMoved(int x, int y) {
return false;
}
@Override
public boolean scrolled(int amount) {
return false;
}
public static void exitGame() {
Gdx.app.exit();
}
public boolean mouseClicked() {
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) {
isMouseClicked = (!(processedMouseClick));
processedMouseClick = true;
return isMouseClicked;
} else {
if (processedMouseClick != false) {
processedMouseClick = false;
}
return false;
}
}
public boolean RightMouseClicked() {
if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT)) {
RMBClicked = (!(processedRMBClick));
processedRMBClick = true;
return RMBClicked;
} else {
if (processedRMBClick != false) {
processedRMBClick = false;
}
return false;
}
}
}