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