GameOption overhaul - moved more scattered bits into the enum.

- Added overridden methods read() and write() for reading from and writing to the options file within the GameOption enum, so that only 1 section needs to be changed when adding new options (instead of 3).
- Added 'displayName' field to the GameOption enum, instead of repeating it in the parseOptions() and saveOptions() methods.
- Added internal options (directories, port, theme song) into the GameOption enum for consistency.
- Removed GameOption.NULL.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-06-12 15:04:20 -05:00
parent 101425a562
commit 90295eefb8
2 changed files with 326 additions and 307 deletions

View File

@ -34,6 +34,7 @@ import java.io.OutputStreamWriter;
import java.net.URI; import java.net.URI;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -151,8 +152,63 @@ public class Options {
/** Game options. */ /** Game options. */
public enum GameOption { public enum GameOption {
NULL (null, null), // internal options (not displayed in-game)
SCREEN_RESOLUTION ("Screen Resolution", "Restart (Ctrl+Shift+F5) to apply resolution changes.") { BEATMAP_DIRECTORY ("BeatmapDirectory") {
@Override
public String write() { return getBeatmapDir().getAbsolutePath(); }
@Override
public void read(String s) { beatmapDir = new File(s); }
},
OSZ_DIRECTORY ("OSZDirectory") {
@Override
public String write() { return getOSZDir().getAbsolutePath(); }
@Override
public void read(String s) { oszDir = new File(s); }
},
SCREENSHOT_DIRECTORY ("ScreenshotDirectory") {
@Override
public String write() { return getScreenshotDir().getAbsolutePath(); }
@Override
public void read(String s) { screenshotDir = new File(s); }
},
REPLAY_DIRECTORY ("ReplayDirectory") {
@Override
public String write() { return getReplayDir().getAbsolutePath(); }
@Override
public void read(String s) { replayDir = new File(s); }
},
SKIN_DIRECTORY ("SkinDirectory") {
@Override
public String write() { return getSkinRootDir().getAbsolutePath(); }
@Override
public void read(String s) { skinRootDir = new File(s); }
},
THEME_SONG ("ThemeSong") {
@Override
public String write() { return themeString; }
@Override
public void read(String s) { themeString = s; }
},
PORT ("Port") {
@Override
public String write() { return Integer.toString(port); }
@Override
public void read(String s) {
int i = Integer.parseInt(s);
if (i > 0 && i < 65535)
port = i;
}
},
// in-game options
SCREEN_RESOLUTION ("Screen Resolution", "ScreenResolution", "Restart (Ctrl+Shift+F5) to apply resolution changes.") {
@Override @Override
public String getValueString() { return resolution.toString(); } public String getValueString() { return resolution.toString(); }
@ -160,13 +216,21 @@ public class Options {
public void click(GameContainer container) { public void click(GameContainer container) {
do { do {
resolution = resolution.next(); resolution = resolution.next();
} while (resolution != Resolution.RES_800_600 && } while (resolution != Resolution.RES_800_600 && (
(container.getScreenWidth() < resolution.getWidth() || container.getScreenWidth() < resolution.getWidth() ||
container.getScreenHeight() < resolution.getHeight())); container.getScreenHeight() < resolution.getHeight()));
} }
@Override
public void read(String s) {
try {
Resolution res = Resolution.valueOf(String.format("RES_%s", s.replace('x', '_')));
resolution = res;
} catch (IllegalArgumentException e) {}
}
}, },
// FULLSCREEN ("Fullscreen Mode", "Restart to apply changes.", false), // FULLSCREEN ("Fullscreen Mode", "Fullscreen", "Restart to apply changes.", false),
SKIN ("Skin", "Restart (Ctrl+Shift+F5) to apply skin changes.") { SKIN ("Skin", "Skin", "Restart (Ctrl+Shift+F5) to apply skin changes.") {
@Override @Override
public String getValueString() { return skinName; } public String getValueString() { return skinName; }
@ -175,8 +239,11 @@ public class Options {
skinDirIndex = (skinDirIndex + 1) % skinDirs.length; skinDirIndex = (skinDirIndex + 1) % skinDirs.length;
skinName = skinDirs[skinDirIndex]; skinName = skinDirs[skinDirIndex];
} }
@Override
public void read(String s) { skinName = s; }
}, },
TARGET_FPS ("Frame Limiter", "Higher values may cause high CPU usage.") { TARGET_FPS ("Frame Limiter", "FrameSync", "Higher values may cause high CPU usage.") {
@Override @Override
public String getValueString() { public String getValueString() {
return String.format((getTargetFPS() == 60) ? "%dfps (vsync)" : "%dfps", getTargetFPS()); return String.format((getTargetFPS() == 60) ? "%dfps (vsync)" : "%dfps", getTargetFPS());
@ -188,86 +255,183 @@ public class Options {
container.setTargetFrameRate(getTargetFPS()); container.setTargetFrameRate(getTargetFPS());
container.setVSync(getTargetFPS() == 60); container.setVSync(getTargetFPS() == 60);
} }
@Override
public String write() { return Integer.toString(targetFPS[targetFPSindex]); }
@Override
public void read(String s) {
int i = Integer.parseInt(s);
for (int j = 0; j < targetFPS.length; j++) {
if (i == targetFPS[j]) {
targetFPSindex = j;
break;
}
}
}
}, },
MASTER_VOLUME ("Master Volume", "Global volume level.", 35, 0, 100) { MASTER_VOLUME ("Master Volume", "VolumeUniversal", "Global volume level.", 35, 0, 100) {
@Override @Override
public void drag(GameContainer container, int d) { public void drag(GameContainer container, int d) {
super.drag(container, d); super.drag(container, d);
container.setMusicVolume(getMasterVolume() * getMusicVolume()); container.setMusicVolume(getMasterVolume() * getMusicVolume());
} }
@Override
public void read(String s) { readIntInRange(s, 0, 100); }
}, },
MUSIC_VOLUME ("Music Volume", "Volume of music.", 80, 0, 100) { MUSIC_VOLUME ("Music Volume", "VolumeMusic", "Volume of music.", 80, 0, 100) {
@Override @Override
public void drag(GameContainer container, int d) { public void drag(GameContainer container, int d) {
super.drag(container, d); super.drag(container, d);
container.setMusicVolume(getMasterVolume() * getMusicVolume()); container.setMusicVolume(getMasterVolume() * getMusicVolume());
} }
@Override
public void read(String s) { readIntInRange(s, 0, 100); }
}, },
EFFECT_VOLUME ("Effect Volume", "Volume of menu and game sounds.", 70, 0, 100), EFFECT_VOLUME ("Effect Volume", "VolumeEffect", "Volume of menu and game sounds.", 70, 0, 100) {
HITSOUND_VOLUME ("Hit Sound Volume", "Volume of hit sounds.", 30, 0, 100), @Override
MUSIC_OFFSET ("Music Offset", "Adjust this value if hit objects are out of sync.", -75, -500, 500) { public void read(String s) { readIntInRange(s, 0, 100); }
},
HITSOUND_VOLUME ("Hit Sound Volume", "VolumeHitSound", "Volume of hit sounds.", 30, 0, 100) {
@Override
public void read(String s) { readIntInRange(s, 0, 100); }
},
MUSIC_OFFSET ("Music Offset", "Offset", "Adjust this value if hit objects are out of sync.", -75, -500, 500) {
@Override @Override
public String getValueString() { return String.format("%dms", val); } public String getValueString() { return String.format("%dms", val); }
@Override
public void read(String s) { readIntInRange(s, -500, 500); }
}, },
SCREENSHOT_FORMAT ("Screenshot Format", "Press F12 to take a screenshot.") { SCREENSHOT_FORMAT ("Screenshot Format", "ScreenshotFormat", "Press F12 to take a screenshot.") {
@Override @Override
public String getValueString() { return screenshotFormat[screenshotFormatIndex].toUpperCase(); } public String getValueString() { return screenshotFormat[screenshotFormatIndex].toUpperCase(); }
@Override @Override
public void click(GameContainer container) { screenshotFormatIndex = (screenshotFormatIndex + 1) % screenshotFormat.length; } public void click(GameContainer container) { screenshotFormatIndex = (screenshotFormatIndex + 1) % screenshotFormat.length; }
@Override
public String write() { return Integer.toString(screenshotFormatIndex); }
@Override
public void read(String s) {
int i = Integer.parseInt(s);
if (i >= 0 && i < screenshotFormat.length)
screenshotFormatIndex = i;
}
}, },
SHOW_FPS ("Show FPS Counter", "Show an FPS counter in the bottom-right hand corner.", true), SHOW_FPS ("Show FPS Counter", "FpsCounter", "Show an FPS counter in the bottom-right hand corner.", true),
SHOW_HIT_LIGHTING ("Show Hit Lighting", "Adds an effect behind hit explosions.", true), SHOW_HIT_LIGHTING ("Show Hit Lighting", "HitLighting", "Adds an effect behind hit explosions.", true),
SHOW_COMBO_BURSTS ("Show Combo Bursts", "A character image is displayed at combo milestones.", true), SHOW_COMBO_BURSTS ("Show Combo Bursts", "ComboBurst", "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), SHOW_PERFECT_HIT ("Show Perfect Hits", "PerfectHit", "Whether to show perfect hit result bursts (300s, slider ticks).", true),
SHOW_FOLLOW_POINTS ("Show Follow Points", "Whether to show follow points between hit objects.", true), SHOW_FOLLOW_POINTS ("Show Follow Points", "FollowPoints", "Whether to show follow points between hit objects.", true),
NEW_CURSOR ("Enable New Cursor", "Use the new cursor style (may cause higher CPU usage).", true) { NEW_CURSOR ("Enable New Cursor", "NewCursor", "Use the new cursor style (may cause higher CPU usage).", true) {
@Override @Override
public void click(GameContainer container) { public void click(GameContainer container) {
super.click(container); super.click(container);
UI.getCursor().reset(); UI.getCursor().reset();
} }
}, },
DYNAMIC_BACKGROUND ("Enable Dynamic Backgrounds", "The song background will be used as the main menu background.", true), DYNAMIC_BACKGROUND ("Enable Dynamic Backgrounds", "DynamicBackground", "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), BACKGROUND_DIM ("Background Dim", "DimLevel", "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), @Override
IGNORE_BEATMAP_SKINS ("Ignore All Beatmap Skins", "Never use skin element overrides provided by beatmaps.", false), public void read(String s) { readIntInRange(s, 0, 100); }
FIXED_CS ("Fixed Circle Size (CS)", "Determines the size of circles and sliders.", 0, 0, 100) { },
FORCE_DEFAULT_PLAYFIELD ("Force Default Playfield", "ForceDefaultPlayfield", "Override the song background with the default playfield background.", false),
IGNORE_BEATMAP_SKINS ("Ignore All Beatmap Skins", "IgnoreBeatmapSkins", "Never use skin element overrides provided by beatmaps.", false),
FIXED_CS ("Fixed Circle Size (CS)", "FixedCS", "Determines the size of circles and sliders.", 0, 0, 100) {
@Override @Override
public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); } public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); }
@Override
public String write() { return String.format(Locale.US, "%.1f", val / 10f); }
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 10f);
if (i >= 0 && i <= 100)
val = i;
}
}, },
FIXED_HP ("Fixed HP Drain Rate (HP)", "Determines the rate at which health decreases.", 0, 0, 100) { FIXED_HP ("Fixed HP Drain Rate (HP)", "FixedHP", "Determines the rate at which health decreases.", 0, 0, 100) {
@Override @Override
public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); } public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); }
@Override
public String write() { return String.format(Locale.US, "%.1f", val / 10f); }
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 10f);
if (i >= 0 && i <= 100)
val = i;
}
}, },
FIXED_AR ("Fixed Approach Rate (AR)", "Determines how long hit circles stay on the screen.", 0, 0, 100) { FIXED_AR ("Fixed Approach Rate (AR)", "FixedAR", "Determines how long hit circles stay on the screen.", 0, 0, 100) {
@Override @Override
public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); } public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); }
@Override
public String write() { return String.format(Locale.US, "%.1f", val / 10f); }
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 10f);
if (i >= 0 && i <= 100)
val = i;
}
}, },
FIXED_OD ("Fixed Overall Difficulty (OD)", "Determines the time window for hit results.", 0, 0, 100) { FIXED_OD ("Fixed Overall Difficulty (OD)", "FixedOD", "Determines the time window for hit results.", 0, 0, 100) {
@Override @Override
public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); } public String getValueString() { return (val == 0) ? "Disabled" : String.format("%.1f", val / 10f); }
@Override
public String write() { return String.format(Locale.US, "%.1f", val / 10f); }
@Override
public void read(String s) {
int i = (int) (Float.parseFloat(s) * 10f);
if (i >= 0 && i <= 100)
val = i;
}
}, },
LOAD_VERBOSE ("Show Detailed Loading Progress", "Display more specific loading information in the splash screen.", false), LOAD_VERBOSE ("Show Detailed Loading Progress", "LoadVerbose", "Display more specific loading information in the splash screen.", false),
CHECKPOINT ("Track Checkpoint", "Press Ctrl+L while playing to load a checkpoint, and Ctrl+S to set one.", 0, 0, 3599) { CHECKPOINT ("Track Checkpoint", "Checkpoint", "Press Ctrl+L while playing to load a checkpoint, and Ctrl+S to set one.", 0, 0, 3599) {
@Override @Override
public String getValueString() { public String getValueString() {
return (val == 0) ? "Disabled" : String.format("%02d:%02d", return (val == 0) ? "Disabled" : String.format("%02d:%02d",
TimeUnit.SECONDS.toMinutes(val), TimeUnit.SECONDS.toMinutes(val),
val - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(val))); val - TimeUnit.MINUTES.toSeconds(TimeUnit.SECONDS.toMinutes(val)));
} }
@Override
public void read(String s) { readIntInRange(s, 0, 3599); }
}, },
DISABLE_SOUNDS ("Disable All Sound Effects", "May resolve Linux sound driver issues. Requires a restart.", DISABLE_SOUNDS ("Disable All Sound Effects", "DisableSound", "May resolve Linux sound driver issues. Requires a restart.",
(System.getProperty("os.name").toLowerCase().indexOf("linux") > -1)), (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", "keyOsuLeft", "Select this option to input a key.") {
@Override @Override
public String getValueString() { return Keyboard.getKeyName(getGameKeyLeft()); } public String getValueString() { return Keyboard.getKeyName(getGameKeyLeft()); }
@Override
public String write() { return Keyboard.getKeyName(getGameKeyLeft()); }
@Override
public void read(String s) { setGameKeyLeft(Keyboard.getKeyIndex(s)); }
}, },
KEY_RIGHT ("Right Game Key", "Select this option to input a key.") { KEY_RIGHT ("Right Game Key", "keyOsuRight", "Select this option to input a key.") {
@Override @Override
public String getValueString() { return Keyboard.getKeyName(getGameKeyRight()); } public String getValueString() { return Keyboard.getKeyName(getGameKeyRight()); }
@Override
public String write() { return Keyboard.getKeyName(getGameKeyRight()); }
@Override
public void read(String s) { setGameKeyRight(Keyboard.getKeyIndex(s)); }
}, },
SHOW_UNICODE ("Prefer Non-English Metadata", "Where available, song titles will be shown in their native language.", false) { SHOW_UNICODE ("Prefer Non-English Metadata", "ShowUnicode", "Where available, song titles will be shown in their native language.", false) {
@Override @Override
public void click(GameContainer container) { public void click(GameContainer container) {
super.click(container); super.click(container);
@ -282,15 +446,18 @@ public class Options {
} }
} }
}, },
ENABLE_THEME_SONG ("Enable Theme Song", "Whether to play the theme song upon starting opsu!", true), ENABLE_THEME_SONG ("Enable Theme Song", "MenuMusic", "Whether to play the theme song upon starting opsu!", true),
SHOW_HIT_ERROR_BAR ("Show Hit Error Bar", "Shows precisely how accurate you were with each hit.", false), SHOW_HIT_ERROR_BAR ("Show Hit Error Bar", "ScoreMeter", "Shows precisely how accurate you were with each hit.", false),
LOAD_HD_IMAGES ("Load HD Images", String.format("Loads HD (%s) images when available. Increases memory usage and loading times.", GameImage.HD_SUFFIX), true), LOAD_HD_IMAGES ("Load HD Images", "LoadHDImages", String.format("Loads HD (%s) images when available. Increases memory usage and loading times.", GameImage.HD_SUFFIX), true),
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_WHEEL ("Disable mouse wheel in play mode", "MouseDisableWheel", "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); DISABLE_MOUSE_BUTTONS ("Disable mouse buttons in play mode", "MouseDisableButtons", "This option will disable all mouse buttons.\nSpecifically for people who use their keyboard to click.", false);
/** Option name. */ /** Option name. */
private String name; private String name;
/** Option name, as displayed in the configuration file. */
private String displayName;
/** Option description. */ /** Option description. */
private String description; private String description;
@ -303,43 +470,58 @@ public class Options {
/** The upper and lower bounds on the integer value (if applicable). */ /** The upper and lower bounds on the integer value (if applicable). */
private int max, min; private int max, min;
/** Option types. */
private enum OptionType { BOOLEAN, NUMERIC, OTHER };
/** Whether or not this is a numeric option. */ /** Whether or not this is a numeric option. */
private boolean isNumeric; private OptionType type = OptionType.OTHER;
/** /**
* Constructor. * Constructor for internal options (not displayed in-game).
* @param displayName the option name, as displayed in the configuration file
*/
GameOption(String displayName) {
this.displayName = displayName;
}
/**
* Constructor for other option types.
* @param name the option name * @param name the option name
* @param displayName the option name, as displayed in the configuration file
* @param description the option description * @param description the option description
*/ */
GameOption(String name, String description) { GameOption(String name, String displayName, String description) {
this.name = name; this.name = name;
this.displayName = displayName;
this.description = description; this.description = description;
} }
/** /**
* Constructor. * Constructor for boolean options.
* @param name the option name * @param name the option name
* @param displayName the option name, as displayed in the configuration file
* @param description the option description * @param description the option description
* @param value the default boolean value * @param value the default boolean value
*/ */
GameOption(String name, String description, boolean value) { GameOption(String name, String displayName, String description, boolean value) {
this(name, description); this(name, displayName, description);
this.bool = value; this.bool = value;
this.isNumeric = false; this.type = OptionType.BOOLEAN;
} }
/** /**
* Constructor. * Constructor for numeric options.
* @param name the option name * @param name the option name
* @param displayName the option name, as displayed in the configuration file
* @param description the option description * @param description the option description
* @param value the default integer value * @param value the default integer value
*/ */
GameOption(String name, String description, int value, int min, int max) { GameOption(String name, String displayName, String description, int value, int min, int max) {
this(name, description); this(name, displayName, description);
this.val = value; this.val = value;
this.min = min; this.min = min;
this.max = max; this.max = max;
this.isNumeric = true; this.type = OptionType.NUMERIC;
} }
/** /**
@ -348,6 +530,12 @@ public class Options {
*/ */
public String getName() { return name; } public String getName() { return name; }
/**
* Returns the option name, as displayed in the configuration file.
* @return the display name string
*/
public String getDisplayName() { return displayName; }
/** /**
* Returns the option description. * Returns the option description.
* @return the description string * @return the description string
@ -381,15 +569,18 @@ public class Options {
/** /**
* Returns the value of the option as a string (via override). * Returns the value of the option as a string (via override).
* <p> * <p>
* By default, this returns "{@code val}%" if this is an numeric option, * By default, this returns "{@code val}%" for numeric options,
* or "Yes" or "No" based on the {@code bool} field otherwise. * "Yes" or "No" based on the {@code bool} field for boolean options,
* and an empty string otherwise.
* @return the value string * @return the value string
*/ */
public String getValueString() { public String getValueString() {
if (isNumeric) if (type == OptionType.NUMERIC)
return String.format("%d%%", val); return String.format("%d%%", val);
else else if (type == OptionType.BOOLEAN)
return (bool) ? "Yes" : "No"; return (bool) ? "Yes" : "No";
else
return "";
} }
/** /**
@ -403,17 +594,64 @@ public class Options {
/** /**
* Processes a mouse drag action (via override). * Processes a mouse drag action (via override).
* <p> * <p>
* By default, if this is a numeric option, the {@code val} field will * By default, only if this is a numeric option, the {@code val} field
* be shifted by {@code d} within the given bounds. * 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) if (type == OptionType.NUMERIC)
val = Utils.getBoundedValue(val, d, min, max); val = Utils.getBoundedValue(val, d, min, max);
} }
/**
* Returns the string to write to the configuration file (via override).
* <p>
* By default, this returns "{@code val}" for numeric options,
* "true" or "false" based on the {@code bool} field for boolean options,
* and {@link #getValueString()} otherwise.
* @return the string to write
*/
public String write() {
if (type == OptionType.NUMERIC)
return Integer.toString(val);
else if (type == OptionType.BOOLEAN)
return Boolean.toString(bool);
else
return getValueString();
}
/**
* Reads the value of the option from the configuration file (via override).
* <p>
* By default, this sets {@code val} for numeric options,
* sets {@code bool} for boolean options, and does nothing otherwise.
* @param s the value string read from the configuration file
*/
public void read(String s) {
if (type == OptionType.NUMERIC)
val = Integer.parseInt(s);
else if (type == OptionType.BOOLEAN)
bool = Boolean.parseBoolean(s);
}
/**
* Reads the value of the option from the configuration file, and sets
* {@code val} only if the value is between the given range (inclusive).
* @param s the value string read from the configuration file
* @param min the lower bound
* @param max the upper bound
*/
protected void readIntInRange(String s, int min, int max) {
int i = Integer.parseInt(s);
if (i >= min && i <= max)
val = i;
}
}; };
/** Map of option display names to GameOptions. */
private static HashMap<String, GameOption> optionMap;
/** Screen resolutions. */ /** Screen resolutions. */
private enum Resolution { private enum Resolution {
RES_800_600 (800, 600), RES_800_600 (800, 600),
@ -1000,10 +1238,16 @@ public class Options {
return; return;
} }
// create option map
if (optionMap == null) {
optionMap = new HashMap<String, GameOption>();
for (GameOption option : GameOption.values())
optionMap.put(option.getDisplayName(), option);
}
// read file
try (BufferedReader in = new BufferedReader(new FileReader(OPTIONS_FILE))) { try (BufferedReader in = new BufferedReader(new FileReader(OPTIONS_FILE))) {
String line; String line;
String name, value;
int i;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
line = line.trim(); line = line.trim();
if (line.length() < 2 || line.charAt(0) == '#') if (line.length() < 2 || line.charAt(0) == '#')
@ -1011,163 +1255,17 @@ public class Options {
int index = line.indexOf('='); int index = line.indexOf('=');
if (index == -1) if (index == -1)
continue; continue;
name = line.substring(0, index).trim();
value = line.substring(index + 1).trim(); // read option
String name = line.substring(0, index).trim();
GameOption option = optionMap.get(name);
if (option != null) {
try { try {
switch (name) { String value = line.substring(index + 1).trim();
case "BeatmapDirectory": option.read(value);
beatmapDir = new File(value);
break;
case "OSZDirectory":
oszDir = new File(value);
break;
case "ScreenshotDirectory":
screenshotDir = new File(value);
break;
case "ReplayDirectory":
replayDir = new File(value);
break;
case "SkinDirectory":
skinRootDir = new File(value);
break;
case "ThemeSong":
themeString = value;
break;
case "Port":
i = Integer.parseInt(value);
if (i > 0 && i <= 65535)
port = i;
break;
case "ScreenResolution":
try {
Resolution res = Resolution.valueOf(String.format("RES_%s", value.replace('x', '_')));
resolution = res;
} catch (IllegalArgumentException e) {}
break;
// case "Fullscreen":
// GameOption.FULLSCREEN.setValue(Boolean.parseBoolean(value));
// break;
case "Skin":
skinName = value;
break;
case "FrameSync":
i = Integer.parseInt(value);
for (int j = 0; j < targetFPS.length; j++) {
if (i == targetFPS[j])
targetFPSindex = j;
}
break;
case "ScreenshotFormat":
i = Integer.parseInt(value);
if (i >= 0 && i < screenshotFormat.length)
screenshotFormatIndex = i;
break;
case "FpsCounter":
GameOption.SHOW_FPS.setValue(Boolean.parseBoolean(value));
break;
case "ShowUnicode":
GameOption.SHOW_UNICODE.setValue(Boolean.parseBoolean(value));
break;
case "NewCursor":
GameOption.NEW_CURSOR.setValue(Boolean.parseBoolean(value));
break;
case "DynamicBackground":
GameOption.DYNAMIC_BACKGROUND.setValue(Boolean.parseBoolean(value));
break;
case "LoadVerbose":
GameOption.LOAD_VERBOSE.setValue(Boolean.parseBoolean(value));
break;
case "VolumeUniversal":
i = Integer.parseInt(value);
if (i >= 0 && i <= 100)
GameOption.MASTER_VOLUME.setValue(i);
break;
case "VolumeMusic":
i = Integer.parseInt(value);
if (i >= 0 && i <= 100)
GameOption.MUSIC_VOLUME.setValue(i);
break;
case "VolumeEffect":
i = Integer.parseInt(value);
if (i >= 0 && i <= 100)
GameOption.EFFECT_VOLUME.setValue(i);
break;
case "VolumeHitSound":
i = Integer.parseInt(value);
if (i >= 0 && i <= 100)
GameOption.HITSOUND_VOLUME.setValue(i);
break;
case "Offset":
i = Integer.parseInt(value);
if (i >= -500 && i <= 500)
GameOption.MUSIC_OFFSET.setValue(i);
break;
case "DisableSound":
GameOption.DISABLE_SOUNDS.setValue(Boolean.parseBoolean(value));
break;
case "keyOsuLeft":
setGameKeyLeft(Keyboard.getKeyIndex(value));
break;
case "keyOsuRight":
setGameKeyRight(Keyboard.getKeyIndex(value));
break;
case "MouseDisableWheel":
GameOption.DISABLE_MOUSE_WHEEL.setValue(Boolean.parseBoolean(value));
break;
case "MouseDisableButtons":
GameOption.DISABLE_MOUSE_BUTTONS.setValue(Boolean.parseBoolean(value));
break;
case "DimLevel":
i = Integer.parseInt(value);
if (i >= 0 && i <= 100)
GameOption.BACKGROUND_DIM.setValue(i);
break;
case "ForceDefaultPlayfield":
GameOption.FORCE_DEFAULT_PLAYFIELD.setValue(Boolean.parseBoolean(value));
break;
case "IgnoreBeatmapSkins":
GameOption.IGNORE_BEATMAP_SKINS.setValue(Boolean.parseBoolean(value));
break;
case "HitLighting":
GameOption.SHOW_HIT_LIGHTING.setValue(Boolean.parseBoolean(value));
break;
case "ComboBurst":
GameOption.SHOW_COMBO_BURSTS.setValue(Boolean.parseBoolean(value));
break;
case "PerfectHit":
GameOption.SHOW_PERFECT_HIT.setValue(Boolean.parseBoolean(value));
break;
case "FollowPoints":
GameOption.SHOW_FOLLOW_POINTS.setValue(Boolean.parseBoolean(value));
break;
case "ScoreMeter":
GameOption.SHOW_HIT_ERROR_BAR.setValue(Boolean.parseBoolean(value));
break;
case "LoadHDImages":
GameOption.LOAD_HD_IMAGES.setValue(Boolean.parseBoolean(value));
break;
case "FixedCS":
GameOption.FIXED_CS.setValue((int) (Float.parseFloat(value) * 10f));
break;
case "FixedHP":
GameOption.FIXED_HP.setValue((int) (Float.parseFloat(value) * 10f));
break;
case "FixedAR":
GameOption.FIXED_AR.setValue((int) (Float.parseFloat(value) * 10f));
break;
case "FixedOD":
GameOption.FIXED_OD.setValue((int) (Float.parseFloat(value) * 10f));
break;
case "Checkpoint":
setCheckpoint(Integer.parseInt(value));
break;
case "MenuMusic":
GameOption.ENABLE_THEME_SONG.setValue(Boolean.parseBoolean(value));
break;
}
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
Log.warn(String.format("Format error in options file for line: '%s'.", line), e); Log.warn(String.format("Format error in options file for line: '%s'.", line), e);
continue; }
} }
} }
} catch (IOException e) { } catch (IOException e) {
@ -1192,90 +1290,12 @@ public class Options {
writer.newLine(); writer.newLine();
// options // options
writer.write(String.format("BeatmapDirectory = %s", getBeatmapDir().getAbsolutePath())); for (GameOption option : GameOption.values()) {
writer.newLine(); writer.write(option.getDisplayName());
writer.write(String.format("OSZDirectory = %s", getOSZDir().getAbsolutePath())); writer.write(" = ");
writer.newLine(); writer.write(option.write());
writer.write(String.format("ScreenshotDirectory = %s", getScreenshotDir().getAbsolutePath()));
writer.newLine();
writer.write(String.format("ReplayDirectory = %s", getReplayDir().getAbsolutePath()));
writer.newLine();
writer.write(String.format("SkinDirectory = %s", getSkinRootDir().getAbsolutePath()));
writer.newLine();
writer.write(String.format("ThemeSong = %s", themeString));
writer.newLine();
writer.write(String.format("Port = %d", port));
writer.newLine();
writer.write(String.format("ScreenResolution = %s", resolution.toString()));
writer.newLine();
// writer.write(String.format("Fullscreen = %b", isFullscreen()));
// writer.newLine();
writer.write(String.format("Skin = %s", skinName));
writer.newLine();
writer.write(String.format("FrameSync = %d", targetFPS[targetFPSindex]));
writer.newLine();
writer.write(String.format("FpsCounter = %b", isFPSCounterEnabled()));
writer.newLine();
writer.write(String.format("ShowUnicode = %b", useUnicodeMetadata()));
writer.newLine();
writer.write(String.format("ScreenshotFormat = %d", screenshotFormatIndex));
writer.newLine();
writer.write(String.format("NewCursor = %b", isNewCursorEnabled()));
writer.newLine();
writer.write(String.format("DynamicBackground = %b", isDynamicBackgroundEnabled()));
writer.newLine();
writer.write(String.format("LoadVerbose = %b", isLoadVerbose()));
writer.newLine();
writer.write(String.format("VolumeUniversal = %d", GameOption.MASTER_VOLUME.getIntegerValue()));
writer.newLine();
writer.write(String.format("VolumeMusic = %d", GameOption.MUSIC_VOLUME.getIntegerValue()));
writer.newLine();
writer.write(String.format("VolumeEffect = %d", GameOption.EFFECT_VOLUME.getIntegerValue()));
writer.newLine();
writer.write(String.format("VolumeHitSound = %d", GameOption.HITSOUND_VOLUME.getIntegerValue()));
writer.newLine();
writer.write(String.format("Offset = %d", getMusicOffset()));
writer.newLine();
writer.write(String.format("DisableSound = %b", isSoundDisabled()));
writer.newLine();
writer.write(String.format("keyOsuLeft = %s", Keyboard.getKeyName(getGameKeyLeft())));
writer.newLine();
writer.write(String.format("keyOsuRight = %s", Keyboard.getKeyName(getGameKeyRight())));
writer.newLine();
writer.write(String.format("MouseDisableWheel = %b", isMouseWheelDisabled()));
writer.newLine();
writer.write(String.format("MouseDisableButtons = %b", isMouseDisabled()));
writer.newLine();
writer.write(String.format("DimLevel = %d", GameOption.BACKGROUND_DIM.getIntegerValue()));
writer.newLine();
writer.write(String.format("ForceDefaultPlayfield = %b", isDefaultPlayfieldForced()));
writer.newLine();
writer.write(String.format("IgnoreBeatmapSkins = %b", isBeatmapSkinIgnored()));
writer.newLine();
writer.write(String.format("HitLighting = %b", isHitLightingEnabled()));
writer.newLine();
writer.write(String.format("ComboBurst = %b", isComboBurstEnabled()));
writer.newLine();
writer.write(String.format("PerfectHit = %b", isPerfectHitBurstEnabled()));
writer.newLine();
writer.write(String.format("FollowPoints = %b", isFollowPointEnabled()));
writer.newLine();
writer.write(String.format("ScoreMeter = %b", isHitErrorBarEnabled()));
writer.newLine();
writer.write(String.format("LoadHDImages = %b", loadHDImages()));
writer.newLine();
writer.write(String.format(Locale.US, "FixedCS = %.1f", getFixedCS()));
writer.newLine();
writer.write(String.format(Locale.US, "FixedHP = %.1f", getFixedHP()));
writer.newLine();
writer.write(String.format(Locale.US, "FixedAR = %.1f", getFixedAR()));
writer.newLine();
writer.write(String.format(Locale.US, "FixedOD = %.1f", getFixedOD()));
writer.newLine();
writer.write(String.format("Checkpoint = %d", GameOption.CHECKPOINT.getIntegerValue()));
writer.newLine();
writer.write(String.format("MenuMusic = %b", isThemeSongEnabled()));
writer.newLine(); writer.newLine();
}
writer.close(); writer.close();
} catch (IOException e) { } catch (IOException e) {
ErrorHandler.error(String.format("Failed to write to file '%s'.", OPTIONS_FILE.getAbsolutePath()), e, false); ErrorHandler.error(String.format("Failed to write to file '%s'.", OPTIONS_FILE.getAbsolutePath()), e, false);

View File

@ -306,7 +306,7 @@ public class OptionsMenu extends BasicGameState {
// options (click only) // options (click only)
GameOption option = getOptionAt(y); GameOption option = getOptionAt(y);
if (option != GameOption.NULL) if (option != null)
option.click(container); option.click(container);
// special key entry states // special key entry states
@ -342,7 +342,7 @@ public class OptionsMenu extends BasicGameState {
// options (drag only) // options (drag only)
GameOption option = getOptionAt(oldy); GameOption option = getOptionAt(oldy);
if (option != GameOption.NULL) if (option != null)
option.drag(container, diff); option.drag(container, diff);
} }
@ -429,14 +429,13 @@ public class OptionsMenu extends BasicGameState {
* @return the option, or GameOption.NULL if no such option exists * @return the option, or GameOption.NULL if no such option exists
*/ */
private GameOption getOptionAt(int y) { private GameOption getOptionAt(int y) {
GameOption option = GameOption.NULL;
if (y < textY || y > textY + (offsetY * maxOptionsScreen)) if (y < textY || y > textY + (offsetY * maxOptionsScreen))
return option; return null;
int index = (y - textY + Utils.FONT_LARGE.getLineHeight()) / offsetY; int index = (y - textY + Utils.FONT_LARGE.getLineHeight()) / offsetY;
if (index < currentTab.options.length) if (index >= currentTab.options.length)
option = currentTab.options[index]; return null;
return option;
return currentTab.options[index];
} }
} }