Simplified Options class.

- Boolean and integer option values are now stored in a GameOption field instead of individual static fields in the Options class.
- Added default method bodies for getValueString(), click(), and drag() based on the option type.

Also made the options file parser continue after a NumberFormatException instead of quitting immediately.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-03-03 00:40:51 -05:00
parent de949ef11c
commit 11e555492e

View File

@@ -94,6 +94,9 @@ public class Options {
/** The current skin directory (for user skins). */ /** The current skin directory (for user skins). */
private static File skinDir; private static File skinDir;
/** Port binding. */
private static int port = 49250;
/** /**
* Returns the directory based on the XDG base directory specification for * Returns the directory based on the XDG base directory specification for
* Unix-like operating systems, only if the system property "XDG" has been defined. * Unix-like operating systems, only if the system property "XDG" has been defined.
@@ -144,13 +147,7 @@ public class Options {
container.getScreenHeight() < resolution.getHeight())); container.getScreenHeight() < resolution.getHeight()));
} }
}, },
// FULLSCREEN ("Fullscreen Mode", "Restart to apply changes.") { // FULLSCREEN ("Fullscreen Mode", "Restart to apply changes.", false),
// @Override
// public String getValueString() { return fullscreen ? "Yes" : "No"; }
//
// @Override
// public void click(GameContainer container) { fullscreen = !fullscreen; }
// },
TARGET_FPS ("Frame Limiter", "Higher values may cause high CPU usage.") { TARGET_FPS ("Frame Limiter", "Higher values may cause high CPU usage.") {
@Override @Override
public String getValueString() { public String getValueString() {
@@ -164,46 +161,25 @@ public class Options {
container.setVSync(getTargetFPS() == 60); container.setVSync(getTargetFPS() == 60);
} }
}, },
MASTER_VOLUME ("Master Volume", "Global volume level.") { MASTER_VOLUME ("Master Volume", "Global volume level.", 35, 0, 100) {
@Override
public String getValueString() { return String.format("%d%%", masterVolume); }
@Override @Override
public void drag(GameContainer container, int d) { public void drag(GameContainer container, int d) {
masterVolume = Utils.getBoundedValue(masterVolume, d, 0, 100); super.drag(container, d);
container.setMusicVolume(getMasterVolume() * getMusicVolume()); container.setMusicVolume(getMasterVolume() * getMusicVolume());
} }
}, },
MUSIC_VOLUME ("Music Volume", "Volume of music.") { MUSIC_VOLUME ("Music Volume", "Volume of music.", 80, 0, 100) {
@Override
public String getValueString() { return String.format("%d%%", musicVolume); }
@Override @Override
public void drag(GameContainer container, int d) { public void drag(GameContainer container, int d) {
musicVolume = Utils.getBoundedValue(musicVolume, d, 0, 100); super.drag(container, d);
container.setMusicVolume(getMasterVolume() * getMusicVolume()); container.setMusicVolume(getMasterVolume() * getMusicVolume());
} }
}, },
EFFECT_VOLUME ("Effect Volume", "Volume of menu and game sounds.") { EFFECT_VOLUME ("Effect Volume", "Volume of menu and game sounds.", 70, 0, 100),
HITSOUND_VOLUME ("Hit Sound Volume", "Volume of hit sounds.", 30, 0, 100),
MUSIC_OFFSET ("Music Offset", "Adjust this value if hit objects are out of sync.", -150, -500, 500) {
@Override @Override
public String getValueString() { return String.format("%d%%", effectVolume); } public String getValueString() { return String.format("%dms", val); }
@Override
public void drag(GameContainer container, int d) { effectVolume = Utils.getBoundedValue(effectVolume, d, 0, 100); }
},
HITSOUND_VOLUME ("Hit Sound Volume", "Volume of hit sounds.") {
@Override
public String getValueString() { return String.format("%d%%", hitSoundVolume); }
@Override
public void drag(GameContainer container, int d) { hitSoundVolume = Utils.getBoundedValue(hitSoundVolume, d, 0, 100); }
},
MUSIC_OFFSET ("Music Offset", "Adjust this value if hit objects are out of sync.") {
@Override
public String getValueString() { return String.format("%dms", musicOffset); }
@Override
public void drag(GameContainer container, int d) { musicOffset = Utils.getBoundedValue(musicOffset, d, -500, 500); }
}, },
SCREENSHOT_FORMAT ("Screenshot Format", "Press F12 to take a screenshot.") { SCREENSHOT_FORMAT ("Screenshot Format", "Press F12 to take a screenshot.") {
@Override @Override
@@ -212,125 +188,48 @@ public class Options {
@Override @Override
public void click(GameContainer container) { screenshotFormatIndex = (screenshotFormatIndex + 1) % screenshotFormat.length; } public void click(GameContainer container) { screenshotFormatIndex = (screenshotFormatIndex + 1) % screenshotFormat.length; }
}, },
SHOW_FPS ("Show FPS Counter", "Show an FPS counter in the bottom-right hand corner.") { SHOW_FPS ("Show FPS Counter", "Show an FPS counter in the bottom-right hand corner.", true),
@Override SHOW_HIT_LIGHTING ("Show Hit Lighting", "Adds an effect behind hit explosions.", true),
public String getValueString() { return showFPS ? "Yes" : "No"; } SHOW_COMBO_BURSTS ("Show Combo Bursts", "A character image is displayed at combo milestones.", true),
SHOW_PERFECT_HIT ("Show Perfect Hits", "Whether to show perfect hit result bursts (300s, slider ticks).", true),
@Override NEW_CURSOR ("Enable New Cursor", "Use the new cursor style (may cause higher CPU usage).", true) {
public void click(GameContainer container) { showFPS = !showFPS; }
},
SHOW_HIT_LIGHTING ("Show Hit Lighting", "Adds an effect behind hit explosions.") {
@Override
public String getValueString() { return showHitLighting ? "Yes" : "No"; }
@Override
public void click(GameContainer container) { showHitLighting = !showHitLighting; }
},
SHOW_COMBO_BURSTS ("Show Combo Bursts", "A character image is displayed at combo milestones.") {
@Override
public String getValueString() { return showComboBursts ? "Yes" : "No"; }
@Override
public void click(GameContainer container) { showComboBursts = !showComboBursts; }
},
SHOW_PERFECT_HIT ("Show Perfect Hits", "Whether to show perfect hit result bursts (300s, slider ticks).") {
@Override
public String getValueString() { return showPerfectHit ? "Yes" : "No"; }
@Override
public void click(GameContainer container) { showPerfectHit = !showPerfectHit; }
},
NEW_CURSOR ("Enable New Cursor", "Use the new cursor style (may cause higher CPU usage).") {
@Override
public String getValueString() { return newCursor ? "Yes" : "No"; }
@Override @Override
public void click(GameContainer container) { public void click(GameContainer container) {
newCursor = !newCursor; super.click(container);
Utils.resetCursor(); Utils.resetCursor();
} }
}, },
DYNAMIC_BACKGROUND ("Enable Dynamic Backgrounds", "The song background will be used as the main menu background.") { DYNAMIC_BACKGROUND ("Enable Dynamic Backgrounds", "The song background will be used as the main menu background.", true),
BACKGROUND_DIM ("Background Dim", "Percentage to dim the background image during gameplay.", 50, 0, 100),
FORCE_DEFAULT_PLAYFIELD ("Force Default Playfield", "Override the song background with the default playfield background.", false),
IGNORE_BEATMAP_SKINS ("Ignore All Beatmap Skins", "Never use skin element overrides provided by beatmaps.", false),
FIXED_CS ("Fixed Circle Size (CS)", "Determines the size of circles and sliders.", 0, 0, 100) {
@Override @Override
public String getValueString() { return dynamicBackground ? "Yes" : "No"; } public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); }
@Override
public void click(GameContainer container) { dynamicBackground = !dynamicBackground; }
}, },
BACKGROUND_DIM ("Background Dim", "Percentage to dim the background image during gameplay.") { FIXED_HP ("Fixed HP Drain Rate (HP)", "Determines the rate at which health decreases.", 0, 0, 100) {
@Override @Override
public String getValueString() { return String.format("%d%%", backgroundDim); } public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); }
@Override
public void drag(GameContainer container, int d) { backgroundDim = Utils.getBoundedValue(backgroundDim, d, 0, 100); }
}, },
FORCE_DEFAULT_PLAYFIELD ("Force Default Playfield", "Override the song background with the default playfield background.") { FIXED_AR ("Fixed Approach Rate (AR)", "Determines how long hit circles stay on the screen.", 0, 0, 100) {
@Override @Override
public String getValueString() { return forceDefaultPlayfield ? "Yes" : "No"; } public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); }
@Override
public void click(GameContainer container) { forceDefaultPlayfield = !forceDefaultPlayfield; }
}, },
IGNORE_BEATMAP_SKINS ("Ignore All Beatmap Skins", "Never use skin element overrides provided by beatmaps.") { FIXED_OD ("Fixed Overall Difficulty (OD)", "Determines the time window for hit results.", 0, 0, 100) {
@Override @Override
public String getValueString() { return ignoreBeatmapSkins ? "Yes" : "No"; } public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); }
@Override
public void click(GameContainer container) { ignoreBeatmapSkins = !ignoreBeatmapSkins; }
}, },
FIXED_CS ("Fixed Circle Size (CS)", "Determines the size of circles and sliders.") { LOAD_VERBOSE ("Show Detailed Loading Progress", "Display more specific loading information in the splash screen.", false),
@Override CHECKPOINT ("Track Checkpoint", "Press Ctrl+L while playing to load a checkpoint, and Ctrl+S to set one.", 0, 0, 3599) {
public String getValueString() { return (fixedCS == 0f) ? "Disabled" : String.format("%.1f", fixedCS); }
@Override
public void drag(GameContainer container, int d) { fixedCS = Utils.getBoundedValue(fixedCS, d / 10f, 0f, 10f); }
},
FIXED_HP ("Fixed HP Drain Rate (HP)", "Determines the rate at which health decreases.") {
@Override
public String getValueString() { return (fixedHP == 0f) ? "Disabled" : String.format("%.1f", fixedHP); }
@Override
public void drag(GameContainer container, int d) { fixedHP = Utils.getBoundedValue(fixedHP, d / 10f, 0f, 10f); }
},
FIXED_AR ("Fixed Approach Rate (AR)", "Determines how long hit circles stay on the screen.") {
@Override
public String getValueString() { return (fixedAR == 0f) ? "Disabled" : String.format("%.1f", fixedAR); }
@Override
public void drag(GameContainer container, int d) { fixedAR = Utils.getBoundedValue(fixedAR, d / 10f, 0f, 10f); }
},
FIXED_OD ("Fixed Overall Difficulty (OD)", "Determines the time window for hit results.") {
@Override
public String getValueString() { return (fixedOD == 0f) ? "Disabled" : String.format("%.1f", fixedOD); }
@Override
public void drag(GameContainer container, int d) { fixedOD = Utils.getBoundedValue(fixedOD, d / 10f, 0f, 10f); }
},
LOAD_VERBOSE ("Show Detailed Loading Progress", "Display more specific loading information in the splash screen.") {
@Override
public String getValueString() { return loadVerbose ? "Yes" : "No"; }
@Override
public void click(GameContainer container) { loadVerbose = !loadVerbose; }
},
CHECKPOINT ("Track Checkpoint", "Press Ctrl+L while playing to load a checkpoint, and Ctrl+S to set one.") {
@Override @Override
public String getValueString() { public String getValueString() {
return (checkpoint == 0) ? "Disabled" : String.format("%02d:%02d", return (val == 0) ? "Disabled" : String.format("%02d:%02d",
TimeUnit.SECONDS.toMinutes(checkpoint), TimeUnit.SECONDS.toMinutes(val),
checkpoint - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(checkpoint))); val - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(val)));
} }
@Override
public void drag(GameContainer container, int d) { checkpoint = Utils.getBoundedValue(checkpoint, d, 0, 3599); }
},
DISABLE_SOUNDS ("Disable All Sound Effects", "May resolve Linux sound driver issues. Requires a restart.") {
@Override
public String getValueString() { return disableSound ? "Yes" : "No"; }
@Override
public void click(GameContainer container) { disableSound = !disableSound; }
}, },
DISABLE_SOUNDS ("Disable All Sound Effects", "May resolve Linux sound driver issues. Requires a restart.",
(System.getProperty("os.name").toLowerCase().indexOf("linux") > -1)),
KEY_LEFT ("Left Game Key", "Select this option to input a key.") { KEY_LEFT ("Left Game Key", "Select this option to input a key.") {
@Override @Override
public String getValueString() { return Keyboard.getKeyName(getGameKeyLeft()); } public String getValueString() { return Keyboard.getKeyName(getGameKeyLeft()); }
@@ -339,14 +238,11 @@ public class Options {
@Override @Override
public String getValueString() { return Keyboard.getKeyName(getGameKeyRight()); } public String getValueString() { return Keyboard.getKeyName(getGameKeyRight()); }
}, },
SHOW_UNICODE ("Prefer Non-English Metadata", "Where available, song titles will be shown in their native language.") { SHOW_UNICODE ("Prefer Non-English Metadata", "Where available, song titles will be shown in their native language.", false) {
@Override
public String getValueString() { return showUnicode ? "Yes" : "No"; }
@Override @Override
public void click(GameContainer container) { public void click(GameContainer container) {
showUnicode = !showUnicode; super.click(container);
if (showUnicode) { if (bool) {
try { try {
Utils.FONT_LARGE.loadGlyphs(); Utils.FONT_LARGE.loadGlyphs();
Utils.FONT_MEDIUM.loadGlyphs(); Utils.FONT_MEDIUM.loadGlyphs();
@@ -357,34 +253,10 @@ public class Options {
} }
} }
}, },
ENABLE_THEME_SONG ("Enable Theme Song", "Whether to play the theme song upon starting opsu!") { ENABLE_THEME_SONG ("Enable Theme Song", "Whether to play the theme song upon starting opsu!", true),
@Override SHOW_HIT_ERROR_BAR ("Show Hit Error Bar", "Shows precisely how accurate you were with each hit.", false),
public String getValueString() { return themeSongEnabled ? "Yes" : "No"; } 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.", false),
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.", false);
@Override
public void click(GameContainer container) { themeSongEnabled = !themeSongEnabled; }
},
SHOW_HIT_ERROR_BAR ("Show Hit Error Bar", "Shows precisely how accurate you were with each hit.") {
@Override
public String getValueString() { return showHitErrorBar ? "Yes" : "No"; }
@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. */ /** Option name. */
private String name; private String name;
@@ -392,6 +264,18 @@ public class Options {
/** Option description. */ /** Option description. */
private String description; private String description;
/** The boolean value for the option (if applicable). */
protected boolean bool;
/** The integer value for the option (if applicable). */
protected int val;
/** The upper and lower bounds on the integer value (if applicable). */
private int max, min;
/** Whether or not this is a numeric option. */
private boolean isNumeric;
/** /**
* Constructor. * Constructor.
* @param name the option name * @param name the option name
@@ -402,6 +286,32 @@ public class Options {
this.description = description; this.description = description;
} }
/**
* Constructor.
* @param name the option name
* @param description the option description
* @param value the default boolean value
*/
GameOption(String name, String description, boolean value) {
this(name, description);
this.bool = value;
this.isNumeric = false;
}
/**
* Constructor.
* @param name the option name
* @param description the option description
* @param value the default integer value
*/
GameOption(String name, String description, int value, int min, int max) {
this(name, description);
this.val = value;
this.min = min;
this.max = max;
this.isNumeric = true;
}
/** /**
* Returns the option name. * Returns the option name.
* @return the name string * @return the name string
@@ -409,29 +319,69 @@ public class Options {
public String getName() { return name; } public String getName() { return name; }
/** /**
* Returns the option description * Returns the option description.
* @return the description string * @return the description string
*/ */
public String getDescription() { return description; } public String getDescription() { return description; }
/**
* Returns the boolean value for the option, if applicable.
* @return the boolean value
*/
public boolean getBooleanValue() { return bool; }
/**
* Returns the integer value for the option, if applicable.
* @return the integer value
*/
public int getIntegerValue() { return val; }
/**
* Sets the boolean value for the option.
* @param value the new boolean value
*/
public void setValue(boolean value) { this.bool = value; }
/**
* Sets the integer value for the option.
* @param value the new integer value
*/
public void setValue(int value) { this.val = value; }
/** /**
* Returns the value of the option as a string (via override). * Returns the value of the option as a string (via override).
* <p>
* By default, this returns "{@code val}%" if this is an numeric option,
* or "Yes" or "No" based on the {@code bool} field otherwise.
* @return the value string * @return the value string
*/ */
public String getValueString() { return ""; } public String getValueString() {
if (isNumeric)
return String.format("%d%%", val);
else
return (bool) ? "Yes" : "No";
}
/** /**
* Processes a mouse click action (via override). * Processes a mouse click action (via override).
* <p>
* By default, this inverts the current {@code bool} field.
* @param container the game container * @param container the game container
*/ */
public void click(GameContainer container) {} public void click(GameContainer container) { bool = !bool; }
/** /**
* Processes a mouse drag action (via override). * Processes a mouse drag action (via override).
* <p>
* By default, if this is a numeric option, the {@code val} field will
* be shifted by {@code d} within the given bounds.
* @param container the game container * @param container the game container
* @param d the dragged distance (modified by multiplier) * @param d the dragged distance (modified by multiplier)
*/ */
public void drag(GameContainer container, int d) {} public void drag(GameContainer container, int d) {
if (isNumeric)
val = Utils.getBoundedValue(val, d, min, max);
}
}; };
/** Screen resolutions. */ /** Screen resolutions. */
@@ -492,101 +442,18 @@ public class Options {
/** Current screen resolution. */ /** Current screen resolution. */
private static Resolution resolution = Resolution.RES_1024_768; private static Resolution resolution = Resolution.RES_1024_768;
// /** Whether or not the game should run in fullscreen mode. */
// private static boolean fullscreen = false;
/** Frame limiters. */ /** Frame limiters. */
private static final int[] targetFPS = { 60, 120, 240 }; private static final int[] targetFPS = { 60, 120, 240 };
/** Index in targetFPS[] array. */ /** Index in targetFPS[] array. */
private static int targetFPSindex = 0; private static int targetFPSindex = 0;
/** Whether or not to show the FPS. */
private static boolean showFPS = true;
/** Whether or not to show hit lighting effects. */
private static boolean showHitLighting = true;
/** Whether or not to show combo burst images. */
private static boolean showComboBursts = true;
/** Global volume level. */
private static int masterVolume = 35;
/** Default music volume. */
private static int musicVolume = 80;
/** Default sound effect volume. */
private static int effectVolume = 70;
/** Default hit sound volume. */
private static int hitSoundVolume = 30;
/** Offset time, in milliseconds, for music position-related elements. */
private static int musicOffset = -150;
/** Screenshot file formats. */ /** Screenshot file formats. */
private static String[] screenshotFormat = { "png", "jpg", "bmp" }; private static String[] screenshotFormat = { "png", "jpg", "bmp" };
/** Index in screenshotFormat[] array. */ /** Index in screenshotFormat[] array. */
private static int screenshotFormatIndex = 0; private static int screenshotFormatIndex = 0;
/** Port binding. */
private static int port = 49250;
/** Whether or not to use the new cursor type. */
private static boolean newCursor = true;
/** Whether or not dynamic backgrounds are enabled. */
private static boolean dynamicBackground = true;
/** Whether or not to display perfect hit results. */
private static boolean showPerfectHit = true;
/** Percentage to dim background images during gameplay. */
private static int backgroundDim = 50;
/** Whether or not to always display the default playfield background. */
private static boolean forceDefaultPlayfield = false;
/** Whether or not to ignore resources in the beatmap folders. */
private static boolean ignoreBeatmapSkins = false;
/** Whether or not to play the theme song. */
private static boolean themeSongEnabled = true;
/** 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,
fixedAR = 0f, fixedOD = 0f;
/** Whether or not to display the files being loaded in the splash screen. */
private static boolean loadVerbose = false;
/** Track checkpoint time, in seconds. */
private static int checkpoint = 0;
/**
* Whether or not to disable all sounds.
* This will prevent SoundController from loading sound files.
* <p>
* By default, sound is disabled on Linux due to possible driver issues.
*/
private static boolean disableSound =
(System.getProperty("os.name").toLowerCase().indexOf("linux") > -1);
/** Whether or not to display non-English metadata. */
private static boolean showUnicode = false;
/** Left and right game keys. */ /** Left and right game keys. */
private static int private static int
keyLeft = Keyboard.KEY_NONE, keyLeft = Keyboard.KEY_NONE,
@@ -605,7 +472,7 @@ public class Options {
* Returns the master volume level. * Returns the master volume level.
* @return the volume [0, 1] * @return the volume [0, 1]
*/ */
public static float getMasterVolume() { return masterVolume / 100f; } public static float getMasterVolume() { return GameOption.MASTER_VOLUME.getIntegerValue() / 100f; }
/** /**
* Sets the master volume level (if within valid range). * Sets the master volume level (if within valid range).
@@ -614,7 +481,7 @@ public class Options {
*/ */
public static void setMasterVolume(GameContainer container, float volume) { public static void setMasterVolume(GameContainer container, float volume) {
if (volume >= 0f && volume <= 1f) { if (volume >= 0f && volume <= 1f) {
masterVolume = (int) (volume * 100f); GameOption.MASTER_VOLUME.setValue((int) (volume * 100f));
container.setMusicVolume(getMasterVolume() * getMusicVolume()); container.setMusicVolume(getMasterVolume() * getMusicVolume());
} }
} }
@@ -623,25 +490,25 @@ public class Options {
* Returns the default music volume. * Returns the default music volume.
* @return the volume [0, 1] * @return the volume [0, 1]
*/ */
public static float getMusicVolume() { return musicVolume / 100f; } public static float getMusicVolume() { return GameOption.MUSIC_VOLUME.getIntegerValue() / 100f; }
/** /**
* Returns the default sound effect volume. * Returns the default sound effect volume.
* @return the sound volume [0, 1] * @return the sound volume [0, 1]
*/ */
public static float getEffectVolume() { return effectVolume / 100f; } public static float getEffectVolume() { return GameOption.EFFECT_VOLUME.getIntegerValue() / 100f; }
/** /**
* Returns the default hit sound volume. * Returns the default hit sound volume.
* @return the hit sound volume [0, 1] * @return the hit sound volume [0, 1]
*/ */
public static float getHitSoundVolume() { return hitSoundVolume / 100f; } public static float getHitSoundVolume() { return GameOption.HITSOUND_VOLUME.getIntegerValue() / 100f; }
/** /**
* Returns the music offset time. * Returns the music offset time.
* @return the offset (in milliseconds) * @return the offset (in milliseconds)
*/ */
public static int getMusicOffset() { return musicOffset; } public static int getMusicOffset() { return GameOption.MUSIC_OFFSET.getIntegerValue(); }
/** /**
* Returns the screenshot file format. * Returns the screenshot file format.
@@ -686,19 +553,19 @@ public class Options {
* Returns whether or not the FPS counter display is enabled. * Returns whether or not the FPS counter display is enabled.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isFPSCounterEnabled() { return showFPS; } public static boolean isFPSCounterEnabled() { return GameOption.SHOW_FPS.getBooleanValue(); }
/** /**
* Returns whether or not hit lighting effects are enabled. * Returns whether or not hit lighting effects are enabled.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isHitLightingEnabled() { return showHitLighting; } public static boolean isHitLightingEnabled() { return GameOption.SHOW_HIT_LIGHTING.getBooleanValue(); }
/** /**
* Returns whether or not combo burst effects are enabled. * Returns whether or not combo burst effects are enabled.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isComboBurstEnabled() { return showComboBursts; } public static boolean isComboBurstEnabled() { return GameOption.SHOW_COMBO_BURSTS.getBooleanValue(); }
/** /**
* Returns the port number to bind to. * Returns the port number to bind to.
@@ -710,91 +577,91 @@ public class Options {
* Returns whether or not the new cursor type is enabled. * Returns whether or not the new cursor type is enabled.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isNewCursorEnabled() { return newCursor; } public static boolean isNewCursorEnabled() { return GameOption.NEW_CURSOR.getBooleanValue(); }
/** /**
* Returns whether or not the main menu background should be the current track image. * Returns whether or not the main menu background should be the current track image.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isDynamicBackgroundEnabled() { return dynamicBackground; } public static boolean isDynamicBackgroundEnabled() { return GameOption.DYNAMIC_BACKGROUND.getBooleanValue(); }
/** /**
* Returns whether or not to show perfect hit result bursts. * Returns whether or not to show perfect hit result bursts.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isPerfectHitBurstEnabled() { return showPerfectHit; } public static boolean isPerfectHitBurstEnabled() { return GameOption.SHOW_PERFECT_HIT.getBooleanValue(); }
/** /**
* Returns the background dim level. * Returns the background dim level.
* @return the alpha level [0, 1] * @return the alpha level [0, 1]
*/ */
public static float getBackgroundDim() { return (100 - backgroundDim) / 100f; } public static float getBackgroundDim() { return (100 - GameOption.BACKGROUND_DIM.getIntegerValue()) / 100f; }
/** /**
* Returns whether or not to override the song background with the default playfield background. * Returns whether or not to override the song background with the default playfield background.
* @return true if forced * @return true if forced
*/ */
public static boolean isDefaultPlayfieldForced() { return forceDefaultPlayfield; } public static boolean isDefaultPlayfieldForced() { return GameOption.FORCE_DEFAULT_PLAYFIELD.getBooleanValue(); }
/** /**
* Returns whether or not beatmap skins are ignored. * Returns whether or not beatmap skins are ignored.
* @return true if ignored * @return true if ignored
*/ */
public static boolean isBeatmapSkinIgnored() { return ignoreBeatmapSkins; } public static boolean isBeatmapSkinIgnored() { return GameOption.IGNORE_BEATMAP_SKINS.getBooleanValue(); }
/** /**
* Returns the fixed circle size override, if any. * Returns the fixed circle size override, if any.
* @return the CS value (0, 10], 0 if disabled * @return the CS value (0, 10], 0f if disabled
*/ */
public static float getFixedCS() { return fixedCS; } public static float getFixedCS() { return GameOption.FIXED_CS.getIntegerValue() / 10f; }
/** /**
* Returns the fixed HP drain rate override, if any. * Returns the fixed HP drain rate override, if any.
* @return the HP value (0, 10], 0 if disabled * @return the HP value (0, 10], 0f if disabled
*/ */
public static float getFixedHP() { return fixedHP; } public static float getFixedHP() { return GameOption.FIXED_HP.getIntegerValue() / 10f; }
/** /**
* Returns the fixed approach rate override, if any. * Returns the fixed approach rate override, if any.
* @return the AR value (0, 10], 0 if disabled * @return the AR value (0, 10], 0f if disabled
*/ */
public static float getFixedAR() { return fixedAR; } public static float getFixedAR() { return GameOption.FIXED_AR.getIntegerValue() / 10f; }
/** /**
* Returns the fixed overall difficulty override, if any. * Returns the fixed overall difficulty override, if any.
* @return the OD value (0, 10], 0 if disabled * @return the OD value (0, 10], 0f if disabled
*/ */
public static float getFixedOD() { return fixedOD; } public static float getFixedOD() { return GameOption.FIXED_OD.getIntegerValue() / 10f; }
/** /**
* Returns whether or not to render loading text in the splash screen. * Returns whether or not to render loading text in the splash screen.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isLoadVerbose() { return loadVerbose; } public static boolean isLoadVerbose() { return GameOption.LOAD_VERBOSE.getBooleanValue(); }
/** /**
* Returns the track checkpoint time. * Returns the track checkpoint time.
* @return the checkpoint time (in ms) * @return the checkpoint time (in ms)
*/ */
public static int getCheckpoint() { return checkpoint * 1000; } public static int getCheckpoint() { return GameOption.CHECKPOINT.getIntegerValue() * 1000; }
/** /**
* Returns whether or not all sound effects are disabled. * Returns whether or not all sound effects are disabled.
* @return true if disabled * @return true if disabled
*/ */
public static boolean isSoundDisabled() { return disableSound; } public static boolean isSoundDisabled() { return GameOption.DISABLE_SOUNDS.getBooleanValue(); }
/** /**
* Returns whether or not to use non-English metadata where available. * Returns whether or not to use non-English metadata where available.
* @return true if Unicode preferred * @return true if Unicode preferred
*/ */
public static boolean useUnicodeMetadata() { return showUnicode; } public static boolean useUnicodeMetadata() { return GameOption.SHOW_UNICODE.getBooleanValue(); }
/** /**
* Returns whether or not to play the theme song. * Returns whether or not to play the theme song.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isThemeSongEnabled() { return themeSongEnabled; } public static boolean isThemeSongEnabled() { return GameOption.ENABLE_THEME_SONG.getBooleanValue(); }
/** /**
* Sets the track checkpoint time, if within bounds. * Sets the track checkpoint time, if within bounds.
@@ -803,7 +670,7 @@ public class Options {
*/ */
public static boolean setCheckpoint(int time) { public static boolean setCheckpoint(int time) {
if (time >= 0 && time < 3600) { if (time >= 0 && time < 3600) {
checkpoint = time; GameOption.CHECKPOINT.setValue(time);
return true; return true;
} }
return false; return false;
@@ -813,19 +680,19 @@ public class Options {
* Returns whether or not to show the hit error bar. * Returns whether or not to show the hit error bar.
* @return true if enabled * @return true if enabled
*/ */
public static boolean isHitErrorBarEnabled() { return showHitErrorBar; } public static boolean isHitErrorBarEnabled() { return GameOption.SHOW_HIT_ERROR_BAR.getBooleanValue(); }
/** /**
* Returns whether or not the mouse wheel is disabled during gameplay. * Returns whether or not the mouse wheel is disabled during gameplay.
* @return true if disabled * @return true if disabled
*/ */
public static boolean isMouseWheelDisabled() { return disableMouseWheel; } public static boolean isMouseWheelDisabled() { return GameOption.DISABLE_MOUSE_WHEEL.getBooleanValue(); }
/** /**
* Returns whether or not the mouse buttons are disabled during gameplay. * Returns whether or not the mouse buttons are disabled during gameplay.
* @return true if disabled * @return true if disabled
*/ */
public static boolean isMouseDisabled() { return disableMouseButtons; } public static boolean isMouseDisabled() { return GameOption.DISABLE_MOUSE_BUTTONS.getBooleanValue(); }
/** /**
* Returns the left game key. * Returns the left game key.
@@ -968,6 +835,7 @@ public class Options {
continue; continue;
name = line.substring(0, index).trim(); name = line.substring(0, index).trim();
value = line.substring(index + 1).trim(); value = line.substring(index + 1).trim();
try {
switch (name) { switch (name) {
case "BeatmapDirectory": case "BeatmapDirectory":
beatmapDir = new File(value); beatmapDir = new File(value);
@@ -996,7 +864,7 @@ public class Options {
} catch (IllegalArgumentException e) {} } catch (IllegalArgumentException e) {}
break; break;
// case "Fullscreen": // case "Fullscreen":
// fullscreen = Boolean.parseBoolean(value); // GameOption.FULLSCREEN.setValue(Boolean.parseBoolean(value));
// break; // break;
case "FrameSync": case "FrameSync":
i = Integer.parseInt(value); i = Integer.parseInt(value);
@@ -1011,47 +879,47 @@ public class Options {
screenshotFormatIndex = i; screenshotFormatIndex = i;
break; break;
case "FpsCounter": case "FpsCounter":
showFPS = Boolean.parseBoolean(value); GameOption.SHOW_FPS.setValue(Boolean.parseBoolean(value));
break; break;
case "ShowUnicode": case "ShowUnicode":
showUnicode = Boolean.parseBoolean(value); GameOption.SHOW_UNICODE.setValue(Boolean.parseBoolean(value));
break; break;
case "NewCursor": case "NewCursor":
newCursor = Boolean.parseBoolean(value); GameOption.NEW_CURSOR.setValue(Boolean.parseBoolean(value));
break; break;
case "DynamicBackground": case "DynamicBackground":
dynamicBackground = Boolean.parseBoolean(value); GameOption.DYNAMIC_BACKGROUND.setValue(Boolean.parseBoolean(value));
break; break;
case "LoadVerbose": case "LoadVerbose":
loadVerbose = Boolean.parseBoolean(value); GameOption.LOAD_VERBOSE.setValue(Boolean.parseBoolean(value));
break; break;
case "VolumeUniversal": case "VolumeUniversal":
i = Integer.parseInt(value); i = Integer.parseInt(value);
if (i >= 0 && i <= 100) if (i >= 0 && i <= 100)
masterVolume = i; GameOption.MASTER_VOLUME.setValue(i);
break; break;
case "VolumeMusic": case "VolumeMusic":
i = Integer.parseInt(value); i = Integer.parseInt(value);
if (i >= 0 && i <= 100) if (i >= 0 && i <= 100)
musicVolume = i; GameOption.MUSIC_VOLUME.setValue(i);
break; break;
case "VolumeEffect": case "VolumeEffect":
i = Integer.parseInt(value); i = Integer.parseInt(value);
if (i >= 0 && i <= 100) if (i >= 0 && i <= 100)
effectVolume = i; GameOption.EFFECT_VOLUME.setValue(i);
break; break;
case "VolumeHitSound": case "VolumeHitSound":
i = Integer.parseInt(value); i = Integer.parseInt(value);
if (i >= 0 && i <= 100) if (i >= 0 && i <= 100)
hitSoundVolume = i; GameOption.HITSOUND_VOLUME.setValue(i);
break; break;
case "Offset": case "Offset":
i = Integer.parseInt(value); i = Integer.parseInt(value);
if (i >= -500 && i <= 500) if (i >= -500 && i <= 500)
musicOffset = i; GameOption.MUSIC_OFFSET.setValue(i);
break; break;
case "DisableSound": case "DisableSound":
disableSound = Boolean.parseBoolean(value); GameOption.DISABLE_SOUNDS.setValue(Boolean.parseBoolean(value));
break; break;
case "keyOsuLeft": case "keyOsuLeft":
if ((value.length() == 1 && Character.isLetterOrDigit(value.charAt(0))) || if ((value.length() == 1 && Character.isLetterOrDigit(value.charAt(0))) ||
@@ -1070,59 +938,60 @@ public class Options {
} }
break; break;
case "MouseDisableWheel": case "MouseDisableWheel":
disableMouseWheel = Boolean.parseBoolean(value); GameOption.DISABLE_MOUSE_WHEEL.setValue(Boolean.parseBoolean(value));
break; break;
case "MouseDisableButtons": case "MouseDisableButtons":
disableMouseButtons = Boolean.parseBoolean(value); GameOption.DISABLE_MOUSE_BUTTONS.setValue(Boolean.parseBoolean(value));
break; break;
case "DimLevel": case "DimLevel":
i = Integer.parseInt(value); i = Integer.parseInt(value);
if (i >= 0 && i <= 100) if (i >= 0 && i <= 100)
backgroundDim = i; GameOption.BACKGROUND_DIM.setValue(i);
break; break;
case "ForceDefaultPlayfield": case "ForceDefaultPlayfield":
forceDefaultPlayfield = Boolean.parseBoolean(value); GameOption.FORCE_DEFAULT_PLAYFIELD.setValue(Boolean.parseBoolean(value));
break; break;
case "IgnoreBeatmapSkins": case "IgnoreBeatmapSkins":
ignoreBeatmapSkins = Boolean.parseBoolean(value); GameOption.IGNORE_BEATMAP_SKINS.setValue(Boolean.parseBoolean(value));
break; break;
case "HitLighting": case "HitLighting":
showHitLighting = Boolean.parseBoolean(value); GameOption.SHOW_HIT_LIGHTING.setValue(Boolean.parseBoolean(value));
break; break;
case "ComboBurst": case "ComboBurst":
showComboBursts = Boolean.parseBoolean(value); GameOption.SHOW_COMBO_BURSTS.setValue(Boolean.parseBoolean(value));
break; break;
case "PerfectHit": case "PerfectHit":
showPerfectHit = Boolean.parseBoolean(value); GameOption.SHOW_PERFECT_HIT.setValue(Boolean.parseBoolean(value));
break; break;
case "ScoreMeter": case "ScoreMeter":
showHitErrorBar = Boolean.parseBoolean(value); GameOption.SHOW_HIT_ERROR_BAR.setValue(Boolean.parseBoolean(value));
break; break;
case "FixedCS": case "FixedCS":
fixedCS = Float.parseFloat(value); GameOption.FIXED_CS.setValue((int) (Float.parseFloat(value) * 10f));
break; break;
case "FixedHP": case "FixedHP":
fixedHP = Float.parseFloat(value); GameOption.FIXED_HP.setValue((int) (Float.parseFloat(value) * 10f));
break; break;
case "FixedAR": case "FixedAR":
fixedAR = Float.parseFloat(value); GameOption.FIXED_AR.setValue((int) (Float.parseFloat(value) * 10f));
break; break;
case "FixedOD": case "FixedOD":
fixedOD = Float.parseFloat(value); GameOption.FIXED_OD.setValue((int) (Float.parseFloat(value) * 10f));
break; break;
case "Checkpoint": case "Checkpoint":
setCheckpoint(Integer.parseInt(value)); setCheckpoint(Integer.parseInt(value));
break; break;
case "MenuMusic": case "MenuMusic":
themeSongEnabled = Boolean.parseBoolean(value); GameOption.ENABLE_THEME_SONG.setValue(Boolean.parseBoolean(value));
break; break;
} }
} catch (NumberFormatException e) {
Log.warn(String.format("Format error in options file for line: '%s'.", line), e);
continue;
}
} }
} catch (IOException e) { } catch (IOException e) {
ErrorHandler.error(String.format("Failed to read file '%s'.", OPTIONS_FILE.getAbsolutePath()), e, false); ErrorHandler.error(String.format("Failed to read file '%s'.", OPTIONS_FILE.getAbsolutePath()), e, false);
} catch (NumberFormatException e) {
Log.warn("Format error in options file.", e);
return;
} }
} }
@@ -1157,67 +1026,67 @@ public class Options {
writer.newLine(); writer.newLine();
writer.write(String.format("ScreenResolution = %s", resolution.toString())); writer.write(String.format("ScreenResolution = %s", resolution.toString()));
writer.newLine(); writer.newLine();
// writer.write(String.format("Fullscreen = %b", fullscreen)); // writer.write(String.format("Fullscreen = %b", isFullscreen()));
// writer.newLine(); // writer.newLine();
writer.write(String.format("FrameSync = %d", targetFPS[targetFPSindex])); writer.write(String.format("FrameSync = %d", targetFPS[targetFPSindex]));
writer.newLine(); writer.newLine();
writer.write(String.format("FpsCounter = %b", showFPS)); writer.write(String.format("FpsCounter = %b", isFPSCounterEnabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("ShowUnicode = %b", showUnicode)); writer.write(String.format("ShowUnicode = %b", useUnicodeMetadata()));
writer.newLine(); writer.newLine();
writer.write(String.format("ScreenshotFormat = %d", screenshotFormatIndex)); writer.write(String.format("ScreenshotFormat = %d", screenshotFormatIndex));
writer.newLine(); writer.newLine();
writer.write(String.format("NewCursor = %b", newCursor)); writer.write(String.format("NewCursor = %b", isNewCursorEnabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("DynamicBackground = %b", dynamicBackground)); writer.write(String.format("DynamicBackground = %b", isDynamicBackgroundEnabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("LoadVerbose = %b", loadVerbose)); writer.write(String.format("LoadVerbose = %b", isLoadVerbose()));
writer.newLine(); writer.newLine();
writer.write(String.format("VolumeUniversal = %d", masterVolume)); writer.write(String.format("VolumeUniversal = %d", GameOption.MASTER_VOLUME.getIntegerValue()));
writer.newLine(); writer.newLine();
writer.write(String.format("VolumeMusic = %d", musicVolume)); writer.write(String.format("VolumeMusic = %d", GameOption.MUSIC_VOLUME.getIntegerValue()));
writer.newLine(); writer.newLine();
writer.write(String.format("VolumeEffect = %d", effectVolume)); writer.write(String.format("VolumeEffect = %d", GameOption.EFFECT_VOLUME.getIntegerValue()));
writer.newLine(); writer.newLine();
writer.write(String.format("VolumeHitSound = %d", hitSoundVolume)); writer.write(String.format("VolumeHitSound = %d", GameOption.HITSOUND_VOLUME.getIntegerValue()));
writer.newLine(); writer.newLine();
writer.write(String.format("Offset = %d", musicOffset)); writer.write(String.format("Offset = %d", getMusicOffset()));
writer.newLine(); writer.newLine();
writer.write(String.format("DisableSound = %b", disableSound)); writer.write(String.format("DisableSound = %b", isSoundDisabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("keyOsuLeft = %s", Keyboard.getKeyName(getGameKeyLeft()))); writer.write(String.format("keyOsuLeft = %s", Keyboard.getKeyName(getGameKeyLeft())));
writer.newLine(); writer.newLine();
writer.write(String.format("keyOsuRight = %s", Keyboard.getKeyName(getGameKeyRight()))); writer.write(String.format("keyOsuRight = %s", Keyboard.getKeyName(getGameKeyRight())));
writer.newLine(); writer.newLine();
writer.write(String.format("MouseDisableWheel = %b", disableMouseWheel)); writer.write(String.format("MouseDisableWheel = %b", isMouseWheelDisabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("MouseDisableButtons = %b", disableMouseButtons)); writer.write(String.format("MouseDisableButtons = %b", isMouseDisabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("DimLevel = %d", backgroundDim)); writer.write(String.format("DimLevel = %d", GameOption.BACKGROUND_DIM.getIntegerValue()));
writer.newLine(); writer.newLine();
writer.write(String.format("ForceDefaultPlayfield = %b", forceDefaultPlayfield)); writer.write(String.format("ForceDefaultPlayfield = %b", isDefaultPlayfieldForced()));
writer.newLine(); writer.newLine();
writer.write(String.format("IgnoreBeatmapSkins = %b", ignoreBeatmapSkins)); writer.write(String.format("IgnoreBeatmapSkins = %b", isBeatmapSkinIgnored()));
writer.newLine(); writer.newLine();
writer.write(String.format("HitLighting = %b", showHitLighting)); writer.write(String.format("HitLighting = %b", isHitLightingEnabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("ComboBurst = %b", showComboBursts)); writer.write(String.format("ComboBurst = %b", isComboBurstEnabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("PerfectHit = %b", showPerfectHit)); writer.write(String.format("PerfectHit = %b", isPerfectHitBurstEnabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("ScoreMeter = %b", showHitErrorBar)); writer.write(String.format("ScoreMeter = %b", isHitErrorBarEnabled()));
writer.newLine(); writer.newLine();
writer.write(String.format(Locale.US, "FixedCS = %.1f", fixedCS)); writer.write(String.format(Locale.US, "FixedCS = %.1f", getFixedCS()));
writer.newLine(); writer.newLine();
writer.write(String.format(Locale.US, "FixedHP = %.1f", fixedHP)); writer.write(String.format(Locale.US, "FixedHP = %.1f", getFixedHP()));
writer.newLine(); writer.newLine();
writer.write(String.format(Locale.US, "FixedAR = %.1f", fixedAR)); writer.write(String.format(Locale.US, "FixedAR = %.1f", getFixedAR()));
writer.newLine(); writer.newLine();
writer.write(String.format(Locale.US, "FixedOD = %.1f", fixedOD)); writer.write(String.format(Locale.US, "FixedOD = %.1f", getFixedOD()));
writer.newLine(); writer.newLine();
writer.write(String.format("Checkpoint = %d", checkpoint)); writer.write(String.format("Checkpoint = %d", GameOption.CHECKPOINT.getIntegerValue()));
writer.newLine(); writer.newLine();
writer.write(String.format("MenuMusic = %b", themeSongEnabled)); writer.write(String.format("MenuMusic = %b", isThemeSongEnabled()));
writer.newLine(); writer.newLine();
writer.close(); writer.close();
} catch (IOException e) { } catch (IOException e) {