Follow-up to #49.

Allowed toggling HD image loading in-game; changed some names; other minor formatting changes.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-03-14 23:28:50 -04:00
parent 637f5dc8d4
commit f7c627e8a2
4 changed files with 57 additions and 70 deletions

View File

@ -372,9 +372,11 @@ public enum GameImage {
/** The unscaled container height that uiscale is based on. */ /** The unscaled container height that uiscale is based on. */
private static final int UNSCALED_HEIGHT = 768; private static final int UNSCALED_HEIGHT = 768;
/** Image Sizes suffixes to try to load images with */ /** Image HD/SD suffixes. */
private static String[] imageSizeSuffix; private static final String[]
SUFFIXES_HD = new String[] { "@2x", "" },
SUFFIXES_SD = new String[] { "" };
/** /**
* Initializes the GameImage class with container dimensions. * Initializes the GameImage class with container dimensions.
@ -385,11 +387,6 @@ public enum GameImage {
containerWidth = width; containerWidth = width;
containerHeight = height; containerHeight = height;
uiscale = (float) containerHeight / UNSCALED_HEIGHT; uiscale = (float) containerHeight / UNSCALED_HEIGHT;
if (Options.is2xImagesEnabled() && uiscale >= 1) {
imageSizeSuffix = new String[]{"@2x",""};
} else {
imageSizeSuffix = new String[]{""};
}
} }
/** /**
@ -463,6 +460,14 @@ public enum GameImage {
return null; return null;
} }
/**
* Returns an array of HD/SD file name suffixes based on the current options
* and UI scale.
*/
private static String[] getSuffixes() {
return (Options.loadHDImages() && uiscale >= 1) ? SUFFIXES_HD : SUFFIXES_SD;
}
/** /**
* Constructor for game-related images (skinnable and preloaded). * Constructor for game-related images (skinnable and preloaded).
* @param filename the image file name * @param filename the image file name
@ -571,32 +576,23 @@ public enum GameImage {
public void setDefaultImage() { public void setDefaultImage() {
if (defaultImage != null || defaultImages != null) if (defaultImage != null || defaultImages != null)
return; return;
// try to load multiple images
if (filenameFormat != null) { if (filenameFormat != null) {
defaultImages = getMutliImages(Options.getSkinDir()); if (((defaultImages = loadImageArray(Options.getSkinDir())) != null) ||
if (defaultImages != null) { ((defaultImages = loadImageArray(null)) != null)) {
process();
return;
}
defaultImages = getMutliImages(null);
if (defaultImages != null) {
process(); process();
return; return;
} }
} }
defaultImage = getSingleImage(Options.getSkinDir()); // try to load a single image
if (defaultImage != null) { if (((defaultImage = loadImageSingle(Options.getSkinDir())) != null) ||
((defaultImage = loadImageSingle(null)) != null)) {
process(); process();
return; return;
} }
defaultImage = getSingleImage(null);
if (defaultImage != null) {
process();
return;
}
ErrorHandler.error(String.format("Could not find default image '%s'.", filename), null, false); ErrorHandler.error(String.format("Could not find default image '%s'.", filename), null, false);
} }
@ -616,43 +612,41 @@ public enum GameImage {
if (Options.isBeatmapSkinIgnored()) if (Options.isBeatmapSkinIgnored())
return false; return false;
skinImages = getMutliImages(dir); // try to load multiple images
if (skinImages != null) { if ((skinImages = loadImageArray(dir)) != null) {
process(); process();
return true; return true;
} }
skinImage = getSingleImage(dir); // try to load a single image
if (skinImage != null) { if ((skinImage = loadImageSingle(dir)) != null) {
process(); process();
return true; return true;
} }
return false; return false;
} }
/** /**
* Attempts to load GameImage with multiple images. * Attempts to load multiple Images from the GameImage.
* @return an array of images or null if not found. * @return an array of the loaded images, or null if not found
*/ */
public Image[] getMutliImages(File dir){ private Image[] loadImageArray(File dir) {
// load image array
if (filenameFormat != null) { if (filenameFormat != null) {
for (String suf : imageSizeSuffix) { for (String suffix : getSuffixes()) {
List<Image> list = new ArrayList<Image>(); List<Image> list = new ArrayList<Image>();
int i = 0; int i = 0;
while (true) { while (true) {
// look for next image // look for next image
String filenameFormatted = String.format(filenameFormat+suf, i++); String filenameFormatted = String.format(filenameFormat + suffix, i++);
String name = getImageFileName(filenameFormatted, dir, type, true); String name = getImageFileName(filenameFormatted, dir, type, true);
if (name == null) if (name == null)
break; break;
// add image to list // add image to list
try { try {
System.out.println(name);
Image img = new Image(name); Image img = new Image(name);
if(suf.equals("@2x")) if (suffix.equals("@2x"))
img = img.getScaledCopy(0.5f); img = img.getScaledCopy(0.5f);
list.add(img); list.add(img);
} catch (SlickException e) { } catch (SlickException e) {
@ -660,27 +654,24 @@ public enum GameImage {
break; break;
} }
} }
if (!list.isEmpty()) { if (!list.isEmpty())
return list.toArray(new Image[list.size()]); return list.toArray(new Image[list.size()]);
}
} }
} }
return null; return null;
} }
/** /**
* Attempts to load GameImage with a single image. * Attempts to load a single Image from the GameImage.
* @return an image or null if not found. * @return the loaded image, or null if not found
*/ */
public Image getSingleImage(File dir){ private Image loadImageSingle(File dir) {
for (String suf : imageSizeSuffix) { for (String suffix : getSuffixes()) {
// load single image String name = getImageFileName(filename + suffix, dir, type, true);
String name = getImageFileName(filename+suf, dir, type, true);
if (name != null) { if (name != null) {
try { try {
Image img = new Image(name); Image img = new Image(name);
System.out.println(name); if (suffix.equals("@2x"))
if(suf.equals("@2x"))
img = img.getScaledCopy(0.5f); img = img.getScaledCopy(0.5f);
return img; return img;
} catch (SlickException e) { } catch (SlickException e) {
@ -734,9 +725,7 @@ public enum GameImage {
* @param h the container height * @param h the container height
* @return the processed image * @return the processed image
*/ */
protected Image process_sub(Image img, int w, int h) { protected Image process_sub(Image img, int w, int h) { return img; }
return img;
}
/** /**
* Performs individual post-loading actions on the image. * Performs individual post-loading actions on the image.

View File

@ -257,7 +257,7 @@ 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", "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", "Shows precisely how accurate you were with each hit.", false),
USE_2X_IMAGE ("Use @2x Images", "Uses @2x images if available.", true), LOAD_HD_IMAGES ("Load HD Images", "Loads HD (@2x) images when available. Increases memory usage and loading times.", 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", "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", "This option will disable all mouse buttons.\nSpecifically for people who use their keyboard to click.", false);
@ -694,14 +694,12 @@ public class Options {
* @return true if enabled * @return true if enabled
*/ */
public static boolean isHitErrorBarEnabled() { return GameOption.SHOW_HIT_ERROR_BAR.getBooleanValue(); } public static boolean isHitErrorBarEnabled() { return GameOption.SHOW_HIT_ERROR_BAR.getBooleanValue(); }
/** /**
* Returns whether or not to use 2x Images * Returns whether or not to load HD (@2x) images.
* @return true if ignored * @return true if HD images are enabled, false if only SD images should be loaded
*/ */
public static boolean is2xImagesEnabled() { return GameOption.USE_2X_IMAGE.getBooleanValue(); } public static boolean loadHDImages() { return GameOption.LOAD_HD_IMAGES.getBooleanValue(); }
/** /**
* Returns whether or not the mouse wheel is disabled during gameplay. * Returns whether or not the mouse wheel is disabled during gameplay.
@ -1030,8 +1028,8 @@ public class Options {
case "ScoreMeter": case "ScoreMeter":
GameOption.SHOW_HIT_ERROR_BAR.setValue(Boolean.parseBoolean(value)); GameOption.SHOW_HIT_ERROR_BAR.setValue(Boolean.parseBoolean(value));
break; break;
case "Use2xImage": case "LoadHDImages":
GameOption.USE_2X_IMAGE.setValue(Boolean.parseBoolean(value)); GameOption.LOAD_HD_IMAGES.setValue(Boolean.parseBoolean(value));
break; break;
case "FixedCS": case "FixedCS":
GameOption.FIXED_CS.setValue((int) (Float.parseFloat(value) * 10f)); GameOption.FIXED_CS.setValue((int) (Float.parseFloat(value) * 10f));
@ -1145,7 +1143,7 @@ public class Options {
writer.newLine(); writer.newLine();
writer.write(String.format("ScoreMeter = %b", isHitErrorBarEnabled())); writer.write(String.format("ScoreMeter = %b", isHitErrorBarEnabled()));
writer.newLine(); writer.newLine();
writer.write(String.format("Use2xImage = %b", is2xImagesEnabled())); writer.write(String.format("LoadHDImages = %b", loadHDImages()));
writer.newLine(); writer.newLine();
writer.write(String.format(Locale.US, "FixedCS = %.1f", getFixedCS())); writer.write(String.format(Locale.US, "FixedCS = %.1f", getFixedCS()));
writer.newLine(); writer.newLine();

View File

@ -55,7 +55,7 @@ public class CircumscribedCircle extends Curve {
/** The number of steps in the curve to draw. */ /** The number of steps in the curve to draw. */
private float step; private float step;
/** Points along the curve. */ /** Points along the curve. */
private Vec2f[] curve; private Vec2f[] curve;
@ -123,7 +123,8 @@ public class CircumscribedCircle extends Curve {
// finds the angles to draw for repeats // finds the angles to draw for repeats
this.drawEndAngle = (float) ((endAng + (startAng > endAng ? HALF_PI : -HALF_PI)) * 180 / Math.PI); this.drawEndAngle = (float) ((endAng + (startAng > endAng ? HALF_PI : -HALF_PI)) * 180 / Math.PI);
this.drawStartAngle = (float) ((startAng + (startAng > endAng ? -HALF_PI : HALF_PI)) * 180 / Math.PI); this.drawStartAngle = (float) ((startAng + (startAng > endAng ? -HALF_PI : HALF_PI)) * 180 / Math.PI);
// calculate points
curve = new Vec2f[(int) step + 1]; curve = new Vec2f[(int) step + 1];
for (int i = 0; i < curve.length; i++) { for (int i = 0; i < curve.length; i++) {
float[] xy = pointAt(i / step); float[] xy = pointAt(i / step);
@ -181,9 +182,8 @@ public class CircumscribedCircle extends Curve {
public void draw() { public void draw() {
Image hitCircle = GameImage.HITCIRCLE.getImage(); Image hitCircle = GameImage.HITCIRCLE.getImage();
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage(); Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
for (int i = 0; i < step; i++) { for (int i = 0; i < step; i++)
hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE); hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE);
}
for (int i = 0; i < step; i++) for (int i = 0; i < step; i++)
hitCircle.drawCentered(curve[i].x, curve[i].y, color); hitCircle.drawCentered(curve[i].x, curve[i].y, color);
} }

View File

@ -90,7 +90,7 @@ public class OptionsMenu extends BasicGameState {
GameOption.FIXED_AR, GameOption.FIXED_AR,
GameOption.FIXED_OD, GameOption.FIXED_OD,
GameOption.CHECKPOINT, GameOption.CHECKPOINT,
GameOption.USE_2X_IMAGE GameOption.LOAD_HD_IMAGES
}); });
/** Total number of tabs. */ /** Total number of tabs. */