ctrl+click slider option to reset to default value

This commit is contained in:
yugecin 2016-11-20 23:19:13 +01:00
parent 7898b669f5
commit b19523ff26
2 changed files with 27 additions and 3 deletions

View File

@ -1189,6 +1189,8 @@ public class Options {
/** The boolean value for the option (if applicable). */ /** The boolean value for the option (if applicable). */
protected boolean bool; protected boolean bool;
private int defaultVal = 0;
/** The integer value for the option (if applicable). */ /** The integer value for the option (if applicable). */
protected int val; protected int val;
@ -1244,6 +1246,7 @@ public class Options {
GameOption(String name, String displayName, String description, int value, int min, int max) { GameOption(String name, String displayName, String description, int value, int min, int max) {
this(name, displayName, description); this(name, displayName, description);
this.val = value; this.val = value;
this.defaultVal = value;
this.min = min; this.min = min;
this.max = max; this.max = max;
this.type = OptionType.NUMERIC; this.type = OptionType.NUMERIC;
@ -1389,6 +1392,10 @@ public class Options {
return max; return max;
} }
public int getDefaultVal() {
return defaultVal;
}
} }
/** Map of option display names to GameOptions. */ /** Map of option display names to GameOptions. */

View File

@ -422,6 +422,13 @@ public class OptionsMenu extends BasicGameState {
keyEntryLeft = false; keyEntryLeft = false;
keyEntryRight = true; keyEntryRight = true;
} }
// ctrl+click to reset slider options
if (selectedOption != null && selectedOption.isDragOption() && (input.isKeyDown(Input.KEY_LCONTROL) || input.isKeyDown(Input.KEY_RCONTROL))) {
selectedOption.setValue(selectedOption.getDefaultVal() - 1);
// trigger update
selectedOption.drag(container, 1);
}
} }
@Override @Override
@ -438,6 +445,18 @@ public class OptionsMenu extends BasicGameState {
if (keyEntryLeft || keyEntryRight) if (keyEntryLeft || keyEntryRight)
return; return;
if (selectedOption == null || !selectedOption.isDragOption()) {
return;
}
// check control keys (reset to default value on ctrl+click)
if (input.isKeyDown(Input.KEY_LCONTROL) || input.isKeyDown(Input.KEY_RCONTROL)) {
selectedOption.setValue(selectedOption.getDefaultVal() - 1);
// trigger update
selectedOption.drag(container, 1);
return;
}
// check mouse button (right click scrolls faster) // check mouse button (right click scrolls faster)
int multiplier; int multiplier;
if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON)) if (input.isMouseButtonDown(Input.MOUSE_RIGHT_BUTTON))
@ -454,9 +473,7 @@ public class OptionsMenu extends BasicGameState {
diff = ((diff > 0) ? 1 : -1) * multiplier; diff = ((diff > 0) ? 1 : -1) * multiplier;
// options (drag only) // options (drag only)
if (selectedOption != null) { selectedOption.drag(container, diff);
selectedOption.drag(container, diff);
}
} }
@Override @Override