Added options to disable the mouse wheel or mouse buttons during gameplay.

- Clicking the mouse wheel now pauses the game (with these options disabled).
- Created an "Input" category in the options menu.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-02 22:12:57 -05:00
parent 4bf5943ee0
commit de949ef11c
5 changed files with 87 additions and 10 deletions

View File

@ -370,6 +370,20 @@ public class Options {
@Override
public void click(GameContainer container) { showHitErrorBar = !showHitErrorBar; }
},
DISABLE_MOUSE_WHEEL ("Disable mouse wheel in play mode", "During play, you can use the mouse wheel to adjust the volume and pause the game.\nThis will disable that functionality.") {
@Override
public String getValueString() { return disableMouseWheel ? "Yes" : "No"; }
@Override
public void click(GameContainer container) { disableMouseWheel = !disableMouseWheel; }
},
DISABLE_MOUSE_BUTTONS ("Disable mouse buttons in play mode", "This option will disable all mouse buttons.\nSpecifically for people who use their keyboard to click.") {
@Override
public String getValueString() { return disableMouseButtons ? "Yes" : "No"; }
@Override
public void click(GameContainer container) { disableMouseButtons = !disableMouseButtons; }
};
/** Option name. */
@ -544,6 +558,12 @@ public class Options {
/** Whether or not to show the hit error bar. */
private static boolean showHitErrorBar = false;
/** Whether or not to disable the mouse wheel during gameplay. */
private static boolean disableMouseWheel = false;
/** Whether or not to disable the mouse buttons during gameplay. */
private static boolean disableMouseButtons = false;
/** Fixed difficulty overrides. */
private static float
fixedCS = 0f, fixedHP = 0f,
@ -795,6 +815,18 @@ public class Options {
*/
public static boolean isHitErrorBarEnabled() { return showHitErrorBar; }
/**
* Returns whether or not the mouse wheel is disabled during gameplay.
* @return true if disabled
*/
public static boolean isMouseWheelDisabled() { return disableMouseWheel; }
/**
* Returns whether or not the mouse buttons are disabled during gameplay.
* @return true if disabled
*/
public static boolean isMouseDisabled() { return disableMouseButtons; }
/**
* Returns the left game key.
* @return the left key code
@ -1037,6 +1069,12 @@ public class Options {
keyRight = i;
}
break;
case "MouseDisableWheel":
disableMouseWheel = Boolean.parseBoolean(value);
break;
case "MouseDisableButtons":
disableMouseButtons = Boolean.parseBoolean(value);
break;
case "DimLevel":
i = Integer.parseInt(value);
if (i >= 0 && i <= 100)
@ -1151,6 +1189,10 @@ public class Options {
writer.newLine();
writer.write(String.format("keyOsuRight = %s", Keyboard.getKeyName(getGameKeyRight())));
writer.newLine();
writer.write(String.format("MouseDisableWheel = %b", disableMouseWheel));
writer.newLine();
writer.write(String.format("MouseDisableButtons = %b", disableMouseButtons));
writer.newLine();
writer.write(String.format("DimLevel = %d", backgroundDim));
writer.newLine();
writer.write(String.format("ForceDefaultPlayfield = %b", forceDefaultPlayfield));

View File

@ -237,11 +237,12 @@ public class OsuHitObject {
/**
* Returns the edge hit sound type.
* @param index the slider edge index (ignored for non-sliders)
* @return the sound type (SOUND_* bitmask)
*/
public byte getEdgeHitSoundType(int i) {
public byte getEdgeHitSoundType(int index) {
if (edgeHitSound != null)
return edgeHitSound[i];
return edgeHitSound[index];
else
return hitSound;
}

View File

@ -393,7 +393,8 @@ public class Utils {
final float scale = 1.25f;
int state = game.getCurrentStateID();
if (((state == Opsu.STATE_GAME || state == Opsu.STATE_GAMEPAUSEMENU) && isGameKeyPressed()) ||
(input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) || input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON))) {
((input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) || input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) &&
!(state == Opsu.STATE_GAME && Options.isMouseDisabled()))) {
cursor = cursor.getScaledCopy(scale);
if (newStyle)
cursorMiddle = cursorMiddle.getScaledCopy(scale);
@ -487,8 +488,10 @@ public class Utils {
* @return true if pressed
*/
public static boolean isGameKeyPressed() {
return (input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ||
input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON) ||
boolean mouseDown = !Options.isMouseDisabled() && (
input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON) ||
input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON));
return (mouseDown ||
input.isKeyDown(Options.getGameKeyLeft()) ||
input.isKeyDown(Options.getGameKeyRight()));
}

View File

@ -533,9 +533,9 @@ public class Game extends BasicGameState {
// game keys
if (!Keyboard.isRepeatEvent()) {
if (key == Options.getGameKeyLeft())
mousePressed(Input.MOUSE_LEFT_BUTTON, input.getMouseX(), input.getMouseY());
gameKeyPressed(Input.MOUSE_LEFT_BUTTON, input.getMouseX(), input.getMouseY());
else if (key == Options.getGameKeyRight())
mousePressed(Input.MOUSE_RIGHT_BUTTON, input.getMouseX(), input.getMouseY());
gameKeyPressed(Input.MOUSE_RIGHT_BUTTON, input.getMouseX(), input.getMouseY());
}
switch (key) {
@ -626,9 +626,33 @@ public class Game extends BasicGameState {
@Override
public void mousePressed(int button, int x, int y) {
if (button == Input.MOUSE_MIDDLE_BUTTON)
if (Options.isMouseDisabled())
return;
// mouse wheel: pause the game
if (button == Input.MOUSE_MIDDLE_BUTTON && !Options.isMouseWheelDisabled()) {
int trackPosition = MusicController.getPosition();
if (pauseTime < 0 && breakTime <= 0 && trackPosition >= osu.objects[0].getTime()) {
pausedMouseX = x;
pausedMouseY = y;
pausePulse = 0f;
}
if (MusicController.isPlaying() || isLeadIn())
pauseTime = trackPosition;
game.enterState(Opsu.STATE_GAMEPAUSEMENU, new EmptyTransition(), new FadeInTransition(Color.black));
return;
}
gameKeyPressed(button, x, y);
}
/**
* Handles a game key pressed event.
* @param button the index of the button pressed
* @param x the mouse x coordinate
* @param y the mouse y coordinate
*/
private void gameKeyPressed(int button, int x, int y) {
// returning from pause screen
if (pauseTime > -1) {
double distance = Math.hypot(pausedMouseX - x, pausedMouseY - y);
@ -670,6 +694,9 @@ public class Game extends BasicGameState {
@Override
public void mouseWheelMoved(int newValue) {
if (Options.isMouseWheelDisabled() || Options.isMouseDisabled())
return;
Utils.changeVolume((newValue < 0) ? -1 : 1);
}

View File

@ -68,8 +68,6 @@ public class OptionsMenu extends BasicGameState {
GameOption.ENABLE_THEME_SONG
}),
GAMEPLAY ("Gameplay", new GameOption[] {
GameOption.KEY_LEFT,
GameOption.KEY_RIGHT,
GameOption.BACKGROUND_DIM,
GameOption.FORCE_DEFAULT_PLAYFIELD,
GameOption.IGNORE_BEATMAP_SKINS,
@ -78,6 +76,12 @@ public class OptionsMenu extends BasicGameState {
GameOption.SHOW_PERFECT_HIT,
GameOption.SHOW_HIT_ERROR_BAR
}),
INPUT ("Input", new GameOption[] {
GameOption.KEY_LEFT,
GameOption.KEY_RIGHT,
GameOption.DISABLE_MOUSE_WHEEL,
GameOption.DISABLE_MOUSE_BUTTONS
}),
CUSTOM ("Custom", new GameOption[] {
GameOption.FIXED_CS,
GameOption.FIXED_HP,