Added track previews to the downloads menu.

Currently uses the osu! server to load MP3 previews.

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-03-19 15:58:50 -04:00
parent 7d5899ba7e
commit ec042159a8
8 changed files with 207 additions and 28 deletions

View File

@@ -123,6 +123,21 @@ public class DownloadNode {
(cy > y && cy < y + buttonHeight));
}
/**
* Returns true if the coordinates are within the bounds of the
* download result action icon at the given index.
* @param cx the x coordinate
* @param cy the y coordinate
* @param index the index (to offset the button from the topmost button)
*/
public static boolean resultIconContains(float cx, float cy, int index) {
int iconWidth = GameImage.MUSIC_PLAY.getImage().getWidth();
float x = buttonBaseX + buttonWidth * 0.001f;
float y = buttonBaseY + (index * buttonOffset) + buttonHeight / 2f;
return ((cx > x && cx < x + iconWidth) &&
(cy > y - iconWidth / 2 && cy < y + iconWidth / 2));
}
/**
* Returns true if the coordinates are within the bounds of the
* download result button area.
@@ -283,9 +298,10 @@ public class DownloadNode {
* @param index the index (to offset the button from the topmost button)
* @param hover true if the mouse is hovering over this button
* @param focus true if the button is focused
* @param previewing true if the beatmap is currently being previewed
*/
public void drawResult(Graphics g, int index, boolean hover, boolean focus) {
float textX = buttonBaseX + buttonWidth * 0.02f;
public void drawResult(Graphics g, int index, boolean hover, boolean focus, boolean previewing) {
float textX = buttonBaseX + buttonWidth * 0.001f;
float edgeX = buttonBaseX + buttonWidth * 0.985f;
float y = buttonBaseY + index * buttonOffset;
float marginY = buttonHeight * 0.04f;
@@ -310,6 +326,11 @@ public class DownloadNode {
}
}
// preview button
Image img = (previewing) ? GameImage.MUSIC_PAUSE.getImage() : GameImage.MUSIC_PLAY.getImage();
img.drawCentered(textX + img.getWidth() / 2, y + buttonHeight / 2f);
textX += img.getWidth() + buttonWidth * 0.001f;
// text
Utils.FONT_BOLD.drawString(
textX, y + marginY,