More graphical updates, some code cleanup, and minor fixes.

- The MenuButton class now fully supports hover effects (scale, fade, rotate) for Animations.
- Used a fixed location for the selection buttons in the song menu (previously based on the "back" button width, which varies widely in different skins).
- Added hover effects for "retry" and "exit" buttons in the ranking screen.
- Changed animation speed of back/skip buttons.
- Fixed a bug where main menu showed the incorrect number of songs loaded during searches.
- Removed unneeded draw() methods in Utils for color filters (since 69f5aa5).
- Moved Utils.drawCentered(Image, ...) into the Image class.
- Added overwritten Image class to Maven excludes.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han 2015-02-19 00:33:32 -05:00
parent 1a4120a736
commit 25a7a826f1
14 changed files with 107 additions and 108 deletions

View File

@ -100,6 +100,7 @@
<!-- Overwritten classes --> <!-- Overwritten classes -->
<artifact>org.slick2d:slick2d-core</artifact> <artifact>org.slick2d:slick2d-core</artifact>
<excludes> <excludes>
<exclude>org/newdawn/slick/Image.*</exclude>
<exclude>org/newdawn/slick/Music.*</exclude> <exclude>org/newdawn/slick/Music.*</exclude>
<exclude>org/newdawn/slick/openal/AudioInputStream*</exclude> <exclude>org/newdawn/slick/openal/AudioInputStream*</exclude>
<exclude>org/newdawn/slick/openal/OpenALStreamPlayer*</exclude> <exclude>org/newdawn/slick/openal/OpenALStreamPlayer*</exclude>

View File

