Glyph loading fixes and improvements (for Unicode fonts).
- Glyphs are now loaded for specific fonts as needed, not for all of them at once. This reduces lag and saves memory. - Fixed glyphs not being loaded in the downloads menu. - Moved Utils.loadGlyphs() calls directly above text drawing code (easier to maintain, and fixes a bug with text flickering once). Also removed MusicController methods 'getTrackName()' and 'getArtistName()' (not needed). Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
ec042159a8
commit
e6576bd7f9
|
@ -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);
|
||||
|
|
|
@ -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<String> loadedGlyphs = new HashSet<String>();
|
||||
/** Set of all Unicode strings already loaded per font. */
|
||||
private static HashMap<UnicodeFont, HashSet<String>> loadedGlyphs = new HashMap<UnicodeFont, HashSet<String>>();
|
||||
|
||||
/**
|
||||
* 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<String> set = loadedGlyphs.get(font);
|
||||
if (set == null) {
|
||||
set = new HashSet<String>();
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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.",
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user