Beatmap downloader improvements and fixes.
Updates: - Added some buttons to downloads menu: clear inactive downloads, import beatmaps, reset search, and show/hide unranked maps. - Small changes to OsuParser, OszUnpacker, and OsuGroupList (mostly adding return values) to allow parsing only newly unpacked beatmaps. - Added alpha fade hover effect to MenuButton, as an alternative to expanding (used for 3-part menu buttons). - Added text rendering fields to MenuButton (also for the 3-part menu buttons). - Added sound effects to downloads menu. Fixes: - Check downloads for illegal filename characters, and remove them if necessary. - The number of results and downloads shown now supports all resolutions. - Confirmation dialog no longer appears when restarting the application (since downloads are static). - Do not set a focus node immediately if the theme song will be played. - Always play the theme song if no songs are loaded (even if disabled in settings). Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
@@ -28,6 +28,7 @@ import java.io.File;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -109,6 +110,19 @@ public class Utils {
|
||||
/** Set of all Unicode strings already loaded. */
|
||||
private static HashSet<String> loadedGlyphs = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* List of illegal filename characters.
|
||||
* @see #cleanFileName(String, char)
|
||||
*/
|
||||
private final static int[] illegalChars = {
|
||||
34, 60, 62, 124, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
|
||||
24, 25, 26, 27, 28, 29, 30, 31, 58, 42, 63, 92, 47
|
||||
};
|
||||
static {
|
||||
Arrays.sort(illegalChars);
|
||||
}
|
||||
|
||||
// game-related variables
|
||||
private static GameContainer container;
|
||||
private static StateBasedGame game;
|
||||
@@ -211,7 +225,7 @@ public class Utils {
|
||||
backButton = new MenuButton(back,
|
||||
back.getWidth() / 2f,
|
||||
height - (back.getHeight() / 2f));
|
||||
backButton.setHoverDir(MenuButton.Expand.UP_RIGHT);
|
||||
backButton.setHoverExpand(MenuButton.Expand.UP_RIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -704,4 +718,24 @@ public class Utils {
|
||||
char pre = "KMGTPE".charAt(exp - 1);
|
||||
return String.format("%.1f %cB", bytes / Math.pow(1024, exp), pre);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans a file name.
|
||||
* @param badFileName the original name string
|
||||
* @param replace the character to replace illegal characters with (or 0 if none)
|
||||
* @return the cleaned file name
|
||||
* @author Sarel Botha (http://stackoverflow.com/a/5626340)
|
||||
*/
|
||||
public static String cleanFileName(String badFileName, char replace) {
|
||||
boolean doReplace = (replace > 0 && Arrays.binarySearch(illegalChars, replace) < 0);
|
||||
StringBuilder cleanName = new StringBuilder();
|
||||
for (int i = 0, n = badFileName.length(); i < n; i++) {
|
||||
int c = badFileName.charAt(i);
|
||||
if (Arrays.binarySearch(illegalChars, c) < 0)
|
||||
cleanName.append((char) c);
|
||||
else if (doReplace)
|
||||
cleanName.append(replace);
|
||||
}
|
||||
return cleanName.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user