@ -167,57 +167,67 @@ public class MenuButton {
/** /**
* Draws the button. * Draws the button.
*/ */
public void draw() { draw(null); } public void draw() { draw(Color.white); }
/** /**
* Draw the button with a color filter. * Draw the button with a color filter.
* @param filter the color to filter with when drawing * @param filter the color to filter with when drawing
*/ */
@SuppressWarnings("deprecation")
public void draw(Color filter) { public void draw(Color filter) {
if (img != null) { // animations: get current frame
if (imgL == null) { Image image = this.img;
if (hoverEffect == 0) if (image == null) {
Utils.draw(img, x - xRadius, y - yRadius, filter); anim.updateNoDraw();
else { image = anim.getCurrentFrame();
Image hoverImg = img; }
float oldAlpha = img.getAlpha();
float oldAngle = img.getRotation(); // normal images
if ((hoverEffect & EFFECT_EXPAND) > 0) { if (imgL == null) {
if (scale != 1f) { if (hoverEffect == 0)
hoverImg = hoverImg.getScaledCopy(scale); image.draw(x - xRadius, y - yRadius, filter);
hoverImg.setAlpha(oldAlpha); else {
} float oldAlpha = image.getAlpha();
} float oldAngle = image.getRotation();
if ((hoverEffect & EFFECT_FADE) > 0) if ((hoverEffect & EFFECT_EXPAND) > 0) {
hoverImg.setAlpha(alpha); if (scale != 1f) {
if ((hoverEffect & EFFECT_ROTATE) > 0) image = image.getScaledCopy(scale);
hoverImg.setRotation(angle); image.setAlpha(oldAlpha);
Utils.draw(hoverImg, x - xRadius, y - yRadius, filter);
if (hoverImg != img) {
hoverImg.setAlpha(oldAlpha);
hoverImg.setRotation(oldAngle);
} }
} }
} else { if ((hoverEffect & EFFECT_FADE) > 0)
if (hoverEffect == 0) { image.setAlpha(alpha);
Utils.draw(img, x - xRadius + imgL.getWidth(), y - yRadius, filter); if ((hoverEffect & EFFECT_ROTATE) > 0)
Utils.draw(imgL, x - xRadius, y - yRadius, filter); image.setRotation(angle);
Utils.draw(imgR, x + xRadius - imgR.getWidth(), y - yRadius, filter); image.draw(x - xRadius, y - yRadius, filter);
} else if ((hoverEffect & EFFECT_FADE) > 0) { if (image != this.img) {
float a = img.getAlpha(), aL = imgL.getAlpha(), aR = imgR.getAlpha(); image.setAlpha(oldAlpha);
img.setAlpha(alpha); image.setRotation(oldAngle);
imgL.setAlpha(alpha);
imgR.setAlpha(alpha);
Utils.draw(img, x - xRadius + imgL.getWidth(), y - yRadius, filter);
Utils.draw(imgL, x - xRadius, y - yRadius, filter);
Utils.draw(imgR, x + xRadius - imgR.getWidth(), y - yRadius, filter);
img.setAlpha(a);
imgL.setAlpha(aL);
imgR.setAlpha(aR);
} }
} }
} else }
Utils.draw(anim, x - xRadius, y - yRadius, filter);
// 3-part images
else {
if (hoverEffect == 0) {
image.draw(x - xRadius + imgL.getWidth(), y - yRadius, filter);
imgL.draw(x - xRadius, y - yRadius, filter);
imgR.draw(x + xRadius - imgR.getWidth(), y - yRadius, filter);
} else if ((hoverEffect & EFFECT_FADE) > 0) {
float a = image.getAlpha(), aL = imgL.getAlpha(), aR = imgR.getAlpha();
image.setAlpha(alpha);
imgL.setAlpha(alpha);
imgR.setAlpha(alpha);
image.draw(x - xRadius + imgL.getWidth(), y - yRadius, filter);
imgL.draw(x - xRadius, y - yRadius, filter);
imgR.draw(x + xRadius - imgR.getWidth(), y - yRadius, filter);
image.setAlpha(a);
imgL.setAlpha(aL);
imgR.setAlpha(aR);
}
}
// text
if (text != null) if (text != null)
font.drawString(x - font.getWidth(text) / 2f, y - font.getLineHeight() / 2f, text, color); font.drawString(x - font.getWidth(text) / 2f, y - font.getLineHeight() / 2f, text, color);
} }
@ -365,14 +375,15 @@ public class MenuButton {
* and expansion direction. * and expansion direction.
*/ */
private void setHoverRadius() { private void setHoverRadius() {
if (img == null) Image image = this.img;
return; if (image == null)
image = anim.getCurrentFrame();
int xOffset = 0, yOffset = 0; int xOffset = 0, yOffset = 0;
if (dir != Expand.CENTER) { if (dir != Expand.CENTER) {
// offset by difference between normal/scaled image dimensions // offset by difference between normal/scaled image dimensions
xOffset = (int) ((scale - 1f) * img.getWidth()); xOffset = (int) ((scale - 1f) * image.getWidth());
yOffset = (int) ((scale - 1f) * img.getHeight()); yOffset = (int) ((scale - 1f) * image.getHeight());
if (dir == Expand.UP || dir == Expand.DOWN) if (dir == Expand.UP || dir == Expand.DOWN)
xOffset = 0; // no horizontal offset xOffset = 0; // no horizontal offset
if (dir == Expand.RIGHT || dir == Expand.LEFT) if (dir == Expand.RIGHT || dir == Expand.LEFT)
@ -382,7 +393,7 @@ public class MenuButton {
if (dir == Expand.DOWN || dir == Expand.DOWN_LEFT || dir == Expand.DOWN_RIGHT) if (dir == Expand.DOWN || dir == Expand.DOWN_LEFT || dir == Expand.DOWN_RIGHT)
yOffset *= -1; // flip y for down yOffset *= -1; // flip y for down
} }
this.xRadius = ((img.getWidth() * scale) + xOffset) / 2f; this.xRadius = ((image.getWidth() * scale) + xOffset) / 2f;
this.yRadius = ((img.getHeight() * scale) + yOffset) / 2f; this.yRadius = ((image.getHeight() * scale) + yOffset) / 2f;
} }
} }

View File

@ -239,6 +239,11 @@ public class OsuGroupList {
*/ */
public int getMapCount() { return mapCount; } public int getMapCount() { return mapCount; }
/**
* Returns the total number of parsed maps sets.
*/
public int getMapSetCount() { return parsedNodes.size(); }
/** /**
* Returns the OsuGroupNode at an index, disregarding expansions. * Returns the OsuGroupNode at an index, disregarding expansions.
*/ */

View File

@ -223,7 +223,7 @@ public class Utils {
// back button // back button
if (GameImage.MENU_BACK.getImages() != null) { if (GameImage.MENU_BACK.getImages() != null) {
Animation back = GameImage.MENU_BACK.getAnimation(200); Animation back = GameImage.MENU_BACK.getAnimation(120);
backButton = new MenuButton(back, back.getWidth() / 2f, height - (back.getHeight() / 2f)); backButton = new MenuButton(back, back.getWidth() / 2f, height - (back.getHeight() / 2f));
} else { } else {
Image back = GameImage.MENU_BACK.getImage(); Image back = GameImage.MENU_BACK.getImage();
@ -258,21 +258,10 @@ public class Utils {
filter = (isHover) ? Utils.COLOR_RED_HOVER : Color.red; filter = (isHover) ? Utils.COLOR_RED_HOVER : Color.red;
textColor = Color.white; textColor = Color.white;
} }
Utils.drawCentered(tabImage, x, y, filter); tabImage.drawCentered(x, y, filter);
Utils.FONT_MEDIUM.drawString(tabTextX, tabTextY, text, textColor); Utils.FONT_MEDIUM.drawString(tabTextX, tabTextY, text, textColor);
} }
/**
* Draws an image based on its center with a color filter.
* @param img the image to draw
* @param x the center x coordinate
* @param y the center y coordinate
* @param color the color filter to apply
*/
public static void drawCentered(Image img, float x, float y, Color color) {
img.draw(x - (img.getWidth() / 2f), y - (img.getHeight() / 2f), color);
}
/** /**
* Draws an animation based on its center. * Draws an animation based on its center.
* @param anim the animation to draw * @param anim the animation to draw
@ -283,34 +272,6 @@ public class Utils {
anim.draw(x - (anim.getWidth() / 2f), y - (anim.getHeight() / 2f)); anim.draw(x - (anim.getWidth() / 2f), y - (anim.getHeight() / 2f));
} }
/**
* Draws an image at the given location.
* @param img the image to draw
* @param x the x coordinate
* @param y the y coordinate
* @param color the color filter to apply
*/
public static void draw(Image img, float x, float y, Color color) {
if (color == null)
img.draw(x, y);
else
img.draw(x, y, color);
}
/**
* Draws an animation at the given location.
* @param anim the animation to draw
* @param x the x coordinate
* @param y the y coordinate
* @param color the color filter to apply
*/
public static void draw(Animation anim, float x, float y, Color color) {
if (color == null)
anim.draw(x, y);
else
anim.draw(x, y, color);
}
/** /**
* Returns a bounded value for a base value and displacement. * Returns a bounded value for a base value and displacement.
* @param base the initial value * @param base the initial value

View File

@ -89,13 +89,13 @@ public class Circle implements HitObject {
float approachScale = 1 + scale * 3; float approachScale = 1 + scale * 3;
color.a = 1 - scale; color.a = 1 - scale;
Utils.drawCentered(GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale), x, y, color); GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
float alpha = Utils.clamp((1 - scale) * 2, 0, 1); float alpha = Utils.clamp((1 - scale) * 2, 0, 1);
color.a = alpha; color.a = alpha;
Utils.COLOR_WHITE_FADE.a = alpha; Utils.COLOR_WHITE_FADE.a = alpha;
Utils.drawCentered(GameImage.HITCIRCLE.getImage(), x, y, color); GameImage.HITCIRCLE.getImage().drawCentered(x, y, color);
Utils.drawCentered(GameImage.HITCIRCLE_OVERLAY.getImage(), x, y, Utils.COLOR_WHITE_FADE); GameImage.HITCIRCLE_OVERLAY.getImage().drawCentered(x, y, Utils.COLOR_WHITE_FADE);
color.a = oldAlpha; color.a = oldAlpha;
Utils.COLOR_WHITE_FADE.a = 1f; Utils.COLOR_WHITE_FADE.a = 1f;

View File

@ -174,12 +174,12 @@ public class Slider implements HitObject {
// end circle // end circle
float[] endPos = curve.pointAt(1); float[] endPos = curve.pointAt(1);
Utils.drawCentered(hitCircle, endPos[0], endPos[1], color); hitCircle.drawCentered(endPos[0], endPos[1], color);
Utils.drawCentered(hitCircleOverlay, endPos[0], endPos[1], Utils.COLOR_WHITE_FADE); hitCircleOverlay.drawCentered(endPos[0], endPos[1], Utils.COLOR_WHITE_FADE);
// start circle // start circle
Utils.drawCentered(hitCircle, x, y, color); hitCircle.drawCentered(x, y, color);
Utils.drawCentered(hitCircleOverlay, x, y, Utils.COLOR_WHITE_FADE); hitCircleOverlay.drawCentered(x, y, Utils.COLOR_WHITE_FADE);
if (sliderClicked) if (sliderClicked)
; // don't draw current combo number if already clicked ; // don't draw current combo number if already clicked
else else
@ -213,7 +213,7 @@ public class Slider implements HitObject {
if (timeDiff >= 0) { if (timeDiff >= 0) {
// approach circle // approach circle
color.a = 1 - scale; color.a = 1 - scale;
Utils.drawCentered(GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale), x, y, color); GameImage.APPROACHCIRCLE.getImage().getScaledCopy(approachScale).drawCentered(x, y, color);
} else { } else {
float[] c = curve.pointAt(getT(trackPosition, false)); float[] c = curve.pointAt(getT(trackPosition, false));
float[] c2 = curve.pointAt(getT(trackPosition, false) + 0.01f); float[] c2 = curve.pointAt(getT(trackPosition, false) + 0.01f);

View File

@ -174,11 +174,11 @@ public class CircumscribedCircle extends Curve {
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage(); Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
for (int i = 0; i < step; i++) { for (int i = 0; i < step; i++) {
float[] xy = pointAt(i / step); float[] xy = pointAt(i / step);
Utils.drawCentered(hitCircleOverlay, xy[0], xy[1], Utils.COLOR_WHITE_FADE); hitCircleOverlay.drawCentered(xy[0], xy[1], Utils.COLOR_WHITE_FADE);
} }
for (int i = 0; i < step; i++) { for (int i = 0; i < step; i++) {
float[] xy = pointAt(i / step); float[] xy = pointAt(i / step);
Utils.drawCentered(hitCircle, xy[0], xy[1], color); hitCircle.drawCentered(xy[0], xy[1], color);
} }
} }

View File

@ -164,9 +164,9 @@ public class LinearBezier extends Curve {
Image hitCircle = GameImage.HITCIRCLE.getImage(); Image hitCircle = GameImage.HITCIRCLE.getImage();
Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage(); Image hitCircleOverlay = GameImage.HITCIRCLE_OVERLAY.getImage();
for (int i = curve.length - 2; i >= 0; i--) for (int i = curve.length - 2; i >= 0; i--)
Utils.drawCentered(hitCircleOverlay, curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE); hitCircleOverlay.drawCentered(curve[i].x, curve[i].y, Utils.COLOR_WHITE_FADE);
for (int i = curve.length - 2; i >= 0; i--) for (int i = curve.length - 2; i >= 0; i--)
Utils.drawCentered(hitCircle, curve[i].x, curve[i].y, color); hitCircle.drawCentered(curve[i].x, curve[i].y, color);
} }
@Override @Override

View File

@ -485,7 +485,7 @@ public class ButtonMenu extends BasicGameState {
RESET_MODS ("Reset All Mods", Color.red) { RESET_MODS ("Reset All Mods", Color.red) {
@Override @Override
public void click(GameContainer container, StateBasedGame game) { public void click(GameContainer container, StateBasedGame game) {
SoundController.playSound(SoundEffect.MENUHIT); SoundController.playSound(SoundEffect.MENUCLICK);
for (GameMod mod : GameMod.values()) { for (GameMod mod : GameMod.values()) {
if (mod.isActive()) if (mod.isActive())
mod.toggle(false); mod.toggle(false);

View File

@ -810,7 +810,7 @@ public class Game extends BasicGameState {
// skip button // skip button
if (GameImage.SKIP.getImages() != null) { if (GameImage.SKIP.getImages() != null) {
Animation skip = GameImage.SKIP.getAnimation(200); Animation skip = GameImage.SKIP.getAnimation(120);
skipButton = new MenuButton(skip, width - skip.getWidth() / 2f, height - (skip.getHeight() / 2f)); skipButton = new MenuButton(skip, width - skip.getWidth() / 2f, height - (skip.getHeight() / 2f));
} else { } else {
Image skip = GameImage.SKIP.getImage(); Image skip = GameImage.SKIP.getImage();

View File

@ -84,6 +84,8 @@ public class GameRanking extends BasicGameState {
width - (exit.getWidth() / 2f), width - (exit.getWidth() / 2f),
(height * 0.97f) - (exit.getHeight() / 2f) (height * 0.97f) - (exit.getHeight() / 2f)
); );
retryButton.setHoverFade(0.6f);
exitButton.setHoverFade(0.6f);
} }
@Override @Override
@ -119,6 +121,10 @@ public class GameRanking extends BasicGameState {
Utils.updateCursor(delta); Utils.updateCursor(delta);
Utils.updateVolumeDisplay(delta); Utils.updateVolumeDisplay(delta);
int mouseX = input.getMouseX(), mouseY = input.getMouseY(); int mouseX = input.getMouseX(), mouseY = input.getMouseY();
if (data.isGameplay()) {
retryButton.hoverUpdate(delta, mouseX, mouseY);
exitButton.hoverUpdate(delta, mouseX, mouseY);
}
Utils.getBackButton().hoverUpdate(delta, mouseX, mouseY); Utils.getBackButton().hoverUpdate(delta, mouseX, mouseY);
} }
@ -174,8 +180,11 @@ public class GameRanking extends BasicGameState {
if (!data.isGameplay()) { if (!data.isGameplay()) {
if (!MusicController.isTrackDimmed()) if (!MusicController.isTrackDimmed())
MusicController.toggleTrackDimmed(0.5f); MusicController.toggleTrackDimmed(0.5f);
} else } else {
SoundController.playSound(SoundEffect.APPLAUSE); SoundController.playSound(SoundEffect.APPLAUSE);
retryButton.resetHover();
exitButton.resetHover();
}
} }
@Override @Override

View File

@ -236,7 +236,7 @@ public class MainMenu extends BasicGameState {
g.setFont(Utils.FONT_MEDIUM); g.setFont(Utils.FONT_MEDIUM);
int lineHeight = Utils.FONT_MEDIUM.getLineHeight() * 9 / 10; int lineHeight = Utils.FONT_MEDIUM.getLineHeight() * 9 / 10;
g.drawString(String.format("Loaded %d songs and %d beatmaps.", g.drawString(String.format("Loaded %d songs and %d beatmaps.",
OsuGroupList.get().size(), OsuGroupList.get().getMapCount()), marginX, marginY); OsuGroupList.get().getMapSetCount(), OsuGroupList.get().getMapCount()), marginX, marginY);
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()) {

View File

@ -253,9 +253,10 @@ public class SongMenu extends BasicGameState {
search.setMaxLength(60); search.setMaxLength(60);
// selection buttons // selection buttons
float selectX = GameImage.MENU_BACK.getAnimation(1).getWidth() * 1.75f; Image selectionMods = GameImage.SELECTION_MODS.getImage();
float selectY = height - GameImage.SELECTION_MODS.getImage().getHeight() / 2f; float selectX = width * 0.183f + selectionMods.getWidth() / 2f;
float selectOffset = GameImage.SELECTION_MODS.getImage().getWidth() * 1.05f; float selectY = height - selectionMods.getHeight() / 2f;
float selectOffset = selectionMods.getWidth() * 1.05f;
selectModsButton = new MenuButton(GameImage.SELECTION_MODS_OVERLAY.getImage(), selectModsButton = new MenuButton(GameImage.SELECTION_MODS_OVERLAY.getImage(),
selectX, selectY); selectX, selectY);
selectRandomButton = new MenuButton(GameImage.SELECTION_RANDOM_OVERLAY.getImage(), selectRandomButton = new MenuButton(GameImage.SELECTION_RANDOM_OVERLAY.getImage(),

View File

@ -556,7 +556,7 @@ public class Image implements Renderable {
} }
/** /**
* Draw the image based on it's center * Draw the image based on its center
* *
* @param x The x coordinate to place the image's center at * @param x The x coordinate to place the image's center at
* @param y The y coordinate to place the image's center at * @param y The y coordinate to place the image's center at
@ -565,6 +565,17 @@ public class Image implements Renderable {
draw(x-(getWidth()/2),y-(getHeight()/2)); draw(x-(getWidth()/2),y-(getHeight()/2));
} }
/**
* Draw the image based on its center with a color filter
*
* @param x The x coordinate to place the image's center at
* @param y The y coordinate to place the image's center at
* @param color The color filter to apply
*/
public void drawCentered(float x, float y, Color color) {
draw(x - (getWidth() / 2f), y - (getHeight() / 2f), color);
}
/** /**
* Draw this image at the specified location * Draw this image at the specified location
* *