Moved all Utils.FONT_* into new class opsu.ui.Fonts.*.
- Moved Utils.loadGlyphs() into this class, and rewrote it to take a single generic string (instead of beatmap title/artist strings, specifically). - Also moved font initialization into this class. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
7b5b96752c
commit
0a7aef7347
|
@ -29,6 +29,7 @@ import itdelatrisu.opsu.objects.curves.Curve;
|
|||
import itdelatrisu.opsu.replay.Replay;
|
||||
import itdelatrisu.opsu.replay.ReplayFrame;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -841,12 +842,12 @@ public class GameData {
|
|||
g.fillRect(0, 0, width, 100 * uiScale);
|
||||
rankingTitle.draw((width * 0.97f) - rankingTitle.getWidth(), 0);
|
||||
float marginX = width * 0.01f, marginY = height * 0.002f;
|
||||
Utils.FONT_LARGE.drawString(marginX, marginY,
|
||||
Fonts.LARGE.drawString(marginX, marginY,
|
||||
String.format("%s - %s [%s]", beatmap.getArtist(), beatmap.getTitle(), beatmap.version), Color.white);
|
||||
Utils.FONT_MEDIUM.drawString(marginX, marginY + Utils.FONT_LARGE.getLineHeight() - 6,
|
||||
Fonts.MEDIUM.drawString(marginX, marginY + Fonts.LARGE.getLineHeight() - 6,
|
||||
String.format("Beatmap by %s", beatmap.creator), Color.white);
|
||||
String player = (scoreData.playerName == null) ? "" : String.format(" by %s", scoreData.playerName);
|
||||
Utils.FONT_MEDIUM.drawString(marginX, marginY + Utils.FONT_LARGE.getLineHeight() + Utils.FONT_MEDIUM.getLineHeight() - 10,
|
||||
Fonts.MEDIUM.drawString(marginX, marginY + Fonts.LARGE.getLineHeight() + Fonts.MEDIUM.getLineHeight() - 10,
|
||||
String.format("Played%s on %s.", player, scoreData.getTimeString()), Color.white);
|
||||
|
||||
// mod icons
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
|
||||
package itdelatrisu.opsu;
|
||||
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -251,14 +253,14 @@ public enum GameImage {
|
|||
MENU_MUSICNOTE ("music-note", "png", false, false) {
|
||||
@Override
|
||||
protected Image process_sub(Image img, int w, int h) {
|
||||
int r = (int) ((Utils.FONT_LARGE.getLineHeight() + Utils.FONT_DEFAULT.getLineHeight() - 8) / getUIscale());
|
||||
int r = (int) ((Fonts.LARGE.getLineHeight() + Fonts.DEFAULT.getLineHeight() - 8) / getUIscale());
|
||||
return img.getScaledCopy(r, r);
|
||||
}
|
||||
},
|
||||
MENU_LOADER ("loader", "png", false, false) {
|
||||
@Override
|
||||
protected Image process_sub(Image img, int w, int h) {
|
||||
int r = (int) ((Utils.FONT_LARGE.getLineHeight() + Utils.FONT_DEFAULT.getLineHeight() - 8) / getUIscale());
|
||||
int r = (int) ((Fonts.LARGE.getLineHeight() + Fonts.DEFAULT.getLineHeight() - 8) / getUIscale());
|
||||
return img.getScaledCopy(r / 48f);
|
||||
}
|
||||
},
|
||||
|
@ -312,7 +314,7 @@ public enum GameImage {
|
|||
DELETE ("delete", "png", false, false) {
|
||||
@Override
|
||||
protected Image process_sub(Image img, int w, int h) {
|
||||
int lineHeight = Utils.FONT_DEFAULT.getLineHeight();
|
||||
int lineHeight = Fonts.DEFAULT.getLineHeight();
|
||||
return img.getScaledCopy(lineHeight, lineHeight);
|
||||
}
|
||||
},
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package itdelatrisu.opsu;
|
||||
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
||||
|
||||
|
@ -97,10 +98,10 @@ public enum GameMod {
|
|||
* @param height the container height
|
||||
*/
|
||||
public void init(int width, int height) {
|
||||
float multY = Utils.FONT_LARGE.getLineHeight() * 2 + height * 0.06f;
|
||||
float multY = Fonts.LARGE.getLineHeight() * 2 + height * 0.06f;
|
||||
float offsetY = GameImage.MOD_EASY.getImage().getHeight() * 1.5f;
|
||||
this.x = width / 30f;
|
||||
this.y = multY + Utils.FONT_LARGE.getLineHeight() * 3f + offsetY * index;
|
||||
this.y = multY + Fonts.LARGE.getLineHeight() * 3f + offsetY * index;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,7 +194,7 @@ public enum GameMod {
|
|||
c.init(width, height);
|
||||
|
||||
// create buttons
|
||||
float baseX = Category.EASY.getX() + Utils.FONT_LARGE.getWidth(Category.EASY.getName()) * 1.25f;
|
||||
float baseX = Category.EASY.getX() + Fonts.LARGE.getWidth(Category.EASY.getName()) * 1.25f;
|
||||
float offsetX = GameImage.MOD_EASY.getImage().getWidth() * 2.1f;
|
||||
for (GameMod mod : GameMod.values()) {
|
||||
Image img = mod.image.getImage();
|
||||
|
|
|
@ -22,6 +22,7 @@ import itdelatrisu.opsu.audio.MusicController;
|
|||
import itdelatrisu.opsu.beatmap.Beatmap;
|
||||
import itdelatrisu.opsu.skins.Skin;
|
||||
import itdelatrisu.opsu.skins.SkinLoader;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
|
@ -287,9 +288,9 @@ public class Options {
|
|||
super.click(container);
|
||||
if (bool) {
|
||||
try {
|
||||
Utils.FONT_LARGE.loadGlyphs();
|
||||
Utils.FONT_MEDIUM.loadGlyphs();
|
||||
Utils.FONT_DEFAULT.loadGlyphs();
|
||||
Fonts.LARGE.loadGlyphs();
|
||||
Fonts.MEDIUM.loadGlyphs();
|
||||
Fonts.DEFAULT.loadGlyphs();
|
||||
} catch (SlickException e) {
|
||||
Log.warn("Failed to load glyphs.", e);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ package itdelatrisu.opsu;
|
|||
import itdelatrisu.opsu.GameData.Grade;
|
||||
import itdelatrisu.opsu.states.SongMenu;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
@ -95,7 +96,7 @@ public class ScoreData implements Comparable<ScoreData> {
|
|||
baseY = topY;
|
||||
buttonWidth = containerWidth * 0.4f;
|
||||
float gradeHeight = GameImage.MENU_BUTTON_BG.getImage().getHeight() * 0.45f;
|
||||
buttonHeight = Math.max(gradeHeight, Utils.FONT_DEFAULT.getLineHeight() * 3.03f);
|
||||
buttonHeight = Math.max(gradeHeight, Fonts.DEFAULT.getLineHeight() * 3.03f);
|
||||
buttonOffset = buttonHeight + gradeHeight / 10f;
|
||||
}
|
||||
|
||||
|
@ -231,7 +232,7 @@ public class ScoreData implements Comparable<ScoreData> {
|
|||
float edgeX = baseX + buttonWidth * 0.98f;
|
||||
float y = baseY + index * (buttonOffset);
|
||||
float midY = y + buttonHeight / 2f;
|
||||
float marginY = Utils.FONT_DEFAULT.getLineHeight() * 0.01f;
|
||||
float marginY = Fonts.DEFAULT.getLineHeight() * 0.01f;
|
||||
|
||||
// rectangle outline
|
||||
g.setColor((focus) ? Colors.BLACK_BG_FOCUS : Colors.BLACK_BG_NORMAL);
|
||||
|
@ -239,9 +240,9 @@ public class ScoreData implements Comparable<ScoreData> {
|
|||
|
||||
// rank
|
||||
if (focus) {
|
||||
Utils.FONT_LARGE.drawString(
|
||||
Fonts.LARGE.drawString(
|
||||
baseX + buttonWidth * 0.04f,
|
||||
y + (buttonHeight - Utils.FONT_LARGE.getLineHeight()) / 2f,
|
||||
y + (buttonHeight - Fonts.LARGE.getLineHeight()) / 2f,
|
||||
Integer.toString(rank + 1), Color.white
|
||||
);
|
||||
}
|
||||
|
@ -250,8 +251,8 @@ public class ScoreData implements Comparable<ScoreData> {
|
|||
img.drawCentered(baseX + buttonWidth * 0.15f, midY);
|
||||
|
||||
// score
|
||||
float textOffset = (buttonHeight - Utils.FONT_MEDIUM.getLineHeight() - Utils.FONT_SMALL.getLineHeight()) / 2f;
|
||||
Utils.FONT_MEDIUM.drawString(
|
||||
float textOffset = (buttonHeight - Fonts.MEDIUM.getLineHeight() - Fonts.SMALL.getLineHeight()) / 2f;
|
||||
Fonts.MEDIUM.drawString(
|
||||
textX, y + textOffset,
|
||||
String.format("Score: %s (%dx)", NumberFormat.getNumberInstance().format(score), combo),
|
||||
Color.white
|
||||
|
@ -259,8 +260,8 @@ public class ScoreData implements Comparable<ScoreData> {
|
|||
|
||||
// hit counts (custom: osu! shows user instead, above score)
|
||||
String player = (playerName == null) ? "" : String.format(" (%s)", playerName);
|
||||
Utils.FONT_SMALL.drawString(
|
||||
textX, y + textOffset + Utils.FONT_MEDIUM.getLineHeight(),
|
||||
Fonts.SMALL.drawString(
|
||||
textX, y + textOffset + Fonts.MEDIUM.getLineHeight(),
|
||||
String.format("300:%d 100:%d 50:%d Miss:%d%s", hit300, hit100, hit50, miss, player),
|
||||
Color.white
|
||||
);
|
||||
|
@ -276,26 +277,26 @@ public class ScoreData implements Comparable<ScoreData> {
|
|||
if (sb.length() > 0) {
|
||||
sb.setLength(sb.length() - 1);
|
||||
String modString = sb.toString();
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
edgeX - Utils.FONT_DEFAULT.getWidth(modString),
|
||||
Fonts.DEFAULT.drawString(
|
||||
edgeX - Fonts.DEFAULT.getWidth(modString),
|
||||
y + marginY, modString, Color.white
|
||||
);
|
||||
}
|
||||
|
||||
// accuracy
|
||||
String accuracy = String.format("%.2f%%", getScorePercent());
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
edgeX - Utils.FONT_DEFAULT.getWidth(accuracy),
|
||||
y + marginY + Utils.FONT_DEFAULT.getLineHeight(),
|
||||
Fonts.DEFAULT.drawString(
|
||||
edgeX - Fonts.DEFAULT.getWidth(accuracy),
|
||||
y + marginY + Fonts.DEFAULT.getLineHeight(),
|
||||
accuracy, Color.white
|
||||
);
|
||||
|
||||
// score difference
|
||||
String diff = (prevScore < 0 || score < prevScore) ?
|
||||
"-" : String.format("+%s", NumberFormat.getNumberInstance().format(score - prevScore));
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
edgeX - Utils.FONT_DEFAULT.getWidth(diff),
|
||||
y + marginY + Utils.FONT_DEFAULT.getLineHeight() * 2,
|
||||
Fonts.DEFAULT.drawString(
|
||||
edgeX - Fonts.DEFAULT.getWidth(diff),
|
||||
y + marginY + Fonts.DEFAULT.getLineHeight() * 2,
|
||||
diff, Color.white
|
||||
);
|
||||
|
||||
|
@ -303,9 +304,9 @@ public class ScoreData implements Comparable<ScoreData> {
|
|||
if (getTimeSince() != null) {
|
||||
Image clock = GameImage.HISTORY.getImage();
|
||||
clock.drawCentered(baseX + buttonWidth * 1.02f + clock.getWidth() / 2f, midY);
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
Fonts.DEFAULT.drawString(
|
||||
baseX + buttonWidth * 1.03f + clock.getWidth(),
|
||||
midY - Utils.FONT_DEFAULT.getLineHeight() / 2f,
|
||||
midY - Fonts.DEFAULT.getLineHeight() / 2f,
|
||||
getTimeSince(), Color.white
|
||||
);
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ import itdelatrisu.opsu.beatmap.HitObject;
|
|||
import itdelatrisu.opsu.downloads.Download;
|
||||
import itdelatrisu.opsu.downloads.DownloadNode;
|
||||
import itdelatrisu.opsu.replay.PlaybackSpeed;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedReader;
|
||||
|
@ -46,8 +46,6 @@ 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;
|
||||
|
||||
|
@ -63,12 +61,8 @@ import org.newdawn.slick.Animation;
|
|||
import org.newdawn.slick.GameContainer;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.UnicodeFont;
|
||||
import org.newdawn.slick.font.effects.ColorEffect;
|
||||
import org.newdawn.slick.font.effects.Effect;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.util.Log;
|
||||
import org.newdawn.slick.util.ResourceLoader;
|
||||
|
||||
import com.sun.jna.platform.FileUtils;
|
||||
|
||||
|
@ -76,14 +70,6 @@ import com.sun.jna.platform.FileUtils;
|
|||
* Contains miscellaneous utilities.
|
||||
*/
|
||||
public class Utils {
|
||||
/** Game fonts. */
|
||||
public static UnicodeFont
|
||||
FONT_DEFAULT, FONT_BOLD,
|
||||
FONT_XLARGE, FONT_LARGE, FONT_MEDIUM, FONT_SMALL;
|
||||
|
||||
/** 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.
|
||||
* @see #cleanFileName(String, char)
|
||||
|
@ -128,23 +114,8 @@ public class Utils {
|
|||
GameImage.init(width, height);
|
||||
|
||||
// create fonts
|
||||
float fontBase = 12f * GameImage.getUIscale();
|
||||
try {
|
||||
Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_NAME));
|
||||
Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
|
||||
FONT_DEFAULT = new UnicodeFont(font);
|
||||
FONT_BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
|
||||
FONT_XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3));
|
||||
FONT_LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
|
||||
FONT_MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
|
||||
FONT_SMALL = new UnicodeFont(font.deriveFont(fontBase));
|
||||
ColorEffect colorEffect = new ColorEffect();
|
||||
loadFont(FONT_DEFAULT, colorEffect);
|
||||
loadFont(FONT_BOLD, colorEffect);
|
||||
loadFont(FONT_XLARGE, colorEffect);
|
||||
loadFont(FONT_LARGE, colorEffect);
|
||||
loadFont(FONT_MEDIUM, colorEffect);
|
||||
loadFont(FONT_SMALL, colorEffect);
|
||||
Fonts.init();
|
||||
} catch (Exception e) {
|
||||
ErrorHandler.error("Failed to load fonts.", e, true);
|
||||
}
|
||||
|
@ -326,54 +297,6 @@ public class Utils {
|
|||
}.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a Unicode font.
|
||||
* @param font the font to load
|
||||
* @param effect the font effect
|
||||
* @throws SlickException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void loadFont(UnicodeFont font, Effect effect) throws SlickException {
|
||||
font.addAsciiGlyphs();
|
||||
font.getEffects().add(effect);
|
||||
font.loadGlyphs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(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 (title != null && !title.isEmpty() && !set.contains(title)) {
|
||||
font.addGlyphs(title);
|
||||
set.add(title);
|
||||
glyphsAdded = true;
|
||||
}
|
||||
if (artist != null && !artist.isEmpty() && !set.contains(artist)) {
|
||||
font.addGlyphs(artist);
|
||||
set.add(artist);
|
||||
glyphsAdded = true;
|
||||
}
|
||||
if (glyphsAdded) {
|
||||
try {
|
||||
font.loadGlyphs();
|
||||
} catch (SlickException e) {
|
||||
Log.warn("Failed to load glyphs.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a human-readable representation of a given number of bytes.
|
||||
* @param bytes the number of bytes
|
||||
|
|
|
@ -21,8 +21,8 @@ package itdelatrisu.opsu.beatmap;
|
|||
import itdelatrisu.opsu.GameData.Grade;
|
||||
import itdelatrisu.opsu.GameImage;
|
||||
import itdelatrisu.opsu.Options;
|
||||
import itdelatrisu.opsu.Utils;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
|
||||
import org.newdawn.slick.Color;
|
||||
import org.newdawn.slick.Image;
|
||||
|
@ -99,14 +99,14 @@ public class BeatmapSetNode {
|
|||
|
||||
// draw text
|
||||
if (Options.useUnicodeMetadata()) { // load glyphs
|
||||
Utils.loadGlyphs(Utils.FONT_MEDIUM, beatmap.titleUnicode, null);
|
||||
Utils.loadGlyphs(Utils.FONT_DEFAULT, null, beatmap.artistUnicode);
|
||||
Fonts.loadGlyphs(Fonts.MEDIUM, beatmap.titleUnicode);
|
||||
Fonts.loadGlyphs(Fonts.DEFAULT, beatmap.artistUnicode);
|
||||
}
|
||||
Utils.FONT_MEDIUM.drawString(cx, cy, beatmap.getTitle(), textColor);
|
||||
Utils.FONT_DEFAULT.drawString(cx, cy + Utils.FONT_MEDIUM.getLineHeight() - 2,
|
||||
Fonts.MEDIUM.drawString(cx, cy, beatmap.getTitle(), textColor);
|
||||
Fonts.DEFAULT.drawString(cx, cy + Fonts.MEDIUM.getLineHeight() - 2,
|
||||
String.format("%s // %s", beatmap.getArtist(), beatmap.creator), textColor);
|
||||
if (expanded || beatmapSet.size() == 1)
|
||||
Utils.FONT_BOLD.drawString(cx, cy + Utils.FONT_MEDIUM.getLineHeight() + Utils.FONT_DEFAULT.getLineHeight() - 4,
|
||||
Fonts.BOLD.drawString(cx, cy + Fonts.MEDIUM.getLineHeight() + Fonts.DEFAULT.getLineHeight() - 4,
|
||||
beatmap.version, textColor);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ import itdelatrisu.opsu.downloads.Download.DownloadListener;
|
|||
import itdelatrisu.opsu.downloads.Download.Status;
|
||||
import itdelatrisu.opsu.downloads.servers.DownloadServer;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -81,16 +82,16 @@ public class DownloadNode {
|
|||
buttonBaseX = width * 0.024f;
|
||||
buttonBaseY = height * 0.2f;
|
||||
buttonWidth = width * 0.7f;
|
||||
buttonHeight = Utils.FONT_MEDIUM.getLineHeight() * 2.1f;
|
||||
buttonHeight = Fonts.MEDIUM.getLineHeight() * 2.1f;
|
||||
buttonOffset = buttonHeight * 1.1f;
|
||||
|
||||
// download info
|
||||
infoBaseX = width * 0.75f;
|
||||
infoBaseY = height * 0.07f + Utils.FONT_LARGE.getLineHeight() * 2f;
|
||||
infoBaseY = height * 0.07f + Fonts.LARGE.getLineHeight() * 2f;
|
||||
infoWidth = width * 0.25f;
|
||||
infoHeight = Utils.FONT_DEFAULT.getLineHeight() * 2.4f;
|
||||
infoHeight = Fonts.DEFAULT.getLineHeight() * 2.4f;
|
||||
|
||||
float searchY = (height * 0.05f) + Utils.FONT_LARGE.getLineHeight();
|
||||
float searchY = (height * 0.05f) + Fonts.LARGE.getLineHeight();
|
||||
float buttonHeight = height * 0.038f;
|
||||
maxResultsShown = (int) ((height - buttonBaseY - searchY) / buttonOffset);
|
||||
maxDownloadsShown = (int) ((height - infoBaseY - searchY - buttonHeight) / infoHeight);
|
||||
|
@ -257,7 +258,7 @@ public class DownloadNode {
|
|||
});
|
||||
this.download = download;
|
||||
if (Options.useUnicodeMetadata()) // load glyphs
|
||||
Utils.loadGlyphs(Utils.FONT_LARGE, getTitle(), null);
|
||||
Fonts.loadGlyphs(Fonts.LARGE, getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -344,19 +345,21 @@ public class DownloadNode {
|
|||
|
||||
// text
|
||||
// TODO: if the title/artist line is too long, shorten it (e.g. add "...") instead of just clipping
|
||||
if (Options.useUnicodeMetadata()) // load glyphs
|
||||
Utils.loadGlyphs(Utils.FONT_BOLD, getTitle(), getArtist());
|
||||
g.setClip((int) textX, (int) (y + marginY), (int) (edgeX - textX - Utils.FONT_DEFAULT.getWidth(creator)), Utils.FONT_BOLD.getLineHeight());
|
||||
Utils.FONT_BOLD.drawString(
|
||||
if (Options.useUnicodeMetadata()) { // load glyphs
|
||||
Fonts.loadGlyphs(Fonts.BOLD, getTitle());
|
||||
Fonts.loadGlyphs(Fonts.BOLD, getArtist());
|
||||
}
|
||||
g.setClip((int) textX, (int) (y + marginY), (int) (edgeX - textX - Fonts.DEFAULT.getWidth(creator)), Fonts.BOLD.getLineHeight());
|
||||
Fonts.BOLD.drawString(
|
||||
textX, y + marginY,
|
||||
String.format("%s - %s%s", getArtist(), getTitle(),
|
||||
(dl != null) ? String.format(" [%s]", dl.getStatus().getName()) : ""), Color.white);
|
||||
g.clearClip();
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
textX, y + marginY + Utils.FONT_BOLD.getLineHeight(),
|
||||
Fonts.DEFAULT.drawString(
|
||||
textX, y + marginY + Fonts.BOLD.getLineHeight(),
|
||||
String.format("Last updated: %s", date), Color.white);
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
edgeX - Utils.FONT_DEFAULT.getWidth(creator), y + marginY,
|
||||
Fonts.DEFAULT.drawString(
|
||||
edgeX - Fonts.DEFAULT.getWidth(creator), y + marginY,
|
||||
creator, Color.white);
|
||||
}
|
||||
|
||||
|
@ -398,8 +401,8 @@ public class DownloadNode {
|
|||
info = String.format("%s: %.1f%% (%s/%s)", status.getName(), progress,
|
||||
Utils.bytesToString(download.readSoFar()), Utils.bytesToString(download.contentLength()));
|
||||
}
|
||||
Utils.FONT_BOLD.drawString(textX, y + marginY, getTitle(), Color.white);
|
||||
Utils.FONT_DEFAULT.drawString(textX, y + marginY + Utils.FONT_BOLD.getLineHeight(), info, Color.white);
|
||||
Fonts.BOLD.drawString(textX, y + marginY, getTitle(), Color.white);
|
||||
Fonts.DEFAULT.drawString(textX, y + marginY + Fonts.BOLD.getLineHeight(), info, Color.white);
|
||||
|
||||
// 'x' button
|
||||
if (hover) {
|
||||
|
|
|
@ -29,6 +29,7 @@ import itdelatrisu.opsu.audio.SoundController;
|
|||
import itdelatrisu.opsu.audio.SoundEffect;
|
||||
import itdelatrisu.opsu.beatmap.BeatmapSetList;
|
||||
import itdelatrisu.opsu.beatmap.BeatmapSetNode;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
import itdelatrisu.opsu.ui.animations.AnimatedValue;
|
||||
|
@ -189,15 +190,15 @@ public class ButtonMenu extends BasicGameState {
|
|||
float mult = GameMod.getScoreMultiplier();
|
||||
String multString = String.format("Score Multiplier: %.2fx", mult);
|
||||
Color multColor = (mult == 1f) ? Color.white : (mult > 1f) ? Color.green : Color.red;
|
||||
float multY = Utils.FONT_LARGE.getLineHeight() * 2 + height * 0.06f;
|
||||
Utils.FONT_LARGE.drawString(
|
||||
(width - Utils.FONT_LARGE.getWidth(multString)) / 2f,
|
||||
float multY = Fonts.LARGE.getLineHeight() * 2 + height * 0.06f;
|
||||
Fonts.LARGE.drawString(
|
||||
(width - Fonts.LARGE.getWidth(multString)) / 2f,
|
||||
multY, multString, multColor);
|
||||
|
||||
// category text
|
||||
for (GameMod.Category category : GameMod.Category.values()) {
|
||||
Utils.FONT_LARGE.drawString(category.getX(),
|
||||
category.getY() - Utils.FONT_LARGE.getLineHeight() / 2f,
|
||||
Fonts.LARGE.drawString(category.getX(),
|
||||
category.getY() - Fonts.LARGE.getLineHeight() / 2f,
|
||||
category.getName(), category.getColor());
|
||||
}
|
||||
|
||||
|
@ -293,7 +294,7 @@ public class ButtonMenu extends BasicGameState {
|
|||
menuButtons = new MenuButton[buttons.length];
|
||||
for (int i = 0; i < buttons.length; i++) {
|
||||
MenuButton b = new MenuButton(button, buttonL, buttonR, center, baseY + (i * offsetY));
|
||||
b.setText(String.format("%d. %s", i + 1, buttons[i].getText()), Utils.FONT_XLARGE, Color.white);
|
||||
b.setText(String.format("%d. %s", i + 1, buttons[i].getText()), Fonts.XLARGE, Color.white);
|
||||
b.setHoverFade();
|
||||
menuButtons[i] = b;
|
||||
}
|
||||
|
@ -306,7 +307,7 @@ public class ButtonMenu extends BasicGameState {
|
|||
*/
|
||||
protected float getBaseY(GameContainer container, StateBasedGame game) {
|
||||
float baseY = container.getHeight() * 0.2f;
|
||||
baseY += ((getTitle(container, game).length - 1) * Utils.FONT_LARGE.getLineHeight());
|
||||
baseY += ((getTitle(container, game).length - 1) * Fonts.LARGE.getLineHeight());
|
||||
return baseY;
|
||||
}
|
||||
|
||||
|
@ -320,9 +321,9 @@ public class ButtonMenu extends BasicGameState {
|
|||
// draw title
|
||||
if (actualTitle != null) {
|
||||
float marginX = container.getWidth() * 0.015f, marginY = container.getHeight() * 0.01f;
|
||||
int lineHeight = Utils.FONT_LARGE.getLineHeight();
|
||||
int lineHeight = Fonts.LARGE.getLineHeight();
|
||||
for (int i = 0, size = actualTitle.size(); i < size; i++)
|
||||
Utils.FONT_LARGE.drawString(marginX, marginY + (i * lineHeight), actualTitle.get(i), Color.white);
|
||||
Fonts.LARGE.drawString(marginX, marginY + (i * lineHeight), actualTitle.get(i), Color.white);
|
||||
}
|
||||
|
||||
// draw buttons
|
||||
|
@ -418,8 +419,8 @@ public class ButtonMenu extends BasicGameState {
|
|||
int maxLineWidth = (int) (container.getWidth() * 0.96f);
|
||||
for (int i = 0; i < title.length; i++) {
|
||||
// wrap text if too long
|
||||
if (Utils.FONT_LARGE.getWidth(title[i]) > maxLineWidth) {
|
||||
List<String> list = Utils.wrap(title[i], Utils.FONT_LARGE, maxLineWidth);
|
||||
if (Fonts.LARGE.getWidth(title[i]) > maxLineWidth) {
|
||||
List<String> list = Utils.wrap(title[i], Fonts.LARGE, maxLineWidth);
|
||||
actualTitle.addAll(list);
|
||||
} else
|
||||
actualTitle.add(title[i]);
|
||||
|
|
|
@ -38,6 +38,7 @@ import itdelatrisu.opsu.downloads.servers.HexideServer;
|
|||
import itdelatrisu.opsu.downloads.servers.MnetworkServer;
|
||||
import itdelatrisu.opsu.downloads.servers.YaSOnlineServer;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
|
||||
|
@ -261,17 +262,17 @@ public class DownloadsMenu extends BasicGameState {
|
|||
int width = container.getWidth();
|
||||
int height = container.getHeight();
|
||||
float baseX = width * 0.024f;
|
||||
float searchY = (height * 0.04f) + Utils.FONT_LARGE.getLineHeight();
|
||||
float searchY = (height * 0.04f) + Fonts.LARGE.getLineHeight();
|
||||
float searchWidth = width * 0.3f;
|
||||
|
||||
// search
|
||||
searchTimer = SEARCH_DELAY;
|
||||
searchResultString = "Loading data from server...";
|
||||
search = new TextField(
|
||||
container, Utils.FONT_DEFAULT, (int) baseX, (int) searchY,
|
||||
(int) searchWidth, Utils.FONT_MEDIUM.getLineHeight()
|
||||
container, Fonts.DEFAULT, (int) baseX, (int) searchY,
|
||||
(int) searchWidth, Fonts.MEDIUM.getLineHeight()
|
||||
);
|
||||
search.setBackgroundColor(DownloadNode.BG_NORMAL);
|
||||
search.setBackgroundColor(Colors.BLACK_BG_NORMAL);
|
||||
search.setBorderColor(Color.white);
|
||||
search.setTextColor(Color.white);
|
||||
search.setConsumeEvents(false);
|
||||
|
@ -296,7 +297,7 @@ public class DownloadsMenu extends BasicGameState {
|
|||
float rankedWidth = width * 0.15f;
|
||||
float serverWidth = width * 0.12f;
|
||||
float lowerWidth = width * 0.12f;
|
||||
float topButtonY = searchY + Utils.FONT_MEDIUM.getLineHeight() / 2f;
|
||||
float topButtonY = searchY + Fonts.MEDIUM.getLineHeight() / 2f;
|
||||
float lowerButtonY = height * 0.995f - searchY - buttonHeight / 2f;
|
||||
Image button = GameImage.MENU_BUTTON_MID.getImage();
|
||||
Image buttonL = GameImage.MENU_BUTTON_LEFT.getImage();
|
||||
|
@ -322,9 +323,9 @@ public class DownloadsMenu extends BasicGameState {
|
|||
baseX + searchWidth + buttonMarginX * 2f + resetButtonWidth + rankedButtonWidth / 2f, topButtonY);
|
||||
serverButton = new MenuButton(serverButtonImage, buttonL, buttonR,
|
||||
baseX + searchWidth + buttonMarginX * 3f + resetButtonWidth + rankedButtonWidth + serverButtonWidth / 2f, topButtonY);
|
||||
clearButton.setText("Clear", Utils.FONT_MEDIUM, Color.white);
|
||||
importButton.setText("Import All", Utils.FONT_MEDIUM, Color.white);
|
||||
resetButton.setText("Reset", Utils.FONT_MEDIUM, Color.white);
|
||||
clearButton.setText("Clear", Fonts.MEDIUM, Color.white);
|
||||
importButton.setText("Import All", Fonts.MEDIUM, Color.white);
|
||||
resetButton.setText("Reset", Fonts.MEDIUM, Color.white);
|
||||
clearButton.setHoverFade();
|
||||
importButton.setHoverFade();
|
||||
resetButton.setHoverFade();
|
||||
|
@ -343,13 +344,13 @@ public class DownloadsMenu extends BasicGameState {
|
|||
GameImage.SEARCH_BG.getImage().draw();
|
||||
|
||||
// title
|
||||
Utils.FONT_LARGE.drawString(width * 0.024f, height * 0.03f, "Download Beatmaps!", Color.white);
|
||||
Fonts.LARGE.drawString(width * 0.024f, height * 0.03f, "Download Beatmaps!", Color.white);
|
||||
|
||||
// search
|
||||
g.setColor(Color.white);
|
||||
g.setLineWidth(2f);
|
||||
search.render(container, g);
|
||||
Utils.FONT_BOLD.drawString(
|
||||
Fonts.BOLD.drawString(
|
||||
search.getX() + search.getWidth() * 0.01f, search.getY() + search.getHeight() * 1.3f,
|
||||
searchResultString, Color.white
|
||||
);
|
||||
|
@ -377,9 +378,9 @@ public class DownloadsMenu extends BasicGameState {
|
|||
float baseX = width * 0.024f;
|
||||
float buttonY = height * 0.2f;
|
||||
float buttonWidth = width * 0.7f;
|
||||
Utils.FONT_BOLD.drawString(
|
||||
baseX + (buttonWidth - Utils.FONT_BOLD.getWidth("Page 1")) / 2f,
|
||||
buttonY - Utils.FONT_BOLD.getLineHeight() * 1.3f,
|
||||
Fonts.BOLD.drawString(
|
||||
baseX + (buttonWidth - Fonts.BOLD.getWidth("Page 1")) / 2f,
|
||||
buttonY - Fonts.BOLD.getLineHeight() * 1.3f,
|
||||
String.format("Page %d", page), Color.white
|
||||
);
|
||||
if (page > 1)
|
||||
|
@ -391,10 +392,10 @@ public class DownloadsMenu extends BasicGameState {
|
|||
|
||||
// downloads
|
||||
float downloadsX = width * 0.75f, downloadsY = search.getY();
|
||||
g.setColor(DownloadNode.BG_NORMAL);
|
||||
g.setColor(Colors.BLACK_BG_NORMAL);
|
||||
g.fillRect(downloadsX, downloadsY,
|
||||
width * 0.25f, height - downloadsY * 2f);
|
||||
Utils.FONT_LARGE.drawString(downloadsX + width * 0.015f, downloadsY + height * 0.015f, "Downloads", Color.white);
|
||||
Fonts.LARGE.drawString(downloadsX + width * 0.015f, downloadsY + height * 0.015f, "Downloads", Color.white);
|
||||
int downloadsSize = DownloadList.get().size();
|
||||
if (downloadsSize > 0) {
|
||||
int maxDownloadsShown = DownloadNode.maxDownloadsShown();
|
||||
|
@ -417,9 +418,9 @@ public class DownloadsMenu extends BasicGameState {
|
|||
clearButton.draw(Color.gray);
|
||||
importButton.draw(Color.orange);
|
||||
resetButton.draw(Color.red);
|
||||
rankedButton.setText((rankedOnly) ? "Show Unranked" : "Hide Unranked", Utils.FONT_MEDIUM, Color.white);
|
||||
rankedButton.setText((rankedOnly) ? "Show Unranked" : "Hide Unranked", Fonts.MEDIUM, Color.white);
|
||||
rankedButton.draw(Color.magenta);
|
||||
serverButton.setText(SERVERS[serverIndex].getName(), Utils.FONT_MEDIUM, Color.white);
|
||||
serverButton.setText(SERVERS[serverIndex].getName(), Fonts.MEDIUM, Color.white);
|
||||
serverButton.draw(Color.blue);
|
||||
|
||||
// importing beatmaps
|
||||
|
|
|
@ -47,6 +47,7 @@ import itdelatrisu.opsu.replay.PlaybackSpeed;
|
|||
import itdelatrisu.opsu.replay.Replay;
|
||||
import itdelatrisu.opsu.replay.ReplayFrame;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
import itdelatrisu.opsu.ui.animations.AnimationEquation;
|
||||
|
@ -479,7 +480,7 @@ public class Game extends BasicGameState {
|
|||
float oldAlpha = Colors.WHITE_FADE.a;
|
||||
if (timeDiff < -500)
|
||||
Colors.WHITE_FADE.a = (1000 + timeDiff) / 500f;
|
||||
Utils.FONT_MEDIUM.drawString(
|
||||
Fonts.MEDIUM.drawString(
|
||||
2 + (width / 100), retryHeight,
|
||||
String.format("%d retries and counting...", retries),
|
||||
Colors.WHITE_FADE
|
||||
|
|
|
@ -32,6 +32,7 @@ import itdelatrisu.opsu.beatmap.BeatmapSetNode;
|
|||
import itdelatrisu.opsu.downloads.Updater;
|
||||
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.MenuButton.Expand;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
|
@ -292,15 +293,17 @@ public class MainMenu extends BasicGameState {
|
|||
|
||||
// draw text
|
||||
float marginX = width * 0.015f, topMarginY = height * 0.01f, bottomMarginY = height * 0.015f;
|
||||
g.setFont(Utils.FONT_MEDIUM);
|
||||
float lineHeight = Utils.FONT_MEDIUM.getLineHeight() * 0.925f;
|
||||
g.setFont(Fonts.MEDIUM);
|
||||
float lineHeight = Fonts.MEDIUM.getLineHeight() * 0.925f;
|
||||
g.drawString(String.format("Loaded %d songs and %d beatmaps.",
|
||||
BeatmapSetList.get().getMapSetCount(), BeatmapSetList.get().getMapCount()), marginX, topMarginY);
|
||||
if (MusicController.isTrackLoading())
|
||||
g.drawString("Track loading...", marginX, topMarginY + lineHeight);
|
||||
else if (MusicController.trackExists()) {
|
||||
if (Options.useUnicodeMetadata()) // load glyphs
|
||||
Utils.loadGlyphs(Utils.FONT_MEDIUM, beatmap.titleUnicode, beatmap.artistUnicode);
|
||||
if (Options.useUnicodeMetadata()) { // load glyphs
|
||||
Fonts.loadGlyphs(Fonts.MEDIUM, beatmap.titleUnicode);
|
||||
Fonts.loadGlyphs(Fonts.MEDIUM, beatmap.artistUnicode);
|
||||
}
|
||||
g.drawString((MusicController.isPlaying()) ? "Now Playing:" : "Paused:", marginX, topMarginY + lineHeight);
|
||||
g.drawString(String.format("%s: %s", beatmap.getArtist(), beatmap.getTitle()), marginX + 25, topMarginY + (lineHeight * 2));
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import itdelatrisu.opsu.audio.MusicController;
|
|||
import itdelatrisu.opsu.audio.SoundController;
|
||||
import itdelatrisu.opsu.audio.SoundEffect;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
|
||||
|
@ -185,8 +186,8 @@ public class OptionsMenu extends BasicGameState {
|
|||
|
||||
// option tabs
|
||||
Image tabImage = GameImage.MENU_TAB.getImage();
|
||||
float tabX = width * 0.032f + Utils.FONT_DEFAULT.getWidth("Change the way opsu! behaves") + (tabImage.getWidth() / 2);
|
||||
float tabY = Utils.FONT_XLARGE.getLineHeight() + Utils.FONT_DEFAULT.getLineHeight() +
|
||||
float tabX = width * 0.032f + Fonts.DEFAULT.getWidth("Change the way opsu! behaves") + (tabImage.getWidth() / 2);
|
||||
float tabY = Fonts.XLARGE.getLineHeight() + Fonts.DEFAULT.getLineHeight() +
|
||||
height * 0.015f - (tabImage.getHeight() / 2f);
|
||||
int tabOffset = Math.min(tabImage.getWidth(), width / OptionTab.SIZE);
|
||||
for (OptionTab tab : OptionTab.values())
|
||||
|
@ -210,8 +211,8 @@ public class OptionsMenu extends BasicGameState {
|
|||
|
||||
// title
|
||||
float marginX = width * 0.015f, marginY = height * 0.01f;
|
||||
Utils.FONT_XLARGE.drawString(marginX, marginY, "Options", Color.white);
|
||||
Utils.FONT_DEFAULT.drawString(marginX, marginY + Utils.FONT_XLARGE.getLineHeight() * 0.92f,
|
||||
Fonts.XLARGE.drawString(marginX, marginY, "Options", Color.white);
|
||||
Fonts.DEFAULT.drawString(marginX, marginY + Fonts.XLARGE.getLineHeight() * 0.92f,
|
||||
"Change the way opsu! behaves", Color.white);
|
||||
|
||||
// game options
|
||||
|
@ -255,9 +256,9 @@ public class OptionsMenu extends BasicGameState {
|
|||
String prompt = (keyEntryLeft) ?
|
||||
"Please press the new left-click key." :
|
||||
"Please press the new right-click key.";
|
||||
Utils.FONT_LARGE.drawString(
|
||||
(width / 2) - (Utils.FONT_LARGE.getWidth(prompt) / 2),
|
||||
(height / 2) - Utils.FONT_LARGE.getLineHeight(), prompt
|
||||
Fonts.LARGE.drawString(
|
||||
(width / 2) - (Fonts.LARGE.getWidth(prompt) / 2),
|
||||
(height / 2) - Fonts.LARGE.getLineHeight(), prompt
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -414,13 +415,13 @@ public class OptionsMenu extends BasicGameState {
|
|||
*/
|
||||
private void drawOption(GameOption option, int pos, boolean focus) {
|
||||
int width = container.getWidth();
|
||||
int textHeight = Utils.FONT_LARGE.getLineHeight();
|
||||
int textHeight = Fonts.LARGE.getLineHeight();
|
||||
float y = textY + (pos * offsetY);
|
||||
Color color = (focus) ? Color.cyan : Color.white;
|
||||
|
||||
Utils.FONT_LARGE.drawString(width / 30, y, option.getName(), color);
|
||||
Utils.FONT_LARGE.drawString(width / 2, y, option.getValueString(), color);
|
||||
Utils.FONT_SMALL.drawString(width / 30, y + textHeight, option.getDescription(), color);
|
||||
Fonts.LARGE.drawString(width / 30, y, option.getName(), color);
|
||||
Fonts.LARGE.drawString(width / 2, y, option.getValueString(), color);
|
||||
Fonts.SMALL.drawString(width / 30, y + textHeight, option.getDescription(), color);
|
||||
g.setColor(Colors.WHITE_ALPHA);
|
||||
g.drawLine(0, y + textHeight, width, y + textHeight);
|
||||
}
|
||||
|
@ -434,7 +435,7 @@ public class OptionsMenu extends BasicGameState {
|
|||
if (y < textY || y > textY + (offsetY * maxOptionsScreen))
|
||||
return null;
|
||||
|
||||
int index = (y - textY + Utils.FONT_LARGE.getLineHeight()) / offsetY;
|
||||
int index = (y - textY + Fonts.LARGE.getLineHeight()) / offsetY;
|
||||
if (index >= currentTab.options.length)
|
||||
return null;
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import itdelatrisu.opsu.db.BeatmapDB;
|
|||
import itdelatrisu.opsu.db.ScoreDB;
|
||||
import itdelatrisu.opsu.states.ButtonMenu.MenuState;
|
||||
import itdelatrisu.opsu.ui.Colors;
|
||||
import itdelatrisu.opsu.ui.Fonts;
|
||||
import itdelatrisu.opsu.ui.MenuButton;
|
||||
import itdelatrisu.opsu.ui.UI;
|
||||
import itdelatrisu.opsu.ui.animations.AnimatedValue;
|
||||
|
@ -226,8 +227,8 @@ public class SongMenu extends BasicGameState {
|
|||
|
||||
// header/footer coordinates
|
||||
headerY = height * 0.0075f + GameImage.MENU_MUSICNOTE.getImage().getHeight() +
|
||||
Utils.FONT_BOLD.getLineHeight() + Utils.FONT_DEFAULT.getLineHeight() +
|
||||
Utils.FONT_SMALL.getLineHeight();
|
||||
Fonts.BOLD.getLineHeight() + Fonts.DEFAULT.getLineHeight() +
|
||||
Fonts.SMALL.getLineHeight();
|
||||
footerY = height - GameImage.SELECTION_MODS.getImage().getHeight();
|
||||
|
||||
// initialize sorts
|
||||
|
@ -248,11 +249,11 @@ public class SongMenu extends BasicGameState {
|
|||
buttonOffset = (footerY - headerY - DIVIDER_LINE_WIDTH) / MAX_SONG_BUTTONS;
|
||||
|
||||
// search
|
||||
int textFieldX = (int) (width * 0.7125f + Utils.FONT_BOLD.getWidth("Search: "));
|
||||
int textFieldY = (int) (headerY + Utils.FONT_BOLD.getLineHeight() / 2);
|
||||
int textFieldX = (int) (width * 0.7125f + Fonts.BOLD.getWidth("Search: "));
|
||||
int textFieldY = (int) (headerY + Fonts.BOLD.getLineHeight() / 2);
|
||||
search = new TextField(
|
||||
container, Utils.FONT_BOLD, textFieldX, textFieldY,
|
||||
(int) (width * 0.99f) - textFieldX, Utils.FONT_BOLD.getLineHeight()
|
||||
container, Fonts.BOLD, textFieldX, textFieldY,
|
||||
(int) (width * 0.99f) - textFieldX, Fonts.BOLD.getLineHeight()
|
||||
);
|
||||
search.setBackgroundColor(Color.transparent);
|
||||
search.setBorderColor(Color.transparent);
|
||||
|
@ -343,26 +344,27 @@ public class SongMenu extends BasicGameState {
|
|||
songInfo = focusNode.getInfo();
|
||||
if (Options.useUnicodeMetadata()) { // load glyphs
|
||||
Beatmap beatmap = focusNode.getBeatmapSet().get(0);
|
||||
Utils.loadGlyphs(Utils.FONT_LARGE, beatmap.titleUnicode, beatmap.artistUnicode);
|
||||
Fonts.loadGlyphs(Fonts.LARGE, beatmap.titleUnicode);
|
||||
Fonts.loadGlyphs(Fonts.LARGE, beatmap.artistUnicode);
|
||||
}
|
||||
}
|
||||
marginX += 5;
|
||||
float headerTextY = marginY * 0.2f;
|
||||
Utils.FONT_LARGE.drawString(marginX + iconWidth * 1.05f, headerTextY, songInfo[0], Color.white);
|
||||
headerTextY += Utils.FONT_LARGE.getLineHeight() - 6;
|
||||
Utils.FONT_DEFAULT.drawString(marginX + iconWidth * 1.05f, headerTextY, songInfo[1], Color.white);
|
||||
headerTextY += Utils.FONT_DEFAULT.getLineHeight() - 2;
|
||||
Fonts.LARGE.drawString(marginX + iconWidth * 1.05f, headerTextY, songInfo[0], Color.white);
|
||||
headerTextY += Fonts.LARGE.getLineHeight() - 6;
|
||||
Fonts.DEFAULT.drawString(marginX + iconWidth * 1.05f, headerTextY, songInfo[1], Color.white);
|
||||
headerTextY += Fonts.DEFAULT.getLineHeight() - 2;
|
||||
float speedModifier = GameMod.getSpeedMultiplier();
|
||||
Color color2 = (speedModifier == 1f) ? Color.white :
|
||||
(speedModifier > 1f) ? Colors.RED_HIGHLIGHT : Colors.BLUE_HIGHLIGHT;
|
||||
Utils.FONT_BOLD.drawString(marginX, headerTextY, songInfo[2], color2);
|
||||
headerTextY += Utils.FONT_BOLD.getLineHeight() - 4;
|
||||
Utils.FONT_DEFAULT.drawString(marginX, headerTextY, songInfo[3], Color.white);
|
||||
headerTextY += Utils.FONT_DEFAULT.getLineHeight() - 4;
|
||||
Fonts.BOLD.drawString(marginX, headerTextY, songInfo[2], color2);
|
||||
headerTextY += Fonts.BOLD.getLineHeight() - 4;
|
||||
Fonts.DEFAULT.drawString(marginX, headerTextY, songInfo[3], Color.white);
|
||||
headerTextY += Fonts.DEFAULT.getLineHeight() - 4;
|
||||
float multiplier = GameMod.getDifficultyMultiplier();
|
||||
Color color4 = (multiplier == 1f) ? Color.white :
|
||||
(multiplier > 1f) ? Colors.RED_HIGHLIGHT : Colors.BLUE_HIGHLIGHT;
|
||||
Utils.FONT_SMALL.drawString(marginX, headerTextY, songInfo[4], color4);
|
||||
Fonts.SMALL.drawString(marginX, headerTextY, songInfo[4], color4);
|
||||
}
|
||||
|
||||
// score buttons
|
||||
|
@ -410,8 +412,8 @@ public class SongMenu extends BasicGameState {
|
|||
int searchX = search.getX(), searchY = search.getY();
|
||||
float searchBaseX = width * 0.7f;
|
||||
float searchTextX = width * 0.7125f;
|
||||
float searchRectHeight = Utils.FONT_BOLD.getLineHeight() * 2;
|
||||
float searchExtraHeight = Utils.FONT_DEFAULT.getLineHeight() * 0.7f;
|
||||
float searchRectHeight = Fonts.BOLD.getLineHeight() * 2;
|
||||
float searchExtraHeight = Fonts.DEFAULT.getLineHeight() * 0.7f;
|
||||
float searchProgress = (searchTransitionTimer < SEARCH_TRANSITION_TIME) ?
|
||||
((float) searchTransitionTimer / SEARCH_TRANSITION_TIME) : 1f;
|
||||
float oldAlpha = Colors.BLACK_ALPHA.a;
|
||||
|
@ -425,16 +427,16 @@ public class SongMenu extends BasicGameState {
|
|||
g.setColor(Colors.BLACK_ALPHA);
|
||||
g.fillRect(searchBaseX, headerY + DIVIDER_LINE_WIDTH / 2, width - searchBaseX, searchRectHeight);
|
||||
Colors.BLACK_ALPHA.a = oldAlpha;
|
||||
Utils.FONT_BOLD.drawString(searchTextX, searchY, "Search:", Colors.GREEN_SEARCH);
|
||||
Fonts.BOLD.drawString(searchTextX, searchY, "Search:", Colors.GREEN_SEARCH);
|
||||
if (searchEmpty)
|
||||
Utils.FONT_BOLD.drawString(searchX, searchY, "Type to search!", Color.white);
|
||||
Fonts.BOLD.drawString(searchX, searchY, "Type to search!", Color.white);
|
||||
else {
|
||||
g.setColor(Color.white);
|
||||
// TODO: why is this needed to correctly position the TextField?
|
||||
search.setLocation(searchX - 3, searchY - 1);
|
||||
search.render(container, g);
|
||||
search.setLocation(searchX, searchY);
|
||||
Utils.FONT_DEFAULT.drawString(searchTextX, searchY + Utils.FONT_BOLD.getLineHeight(),
|
||||
Fonts.DEFAULT.drawString(searchTextX, searchY + Fonts.BOLD.getLineHeight(),
|
||||
(searchResultString == null) ? "Searching..." : searchResultString, Color.white);
|
||||
}
|
||||
|
||||
|
|
113
src/itdelatrisu/opsu/ui/Fonts.java
Normal file
113
src/itdelatrisu/opsu/ui/Fonts.java
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* opsu! - an open-source osu! client
|
||||
* Copyright (C) 2014, 2015 Jeffrey Han
|
||||
*
|
||||
* opsu! is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* opsu! is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with opsu!. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package itdelatrisu.opsu.ui;
|
||||
|
||||
import itdelatrisu.opsu.GameImage;
|
||||
import itdelatrisu.opsu.Options;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.UnicodeFont;
|
||||
import org.newdawn.slick.font.effects.ColorEffect;
|
||||
import org.newdawn.slick.font.effects.Effect;
|
||||
import org.newdawn.slick.util.Log;
|
||||
import org.newdawn.slick.util.ResourceLoader;
|
||||
|
||||
/**
|
||||
* Fonts used for drawing.
|
||||
*/
|
||||
public class Fonts {
|
||||
public static UnicodeFont DEFAULT, BOLD, XLARGE, LARGE, MEDIUM, SMALL;
|
||||
|
||||
/** Set of all Unicode strings already loaded per font. */
|
||||
private static HashMap<UnicodeFont, HashSet<String>> loadedGlyphs = new HashMap<UnicodeFont, HashSet<String>>();
|
||||
|
||||
// This class should not be instantiated.
|
||||
private Fonts() {}
|
||||
|
||||
/**
|
||||
* Initializes all fonts.
|
||||
* @throws SlickException if ASCII glyphs could not be loaded
|
||||
* @throws FontFormatException if any font stream data does not contain the required font tables
|
||||
* @throws IOException if a font stream cannot be completely read
|
||||
*/
|
||||
public static void init() throws SlickException, FontFormatException, IOException {
|
||||
float fontBase = 12f * GameImage.getUIscale();
|
||||
Font javaFont = Font.createFont(Font.TRUETYPE_FONT, ResourceLoader.getResourceAsStream(Options.FONT_NAME));
|
||||
Font font = javaFont.deriveFont(Font.PLAIN, (int) (fontBase * 4 / 3));
|
||||
DEFAULT = new UnicodeFont(font);
|
||||
BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
|
||||
XLARGE = new UnicodeFont(font.deriveFont(fontBase * 3));
|
||||
LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
|
||||
MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
|
||||
SMALL = new UnicodeFont(font.deriveFont(fontBase));
|
||||
ColorEffect colorEffect = new ColorEffect();
|
||||
loadFont(DEFAULT, colorEffect);
|
||||
loadFont(BOLD, colorEffect);
|
||||
loadFont(XLARGE, colorEffect);
|
||||
loadFont(LARGE, colorEffect);
|
||||
loadFont(MEDIUM, colorEffect);
|
||||
loadFont(SMALL, colorEffect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads a Unicode font and its ASCII glyphs.
|
||||
* @param font the font to load
|
||||
* @param effect the font effect
|
||||
* @throws SlickException if the glyphs could not be loaded
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void loadFont(UnicodeFont font, Effect effect) throws SlickException {
|
||||
font.addAsciiGlyphs();
|
||||
font.getEffects().add(effect);
|
||||
font.loadGlyphs();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds and loads glyphs for a font.
|
||||
* @param font the font to add the glyphs to
|
||||
* @param s the string containing the glyphs to load
|
||||
*/
|
||||
public static void loadGlyphs(UnicodeFont font, String s) {
|
||||
if (s == null || s.isEmpty())
|
||||
return;
|
||||
|
||||
// get set of added strings
|
||||
HashSet<String> set = loadedGlyphs.get(font);
|
||||
if (set == null) {
|
||||
set = new HashSet<String>();
|
||||
loadedGlyphs.put(font, set);
|
||||
} else if (set.contains(s))
|
||||
return; // string already in set
|
||||
|
||||
// load glyphs
|
||||
font.addGlyphs(s);
|
||||
set.add(s);
|
||||
try {
|
||||
font.loadGlyphs();
|
||||
} catch (SlickException e) {
|
||||
Log.warn(String.format("Failed to load glyphs for string '%s'.", s), e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -178,7 +178,7 @@ public class UI {
|
|||
*/
|
||||
public static void drawTab(float x, float y, String text, boolean selected, boolean isHover) {
|
||||
Image tabImage = GameImage.MENU_TAB.getImage();
|
||||
float tabTextX = x - (Utils.FONT_MEDIUM.getWidth(text) / 2);
|
||||
float tabTextX = x - (Fonts.MEDIUM.getWidth(text) / 2);
|
||||
float tabTextY = y - (tabImage.getHeight() / 2);
|
||||
Color filter, textColor;
|
||||
if (selected) {
|
||||
|
@ -189,7 +189,7 @@ public class UI {
|
|||
textColor = Color.white;
|
||||
}
|
||||
tabImage.drawCentered(x, y, filter);
|
||||
Utils.FONT_MEDIUM.drawString(tabTextX, tabTextY, text, textColor);
|
||||
Fonts.MEDIUM.drawString(tabTextX, tabTextY, text, textColor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -201,14 +201,14 @@ public class UI {
|
|||
return;
|
||||
|
||||
String fps = String.format("%dFPS", container.getFPS());
|
||||
Utils.FONT_BOLD.drawString(
|
||||
container.getWidth() * 0.997f - Utils.FONT_BOLD.getWidth(fps),
|
||||
container.getHeight() * 0.997f - Utils.FONT_BOLD.getHeight(fps),
|
||||
Fonts.BOLD.drawString(
|
||||
container.getWidth() * 0.997f - Fonts.BOLD.getWidth(fps),
|
||||
container.getHeight() * 0.997f - Fonts.BOLD.getHeight(fps),
|
||||
Integer.toString(container.getFPS()), Color.white
|
||||
);
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
container.getWidth() * 0.997f - Utils.FONT_BOLD.getWidth("FPS"),
|
||||
container.getHeight() * 0.997f - Utils.FONT_BOLD.getHeight("FPS"),
|
||||
Fonts.DEFAULT.drawString(
|
||||
container.getWidth() * 0.997f - Fonts.BOLD.getWidth("FPS"),
|
||||
container.getHeight() * 0.997f - Fonts.BOLD.getHeight("FPS"),
|
||||
"FPS", Color.white
|
||||
);
|
||||
}
|
||||
|
@ -298,16 +298,16 @@ public class UI {
|
|||
// draw loading info
|
||||
float marginX = container.getWidth() * 0.02f, marginY = container.getHeight() * 0.02f;
|
||||
float lineY = container.getHeight() - marginY;
|
||||
int lineOffsetY = Utils.FONT_MEDIUM.getLineHeight();
|
||||
int lineOffsetY = Fonts.MEDIUM.getLineHeight();
|
||||
if (Options.isLoadVerbose()) {
|
||||
// verbose: display percentages and file names
|
||||
Utils.FONT_MEDIUM.drawString(
|
||||
Fonts.MEDIUM.drawString(
|
||||
marginX, lineY - (lineOffsetY * 2),
|
||||
String.format("%s (%d%%)", text, progress), Color.white);
|
||||
Utils.FONT_MEDIUM.drawString(marginX, lineY - lineOffsetY, file, Color.white);
|
||||
Fonts.MEDIUM.drawString(marginX, lineY - lineOffsetY, file, Color.white);
|
||||
} else {
|
||||
// draw loading bar
|
||||
Utils.FONT_MEDIUM.drawString(marginX, lineY - (lineOffsetY * 2), text, Color.white);
|
||||
Fonts.MEDIUM.drawString(marginX, lineY - (lineOffsetY * 2), text, Color.white);
|
||||
g.setColor(Color.white);
|
||||
g.fillRoundRect(marginX, lineY - (lineOffsetY / 2f),
|
||||
(container.getWidth() - (marginX * 2f)) * progress / 100f, lineOffsetY / 4f, 4
|
||||
|
@ -376,20 +376,20 @@ public class UI {
|
|||
int containerWidth = container.getWidth(), containerHeight = container.getHeight();
|
||||
int margin = containerWidth / 100, textMarginX = 2;
|
||||
int offset = GameImage.CURSOR_MIDDLE.getImage().getWidth() / 2;
|
||||
int lineHeight = Utils.FONT_SMALL.getLineHeight();
|
||||
int lineHeight = Fonts.SMALL.getLineHeight();
|
||||
int textWidth = textMarginX * 2, textHeight = lineHeight;
|
||||
if (tooltipNewlines) {
|
||||
String[] lines = tooltip.split("\\n");
|
||||
int maxWidth = Utils.FONT_SMALL.getWidth(lines[0]);
|
||||
int maxWidth = Fonts.SMALL.getWidth(lines[0]);
|
||||
for (int i = 1; i < lines.length; i++) {
|
||||
int w = Utils.FONT_SMALL.getWidth(lines[i]);
|
||||
int w = Fonts.SMALL.getWidth(lines[i]);
|
||||
if (w > maxWidth)
|
||||
maxWidth = w;
|
||||
}
|
||||
textWidth += maxWidth;
|
||||
textHeight += lineHeight * (lines.length - 1);
|
||||
} else
|
||||
textWidth += Utils.FONT_SMALL.getWidth(tooltip);
|
||||
textWidth += Fonts.SMALL.getWidth(tooltip);
|
||||
|
||||
// get drawing coordinates
|
||||
int x = input.getMouseX() + offset, y = input.getMouseY() + offset;
|
||||
|
@ -417,7 +417,7 @@ public class UI {
|
|||
Colors.DARK_GRAY.a = oldAlpha;
|
||||
oldAlpha = Colors.WHITE_ALPHA.a;
|
||||
Colors.WHITE_ALPHA.a = alpha;
|
||||
Utils.FONT_SMALL.drawString(x + textMarginX, y, tooltip, Colors.WHITE_ALPHA);
|
||||
Fonts.SMALL.drawString(x + textMarginX, y, tooltip, Colors.WHITE_ALPHA);
|
||||
Colors.WHITE_ALPHA.a = oldAlpha;
|
||||
}
|
||||
|
||||
|
@ -473,15 +473,15 @@ public class UI {
|
|||
if (barNotifTimer >= BAR_NOTIFICATION_TIME * 0.9f)
|
||||
alpha -= 1 - ((BAR_NOTIFICATION_TIME - barNotifTimer) / (BAR_NOTIFICATION_TIME * 0.1f));
|
||||
int midX = container.getWidth() / 2, midY = container.getHeight() / 2;
|
||||
float barHeight = Utils.FONT_LARGE.getLineHeight() * (1f + 0.6f * Math.min(barNotifTimer * 15f / BAR_NOTIFICATION_TIME, 1f));
|
||||
float barHeight = Fonts.LARGE.getLineHeight() * (1f + 0.6f * Math.min(barNotifTimer * 15f / BAR_NOTIFICATION_TIME, 1f));
|
||||
float oldAlphaB = Colors.BLACK_ALPHA.a, oldAlphaW = Colors.WHITE_ALPHA.a;
|
||||
Colors.BLACK_ALPHA.a *= alpha;
|
||||
Colors.WHITE_ALPHA.a = alpha;
|
||||
g.setColor(Colors.BLACK_ALPHA);
|
||||
g.fillRect(0, midY - barHeight / 2f, container.getWidth(), barHeight);
|
||||
Utils.FONT_LARGE.drawString(
|
||||
midX - Utils.FONT_LARGE.getWidth(barNotif) / 2f,
|
||||
midY - Utils.FONT_LARGE.getLineHeight() / 2.2f,
|
||||
Fonts.LARGE.drawString(
|
||||
midX - Fonts.LARGE.getWidth(barNotif) / 2f,
|
||||
midY - Fonts.LARGE.getLineHeight() / 2.2f,
|
||||
barNotif, Colors.WHITE_ALPHA);
|
||||
Colors.BLACK_ALPHA.a = oldAlphaB;
|
||||
Colors.WHITE_ALPHA.a = oldAlphaW;
|
||||
|
|
Loading…
Reference in New Issue
Block a user