Use UnicodeFont instead of TrueTypeFont.
- Fixes issue #4. Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
parent
83e486054f
commit
9a94c03b4e
|
@ -36,7 +36,8 @@ import org.newdawn.slick.GameContainer;
|
|||
import org.newdawn.slick.Image;
|
||||
import org.newdawn.slick.Input;
|
||||
import org.newdawn.slick.SlickException;
|
||||
import org.newdawn.slick.TrueTypeFont;
|
||||
import org.newdawn.slick.UnicodeFont;
|
||||
import org.newdawn.slick.font.effects.ColorEffect;
|
||||
import org.newdawn.slick.imageout.ImageOut;
|
||||
import org.newdawn.slick.state.StateBasedGame;
|
||||
import org.newdawn.slick.util.Log;
|
||||
|
@ -72,7 +73,7 @@ public class Utils {
|
|||
/**
|
||||
* Game fonts.
|
||||
*/
|
||||
public static TrueTypeFont
|
||||
public static UnicodeFont
|
||||
FONT_DEFAULT, FONT_BOLD,
|
||||
FONT_XLARGE, FONT_LARGE, FONT_MEDIUM, FONT_SMALL;
|
||||
|
||||
|
@ -117,6 +118,7 @@ public class Utils {
|
|||
* @param game the game object
|
||||
* @throws SlickException
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void init(GameContainer container, StateBasedGame game)
|
||||
throws SlickException {
|
||||
Utils.container = container;
|
||||
|
@ -155,12 +157,31 @@ public class Utils {
|
|||
fontBase = 14f;
|
||||
|
||||
Font font = new Font("Lucida Sans Unicode", Font.PLAIN, (int) (fontBase * 4 / 3));
|
||||
FONT_DEFAULT = new TrueTypeFont(font, false);
|
||||
FONT_BOLD = new TrueTypeFont(font.deriveFont(Font.BOLD), false);
|
||||
FONT_XLARGE = new TrueTypeFont(font.deriveFont(fontBase * 4), false);
|
||||
FONT_LARGE = new TrueTypeFont(font.deriveFont(fontBase * 2), false);
|
||||
FONT_MEDIUM = new TrueTypeFont(font.deriveFont(fontBase * 3 / 2), false);
|
||||
FONT_SMALL = new TrueTypeFont(font.deriveFont(fontBase), false);
|
||||
FONT_DEFAULT = new UnicodeFont(font);
|
||||
FONT_BOLD = new UnicodeFont(font.deriveFont(Font.BOLD));
|
||||
FONT_XLARGE = new UnicodeFont(font.deriveFont(fontBase * 4));
|
||||
FONT_LARGE = new UnicodeFont(font.deriveFont(fontBase * 2));
|
||||
FONT_MEDIUM = new UnicodeFont(font.deriveFont(fontBase * 3 / 2));
|
||||
FONT_SMALL = new UnicodeFont(font.deriveFont(fontBase));
|
||||
FONT_DEFAULT.addAsciiGlyphs();
|
||||
FONT_BOLD.addAsciiGlyphs();
|
||||
FONT_XLARGE.addAsciiGlyphs();
|
||||
FONT_LARGE.addAsciiGlyphs();
|
||||
FONT_MEDIUM.addAsciiGlyphs();
|
||||
FONT_SMALL.addAsciiGlyphs();
|
||||
ColorEffect colorEffect = new ColorEffect();
|
||||
FONT_DEFAULT.getEffects().add(colorEffect);
|
||||
FONT_BOLD.getEffects().add(colorEffect);
|
||||
FONT_XLARGE.getEffects().add(colorEffect);
|
||||
FONT_LARGE.getEffects().add(colorEffect);
|
||||
FONT_MEDIUM.getEffects().add(colorEffect);
|
||||
FONT_SMALL.getEffects().add(colorEffect);
|
||||
FONT_DEFAULT.loadGlyphs();
|
||||
FONT_BOLD.loadGlyphs();
|
||||
FONT_XLARGE.loadGlyphs();
|
||||
FONT_LARGE.loadGlyphs();
|
||||
FONT_MEDIUM.loadGlyphs();
|
||||
FONT_SMALL.loadGlyphs();
|
||||
|
||||
// tab image
|
||||
tab = new Image("selection-tab.png");
|
||||
|
|
|
@ -100,11 +100,11 @@ public class MainMenuExit extends BasicGameState {
|
|||
g.setFont(Utils.FONT_XLARGE);
|
||||
g.drawString("1. Yes",
|
||||
yesButton.getX() - (Utils.FONT_XLARGE.getWidth("1. Yes") / 2f),
|
||||
yesButton.getY() - (Utils.FONT_XLARGE.getHeight() / 2f)
|
||||
yesButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f)
|
||||
);
|
||||
g.drawString("2. No",
|
||||
noButton.getX() - (Utils.FONT_XLARGE.getWidth("2. No") / 2f),
|
||||
noButton.getY() - (Utils.FONT_XLARGE.getHeight() / 2f)
|
||||
noButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f)
|
||||
);
|
||||
|
||||
Utils.drawFPS();
|
||||
|
|
|
@ -410,7 +410,7 @@ public class Options extends BasicGameState {
|
|||
Image tab = Utils.getTabImage();
|
||||
int subtextWidth = Utils.FONT_DEFAULT.getWidth("Click or drag an option to change it.");
|
||||
float tabX = (width / 50) + (tab.getWidth() / 2f);
|
||||
float tabY = 15 + Utils.FONT_XLARGE.getHeight() + (tab.getHeight() / 2f);
|
||||
float tabY = 15 + Utils.FONT_XLARGE.getLineHeight() + (tab.getHeight() / 2f);
|
||||
float tabOffset = (float) Math.min(tab.getWidth(),
|
||||
((width - subtextWidth - tab.getWidth()) / 2) / TAB_MAX);
|
||||
for (int i = 0; i < optionTabs.length; i++)
|
||||
|
@ -433,7 +433,7 @@ public class Options extends BasicGameState {
|
|||
);
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
(width / 2) - (Utils.FONT_DEFAULT.getWidth("Click or drag an option to change it.") / 2),
|
||||
10 + Utils.FONT_XLARGE.getHeight(), "Click or drag an option to change it."
|
||||
10 + Utils.FONT_XLARGE.getLineHeight(), "Click or drag an option to change it."
|
||||
);
|
||||
|
||||
// game options
|
||||
|
@ -487,7 +487,7 @@ public class Options extends BasicGameState {
|
|||
g.setColor(Color.white);
|
||||
Utils.FONT_LARGE.drawString(
|
||||
(width / 2) - (Utils.FONT_LARGE.getWidth("Please enter a letter or digit.") / 2),
|
||||
(height / 2) - Utils.FONT_LARGE.getHeight(), "Please enter a letter or digit."
|
||||
(height / 2) - Utils.FONT_LARGE.getLineHeight(), "Please enter a letter or digit."
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -922,7 +922,7 @@ public class Options extends BasicGameState {
|
|||
*/
|
||||
private void drawOption(int pos, String label, String value, String notes) {
|
||||
int width = container.getWidth();
|
||||
int textHeight = Utils.FONT_LARGE.getHeight();
|
||||
int textHeight = Utils.FONT_LARGE.getLineHeight();
|
||||
float y = textY + (pos * offsetY);
|
||||
|
||||
g.setColor(Color.white);
|
||||
|
@ -945,7 +945,7 @@ public class Options extends BasicGameState {
|
|||
if (y < textY || y > textY + (offsetY * maxOptionsScreen))
|
||||
return option;
|
||||
|
||||
int index = (y - textY + Utils.FONT_LARGE.getHeight()) / offsetY;
|
||||
int index = (y - textY + Utils.FONT_LARGE.getLineHeight()) / offsetY;
|
||||
switch (currentTab) {
|
||||
case TAB_DISPLAY:
|
||||
if (index < displayOptions.length)
|
||||
|
|
|
@ -169,7 +169,7 @@ public class SongMenu extends BasicGameState {
|
|||
container, Utils.FONT_DEFAULT,
|
||||
(int) buttonX + (tab.getWidth() / 2) + searchIcon.getWidth(),
|
||||
(int) ((height * 0.15f) - (tab.getHeight() * 2.5f)),
|
||||
(int) (buttonWidth / 2), Utils.FONT_DEFAULT.getHeight()
|
||||
(int) (buttonWidth / 2), Utils.FONT_DEFAULT.getLineHeight()
|
||||
);
|
||||
search.setBackgroundColor(Color.transparent);
|
||||
search.setBorderColor(Color.transparent);
|
||||
|
@ -182,7 +182,7 @@ public class SongMenu extends BasicGameState {
|
|||
optionsButton = new GUIMenuButton(optionsIcon, search.getX() - (optionsIcon.getWidth() * 1.5f), search.getY());
|
||||
|
||||
// music note
|
||||
int musicNoteDim = (int) (Utils.FONT_LARGE.getHeight() * 0.75f + Utils.FONT_DEFAULT.getHeight());
|
||||
int musicNoteDim = (int) (Utils.FONT_LARGE.getLineHeight() * 0.75f + Utils.FONT_DEFAULT.getLineHeight());
|
||||
musicNote = new Image("music-note.png").getScaledCopy(musicNoteDim, musicNoteDim);
|
||||
|
||||
// loader
|
||||
|
@ -227,7 +227,7 @@ public class SongMenu extends BasicGameState {
|
|||
g.setColor(Color.white);
|
||||
Utils.FONT_LARGE.drawString(iconWidth + 5, -3, info[0]);
|
||||
Utils.FONT_DEFAULT.drawString(
|
||||
iconWidth + 5, -3 + Utils.FONT_LARGE.getHeight() * 0.75f, info[1]);
|
||||
iconWidth + 5, -3 + Utils.FONT_LARGE.getLineHeight() * 0.75f, info[1]);
|
||||
int headerY = iconHeight - 3;
|
||||
Utils.FONT_BOLD.drawString(5, headerY, info[2]);
|
||||
headerY += Utils.FONT_BOLD.getLineHeight() - 6;
|
||||
|
|
Loading…
Reference in New Issue
Block a user