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

@@ -34,7 +34,7 @@ import org.json.JSONObject;
/**
* Download server: http://bloodcat.com/osu/
*/
public class BloodcatServer implements DownloadServer {
public class BloodcatServer extends DownloadServer {
/** Formatted download URL: {@code beatmapSetID} */
private static final String DOWNLOAD_URL = "http://bloodcat.com/osu/s/%d";

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,

View File

@@ -21,15 +21,18 @@ package itdelatrisu.opsu.downloads;
import java.io.IOException;
/**
* Interface for beatmap download servers.
* Abstract class for beatmap download servers.
*/
public interface DownloadServer {
public abstract class DownloadServer {
/** Track preview URL. */
private static final String PREVIEW_URL = "http://b.ppy.sh/preview/%d.mp3";
/**
* Returns a web address to download the given beatmap.
* @param beatmapSetID the beatmap set ID
* @return the URL string
*/
public String getURL(int beatmapSetID);
public abstract String getURL(int beatmapSetID);
/**
* Returns a list of results for a given search query, or null if the
@@ -40,7 +43,7 @@ public interface DownloadServer {
* @return the result array
* @throws IOException if any connection problem occurs
*/
public DownloadNode[] resultList(String query, int page, boolean rankedOnly) throws IOException;
public abstract DownloadNode[] resultList(String query, int page, boolean rankedOnly) throws IOException;
/**
* Returns the total number of results for the last search query.
@@ -48,5 +51,14 @@ public interface DownloadServer {
* {@link #resultList(String, int, boolean)} if multiple pages exist.
* @return the result count, or -1 if no query
*/
public int totalResults();
public abstract int totalResults();
/**
* Returns a web address to preview the given beatmap.
* @param beatmapSetID the beatmap set ID
* @return the URL string
*/
public String getPreviewURL(int beatmapSetID) {
return String.format(PREVIEW_URL, beatmapSetID);
}
}