merge branch 'resolutions' into master, close #11

This commit is contained in:
yugecin 2016-10-11 11:51:56 +02:00
commit 091ea9a13e
2 changed files with 71 additions and 69 deletions

View File

@ -283,25 +283,33 @@ public class Options {
// in-game options // in-game options
SCREEN_RESOLUTION ("Screen Resolution", "ScreenResolution", "Restart (Ctrl+Shift+F5) to apply resolution changes.") { 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 resolutions[resolutionIdx];
}
@Override @Override
public Object[] getListItems() { public Object[] getListItems() {
return Resolution.values(); return resolutions;
} }
@Override @Override
public void clickListItem(int index) { public void clickListItem(int index) {
resolution = Resolution.values()[index]; resolutionIdx = index;
} }
@Override @Override
public void read(String s) { public void read(String s) {
try { try {
resolution = Resolution.valueOf(String.format("RES_%s", s.replace('x', '_'))); resolutionIdx = Integer.parseInt(s);
} catch (IllegalArgumentException ignored) {} } catch (NumberFormatException ignored) { }
}
@Override
public String write() {
return resolutionIdx + "";
} }
}, },
ALLOW_LARGER_RESOLUTIONS ("Allow large resolutions", "AllowLargeRes", "Allow resolutions larger than the native resolution", false),
FULLSCREEN ("Fullscreen Mode", "Fullscreen", "Restart to apply changes.", false), FULLSCREEN ("Fullscreen Mode", "Fullscreen", "Restart to apply changes.", false),
SKIN ("Skin", "Skin", "Restart (Ctrl+Shift+F5) to apply skin changes.") { SKIN ("Skin", "Skin", "Restart (Ctrl+Shift+F5) to apply skin changes.") {
@Override @Override
@ -1276,63 +1284,28 @@ public class Options {
/** Map of option display names to GameOptions. */ /** Map of option display names to GameOptions. */
private static HashMap<String, GameOption> optionMap; private static HashMap<String, GameOption> optionMap;
/** Screen resolutions. */ private static String[] resolutions = {
private enum Resolution { null,
RES_800_600 (800, 600), "800x600",
RES_1024_600 (1024, 600), "1024x600",
RES_1024_768 (1024, 768), "1024x768",
RES_1280_720 (1280, 720), "1280x720",
RES_1280_800 (1280, 800), "1280x800",
RES_1280_960 (1280, 960), "1280x960",
RES_1280_1024 (1280, 1024), "1280x1024",
RES_1366_768 (1366, 768), "1366x768",
RES_1440_900 (1440, 900), "1440x900",
RES_1600_900 (1600, 900), "1600x900",
RES_1600_1200 (1600, 1200), "1600x1200",
RES_1680_1050 (1680, 1050), "1680x1050",
RES_1920_1080 (1920, 1080), "1920x1080",
RES_1920_1200 (1920, 1200), "1920x1200",
RES_2560_1440 (2560, 1440), "2560x1440",
RES_2560_1600 (2560, 1600), "2560x1600",
RES_3840_2160 (3840, 2160); "3840x2160"
};
/** Screen dimensions. */ private static int resolutionIdx;
private int width, height;
/** Enum values. */
private static Resolution[] values = Resolution.values();
/**
* Constructor.
* @param width the screen width
* @param height the screen height
*/
Resolution(int width, int height) {
this.width = width;
this.height = height;
}
/**
* Returns the screen width.
*/
public int getWidth() { return width; }
/**
* Returns the screen height.
*/
public int getHeight() { return height; }
/**
* Returns the next (larger) Resolution.
*/
public Resolution next() { return values[(this.ordinal() + 1) % values.length]; }
@Override
public String toString() { return String.format("%sx%s", width, height); }
}
/** Current screen resolution. */
private static Resolution resolution = Resolution.RES_1024_768;
public static int width; public static int width;
public static int height; public static int height;
@ -1369,6 +1342,14 @@ public class Options {
// This class should not be instantiated. // This class should not be instantiated.
private Options() {} private Options() {}
public static int getResolutionIdx() {
return resolutionIdx;
}
public static boolean allowLargeResolutions() {
return GameOption.ALLOW_LARGER_RESOLUTIONS.getBooleanValue();
}
/** /**
* Returns the target frame rate. * Returns the target frame rate.
* @return the target FPS * @return the target FPS
@ -1451,23 +1432,32 @@ public class Options {
int screenWidth = app.getScreenWidth(); int screenWidth = app.getScreenWidth();
int screenHeight = app.getScreenHeight(); int screenHeight = app.getScreenHeight();
resolutions[0] = screenWidth + "x" + screenHeight;
if (resolutionIdx < 0 || resolutionIdx > resolutions.length) {
resolutionIdx = 0;
}
if (!resolutions[resolutionIdx].matches("^[0-9]+x[0-9]+$")) {
resolutionIdx = 0;
}
String[] res = resolutions[resolutionIdx].split("x");
width = Integer.parseInt(res[0]);
height = Integer.parseInt(res[1]);
// check for larger-than-screen dimensions // check for larger-than-screen dimensions
if (screenWidth < resolution.getWidth() || screenHeight < resolution.getHeight()) if (!GameOption.ALLOW_LARGER_RESOLUTIONS.getBooleanValue() && (screenWidth < width || screenHeight < height)) {
resolution = Resolution.RES_800_600; width = 800;
height = 600;
}
try { try {
app.setDisplayMode(resolution.getWidth(), resolution.getHeight(), false); app.setDisplayMode(width, height, isFullscreen());
app.setFullscreen(isFullscreen());
} catch (SlickException e) { } catch (SlickException e) {
ErrorHandler.error("Failed to set display mode.", e, true); ErrorHandler.error("Failed to set display mode.", e, true);
} }
width = resolution.width;
height = resolution.height;
if (!isFullscreen()) { if (!isFullscreen()) {
// set borderless window if dimensions match screen size // set borderless window if dimensions match screen size
boolean borderless = (screenWidth == resolution.getWidth() && screenHeight == resolution.getHeight()); boolean borderless = (screenWidth == width && screenHeight == height);
System.setProperty("org.lwjgl.opengl.Window.undecorated", Boolean.toString(borderless)); System.setProperty("org.lwjgl.opengl.Window.undecorated", Boolean.toString(borderless));
} }
} }

View File

@ -57,6 +57,7 @@ public class OptionsMenu extends BasicGameState {
DISPLAY ("Display", new GameOption[] { DISPLAY ("Display", new GameOption[] {
GameOption.SCREEN_RESOLUTION, GameOption.SCREEN_RESOLUTION,
GameOption.FULLSCREEN, GameOption.FULLSCREEN,
GameOption.ALLOW_LARGER_RESOLUTIONS,
GameOption.SKIN, GameOption.SKIN,
GameOption.TARGET_FPS, GameOption.TARGET_FPS,
GameOption.SHOW_FPS, GameOption.SHOW_FPS,
@ -508,11 +509,22 @@ public class OptionsMenu extends BasicGameState {
} }
} }
private String resolutionOptions;
@Override @Override
public void enter(GameContainer container, StateBasedGame game) public void enter(GameContainer container, StateBasedGame game)
throws SlickException { throws SlickException {
UI.enter(); UI.enter();
currentTab = OptionTab.DANCE; currentTab = OptionTab.DANCE;
resolutionOptions = "" + Options.getResolutionIdx() + Options.isFullscreen() + Options.allowLargeResolutions();
}
@Override
public void leave(GameContainer container, StateBasedGame game) throws SlickException {
if (!("" + Options.getResolutionIdx() + Options.isFullscreen() + Options.allowLargeResolutions()).equals(resolutionOptions)) {
container.setForceExit(false);
container.exit();
}
} }
/** /**