Disallow escape as click key, move validity checks into Options.java
This commit is contained in:
parent
765aa21dfb
commit
9271e0d473
|
@ -713,7 +713,7 @@ public class Options {
|
||||||
*/
|
*/
|
||||||
public static int getGameKeyLeft() {
|
public static int getGameKeyLeft() {
|
||||||
if (keyLeft == Keyboard.KEY_NONE)
|
if (keyLeft == Keyboard.KEY_NONE)
|
||||||
keyLeft = Input.KEY_Z;
|
setGameKeyLeft(Input.KEY_Z);
|
||||||
return keyLeft;
|
return keyLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -723,21 +723,39 @@ public class Options {
|
||||||
*/
|
*/
|
||||||
public static int getGameKeyRight() {
|
public static int getGameKeyRight() {
|
||||||
if (keyRight == Keyboard.KEY_NONE)
|
if (keyRight == Keyboard.KEY_NONE)
|
||||||
keyRight = Input.KEY_X;
|
setGameKeyRight(Input.KEY_X);
|
||||||
return keyRight;
|
return keyRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the left game key.
|
* Sets the left game key.
|
||||||
|
* This will not be set to the same key as the right game key, nor to reserved keys like ESCAPE.
|
||||||
* @param key the keyboard key
|
* @param key the keyboard key
|
||||||
|
* @return {@code true} if the key was set, {@code false} if it was rejected
|
||||||
*/
|
*/
|
||||||
public static void setGameKeyLeft(int key) { keyLeft = key; }
|
public static boolean setGameKeyLeft(int key) {
|
||||||
|
if (key == keyRight && key != Keyboard.KEY_NONE)
|
||||||
|
return false;
|
||||||
|
if (!isValidClickKey(key))
|
||||||
|
return false;
|
||||||
|
keyLeft = key;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the right game key.
|
* Sets the right game key.
|
||||||
|
* This will not be set to the same key as the left game key, nor to reserved keys like ESCAPE.
|
||||||
* @param key the keyboard key
|
* @param key the keyboard key
|
||||||
|
* @return {@code true} if the key was set, {@code false} if it was rejected
|
||||||
*/
|
*/
|
||||||
public static void setGameKeyRight(int key) { keyRight = key; }
|
public static boolean setGameKeyRight(int key) {
|
||||||
|
if (key == keyLeft && key != Keyboard.KEY_NONE)
|
||||||
|
return false;
|
||||||
|
if (!isValidClickKey(key))
|
||||||
|
return false;
|
||||||
|
keyRight = key;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the beatmap directory.
|
* Returns the beatmap directory.
|
||||||
|
@ -825,6 +843,10 @@ public class Options {
|
||||||
return osu;
|
return osu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isValidClickKey(int keyCode) {
|
||||||
|
return keyCode != Keyboard.KEY_ESCAPE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads user options from the options file, if it exists.
|
* Reads user options from the options file, if it exists.
|
||||||
*/
|
*/
|
||||||
|
@ -935,14 +957,10 @@ public class Options {
|
||||||
GameOption.DISABLE_SOUNDS.setValue(Boolean.parseBoolean(value));
|
GameOption.DISABLE_SOUNDS.setValue(Boolean.parseBoolean(value));
|
||||||
break;
|
break;
|
||||||
case "keyOsuLeft":
|
case "keyOsuLeft":
|
||||||
i = Keyboard.getKeyIndex(value);
|
setGameKeyLeft(Keyboard.getKeyIndex(value));
|
||||||
if (keyRight != i)
|
|
||||||
keyLeft = i;
|
|
||||||
break;
|
break;
|
||||||
case "keyOsuRight":
|
case "keyOsuRight":
|
||||||
i = Keyboard.getKeyIndex(value);
|
setGameKeyRight(Keyboard.getKeyIndex(value));
|
||||||
if (keyLeft != i)
|
|
||||||
keyRight = i;
|
|
||||||
break;
|
break;
|
||||||
case "MouseDisableWheel":
|
case "MouseDisableWheel":
|
||||||
GameOption.DISABLE_MOUSE_WHEEL.setValue(Boolean.parseBoolean(value));
|
GameOption.DISABLE_MOUSE_WHEEL.setValue(Boolean.parseBoolean(value));
|
||||||
|
|
|
@ -347,9 +347,9 @@ public class OptionsMenu extends BasicGameState {
|
||||||
public void keyPressed(int key, char c) {
|
public void keyPressed(int key, char c) {
|
||||||
// key entry state
|
// key entry state
|
||||||
if (keyEntryLeft || keyEntryRight) {
|
if (keyEntryLeft || keyEntryRight) {
|
||||||
if (keyEntryLeft && Options.getGameKeyRight() != key)
|
if (keyEntryLeft)
|
||||||
Options.setGameKeyLeft(key);
|
Options.setGameKeyLeft(key);
|
||||||
else if (keyEntryRight && Options.getGameKeyLeft() != key)
|
else
|
||||||
Options.setGameKeyRight(key);
|
Options.setGameKeyRight(key);
|
||||||
keyEntryLeft = keyEntryRight = false;
|
keyEntryLeft = keyEntryRight = false;
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user