Added support for Unicode (non-English) metadata.

- Setting is off by default, and can be switched on in the options menu.
- Changed default font to "Arial Unicode MS" (CJK), with fallback to "Lucida Sans Console" (non-CJK).  Cross-platform support may be added later.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2014-08-24 23:48:52 -04:00
parent 9a94c03b4e
commit 904a54df26
9 changed files with 130 additions and 21 deletions

View File

@@ -121,7 +121,7 @@ public class GameRanking extends BasicGameState {
// header text
g.setColor(Color.white);
Utils.FONT_LARGE.drawString(10, 0,
String.format("%s - %s [%s]", osu.artist, osu.title, osu.version));
String.format("%s - %s [%s]", osu.getArtist(), osu.getTitle(), osu.version));
Utils.FONT_MEDIUM.drawString(10, Utils.FONT_LARGE.getLineHeight() - 6,
String.format("Beatmap by %s", osu.creator));

View File

@@ -128,7 +128,8 @@ public class Options extends BasicGameState {
CHECKPOINT,
DISABLE_SOUNDS,
KEY_LEFT,
KEY_RIGHT;
KEY_RIGHT,
SHOW_UNICODE;
};
/**
@@ -169,6 +170,7 @@ public class Options extends BasicGameState {
// GameOption.FULLSCREEN,
GameOption.TARGET_FPS,
GameOption.SHOW_FPS,
GameOption.SHOW_UNICODE,
GameOption.SCREENSHOT_FORMAT,
GameOption.NEW_CURSOR,
GameOption.DYNAMIC_BACKGROUND,
@@ -363,6 +365,11 @@ public class Options extends BasicGameState {
private static boolean disableSound =
(System.getProperty("os.name").toLowerCase().indexOf("linux") > -1);
/**
* Whether or not to display non-English metadata.
*/
private static boolean showUnicode = false;
/**
* Left and right game keys.
*/
@@ -607,6 +614,18 @@ public class Options extends BasicGameState {
keyEntryLeft = false;
keyEntryRight = true;
break;
case SHOW_UNICODE:
showUnicode = !showUnicode;
if (showUnicode) {
try {
Utils.FONT_LARGE.loadGlyphs();
Utils.FONT_MEDIUM.loadGlyphs();
Utils.FONT_DEFAULT.loadGlyphs();
} catch (SlickException e) {
Log.warn("Failed to load glyphs.", e);
}
}
break;
default:
break;
}
@@ -780,6 +799,12 @@ public class Options extends BasicGameState {
"Show an FPS counter in the bottom-right hand corner."
);
break;
case SHOW_UNICODE:
drawOption(pos, "Prefer Non-English Metadata",
showUnicode ? "Yes" : "No",
"Where available, song titles will be shown in their native language."
);
break;
case NEW_CURSOR:
drawOption(pos, "Enable New Cursor",
newCursor ? "Yes" : "No",
@@ -1132,6 +1157,12 @@ public class Options extends BasicGameState {
*/
public static boolean isSoundDisabled() { return disableSound; }
/**
* Returns whether or not to use non-English metadata where available.
* @return true if Unicode preferred
*/
public static boolean useUnicodeMetadata() { return showUnicode; }
/**
* Sets the track checkpoint time, if within bounds.
* @param time the track position (in ms)
@@ -1288,6 +1319,9 @@ public class Options extends BasicGameState {
case "FpsCounter":
showFPS = Boolean.parseBoolean(value);
break;
case "ShowUnicode":
showUnicode = Boolean.parseBoolean(value);
break;
case "NewCursor":
newCursor = Boolean.parseBoolean(value);
break;
@@ -1416,6 +1450,8 @@ public class Options extends BasicGameState {
writer.newLine();
writer.write(String.format("FpsCounter = %b", showFPS));
writer.newLine();
writer.write(String.format("ShowUnicode = %b", showUnicode));
writer.newLine();
writer.write(String.format("ScreenshotFormat = %d", screenshotFormatIndex));
writer.newLine();
writer.write(String.format("NewCursor = %b", newCursor));

View File

@@ -240,6 +240,7 @@ public class SongMenu extends BasicGameState {
OsuGroupNode node = startNode;
for (int i = 0; i < MAX_BUTTONS && node != null; i++) {
node.draw(buttonX, buttonY + (i*buttonOffset), (node == focusNode));
Utils.loadGlyphs(node.osuFiles.get(0));
node = node.next;
}
@@ -569,7 +570,9 @@ public class SongMenu extends BasicGameState {
if (flag || (startNode.index == 0 && startNode.osuFileIndex == -1 && startNode.prev == null))
startNode = node;
focusNode = Opsu.groups.getNode(node, pos);
MusicController.play(focusNode.osuFiles.get(focusNode.osuFileIndex), true);
OsuFile osu = focusNode.osuFiles.get(focusNode.osuFileIndex);
MusicController.play(osu, true);
Utils.loadGlyphs(osu);
// check startNode bounds
while (startNode.index >= Opsu.groups.size() + length - MAX_BUTTONS && startNode.prev != null)

View File

@@ -110,7 +110,6 @@ public class Splash extends BasicGameState {
// load other resources in a new thread
final int width = container.getWidth();
final int height = container.getHeight();
final SongMenu menu = (SongMenu) game.getState(Opsu.STATE_SONGMENU);
new Thread() {
@Override
public void run() {
@@ -122,10 +121,6 @@ public class Splash extends BasicGameState {
// parse song directory
OsuParser.parseAllFiles(beatmapDir, width, height);
// initialize song list
Opsu.groups.init();
menu.setFocus(Opsu.groups.getRandomNode(), -1, true);
// load sounds
SoundController.init();
@@ -140,8 +135,13 @@ public class Splash extends BasicGameState {
logo.setAlpha(alpha + (delta / 400f));
// change states when loading complete
if (finished && alpha >= 1f)
if (finished && alpha >= 1f) {
// initialize song list
Opsu.groups.init();
((SongMenu) game.getState(Opsu.STATE_SONGMENU)).setFocus(Opsu.groups.getRandomNode(), -1, true);
game.enterState(Opsu.STATE_MAINMENU);
}
}
@Override