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:
parent
637f5dc8d4
commit
f7c627e8a2
|
@ -372,9 +372,11 @@ public enum GameImage {
|
|||
|
||||
/** The unscaled container height that uiscale is based on. */
|
||||
private static final int UNSCALED_HEIGHT = 768;
|
||||
|
||||
/** Image Sizes suffixes to try to load images with */
|
||||
private static String[] imageSizeSuffix;
|
||||
|
||||
/** Image HD/SD suffixes. */
|
||||
private static final String[]
|
||||
SUFFIXES_HD = new String[] { "@2x", "" },
|
||||
SUFFIXES_SD = new String[] { "" };
|
||||
|
||||
/**
|
||||
* Initializes the GameImage class with container dimensions.
|
||||
|
@ -385,11 +387,6 @@ public enum GameImage {
|
|||
containerWidth = width;
|
||||
containerHeight = 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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).
|
||||
* @param filename the image file name
|
||||
|
@ -571,32 +576,23 @@ public enum GameImage {
|
|||
public void setDefaultImage() {
|
||||
if (defaultImage != null || defaultImages != null)
|
||||
return;
|
||||
|
||||
|
||||
// try to load multiple images
|
||||
if (filenameFormat != null) {
|
||||
defaultImages = getMutliImages(Options.getSkinDir());
|
||||
if (defaultImages != null) {
|
||||
process();
|
||||
return;
|
||||
}
|
||||
defaultImages = getMutliImages(null);
|
||||
if (defaultImages != null) {
|
||||
if (((defaultImages = loadImageArray(Options.getSkinDir())) != null) ||
|
||||
((defaultImages = loadImageArray(null)) != null)) {
|
||||
process();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
defaultImage = getSingleImage(Options.getSkinDir());
|
||||
if (defaultImage != null) {
|
||||
|
||||
// try to load a single image
|
||||
if (((defaultImage = loadImageSingle(Options.getSkinDir())) != null) ||
|
||||
((defaultImage = loadImageSingle(null)) != null)) {
|
||||
process();
|
||||
return;
|
||||
}
|
||||
|
||||
defaultImage = getSingleImage(null);
|
||||
if (defaultImage != null) {
|
||||
process();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ErrorHandler.error(String.format("Could not find default image '%s'.", filename), null, false);
|
||||
}
|
||||
|
||||
|
@ -616,43 +612,41 @@ public enum GameImage {
|
|||
if (Options.isBeatmapSkinIgnored())
|
||||
return false;
|
||||
|
||||
skinImages = getMutliImages(dir);
|
||||
if (skinImages != null) {
|
||||
// try to load multiple images
|
||||
if ((skinImages = loadImageArray(dir)) != null) {
|
||||
process();
|
||||
return true;
|
||||
}
|
||||
|
||||
skinImage = getSingleImage(dir);
|
||||
if (skinImage != null) {
|
||||
|
||||
// try to load a single image
|
||||
if ((skinImage = loadImageSingle(dir)) != null) {
|
||||
process();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to load GameImage with multiple images.
|
||||
* @return an array of images or null if not found.
|
||||
* Attempts to load multiple Images from the GameImage.
|
||||
* @return an array of the loaded images, or null if not found
|
||||
*/
|
||||
public Image[] getMutliImages(File dir){
|
||||
// load image array
|
||||
private Image[] loadImageArray(File dir) {
|
||||
if (filenameFormat != null) {
|
||||
for (String suf : imageSizeSuffix) {
|
||||
for (String suffix : getSuffixes()) {
|
||||
List<Image> list = new ArrayList<Image>();
|
||||
int i = 0;
|
||||
while (true) {
|
||||
// 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);
|
||||
if (name == null)
|
||||
break;
|
||||
|
||||
|
||||
// add image to list
|
||||
try {
|
||||
System.out.println(name);
|
||||
Image img = new Image(name);
|
||||
if(suf.equals("@2x"))
|
||||
if (suffix.equals("@2x"))
|
||||
img = img.getScaledCopy(0.5f);
|
||||
list.add(img);
|
||||
} catch (SlickException e) {
|
||||
|
@ -660,27 +654,24 @@ public enum GameImage {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
if (!list.isEmpty())
|
||||
return list.toArray(new Image[list.size()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to load GameImage with a single image.
|
||||
* @return an image or null if not found.
|
||||
* Attempts to load a single Image from the GameImage.
|
||||
* @return the loaded image, or null if not found
|
||||
*/
|
||||
public Image getSingleImage(File dir){
|
||||
for (String suf : imageSizeSuffix) {
|
||||
// load single image
|
||||
String name = getImageFileName(filename+suf, dir, type, true);
|
||||
private Image loadImageSingle(File dir) {
|
||||
for (String suffix : getSuffixes()) {
|
||||
String name = getImageFileName(filename + suffix, dir, type, true);
|
||||
if (name != null) {
|
||||
try {
|
||||
Image img = new Image(name);
|
||||
System.out.println(name);
|
||||
if(suf.equals("@2x"))
|
||||
if (suffix.equals("@2x"))
|
||||
img = img.getScaledCopy(0.5f);
|
||||
return img;
|
||||
} catch (SlickException e) {
|
||||
|
@ -734,9 +725,7 @@ public enum GameImage {
|
|||
* @param h the container height
|
||||
* @return the processed image
|
||||
*/
|
||||
protected Image process_sub(Image img, int w, int h) {
|
||||
return img;
|
||||
}
|
||||
protected Image process_sub(Image img, int w, int h) { return img; }
|
||||
|
||||
/**
|
||||
* Performs individual post-loading actions on the image.
|
||||
|
|
|
@ -257,7 +257,7 @@ public class Options {
|
|||
},
|
||||
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),
|
||||
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_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
|
||||
*/
|
||||
public static boolean isHitErrorBarEnabled() { return GameOption.SHOW_HIT_ERROR_BAR.getBooleanValue(); }
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not to use 2x Images
|
||||
* @return true if ignored
|
||||
* Returns whether or not to load HD (@2x) images.
|
||||
* @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.
|
||||
|
@ -1030,8 +1028,8 @@ public class Options {
|
|||
case "ScoreMeter":
|
||||
GameOption.SHOW_HIT_ERROR_BAR.setValue(Boolean.parseBoolean(value));
|
||||
break;
|
||||
case "Use2xImage":
|
||||
GameOption.USE_2X_IMAGE.setValue(Boolean.parseBoolean(value));
|
||||
case "LoadHDImages":
|
||||
GameOption.LOAD_HD_IMAGES.setValue(Boolean.parseBoolean(value));
|
||||
break;
|
||||
case "FixedCS":
|
||||
GameOption.FIXED_CS.setValue((int) (Float.parseFloat(value) * 10f));
|
||||
|
@ -1145,7 +1143,7 @@ public class Options {
|
|||
writer.newLine();
|
||||
writer.write(String.format("ScoreMeter = %b", isHitErrorBarEnabled()));
|
||||
writer.newLine();
|
||||
writer.write(String.format("Use2xImage = %b", is2xImagesEnabled()));
|
||||
writer.write(String.format("LoadHDImages = %b", loadHDImages()));
|
||||
writer.newLine();
|
||||
writer.write(String.format(Locale.US, "FixedCS = %.1f", getFixedCS()));
|
||||
writer.newLine();
|
||||
|
|
|
@ -55,7 +55,7 @@ public class CircumscribedCircle extends Curve {
|
|||
|
||||
/** The number of steps in the curve to draw. */
|
||||
private float step;
|
||||
|
||||
|
||||
/** Points along the curve. */
|
||||
private Vec2f[] curve;
|
||||
|
||||
|
@ -123,7 +123,8 @@ public class CircumscribedCircle extends Curve {
|
|||
// finds the angles to draw for repeats
|
||||
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);
|
||||
|
||||
|
||||
// calculate points
|
||||
curve = new Vec2f[(int) step + 1];
|
||||
for (int i = 0; i < curve.length; i++) {
|
||||
float[] xy = pointAt(i / step);
|
||||
|
@ -181,9 +182,8 @@ public class CircumscribedCircle extends Curve {
|
|||
public void draw() {
|
||||
Image hitCircle = GameImage.HITCIRCLE.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);
|
||||
}
|
||||
for (int i = 0; i < step; i++)
|
||||
hitCircle.drawCentered(curve[i].x, curve[i].y, color);
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class OptionsMenu extends BasicGameState {
|
|||
GameOption.FIXED_AR,
|
||||
GameOption.FIXED_OD,
|
||||
GameOption.CHECKPOINT,
|
||||
GameOption.USE_2X_IMAGE
|
||||
GameOption.LOAD_HD_IMAGES
|
||||
});
|
||||
|
||||
/** Total number of tabs. */
|
||||
|
|
Loading…
Reference in New Issue
Block a user