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
g.setColor(Color.white);
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,
String.format("Beatmap by %s", osu.creator));
String.format("Beatmap by %s", osu.creator), Color.white);
// buttons
retryButton.draw();

View File

@ -88,23 +88,23 @@ public class MainMenuExit extends BasicGameState {
public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException {
g.setBackground(Color.black);
g.setColor(Color.white);
// draw text
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
yesButton.draw(Color.green);
noButton.draw(Color.red);
g.setFont(Utils.FONT_XLARGE);
g.drawString("1. Yes",
Utils.FONT_XLARGE.drawString(
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.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f)
noButton.getY() - (Utils.FONT_XLARGE.getLineHeight() / 2f),
"2. No", Color.white
);
Utils.drawFPS();

View File

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

View File

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

View File

@ -165,16 +165,16 @@ public class Splash extends BasicGameState {
* @param file the file being loaded
*/
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 lineOffsetY = Utils.FONT_MEDIUM.getLineHeight();
if (Options.isLoadVerbose()) {
g.drawString(String.format("%s (%d%%)", text, progress), 25, lineY - (lineOffsetY * 2));
g.drawString(file, 25, lineY - lineOffsetY);
Utils.FONT_MEDIUM.drawString(
25, lineY - (lineOffsetY * 2),
String.format("%s (%d%%)", text, progress), Color.white);
Utils.FONT_MEDIUM.drawString(25, lineY - lineOffsetY, file, Color.white);
} 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);
}
}