Eliminated unneeded calls to Graphics.setColor().

The method creates a new Color object each call, so set color in UnicodeFont.drawString() instead.

Also slightly padded the song information text.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-01-16 14:46:45 -05:00
parent 816c9bb659
commit be1ec64f28
5 changed files with 33 additions and 35 deletions

View File

@ -118,11 +118,10 @@ public class GameRanking extends BasicGameState {
} }
// header text // header text
g.setColor(Color.white);
Utils.FONT_LARGE.drawString(10, 0, Utils.FONT_LARGE.drawString(10, 0,
String.format("%s - %s [%s]", osu.getArtist(), osu.getTitle(), osu.version)); String.format("%s - %s [%s]", osu.getArtist(), osu.getTitle(), osu.version), Color.white);
Utils.FONT_MEDIUM.drawString(10, Utils.FONT_LARGE.getLineHeight() - 6, Utils.FONT_MEDIUM.drawString(10, Utils.FONT_LARGE.getLineHeight() - 6,
String.format("Beatmap by %s", osu.creator)); String.format("Beatmap by %s", osu.creator), Color.white);
// buttons // buttons
retryButton.draw(); retryButton.draw();

View File

@ -88,23 +88,23 @@ public class MainMenuExit extends BasicGameState {
public void render(GameContainer container, StateBasedGame game, Graphics g) public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException { throws SlickException {
g.setBackground(Color.black); g.setBackground(Color.black);
g.setColor(Color.white);
// draw text // draw text
float c = container.getWidth() * 0.02f; float c = container.getWidth() * 0.02f;
Utils.FONT_LARGE.drawString(c, c, "Are you sure you want to exit opsu!?"); Utils.FONT_LARGE.drawString(c, c, "Are you sure you want to exit opsu!?", Color.white);
// draw buttons // draw buttons
yesButton.draw(Color.green); yesButton.draw(Color.green);
noButton.draw(Color.red); noButton.draw(Color.red);
g.setFont(Utils.FONT_XLARGE); Utils.FONT_XLARGE.drawString(
g.drawString("1. Yes",
yesButton.getX() - (Utils.FONT_XLARGE.getWidth("1. Yes") / 2f), yesButton.getX() - (Utils.FONT_XLARGE.getWidth("1. Yes") / 2f),
yesButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f) yesButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f),
"1. Yes", Color.white
); );
g.drawString("2. No", Utils.FONT_XLARGE.drawString(
noButton.getX() - (Utils.FONT_XLARGE.getWidth("2. No") / 2f), noButton.getX() - (Utils.FONT_XLARGE.getWidth("2. No") / 2f),
noButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f) noButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f),
"2. No", Color.white
); );
Utils.drawFPS(); Utils.drawFPS();

View File

