diff --git a/build.xml b/build.xml
index e4cba990..42957227 100644
--- a/build.xml
+++ b/build.xml
@@ -131,6 +131,9 @@ then run (code is compiled automatically when you run)
+
+
+
diff --git a/pom.xml b/pom.xml
index bdc9cc69..7b134de6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -125,6 +125,9 @@
org/newdawn/slick/Music.*
org/newdawn/slick/Input.*
org/newdawn/slick/Input$NullOutputStream.*
+ org/newdawn/slick/MouseListener.*
+ org/newdawn/slick/KeyListener.*
+ org/newdawn/slick/InputListener.*
org/newdawn/slick/gui/TextField.*
org/newdawn/slick/openal/AudioInputStream*
org/newdawn/slick/openal/OpenALStreamPlayer*
diff --git a/src/itdelatrisu/opsu/states/DownloadsMenu.java b/src/itdelatrisu/opsu/states/DownloadsMenu.java
index 35ae4699..c9936a57 100644
--- a/src/itdelatrisu/opsu/states/DownloadsMenu.java
+++ b/src/itdelatrisu/opsu/states/DownloadsMenu.java
@@ -306,7 +306,7 @@ public class DownloadsMenu extends ComplexOpsuState {
// search
searchTimer = SEARCH_DELAY;
searchResultString = "Loading data from server...";
- search = new TextField(displayContainer, Fonts.DEFAULT, baseX, searchY, searchWidth, Fonts.MEDIUM.getLineHeight()) {
+ search = new TextField(Fonts.DEFAULT, baseX, searchY, searchWidth, Fonts.MEDIUM.getLineHeight()) {
@Override
public boolean isFocusable() {
return false;
diff --git a/src/itdelatrisu/opsu/states/Game.java b/src/itdelatrisu/opsu/states/Game.java
index 9a16527a..1b242daf 100644
--- a/src/itdelatrisu/opsu/states/Game.java
+++ b/src/itdelatrisu/opsu/states/Game.java
@@ -1150,7 +1150,7 @@ public class Game extends ComplexOpsuState {
break;
case Input.KEY_R:
// restart
- if (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) {
+ if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
if (trackPosition < beatmap.objects[0].getTime()) {
retries--; // don't count this retry (cancel out later increment)
}
@@ -1161,7 +1161,7 @@ public class Game extends ComplexOpsuState {
break;
case Input.KEY_S:
// save checkpoint
- if (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) {
+ if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
if (isLeadIn()) {
break;
}
@@ -1177,7 +1177,7 @@ public class Game extends ComplexOpsuState {
break;
case Input.KEY_L:
// load checkpoint
- if (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) {
+ if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
int checkpoint = OPTION_CHECKPOINT.val * 1000;
if (checkpoint == 0 || checkpoint > beatmap.endTime)
break; // invalid checkpoint
@@ -1396,7 +1396,7 @@ public class Game extends ComplexOpsuState {
keys = ReplayFrame.KEY_K2;
}
if (keys != ReplayFrame.KEY_NONE) {
- gameKeyReleased(keys, displayContainer.input.getMouseX(), displayContainer.input.getMouseY(), MusicController.getPosition());
+ gameKeyReleased(keys, input.getMouseX(), input.getMouseY(), MusicController.getPosition());
}
return true;
diff --git a/src/itdelatrisu/opsu/states/GamePauseMenu.java b/src/itdelatrisu/opsu/states/GamePauseMenu.java
index 2210c463..f1c4ff15 100644
--- a/src/itdelatrisu/opsu/states/GamePauseMenu.java
+++ b/src/itdelatrisu/opsu/states/GamePauseMenu.java
@@ -109,7 +109,7 @@ public class GamePauseMenu extends BaseOpsuState {
return true;
}
- if (key == Input.KEY_R && (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL))) {
+ if (key == Input.KEY_R && (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL))) {
gameState.setRestart(Game.Restart.MANUAL);
displayContainer.switchState(gameState);
return true;
diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java
index eca10ebe..07276496 100644
--- a/src/itdelatrisu/opsu/states/SongMenu.java
+++ b/src/itdelatrisu/opsu/states/SongMenu.java
@@ -389,7 +389,7 @@ public class SongMenu extends ComplexOpsuState {
// search
int textFieldX = (int) (displayContainer.width * 0.7125f + Fonts.BOLD.getWidth("Search: "));
int textFieldY = (int) (headerY + Fonts.BOLD.getLineHeight() / 2);
- searchTextField = new TextField(displayContainer, Fonts.BOLD, textFieldX, textFieldY, (int) (displayContainer.width * 0.99f) - textFieldX, Fonts.BOLD.getLineHeight()) {
+ searchTextField = new TextField(Fonts.BOLD, textFieldX, textFieldY, (int) (displayContainer.width * 0.99f) - textFieldX, Fonts.BOLD.getLineHeight()) {
@Override
public boolean isFocusable() {
return false;
@@ -1042,8 +1042,6 @@ public class SongMenu extends ComplexOpsuState {
return true;
}
- Input input = displayContainer.input;
-
switch (key) {
case Input.KEY_ESCAPE:
if (reloadThread != null) {
@@ -1204,9 +1202,9 @@ public class SongMenu extends ComplexOpsuState {
// check mouse button (right click scrolls faster on songs)
int multiplier;
- if (displayContainer.input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
+ if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) {
multiplier = 10;
- } else if (displayContainer.input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
+ } else if (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)) {
multiplier = 1;
} else {
return false;
@@ -1226,8 +1224,6 @@ public class SongMenu extends ComplexOpsuState {
return true;
}
- Input input = displayContainer.input;
-
if (isInputBlocked()) {
return true;
}
@@ -1768,7 +1764,7 @@ public class SongMenu extends ComplexOpsuState {
}
// turn on "auto" mod if holding "ctrl" key
- if (displayContainer.input.isKeyDown(Input.KEY_RCONTROL) || displayContainer.input.isKeyDown(Input.KEY_LCONTROL)) {
+ if (input.isKeyDown(Input.KEY_RCONTROL) || input.isKeyDown(Input.KEY_LCONTROL)) {
if (!GameMod.AUTO.isActive())
GameMod.AUTO.toggle(true);
}
diff --git a/src/org/newdawn/slick/Input.java b/src/org/newdawn/slick/Input.java
index 64ece8de..326152ec 100644
--- a/src/org/newdawn/slick/Input.java
+++ b/src/org/newdawn/slick/Input.java
@@ -28,281 +28,145 @@
package org.newdawn.slick;
-import java.io.IOException;
-import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
-import java.util.Iterator;
-import org.lwjgl.LWJGLException;
-import org.lwjgl.input.Controller;
-import org.lwjgl.input.Controllers;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
-import org.newdawn.slick.util.Log;
/**
* A wrapped for all keyboard, mouse and controller input
+ * Edited for opsu!
*
* @author kevin
*/
@SuppressWarnings({"rawtypes", "unchecked", "unused"})
public class Input {
- /** The controller index to pass to check all controllers */
- public static final int ANY_CONTROLLER = -1;
-
- /** The maximum number of buttons on controllers */
- private static final int MAX_BUTTONS = 100;
-
- /** */
+
public static final int KEY_ESCAPE = 0x01;
- /** */
public static final int KEY_1 = 0x02;
- /** */
public static final int KEY_2 = 0x03;
- /** */
public static final int KEY_3 = 0x04;
- /** */
public static final int KEY_4 = 0x05;
- /** */
public static final int KEY_5 = 0x06;
- /** */
public static final int KEY_6 = 0x07;
- /** */
public static final int KEY_7 = 0x08;
- /** */
public static final int KEY_8 = 0x09;
- /** */
public static final int KEY_9 = 0x0A;
- /** */
public static final int KEY_0 = 0x0B;
- /** */
public static final int KEY_MINUS = 0x0C; /* - on main keyboard */
- /** */
public static final int KEY_EQUALS = 0x0D;
- /** */
public static final int KEY_BACK = 0x0E; /* backspace */
- /** */
public static final int KEY_TAB = 0x0F;
- /** */
public static final int KEY_Q = 0x10;
- /** */
public static final int KEY_W = 0x11;
- /** */
public static final int KEY_E = 0x12;
- /** */
public static final int KEY_R = 0x13;
- /** */
public static final int KEY_T = 0x14;
- /** */
public static final int KEY_Y = 0x15;
- /** */
public static final int KEY_U = 0x16;
- /** */
public static final int KEY_I = 0x17;
- /** */
public static final int KEY_O = 0x18;
- /** */
public static final int KEY_P = 0x19;
- /** */
public static final int KEY_LBRACKET = 0x1A;
- /** */
public static final int KEY_RBRACKET = 0x1B;
- /** */
public static final int KEY_RETURN = 0x1C; /* Enter on main keyboard */
- /** */
public static final int KEY_ENTER = 0x1C; /* Enter on main keyboard */
- /** */
public static final int KEY_LCONTROL = 0x1D;
- /** */
public static final int KEY_A = 0x1E;
- /** */
public static final int KEY_S = 0x1F;
- /** */
public static final int KEY_D = 0x20;
- /** */
public static final int KEY_F = 0x21;
- /** */
public static final int KEY_G = 0x22;
- /** */
public static final int KEY_H = 0x23;
- /** */
public static final int KEY_J = 0x24;
- /** */
public static final int KEY_K = 0x25;
- /** */
public static final int KEY_L = 0x26;
- /** */
public static final int KEY_SEMICOLON = 0x27;
- /** */
public static final int KEY_APOSTROPHE = 0x28;
- /** */
public static final int KEY_GRAVE = 0x29; /* accent grave */
- /** */
public static final int KEY_LSHIFT = 0x2A;
- /** */
public static final int KEY_BACKSLASH = 0x2B;
- /** */
public static final int KEY_Z = 0x2C;
- /** */
public static final int KEY_X = 0x2D;
- /** */
public static final int KEY_C = 0x2E;
- /** */
public static final int KEY_V = 0x2F;
- /** */
public static final int KEY_B = 0x30;
- /** */
public static final int KEY_N = 0x31;
- /** */
public static final int KEY_M = 0x32;
- /** */
public static final int KEY_COMMA = 0x33;
- /** */
public static final int KEY_PERIOD = 0x34; /* . on main keyboard */
- /** */
public static final int KEY_SLASH = 0x35; /* / on main keyboard */
- /** */
public static final int KEY_RSHIFT = 0x36;
- /** */
public static final int KEY_MULTIPLY = 0x37; /* * on numeric keypad */
- /** */
public static final int KEY_LMENU = 0x38; /* left Alt */
- /** */
public static final int KEY_SPACE = 0x39;
- /** */
public static final int KEY_CAPITAL = 0x3A;
- /** */
public static final int KEY_F1 = 0x3B;
- /** */
public static final int KEY_F2 = 0x3C;
- /** */
public static final int KEY_F3 = 0x3D;
- /** */
public static final int KEY_F4 = 0x3E;
- /** */
public static final int KEY_F5 = 0x3F;
- /** */
public static final int KEY_F6 = 0x40;
- /** */
public static final int KEY_F7 = 0x41;
- /** */
public static final int KEY_F8 = 0x42;
- /** */
public static final int KEY_F9 = 0x43;
- /** */
public static final int KEY_F10 = 0x44;
- /** */
public static final int KEY_NUMLOCK = 0x45;
- /** */
public static final int KEY_SCROLL = 0x46; /* Scroll Lock */
- /** */
public static final int KEY_NUMPAD7 = 0x47;
- /** */
public static final int KEY_NUMPAD8 = 0x48;
- /** */
public static final int KEY_NUMPAD9 = 0x49;
- /** */
public static final int KEY_SUBTRACT = 0x4A; /* - on numeric keypad */
- /** */
public static final int KEY_NUMPAD4 = 0x4B;
- /** */
public static final int KEY_NUMPAD5 = 0x4C;
- /** */
public static final int KEY_NUMPAD6 = 0x4D;
- /** */
public static final int KEY_ADD = 0x4E; /* + on numeric keypad */
- /** */
public static final int KEY_NUMPAD1 = 0x4F;
- /** */
public static final int KEY_NUMPAD2 = 0x50;
- /** */
public static final int KEY_NUMPAD3 = 0x51;
- /** */
public static final int KEY_NUMPAD0 = 0x52;
- /** */
public static final int KEY_DECIMAL = 0x53; /* . on numeric keypad */
- /** */
public static final int KEY_F11 = 0x57;
- /** */
public static final int KEY_F12 = 0x58;
- /** */
public static final int KEY_F13 = 0x64; /* (NEC PC98) */
- /** */
public static final int KEY_F14 = 0x65; /* (NEC PC98) */
- /** */
public static final int KEY_F15 = 0x66; /* (NEC PC98) */
- /** */
public static final int KEY_KANA = 0x70; /* (Japanese keyboard) */
- /** */
public static final int KEY_CONVERT = 0x79; /* (Japanese keyboard) */
- /** */
public static final int KEY_NOCONVERT = 0x7B; /* (Japanese keyboard) */
- /** */
public static final int KEY_YEN = 0x7D; /* (Japanese keyboard) */
- /** */
public static final int KEY_NUMPADEQUALS = 0x8D; /* = on numeric keypad (NEC PC98) */
- /** */
public static final int KEY_CIRCUMFLEX = 0x90; /* (Japanese keyboard) */
- /** */
public static final int KEY_AT = 0x91; /* (NEC PC98) */
- /** */
public static final int KEY_COLON = 0x92; /* (NEC PC98) */
- /** */
public static final int KEY_UNDERLINE = 0x93; /* (NEC PC98) */
- /** */
public static final int KEY_KANJI = 0x94; /* (Japanese keyboard) */
- /** */
public static final int KEY_STOP = 0x95; /* (NEC PC98) */
- /** */
public static final int KEY_AX = 0x96; /* (Japan AX) */
- /** */
public static final int KEY_UNLABELED = 0x97; /* (J3100) */
- /** */
public static final int KEY_NUMPADENTER = 0x9C; /* Enter on numeric keypad */
- /** */
public static final int KEY_RCONTROL = 0x9D;
- /** */
public static final int KEY_NUMPADCOMMA = 0xB3; /* , on numeric keypad (NEC PC98) */
- /** */
public static final int KEY_DIVIDE = 0xB5; /* / on numeric keypad */
- /** */
public static final int KEY_SYSRQ = 0xB7;
- /** */
public static final int KEY_RMENU = 0xB8; /* right Alt */
- /** */
public static final int KEY_PAUSE = 0xC5; /* Pause */
- /** */
public static final int KEY_HOME = 0xC7; /* Home on arrow keypad */
- /** */
public static final int KEY_UP = 0xC8; /* UpArrow on arrow keypad */
- /** */
public static final int KEY_PRIOR = 0xC9; /* PgUp on arrow keypad */
- /** */
public static final int KEY_LEFT = 0xCB; /* LeftArrow on arrow keypad */
- /** */
public static final int KEY_RIGHT = 0xCD; /* RightArrow on arrow keypad */
- /** */
public static final int KEY_END = 0xCF; /* End on arrow keypad */
- /** */
public static final int KEY_DOWN = 0xD0; /* DownArrow on arrow keypad */
- /** */
public static final int KEY_NEXT = 0xD1; /* PgDn on arrow keypad */
- /** */
public static final int KEY_INSERT = 0xD2; /* Insert on arrow keypad */
- /** */
public static final int KEY_DELETE = 0xD3; /* Delete on arrow keypad */
- /** */
public static final int KEY_LWIN = 0xDB; /* Left Windows key */
- /** */
public static final int KEY_RWIN = 0xDC; /* Right Windows key */
- /** */
public static final int KEY_APPS = 0xDD; /* AppMenu key */
- /** */
public static final int KEY_POWER = 0xDE;
- /** */
public static final int KEY_SLEEP = 0xDF;
/** A helper for left ALT */
@@ -346,20 +210,13 @@ public class Input {
/** The middle mouse button indicator */
public static final int MOUSE_MIDDLE_BUTTON = 2;
- /** True if the controllers system has been initialised */
- private static boolean controllersInited = false;
- /** The list of controllers */
- private static ArrayList controllers = new ArrayList();
-
/** The last recorded mouse x position */
private int lastMouseX;
/** The last recorded mouse y position */
private int lastMouseY;
/** THe state of the mouse buttons */
protected boolean[] mousePressed = new boolean[10];
- /** THe state of the controller buttons */
- private boolean[][] controllerPressed = new boolean[100][MAX_BUTTONS];
-
+
/** The character values representing the pressed keys */
protected char[] keys = new char[1024];
/** True if the key has been pressed since last queries */
@@ -367,22 +224,10 @@ public class Input {
/** The time since the next key repeat to be fired for the key */
protected long[] nextRepeat = new long[1024];
- /** The control states from the controllers */
- private boolean[][] controls = new boolean[10][MAX_BUTTONS+10];
- /** True if the event has been consumed */
- protected boolean consumed = false;
- /** A list of listeners to be notified of input events */
- protected HashSet allListeners = new HashSet();
/** The listeners to notify of key events */
- protected ArrayList keyListeners = new ArrayList();
+ protected ArrayList keyListeners = new ArrayList<>();
/** The listener to add */
- protected ArrayList keyListenersToAdd = new ArrayList();
- /** The listeners to notify of mouse events */
- protected ArrayList mouseListeners = new ArrayList();
- /** The listener to add */
- protected ArrayList mouseListenersToAdd = new ArrayList();
- /** The listener to nofiy of controller events */
- protected ArrayList controllerListeners = new ArrayList();
+ protected ArrayList mouseListeners = new ArrayList<>();
/** The current value of the wheel */
private int wheel;
/** The height of the display */
@@ -398,46 +243,9 @@ public class Input {
/** The interval of key repeat */
private int keyRepeatInterval;
- /** True if the input is currently paused */
- private boolean paused;
- /** The scale to apply to screen coordinates */
- private float scaleX = 1;
- /** The scale to apply to screen coordinates */
- private float scaleY = 1;
- /** The offset to apply to screen coordinates */
- private float xoffset = 0;
- /** The offset to apply to screen coordinates */
- private float yoffset = 0;
-
- /** The delay before determining a single or double click */
- private int doubleClickDelay = 250;
- /** The timer running out for a single click */
- private long doubleClickTimeout = 0;
-
- /** The clicked x position */
- private int clickX;
- /** The clicked y position */
- private int clickY;
/** The clicked button */
private int clickButton;
- /** The x position location the mouse was pressed */
- private int pressedX = -1;
-
- /** The x position location the mouse was pressed */
- private int pressedY = -1;
-
- /** The pixel distance the mouse can move to accept a mouse click */
- private int mouseClickTolerance = 5;
-
- /**
- * Disables support for controllers. This means the jinput JAR and native libs
- * are not required.
- */
- public static void disableControllers() {
- controllersInited = true;
- }
-
/**
* Create a new input with the height of the screen
*
@@ -446,58 +254,7 @@ public class Input {
public Input(int height) {
init(height);
}
-
- /**
- * Set the double click interval, the time between the first
- * and second clicks that should be interpreted as a
- * double click.
- *
- * @param delay The delay between clicks
- */
- public void setDoubleClickInterval(int delay) {
- doubleClickDelay = delay;
- }
- /**
- * Set the pixel distance the mouse can move to accept a mouse click.
- * Default is 5.
- *
- * @param mouseClickTolerance The number of pixels.
- */
- public void setMouseClickTolerance (int mouseClickTolerance) {
- this.mouseClickTolerance = mouseClickTolerance;
- }
-
- /**
- * Set the scaling to apply to screen coordinates
- *
- * @param scaleX The scaling to apply to the horizontal axis
- * @param scaleY The scaling to apply to the vertical axis
- */
- public void setScale(float scaleX, float scaleY) {
- this.scaleX = scaleX;
- this.scaleY = scaleY;
- }
-
- /**
- * Set the offset to apply to the screen coodinates
- *
- * @param xoffset The offset on the x-axis
- * @param yoffset The offset on the y-axis
- */
- public void setOffset(float xoffset, float yoffset) {
- this.xoffset = xoffset;
- this.yoffset = yoffset;
- }
-
- /**
- * Reset the transformation being applied to the input to the default
- */
- public void resetInputTransform() {
- setOffset(0, 0);
- setScale(1, 1);
- }
-
/**
* Add a listener to be notified of input events
*
@@ -506,7 +263,6 @@ public class Input {
public void addListener(InputListener listener) {
addKeyListener(listener);
addMouseListener(listener);
- addControllerListener(listener);
}
/**
@@ -515,55 +271,16 @@ public class Input {
* @param listener The listener to be notified
*/
public void addKeyListener(KeyListener listener) {
- keyListenersToAdd.add(listener);
+ keyListeners.add(listener);
}
- /**
- * Add a key listener to be notified of key input events
- *
- * @param listener The listener to be notified
- */
- private void addKeyListenerImpl(KeyListener listener) {
- if (keyListeners.contains(listener)) {
- return;
- }
- keyListeners.add(listener);
- allListeners.add(listener);
- }
-
/**
* Add a mouse listener to be notified of mouse input events
*
* @param listener The listener to be notified
*/
public void addMouseListener(MouseListener listener) {
- mouseListenersToAdd.add(listener);
- }
-
- /**
- * Add a mouse listener to be notified of mouse input events
- *
- * @param listener The listener to be notified
- */
- private void addMouseListenerImpl(MouseListener listener) {
- if (mouseListeners.contains(listener)) {
- return;
- }
mouseListeners.add(listener);
- allListeners.add(listener);
- }
-
- /**
- * Add a controller listener to be notified of controller input events
- *
- * @param listener The listener to be notified
- */
- public void addControllerListener(ControllerListener listener) {
- if (controllerListeners.contains(listener)) {
- return;
- }
- controllerListeners.add(listener);
- allListeners.add(listener);
}
/**
@@ -572,14 +289,12 @@ public class Input {
public void removeAllListeners() {
removeAllKeyListeners();
removeAllMouseListeners();
- removeAllControllerListeners();
}
/**
* Remove all the key listeners from this input
*/
public void removeAllKeyListeners() {
- allListeners.removeAll(keyListeners);
keyListeners.clear();
}
@@ -587,18 +302,9 @@ public class Input {
* Remove all the mouse listeners from this input
*/
public void removeAllMouseListeners() {
- allListeners.removeAll(mouseListeners);
mouseListeners.clear();
}
- /**
- * Remove all the controller listeners from this input
- */
- public void removeAllControllerListeners() {
- allListeners.removeAll(controllerListeners);
- controllerListeners.clear();
- }
-
/**
* Add a listener to be notified of input events. This listener
* will get events before others that are currently registered
@@ -610,9 +316,6 @@ public class Input {
keyListeners.add(0, listener);
mouseListeners.add(0, listener);
- controllerListeners.add(0, listener);
-
- allListeners.add(listener);
}
/**
@@ -623,7 +326,6 @@ public class Input {
public void removeListener(InputListener listener) {
removeKeyListener(listener);
removeMouseListener(listener);
- removeControllerListener(listener);
}
/**
@@ -633,23 +335,6 @@ public class Input {
*/
public void removeKeyListener(KeyListener listener) {
keyListeners.remove(listener);
-
- if (!mouseListeners.contains(listener) && !controllerListeners.contains(listener)) {
- allListeners.remove(listener);
- }
- }
-
- /**
- * Remove a controller listener that will no longer be notified
- *
- * @param listener The listen to be removed
- */
- public void removeControllerListener(ControllerListener listener) {
- controllerListeners.remove(listener);
-
- if (!mouseListeners.contains(listener) && !keyListeners.contains(listener)) {
- allListeners.remove(listener);
- }
}
/**
@@ -659,10 +344,6 @@ public class Input {
*/
public void removeMouseListener(MouseListener listener) {
mouseListeners.remove(listener);
-
- if (!controllerListeners.contains(listener) && !keyListeners.contains(listener)) {
- allListeners.remove(listener);
- }
}
/**
@@ -716,45 +397,7 @@ public class Input {
return false;
}
-
- /**
- * Check if a controller button has been pressed since last
- * time
- *
- * @param button The button to check for (note that this includes directional controls first)
- * @return True if the button has been pressed since last time
- */
- public boolean isControlPressed(int button) {
- return isControlPressed(button, 0);
- }
- /**
- * Check if a controller button has been pressed since last
- * time
- *
- * @param controller The index of the controller to check
- * @param button The button to check for (note that this includes directional controls first)
- * @return True if the button has been pressed since last time
- */
- public boolean isControlPressed(int button, int controller) {
- if (controllerPressed[controller][button]) {
- controllerPressed[controller][button] = false;
- return true;
- }
-
- return false;
- }
-
- /**
- * Clear the state for isControlPressed method. This will reset all
- * controls to not pressed
- */
- public void clearControlPressedRecord() {
- for (int i=0;iisKeyPressed method. This will
* resort in all keys returning that they haven't been pressed, until
@@ -783,31 +426,13 @@ public class Input {
return Keyboard.isKeyDown(code);
}
- /**
- * Get the absolute x position of the mouse cursor within the container
- *
- * @return The absolute x position of the mouse cursor
- */
- public int getAbsoluteMouseX() {
- return Mouse.getX();
- }
-
- /**
- * Get the absolute y position of the mouse cursor within the container
- *
- * @return The absolute y position of the mouse cursor
- */
- public int getAbsoluteMouseY() {
- return height - Mouse.getY();
- }
-
/**
* Get the x position of the mouse cursor
*
* @return The x position of the mouse cursor
*/
public int getMouseX() {
- return (int) ((Mouse.getX() * scaleX)+xoffset);
+ return Mouse.getX();
}
/**
@@ -816,7 +441,7 @@ public class Input {
* @return The y position of the mouse cursor
*/
public int getMouseY() {
- return (int) (((height-Mouse.getY()) * scaleY)+yoffset);
+ return height - Mouse.getY();
}
/**
@@ -843,312 +468,7 @@ public class Input {
return false;
}
-
- /**
- * Get a count of the number of controlles available
- *
- * @return The number of controllers available
- */
- public int getControllerCount() {
- try {
- initControllers();
- } catch (SlickException e) {
- throw new RuntimeException("Failed to initialise controllers");
- }
-
- return controllers.size();
- }
-
- /**
- * Get the number of axis that are avaiable on a given controller
- *
- * @param controller The index of the controller to check
- * @return The number of axis available on the controller
- */
- public int getAxisCount(int controller) {
- return ((Controller) controllers.get(controller)).getAxisCount();
- }
-
- /**
- * Get the value of the axis with the given index
- *
- * @param controller The index of the controller to check
- * @param axis The index of the axis to read
- * @return The axis value at time of reading
- */
- public float getAxisValue(int controller, int axis) {
- return ((Controller) controllers.get(controller)).getAxisValue(axis);
- }
- /**
- * Get the name of the axis with the given index
- *
- * @param controller The index of the controller to check
- * @param axis The index of the axis to read
- * @return The name of the specified axis
- */
- public String getAxisName(int controller, int axis) {
- return ((Controller) controllers.get(controller)).getAxisName(axis);
- }
-
- /**
- * Check if the controller has the left direction pressed
- *
- * @param controller The index of the controller to check
- * @return True if the controller is pressed to the left
- */
- public boolean isControllerLeft(int controller) {
- if (controller >= getControllerCount()) {
- return false;
- }
-
- if (controller == ANY_CONTROLLER) {
- for (int i=0;i= getControllerCount()) {
- return false;
- }
-
- if (controller == ANY_CONTROLLER) {
- for (int i=0;i 0.5f
- || ((Controller) controllers.get(controller)).getPovX() > 0.5f;
- }
-
- /**
- * Check if the controller has the up direction pressed
- *
- * @param controller The index of the controller to check
- * @return True if the controller is pressed to the up
- */
- public boolean isControllerUp(int controller) {
- if (controller >= getControllerCount()) {
- return false;
- }
-
- if (controller == ANY_CONTROLLER) {
- for (int i=0;i= getControllerCount()) {
- return false;
- }
-
- if (controller == ANY_CONTROLLER) {
- for (int i=0;i 0.5f
- || ((Controller) controllers.get(controller)).getPovY() > 0.5f;
-
- }
-
- /**
- * Check if controller button is pressed
- *
- * @param controller The index of the controller to check
- * @param index The index of the button to check
- * @return True if the button is pressed
- */
- public boolean isButtonPressed(int index, int controller) {
- if (controller >= getControllerCount()) {
- return false;
- }
-
- if (controller == ANY_CONTROLLER) {
- for (int i=0;i= 3) && (controller.getButtonCount() < MAX_BUTTONS)) {
- controllers.add(controller);
- }
- }
-
- Log.info("Found "+controllers.size()+" controllers");
- for (int i=0;i doubleClickTimeout) {
- doubleClickTimeout = 0;
- }
- }
-
this.height = height;
- Iterator allStarts = allListeners.iterator();
- while (allStarts.hasNext()) {
- ControlledInputReciever listener = (ControlledInputReciever) allStarts.next();
- listener.inputStarted();
- }
-
while (Keyboard.next()) {
if (Keyboard.getEventKeyState()) {
- int eventKey = resolveEventKey(Keyboard.getEventKey(), Keyboard.getEventCharacter());
-
+ int eventKey = Keyboard.getEventKey();
+
keys[eventKey] = Keyboard.getEventCharacter();
pressed[eventKey] = true;
nextRepeat[eventKey] = System.currentTimeMillis() + keyRepeatInitial;
- consumed = false;
- for (int i=0;i= 0 && Mouse.getEventButton() < mousePressed.length) {
if (Mouse.getEventButtonState()) {
- consumed = false;
mousePressed[Mouse.getEventButton()] = true;
- pressedX = (int) (xoffset + (Mouse.getEventX() * scaleX));
- pressedY = (int) (yoffset + ((height-Mouse.getEventY()) * scaleY));
- lastMouseX = pressedX;
- lastMouseY = pressedY;
+ lastMouseX = Mouse.getEventX();
+ lastMouseY = height - Mouse.getEventY();
- for (int i=0;i nextRepeat[i]) {
nextRepeat[i] = System.currentTimeMillis() + keyRepeatInterval;
- consumed = false;
- for (int j=0;j= BUTTON1) {
- return isButtonPressed((index-BUTTON1), controllerIndex);
- }
-
- throw new RuntimeException("Unknown control index");
- }
-
-
- /**
- * Pauses the polling and sending of input events.
- */
- public void pause() {
- paused = true;
-
- // Reset all polling arrays
- clearKeyPressedRecord();
- clearMousePressedRecord();
- clearControlPressedRecord();
- }
-
- /**
- * Resumes the polling and sending of input events.
- */
- public void resume() {
- paused = false;
- }
-
- /**
- * Notify listeners that the mouse button has been clicked
- *
- * @param button The button that has been clicked
- * @param x The location at which the button was clicked
- * @param y The location at which the button was clicked
- * @param clickCount The number of times the button was clicked (single or double click)
- */
- private void fireMouseClicked(int button, int x, int y, int clickCount) {
- consumed = false;
- for (int i=0;i 0) && (value.length() > 0)) {
- if (displayContainer.input.isKeyDown(Input.KEY_LCONTROL) || displayContainer.input.isKeyDown(Input.KEY_RCONTROL)) {
+ if (input.isKeyDown(Input.KEY_LCONTROL) || input.isKeyDown(Input.KEY_RCONTROL)) {
int sp = 0;
boolean startSpace = Character.isWhitespace(value.charAt(cursorPos - 1));
boolean charSeen = false;
diff --git a/src/yugecin/opsudance/core/DisplayContainer.java b/src/yugecin/opsudance/core/DisplayContainer.java
index ce3a4816..6722f49b 100644
--- a/src/yugecin/opsudance/core/DisplayContainer.java
+++ b/src/yugecin/opsudance/core/DisplayContainer.java
@@ -59,7 +59,7 @@ import static yugecin.opsudance.options.Options.*;
/**
* based on org.newdawn.slick.AppGameContainer
*/
-public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListener, ResolutionChangedListener, SkinChangedListener {
+public class DisplayContainer implements ErrorDumpable, ResolutionChangedListener, SkinChangedListener {
private static SGL GL = Renderer.get();
@@ -72,7 +72,6 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
public final DisplayMode nativeDisplayMode;
private Graphics graphics;
- public Input input;
public int width;
public int height;
@@ -208,12 +207,12 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
setUPS(OPTION_TARGET_UPS.val);
setFPS(targetFPS[targetFPSIndex]);
- state = startingState;
- state.enter();
-
fpsState = new FpsRenderState();
bubNotifState = new BubNotifState();
barNotifState = new BarNotificationState();
+
+ state = startingState;
+ state.enter();
}
@@ -281,7 +280,6 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
public void setup() throws Exception {
width = height = -1;
- Input.disableControllers();
Display.setTitle("opsu!dance");
setupResolutionOptionlist(nativeDisplayMode.getWidth(), nativeDisplayMode.getHeight());
updateDisplayMode(OPTION_SCREEN_RESOLUTION.getValueString());
@@ -434,10 +432,12 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
graphics = new Graphics(width, height);
graphics.setAntiAlias(false);
- input = new Input(height);
- input.enableKeyRepeat();
- input.addKeyListener(this);
- input.addMouseListener(this);
+ if (input == null) {
+ input = new Input(height);
+ input.enableKeyRepeat();
+ input.addListener(new GlobalInputListener());
+ input.addMouseListener(bubNotifState);
+ }
sout("GL ready");
@@ -469,6 +469,7 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
state.writeErrorDump(dump);
}
+ // TODO change this
public boolean isInState(Class extends OpsuState> state) {
return state.isInstance(state);
}
@@ -494,65 +495,10 @@ public class DisplayContainer implements ErrorDumpable, KeyListener, MouseListen
public void switchStateInstantly(OpsuState state) {
this.state.leave();
+ input.removeListener(this.state);
this.state = state;
this.state.enter();
+ input.addListener(this.state);
}
- /*
- * input events below, see org.newdawn.slick.KeyListener & org.newdawn.slick.MouseListener
- */
-
- @Override
- public void keyPressed(int key, char c) {
- state.keyPressed(key, c);
- }
-
- @Override
- public void keyReleased(int key, char c) {
- state.keyReleased(key, c);
- }
-
- @Override
- public void mouseWheelMoved(int change) {
- state.mouseWheelMoved(change);
- }
-
- @Override
- public void mouseClicked(int button, int x, int y, int clickCount) { }
-
- @Override
- public void mousePressed(int button, int x, int y) {
- state.mousePressed(button, x, y);
- }
-
- @Override
- public void mouseReleased(int button, int x, int y) {
- if (bubNotifState.mouseReleased(x, y)) {
- return;
- }
- state.mouseReleased(button, x, y);
- }
-
- @Override
- public void mouseMoved(int oldx, int oldy, int newx, int newy) { }
-
- @Override
- public void mouseDragged(int oldx, int oldy, int newx, int newy) {
- state.mouseDragged(oldx, oldy, newx, newy);
- }
-
- @Override
- public void setInput(Input input) { }
-
- @Override
- public boolean isAcceptingInput() {
- return true;
- }
-
- @Override
- public void inputEnded() { }
-
- @Override
- public void inputStarted() { }
-
}
diff --git a/src/yugecin/opsudance/core/GlobalInputListener.java b/src/yugecin/opsudance/core/GlobalInputListener.java
new file mode 100644
index 00000000..d628dc1c
--- /dev/null
+++ b/src/yugecin/opsudance/core/GlobalInputListener.java
@@ -0,0 +1,83 @@
+/*
+ * opsu!dance - fork of opsu! with cursordance auto
+ * Copyright (C) 2017 yugecin
+ *
+ * opsu!dance is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * opsu!dance is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with opsu!dance. If not, see .
+ */
+package yugecin.opsudance.core;
+
+import itdelatrisu.opsu.states.Game;
+import itdelatrisu.opsu.ui.UI;
+import org.newdawn.slick.Input;
+import org.newdawn.slick.InputListener;
+import yugecin.opsudance.events.BarNotifListener;
+
+import static yugecin.opsudance.core.InstanceContainer.*;
+import static yugecin.opsudance.options.Options.*;
+
+public class GlobalInputListener implements InputListener {
+
+ @Override
+ public boolean keyPressed(int key, char c) {
+ return false;
+ }
+
+ @Override
+ public boolean keyReleased(int key, char c) {
+ if (key == Input.KEY_F7) {
+ OPTION_TARGET_FPS.clickListItem((targetFPSIndex + 1) % targetFPS.length);
+ BarNotifListener.EVENT.make().onBarNotif(String.format("Frame limiter: %s",
+ OPTION_TARGET_FPS.getValueString()));
+ return true;
+ }
+ if (key == Input.KEY_F10) {
+ OPTION_DISABLE_MOUSE_BUTTONS.toggle();
+ return true;
+ }
+ if (key == Input.KEY_F12) {
+ config.takeScreenShot();
+ return true;
+ }
+ if (key == Input.KEY_S && input.isKeyDown(Input.KEY_LMENU) && input.isKeyDown(Input.KEY_LSHIFT) &&
+ input.isKeyDown(Input.KEY_LCONTROL) && !displayContainer.isInState(Game.class)) {
+ skinservice.reloadSkin();
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mouseWheelMoved(int delta) {
+ if (input.isKeyDown(Input.KEY_LALT) || input.isKeyDown(Input.KEY_RALT)) {
+ UI.changeVolume((delta < 0) ? -1 : 1);
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mousePressed(int button, int x, int y) {
+ return false;
+ }
+
+ @Override
+ public boolean mouseReleased(int button, int x, int y) {
+ return false;
+ }
+
+ @Override
+ public boolean mouseDragged(int oldx, int oldy, int newx, int newy) {
+ return false;
+ }
+
+}
diff --git a/src/yugecin/opsudance/core/InstanceContainer.java b/src/yugecin/opsudance/core/InstanceContainer.java
index a51fa91c..a2cb6c75 100644
--- a/src/yugecin/opsudance/core/InstanceContainer.java
+++ b/src/yugecin/opsudance/core/InstanceContainer.java
@@ -23,6 +23,7 @@ import itdelatrisu.opsu.beatmap.OszUnpacker;
import itdelatrisu.opsu.downloads.Updater;
import itdelatrisu.opsu.replay.ReplayImporter;
import itdelatrisu.opsu.states.*;
+import org.newdawn.slick.Input;
import org.newdawn.slick.util.FileSystemLocation;
import org.newdawn.slick.util.ResourceLoader;
import yugecin.opsudance.options.Configuration;
@@ -51,6 +52,7 @@ public class InstanceContainer {
public static Updater updater;
public static DisplayContainer displayContainer;
+ public static Input input;
public static GameObjectRenderer gameObjectRenderer;
diff --git a/src/yugecin/opsudance/core/state/BaseOpsuState.java b/src/yugecin/opsudance/core/state/BaseOpsuState.java
index 5e863bc6..893a4853 100644
--- a/src/yugecin/opsudance/core/state/BaseOpsuState.java
+++ b/src/yugecin/opsudance/core/state/BaseOpsuState.java
@@ -17,18 +17,11 @@
*/
package yugecin.opsudance.core.state;
-import itdelatrisu.opsu.states.Game;
-import itdelatrisu.opsu.ui.UI;
import org.newdawn.slick.Graphics;
-import org.newdawn.slick.Input;
-import yugecin.opsudance.events.BarNotifListener;
import yugecin.opsudance.events.ResolutionChangedListener;
import java.io.StringWriter;
-import static yugecin.opsudance.options.Options.*;
-import static yugecin.opsudance.core.InstanceContainer.*;
-
public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListener {
/**
@@ -91,33 +84,11 @@ public abstract class BaseOpsuState implements OpsuState, ResolutionChangedListe
@Override
public boolean keyReleased(int key, char c) {
- if (key == Input.KEY_F7) {
- OPTION_TARGET_FPS.clickListItem((targetFPSIndex + 1) % targetFPS.length);
- BarNotifListener.EVENT.make().onBarNotif(String.format("Frame limiter: %s",
- OPTION_TARGET_FPS.getValueString()));
- return true;
- }
- if (key == Input.KEY_F10) {
- OPTION_DISABLE_MOUSE_BUTTONS.toggle();
- return true;
- }
- if (key == Input.KEY_F12) {
- config.takeScreenShot();
- return true;
- }
- Input input = displayContainer.input;
- if (key == Input.KEY_S && input.isKeyDown(Input.KEY_LMENU) && input.isKeyDown(Input.KEY_LSHIFT) &&input.isKeyDown(Input.KEY_LCONTROL) && !displayContainer.isInState(Game.class)) {
- skinservice.reloadSkin();
- }
return false;
}
@Override
public boolean mouseWheelMoved(int delta) {
- if (displayContainer.input.isKeyDown(Input.KEY_LALT) || displayContainer.input.isKeyDown(Input.KEY_RALT)) {
- UI.changeVolume((delta < 0) ? -1 : 1);
- return true;
- }
return false;
}
diff --git a/src/yugecin/opsudance/core/state/OpsuState.java b/src/yugecin/opsudance/core/state/OpsuState.java
index 0a0a65ca..204ce8cf 100644
--- a/src/yugecin/opsudance/core/state/OpsuState.java
+++ b/src/yugecin/opsudance/core/state/OpsuState.java
@@ -18,9 +18,10 @@
package yugecin.opsudance.core.state;
import org.newdawn.slick.Graphics;
+import org.newdawn.slick.InputListener;
import yugecin.opsudance.core.errorhandling.ErrorDumpable;
-public interface OpsuState extends ErrorDumpable {
+public interface OpsuState extends ErrorDumpable, InputListener {
void update();
void preRenderUpdate();
@@ -33,34 +34,4 @@ public interface OpsuState extends ErrorDumpable {
*/
boolean onCloseRequest();
- /**
- * @return false to stop event bubbling
- */
- boolean keyPressed(int key, char c);
-
- /**
- * @return false to stop event bubbling
- */
- boolean keyReleased(int key, char c);
-
- /**
- * @return false to stop event bubbling
- */
- boolean mouseWheelMoved(int delta);
-
- /**
- * @return false to stop event bubbling
- */
- boolean mousePressed(int button, int x, int y);
-
- /**
- * @return false to stop event bubbling
- */
- boolean mouseReleased(int button, int x, int y);
-
- /**
- * @return false to stop event bubbling
- */
- boolean mouseDragged(int oldx, int oldy, int newx, int newy);
-
}
diff --git a/src/yugecin/opsudance/core/state/specialstates/BubNotifState.java b/src/yugecin/opsudance/core/state/specialstates/BubNotifState.java
index e8ddebfc..f3dc82d6 100644
--- a/src/yugecin/opsudance/core/state/specialstates/BubNotifState.java
+++ b/src/yugecin/opsudance/core/state/specialstates/BubNotifState.java
@@ -21,6 +21,7 @@ import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.animations.AnimationEquation;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
+import org.newdawn.slick.MouseListener;
import yugecin.opsudance.events.BubNotifListener;
import yugecin.opsudance.events.ResolutionChangedListener;
import yugecin.opsudance.events.SkinChangedListener;
@@ -29,9 +30,9 @@ import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
-import static yugecin.opsudance.core.InstanceContainer.displayContainer;
+import static yugecin.opsudance.core.InstanceContainer.*;
-public class BubNotifState implements BubNotifListener, ResolutionChangedListener, SkinChangedListener {
+public class BubNotifState implements MouseListener, BubNotifListener, ResolutionChangedListener, SkinChangedListener {
public static final int IN_TIME = 633;
public static final int DISPLAY_TIME = 7000 + IN_TIME;
@@ -71,18 +72,6 @@ public class BubNotifState implements BubNotifListener, ResolutionChangedListene
} while (iter.hasNext());
}
- public boolean mouseReleased(int x, int y) {
- if (x < Notification.finalX) {
- return false;
- }
- for (Notification bubble : bubbles) {
- if (bubble.mouseReleased(x, y)) {
- return true;
- }
- }
- return false;
- }
-
private void calculatePositions() {
Notification.width = (int) (displayContainer.width * 0.1703125f);
Notification.baseLine = (int) (displayContainer.height * 0.9645f);
@@ -146,6 +135,34 @@ public class BubNotifState implements BubNotifListener, ResolutionChangedListene
calculatePositions();
}
+ @Override
+ public boolean mouseWheelMoved(int delta) {
+ return false;
+ }
+
+ @Override
+ public boolean mousePressed(int button, int x, int y) {
+ return false;
+ }
+
+ @Override
+ public boolean mouseReleased(int button, int x, int y) {
+ if (x < Notification.finalX) {
+ return false;
+ }
+ for (Notification bubble : bubbles) {
+ if (bubble.mouseReleased(x, y)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public boolean mouseDragged(int oldx, int oldy, int newx, int newy) {
+ return false;
+ }
+
private static class Notification {
private final static int HOVER_ANIM_TIME = 150;
diff --git a/src/yugecin/opsudance/ui/OptionsOverlay.java b/src/yugecin/opsudance/ui/OptionsOverlay.java
index 7bb3bde2..0ab3e725 100644
--- a/src/yugecin/opsudance/ui/OptionsOverlay.java
+++ b/src/yugecin/opsudance/ui/OptionsOverlay.java
@@ -146,7 +146,7 @@ public class OptionsOverlay extends OverlayOpsuState {
dropdownMenus = new HashMap<>();
visibleDropdownMenus = new LinkedList<>();
- searchField = new TextField(displayContainer, null, 0, 0, 0, 0);
+ searchField = new TextField(null, 0, 0, 0, 0);
searchField.setMaxLength(20);
scrollHandler = new KineticScrolling();