Implemented an internal beatmap downloader (using Bloodcat).

The downloads menu can be accessed through the button on the right side of the main menu.  The downloader supports searching and concurrent downloads (NOTE: this is limited by the download server!).  Double-click any search result to begin downloading it to the SongPacks directory; cancel the download by hitting the red 'x' in the upper-right corner.  A confirmation will appear if trying to quit opsu! while downloads are running.

New classes:
- Download: represents an individual download from a remote address to a local path, and provides status and progress information; downloads files using Java NIO.
- DownloadNode: holds a Download object as well as additional beatmap fields, and handles drawing.
- DownloadList: manages the current list of downloads.
- DownloadsMenu: game state controller.
- DownloadServer: interface for a beatmap download server.
- BloodcatServer: implements DownloadServer using Bloodcat.
- ReadableByteChannelWrapper: wrapper for ReadableByteChannel that tracks progress.

Added images:
- "downloads" image by @kouyang.
- "search-background" image from "Minimalist Miku" skin (listed in credits).
- "delete" icon by Visual Pharm (https://www.iconfinder.com/icons/27842/) under CC BY-ND 3.0.

Other changes:
- Added up/down/left/right Expand directions to MenuButton class.
- Removed width/height parameters from OsuParser (leftovers).

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-02-01 02:10:17 -05:00
parent cb5a7d6a4b
commit 70c70fd812
21 changed files with 1701 additions and 22 deletions

View File

@@ -21,6 +21,7 @@ package itdelatrisu.opsu.states;
import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.MenuButton;
import itdelatrisu.opsu.MenuButton.Expand;
import itdelatrisu.opsu.Opsu;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.OsuFile;
@@ -75,6 +76,9 @@ public class MainMenu extends BasicGameState {
/** Music control buttons. */
private MenuButton musicPlay, musicPause, musicNext, musicPrevious;
/** Button linking to Downloads menu. */
private MenuButton downloadsButton;
/** Button linking to repository. */
private MenuButton repoButton;
@@ -138,6 +142,12 @@ public class MainMenu extends BasicGameState {
musicNext.setHoverScale(1.5f);
musicPrevious.setHoverScale(1.5f);
// initialize downloads button
Image dlImg = GameImage.DOWNLOADS.getImage();
downloadsButton = new MenuButton(dlImg, width - dlImg.getWidth() / 2f, height / 2f);
downloadsButton.setHoverDir(Expand.LEFT);
downloadsButton.setHoverScale(1.05f);
// initialize repository button
if (Desktop.isDesktopSupported()) { // only if a webpage can be opened
Image repoImg = GameImage.REPOSITORY.getImage();
@@ -173,6 +183,9 @@ public class MainMenu extends BasicGameState {
g.fillRect(0, height * 8 / 9f, width, height / 9f);
Utils.COLOR_BLACK_ALPHA.a = oldAlpha;
// draw downloads button
downloadsButton.draw();
// draw buttons
if (logoTimer > 0) {
playButton.draw();
@@ -239,6 +252,7 @@ public class MainMenu extends BasicGameState {
exitButton.hoverUpdate(delta, mouseX, mouseY);
if (repoButton != null)
repoButton.hoverUpdate(delta, mouseX, mouseY);
downloadsButton.hoverUpdate(delta, mouseX, mouseY);
musicPlay.hoverUpdate(delta, mouseX, mouseY);
musicPause.hoverUpdate(delta, mouseX, mouseY);
if (musicPlay.contains(mouseX, mouseY))
@@ -319,6 +333,8 @@ public class MainMenu extends BasicGameState {
musicPrevious.setScale(1f);
if (repoButton != null && !repoButton.contains(mouseX, mouseY))
repoButton.setScale(1f);
if (!downloadsButton.contains(mouseX, mouseY))
downloadsButton.setScale(1f);
}
@Override
@@ -355,6 +371,12 @@ public class MainMenu extends BasicGameState {
MusicController.setPosition(0);
}
// downloads button actions
else if (downloadsButton.contains(x, y)) {
SoundController.playSound(SoundEffect.MENUHIT);
game.enterState(Opsu.STATE_DOWNLOADSMENU, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));
}
// repository button actions
else if (repoButton != null && repoButton.contains(x, y)) {
try {
@@ -437,5 +459,6 @@ public class MainMenu extends BasicGameState {
musicPause.setScale(1f);
musicNext.setScale(1f);
musicPrevious.setScale(1f);
downloadsButton.setScale(1f);
}
}