add native resolution to resolution list

This commit is contained in:
yugecin 2016-10-11 11:37:47 +02:00
parent b1887b953b
commit 35695ccf97

View File

@ -283,23 +283,30 @@ 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 + "";
} }
}, },
FULLSCREEN ("Fullscreen Mode", "Fullscreen", "Restart to apply changes.", false), FULLSCREEN ("Fullscreen Mode", "Fullscreen", "Restart to apply changes.", false),
@ -1276,63 +1283,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;
@ -1451,23 +1423,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 (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));
} }
} }