@ -771,7 +771,6 @@ public class Options extends BasicGameState {
public void render(GameContainer container, StateBasedGame game, Graphics g) public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException { throws SlickException {
g.setBackground(Utils.COLOR_BLACK_ALPHA); g.setBackground(Utils.COLOR_BLACK_ALPHA);
g.setColor(Color.white);
int width = container.getWidth(); int width = container.getWidth();
int height = container.getHeight(); int height = container.getHeight();
@ -779,17 +778,17 @@ public class Options extends BasicGameState {
// title // title
Utils.FONT_XLARGE.drawString( Utils.FONT_XLARGE.drawString(
(width / 2) - (Utils.FONT_XLARGE.getWidth("GAME OPTIONS") / 2), (width / 2) - (Utils.FONT_XLARGE.getWidth("GAME OPTIONS") / 2), 10,
10, "GAME OPTIONS" "GAME OPTIONS", Color.white
); );
Utils.FONT_DEFAULT.drawString( Utils.FONT_DEFAULT.drawString(
(width / 2) - (Utils.FONT_DEFAULT.getWidth("Click or drag an option to change it.") / 2), (width / 2) - (Utils.FONT_DEFAULT.getWidth("Click or drag an option to change it.") / 2),
10 + Utils.FONT_XLARGE.getLineHeight(), "Click or drag an option to change it." 10 + Utils.FONT_XLARGE.getLineHeight(),
"Click or drag an option to change it.", Color.white
); );
// game options // game options
g.setLineWidth(1f); g.setLineWidth(1f);
g.setFont(Utils.FONT_LARGE);
switch (currentTab) { switch (currentTab) {
case TAB_DISPLAY: case TAB_DISPLAY:
for (int i = 0; i < displayOptions.length; i++) for (int i = 0; i < displayOptions.length; i++)
@ -999,10 +998,9 @@ public class Options extends BasicGameState {
int textHeight = Utils.FONT_LARGE.getLineHeight(); int textHeight = Utils.FONT_LARGE.getLineHeight();
float y = textY + (pos * offsetY); float y = textY + (pos * offsetY);
g.setColor(Color.white); Utils.FONT_LARGE.drawString(width / 30, y, option.getName(), Color.white);
g.drawString(option.getName(), width / 30, y); Utils.FONT_LARGE.drawString(width / 2, y, option.getValueString(), Color.white);
g.drawString(option.getValueString(), width / 2, y); Utils.FONT_SMALL.drawString(width / 30, y + textHeight, option.getDescription(), Color.white);
Utils.FONT_SMALL.drawString(width / 30, y + textHeight, option.getDescription());
g.setColor(Utils.COLOR_WHITE_ALPHA); g.setColor(Utils.COLOR_WHITE_ALPHA);
g.drawLine(0, y + textHeight, width, y + textHeight); g.drawLine(0, y + textHeight, width, y + textHeight);
} }

View File

@ -265,26 +265,27 @@ public class SongMenu extends BasicGameState {
// header // header
if (focusNode != null) { if (focusNode != null) {
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())
loader.draw(); loader.draw(marginX, marginY);
else else
musicNote.draw(); musicNote.draw(marginX, marginY);
int iconWidth = musicNote.getWidth(); int iconWidth = musicNote.getWidth();
int iconHeight = musicNote.getHeight(); int iconHeight = musicNote.getHeight();
if (songInfo == null) if (songInfo == null)
songInfo = focusNode.getInfo(); songInfo = focusNode.getInfo();
g.setColor(Color.white); marginX += 5;
Utils.FONT_LARGE.drawString(iconWidth + 5, -3, songInfo[0]); Utils.FONT_LARGE.drawString(marginX + iconWidth, marginY, songInfo[0], Color.white);
Utils.FONT_DEFAULT.drawString( Utils.FONT_DEFAULT.drawString(marginX + iconWidth, marginY + Utils.FONT_LARGE.getLineHeight() * 0.75f, songInfo[1], Color.white);
iconWidth + 5, -3 + Utils.FONT_LARGE.getLineHeight() * 0.75f, songInfo[1]); float headerY = marginY + iconHeight;
int headerY = iconHeight - 3; Utils.FONT_BOLD.drawString(marginX, headerY, songInfo[2], Color.white);
Utils.FONT_BOLD.drawString(5, headerY, songInfo[2]);
headerY += Utils.FONT_BOLD.getLineHeight() - 6; headerY += Utils.FONT_BOLD.getLineHeight() - 6;
Utils.FONT_DEFAULT.drawString(5, headerY, songInfo[3]); Utils.FONT_DEFAULT.drawString(marginX, headerY, songInfo[3], Color.white);
headerY += Utils.FONT_DEFAULT.getLineHeight() - 4; headerY += Utils.FONT_DEFAULT.getLineHeight() - 4;
Utils.FONT_SMALL.drawString(5, headerY, songInfo[4]); Utils.FONT_SMALL.drawString(marginX, headerY, songInfo[4], Color.white);
} }
// song buttons // song buttons

View File

@ -165,16 +165,16 @@ public class Splash extends BasicGameState {
* @param file the file being loaded * @param file the file being loaded
*/ */
private void drawLoadProgress(Graphics g, int progress, String text, String file) { private void drawLoadProgress(Graphics g, int progress, String text, String file) {
g.setColor(Color.white);
g.setFont(Utils.FONT_MEDIUM);
int lineY = container.getHeight() - 25; int lineY = container.getHeight() - 25;
int lineOffsetY = Utils.FONT_MEDIUM.getLineHeight(); int lineOffsetY = Utils.FONT_MEDIUM.getLineHeight();
if (Options.isLoadVerbose()) { if (Options.isLoadVerbose()) {
g.drawString(String.format("%s (%d%%)", text, progress), 25, lineY - (lineOffsetY * 2)); Utils.FONT_MEDIUM.drawString(
g.drawString(file, 25, lineY - lineOffsetY); 25, lineY - (lineOffsetY * 2),
String.format("%s (%d%%)", text, progress), Color.white);
Utils.FONT_MEDIUM.drawString(25, lineY - lineOffsetY, file, Color.white);
} else { } else {
g.drawString(text, 25, lineY - (lineOffsetY * 2)); Utils.FONT_MEDIUM.drawString(25, lineY - (lineOffsetY * 2), text, Color.white);
g.setColor(Color.white);
g.fillRect(25, lineY - (lineOffsetY / 2f), (container.getWidth() - 50) * progress / 100f, lineOffsetY / 4f); g.fillRect(25, lineY - (lineOffsetY / 2f), (container.getWidth() - 50) * progress / 100f, lineOffsetY / 4f);
} }
} }