Follow-up to #31: added more reserved keys.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-07 14:24:26 -05:00
parent 04cca79b46
commit 133608dd43
2 changed files with 20 additions and 20 deletions

View File

@ -735,14 +735,13 @@ public class Options {
/** /**
* 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. * This will not be set to the same key as the right game key, nor to any
* reserved keys (see {@link #isValidGameKey(int)}).
* @param key the keyboard key * @param key the keyboard key
* @return {@code true} if the key was set, {@code false} if it was rejected * @return {@code true} if the key was set, {@code false} if it was rejected
*/ */
public static boolean setGameKeyLeft(int key) { public static boolean setGameKeyLeft(int key) {
if (key == keyRight && key != Keyboard.KEY_NONE) if ((key == keyRight && key != Keyboard.KEY_NONE) || !isValidGameKey(key))
return false;
if (!isValidClickKey(key))
return false; return false;
keyLeft = key; keyLeft = key;
return true; return true;
@ -750,19 +749,29 @@ public class Options {
/** /**
* 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. * This will not be set to the same key as the left game key, nor to any
* reserved keys (see {@link #isValidGameKey(int)}).
* @param key the keyboard key * @param key the keyboard key
* @return {@code true} if the key was set, {@code false} if it was rejected * @return {@code true} if the key was set, {@code false} if it was rejected
*/ */
public static boolean setGameKeyRight(int key) { public static boolean setGameKeyRight(int key) {
if (key == keyLeft && key != Keyboard.KEY_NONE) if ((key == keyLeft && key != Keyboard.KEY_NONE) || !isValidGameKey(key))
return false;
if (!isValidClickKey(key))
return false; return false;
keyRight = key; keyRight = key;
return true; return true;
} }
/**
* Checks if the given key is a valid game key.
* @param key the keyboard key
* @return {@code true} if valid, {@code false} otherwise
*/
private static boolean isValidGameKey(int key) {
return (key != Keyboard.KEY_ESCAPE && key != Keyboard.KEY_SPACE &&
key != Keyboard.KEY_UP && key != Keyboard.KEY_DOWN &&
key != Keyboard.KEY_F7 && key != Keyboard.KEY_F10 && key != Keyboard.KEY_F12);
}
/** /**
* Returns the beatmap directory. * Returns the beatmap directory.
* If invalid, this will attempt to search for the directory, * If invalid, this will attempt to search for the directory,
@ -849,10 +858,6 @@ 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.
*/ */

View File

@ -243,14 +243,9 @@ public class OptionsMenu extends BasicGameState {
g.setColor(Utils.COLOR_BLACK_ALPHA); g.setColor(Utils.COLOR_BLACK_ALPHA);
g.fillRect(0, 0, width, height); g.fillRect(0, 0, width, height);
g.setColor(Color.white); g.setColor(Color.white);
String prompt = (keyEntryLeft) ?
String prompt; "Please press the new left-click key." :
if (keyEntryLeft) { "Please press the new right-click key.";
prompt = "Please press the new left-click key";
} else {
prompt = "Please press the new right-click key";
}
Utils.FONT_LARGE.drawString( Utils.FONT_LARGE.drawString(
(width / 2) - (Utils.FONT_LARGE.getWidth(prompt) / 2), (width / 2) - (Utils.FONT_LARGE.getWidth(prompt) / 2),
(height / 2) - Utils.FONT_LARGE.getLineHeight(), prompt (height / 2) - Utils.FONT_LARGE.getLineHeight(), prompt