diff --git a/src/itdelatrisu/opsu/OsuGroupNode.java b/src/itdelatrisu/opsu/OsuGroupNode.java index 18f32a9d..8c8e15d2 100644 --- a/src/itdelatrisu/opsu/OsuGroupNode.java +++ b/src/itdelatrisu/opsu/OsuGroupNode.java @@ -91,6 +91,10 @@ public class OsuGroupNode { } // draw text + if (Options.useUnicodeMetadata()) { // load glyphs + Utils.loadGlyphs(Utils.FONT_MEDIUM, osu.titleUnicode, null); + Utils.loadGlyphs(Utils.FONT_DEFAULT, null, osu.artistUnicode); + } Utils.FONT_MEDIUM.drawString(cx, cy, osu.getTitle(), textColor); Utils.FONT_DEFAULT.drawString(cx, cy + Utils.FONT_MEDIUM.getLineHeight() - 4, String.format("%s // %s", osu.getArtist(), osu.creator), textColor); diff --git a/src/itdelatrisu/opsu/Utils.java b/src/itdelatrisu/opsu/Utils.java index b8f4eb6b..2449d184 100644 --- a/src/itdelatrisu/opsu/Utils.java +++ b/src/itdelatrisu/opsu/Utils.java @@ -42,6 +42,7 @@ import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Scanner; @@ -102,8 +103,8 @@ public class Utils { FONT_DEFAULT, FONT_BOLD, FONT_XLARGE, FONT_LARGE, FONT_MEDIUM, FONT_SMALL; - /** Set of all Unicode strings already loaded. */ - private static HashSet loadedGlyphs = new HashSet(); + /** Set of all Unicode strings already loaded per font. */ + private static HashMap> loadedGlyphs = new HashMap>(); /** * List of illegal filename characters. @@ -331,33 +332,34 @@ public class Utils { } /** - * Adds and loads glyphs for an OsuFile's Unicode title and artist strings. - * @param osu the OsuFile + * Adds and loads glyphs for a beatmap's Unicode title and artist strings. + * @param font the font to add the glyphs to + * @param title the title string + * @param artist the artist string */ - public static void loadGlyphs(OsuFile osu) { - if (!Options.useUnicodeMetadata()) - return; + public static void loadGlyphs(UnicodeFont font, String title, String artist) { + // get set of added strings + HashSet set = loadedGlyphs.get(font); + if (set == null) { + set = new HashSet(); + loadedGlyphs.put(font, set); + } + // add glyphs if not in set boolean glyphsAdded = false; - if (!osu.titleUnicode.isEmpty() && !loadedGlyphs.contains(osu.titleUnicode)) { - Utils.FONT_LARGE.addGlyphs(osu.titleUnicode); - Utils.FONT_MEDIUM.addGlyphs(osu.titleUnicode); - Utils.FONT_DEFAULT.addGlyphs(osu.titleUnicode); - loadedGlyphs.add(osu.titleUnicode); + if (title != null && !title.isEmpty() && !set.contains(title)) { + font.addGlyphs(title); + set.add(title); glyphsAdded = true; } - if (!osu.artistUnicode.isEmpty() && !loadedGlyphs.contains(osu.artistUnicode)) { - Utils.FONT_LARGE.addGlyphs(osu.artistUnicode); - Utils.FONT_MEDIUM.addGlyphs(osu.artistUnicode); - Utils.FONT_DEFAULT.addGlyphs(osu.artistUnicode); - loadedGlyphs.add(osu.artistUnicode); + if (artist != null && !artist.isEmpty() && !set.contains(artist)) { + font.addGlyphs(artist); + set.add(artist); glyphsAdded = true; } if (glyphsAdded) { try { - Utils.FONT_LARGE.loadGlyphs(); - Utils.FONT_MEDIUM.loadGlyphs(); - Utils.FONT_DEFAULT.loadGlyphs(); + font.loadGlyphs(); } catch (SlickException e) { Log.warn("Failed to load glyphs.", e); } diff --git a/src/itdelatrisu/opsu/audio/MusicController.java b/src/itdelatrisu/opsu/audio/MusicController.java index e81c2ea6..b7c5e78a 100644 --- a/src/itdelatrisu/opsu/audio/MusicController.java +++ b/src/itdelatrisu/opsu/audio/MusicController.java @@ -171,24 +171,6 @@ public class MusicController { */ public static OsuFile getOsuFile() { return lastOsu; } - /** - * Returns the name of the current track. - */ - public static String getTrackName() { - if (!trackExists() || lastOsu == null) - return null; - return lastOsu.getTitle(); - } - - /** - * Returns the artist of the current track. - */ - public static String getArtistName() { - if (!trackExists() || lastOsu == null) - return null; - return lastOsu.getArtist(); - } - /** * Returns true if the current track is playing. */ diff --git a/src/itdelatrisu/opsu/downloads/DownloadNode.java b/src/itdelatrisu/opsu/downloads/DownloadNode.java index 4a44d9c6..e919e797 100644 --- a/src/itdelatrisu/opsu/downloads/DownloadNode.java +++ b/src/itdelatrisu/opsu/downloads/DownloadNode.java @@ -332,6 +332,8 @@ public class DownloadNode { textX += img.getWidth() + buttonWidth * 0.001f; // text + if (Options.useUnicodeMetadata()) // load glyphs + Utils.loadGlyphs(Utils.FONT_BOLD, getTitle(), getArtist()); Utils.FONT_BOLD.drawString( textX, y + marginY, String.format("%s - %s%s", getArtist(), getTitle(), diff --git a/src/itdelatrisu/opsu/states/MainMenu.java b/src/itdelatrisu/opsu/states/MainMenu.java index 29440698..15c97efe 100644 --- a/src/itdelatrisu/opsu/states/MainMenu.java +++ b/src/itdelatrisu/opsu/states/MainMenu.java @@ -276,11 +276,10 @@ public class MainMenu extends BasicGameState { if (MusicController.isTrackLoading()) g.drawString("Track loading...", marginX, marginY + lineHeight); else if (MusicController.trackExists()) { + if (Options.useUnicodeMetadata()) // load glyphs + Utils.loadGlyphs(Utils.FONT_MEDIUM, osu.titleUnicode, osu.artistUnicode); g.drawString((MusicController.isPlaying()) ? "Now Playing:" : "Paused:", marginX, marginY + lineHeight); - g.drawString(String.format("%s: %s", - MusicController.getArtistName(), - MusicController.getTrackName()), - marginX + 25, marginY + (lineHeight * 2)); + g.drawString(String.format("%s: %s", osu.getArtist(), osu.getTitle()), marginX + 25, marginY + (lineHeight * 2)); } long time = System.currentTimeMillis() - osuStartTime; g.drawString(String.format("opsu! has been running for %d minutes, %d seconds.", diff --git a/src/itdelatrisu/opsu/states/SongMenu.java b/src/itdelatrisu/opsu/states/SongMenu.java index 3dafc511..e496fcf2 100644 --- a/src/itdelatrisu/opsu/states/SongMenu.java +++ b/src/itdelatrisu/opsu/states/SongMenu.java @@ -311,9 +311,6 @@ public class SongMenu extends BasicGameState { ScoreData[] scores = getScoreDataForNode(node, false); node.draw(buttonX - offset, buttonY + (i*buttonOffset) + DIVIDER_LINE_WIDTH / 2, (scores == null) ? Grade.NULL : scores[0].getGrade(), (node == focusNode)); - - // load glyphs - Utils.loadGlyphs(node.osuFiles.get(0)); } g.clearClip(); @@ -329,6 +326,7 @@ public class SongMenu extends BasicGameState { // header if (focusNode != null) { + // music/loader icon float marginX = width * 0.005f, marginY = height * 0.005f; Image musicNote = GameImage.MENU_MUSICNOTE.getImage(); if (MusicController.isTrackLoading()) @@ -337,8 +335,14 @@ public class SongMenu extends BasicGameState { musicNote.draw(marginX, marginY); int iconWidth = musicNote.getWidth(); - if (songInfo == null) + // song info text + if (songInfo == null) { songInfo = focusNode.getInfo(); + if (Options.useUnicodeMetadata()) { // load glyphs + OsuFile osu = focusNode.osuFiles.get(0); + Utils.loadGlyphs(Utils.FONT_LARGE, osu.titleUnicode, osu.artistUnicode); + } + } marginX += 5; float headerTextY = marginY; Utils.FONT_LARGE.drawString(marginX + iconWidth * 1.05f, headerTextY, songInfo[0], Color.white); @@ -1183,7 +1187,6 @@ public class SongMenu extends BasicGameState { focusNode = OsuGroupList.get().getNode(node, osuFileIndex); OsuFile osu = focusNode.osuFiles.get(focusNode.osuFileIndex); MusicController.play(osu, false, preview); - Utils.loadGlyphs(osu); // load scores scoreMap = ScoreDB.getMapSetScores(osu);