Beatmap downloader improvements and fixes.

Updates:
- Added some buttons to downloads menu: clear inactive downloads, import beatmaps, reset search, and show/hide unranked maps.
- Small changes to OsuParser, OszUnpacker, and OsuGroupList (mostly adding return values) to allow parsing only newly unpacked beatmaps.
- Added alpha fade hover effect to MenuButton, as an alternative to expanding (used for 3-part menu buttons).
- Added text rendering fields to MenuButton (also for the 3-part menu buttons).
- Added sound effects to downloads menu.

Fixes:
- Check downloads for illegal filename characters, and remove them if necessary.
- The number of results and downloads shown now supports all resolutions.
- Confirmation dialog no longer appears when restarting the application (since downloads are static).
- Do not set a focus node immediately if the theme song will be played.
- Always play the theme song if no songs are loaded (even if disabled in settings).

Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
This commit is contained in:
Jeffrey Han
2015-02-02 00:15:16 -05:00
parent cfc0449ab2
commit ec90d6fd03
20 changed files with 517 additions and 183 deletions

View File

@@ -19,6 +19,7 @@
package itdelatrisu.opsu.downloads;
import itdelatrisu.opsu.ErrorHandler;
import itdelatrisu.opsu.Utils;
import java.io.File;
import java.io.FileOutputStream;
@@ -155,8 +156,9 @@ public class Download {
rbc.close();
fos.close();
if (rename != null) {
String cleanedName = Utils.cleanFileName(rename, '-');
Path source = new File(localPath).toPath();
Files.move(source, source.resolveSibling(rename), StandardCopyOption.REPLACE_EXISTING);
Files.move(source, source.resolveSibling(cleanedName), StandardCopyOption.REPLACE_EXISTING);
}
}
} catch (Exception e) {

View File

@@ -22,6 +22,7 @@ import itdelatrisu.opsu.ErrorHandler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@@ -126,6 +127,21 @@ public class DownloadList {
}
}
/**
* Removes all inactive downloads from the list.
*/
public void clearInactiveDownloads() {
Iterator<DownloadNode> iter = nodes.iterator();
while (iter.hasNext()) {
DownloadNode node = iter.next();
Download dl = node.getDownload();
if (dl != null && !dl.isActive()) {
iter.remove();
map.remove(node.getID());
}
}
}
/**
* Shows a confirmation dialog (used before exiting the game).
* @return true if user selects "yes", false otherwise

View File

@@ -23,7 +23,6 @@ import itdelatrisu.opsu.GameImage;
import itdelatrisu.opsu.Options;
import itdelatrisu.opsu.Utils;
import itdelatrisu.opsu.downloads.Download.Status;
import itdelatrisu.opsu.states.DownloadsMenu;
import java.io.File;
@@ -59,6 +58,9 @@ public class DownloadNode {
/** Information drawing values. */
private static float infoBaseX, infoBaseY, infoWidth, infoHeight;
/** Maximum number of results and downloads to display on one screen. */
private static int maxResultsShown, maxDownloadsShown;
/** Container dimensions. */
private static int containerWidth, containerHeight;
@@ -89,8 +91,23 @@ public class DownloadNode {
infoBaseY = height * 0.07f + Utils.FONT_LARGE.getLineHeight() * 2f;
infoWidth = width * 0.25f;
infoHeight = Utils.FONT_DEFAULT.getLineHeight() * 2.4f;
float searchY = (height * 0.05f) + Utils.FONT_LARGE.getLineHeight();
float buttonHeight = height * 0.038f;
maxResultsShown = (int) ((height - buttonBaseY - searchY) / buttonOffset);
maxDownloadsShown = (int) ((height - infoBaseY - searchY - buttonHeight) / infoHeight);
}
/**
* Returns the max number of search result buttons to be shown at a time.
*/
public static int maxResultsShown() { return maxResultsShown; }
/**
* Returns the max number of downloads to be shown at a time.
*/
public static int maxDownloadsShown() { return maxDownloadsShown; }
/**
* Returns true if the coordinates are within the bounds of the
* download result button at the given index.
@@ -112,7 +129,7 @@ public class DownloadNode {
*/
public static boolean resultAreaContains(float cx, float cy) {
return ((cx > buttonBaseX && cx < buttonBaseX + buttonWidth) &&
(cy > buttonBaseY && cy < buttonBaseY + buttonOffset * DownloadsMenu.MAX_RESULT_BUTTONS));
(cy > buttonBaseY && cy < buttonBaseY + buttonOffset * maxResultsShown));
}
/**
@@ -152,7 +169,7 @@ public class DownloadNode {
*/
public static boolean downloadAreaContains(float cx, float cy) {
return ((cx > infoBaseX && cx <= containerWidth) &&
(cy > infoBaseY && cy < infoBaseY + infoHeight * DownloadsMenu.MAX_DOWNLOADS_SHOWN));
(cy > infoBaseY && cy < infoBaseY + infoHeight * maxDownloadsShown));
}
/**
@@ -165,10 +182,10 @@ public class DownloadNode {
float scrollbarWidth = containerWidth * 0.00347f;
float heightRatio = 0.0016f * (total * total) - 0.0705f * total + 0.9965f;
float scrollbarHeight = containerHeight * heightRatio;
float heightDiff = buttonHeight + buttonOffset * (DownloadsMenu.MAX_RESULT_BUTTONS - 1) - scrollbarHeight;
float offsetY = heightDiff * ((float) index / (total - DownloadsMenu.MAX_RESULT_BUTTONS));
float heightDiff = buttonHeight + buttonOffset * (maxResultsShown - 1) - scrollbarHeight;
float offsetY = heightDiff * ((float) index / (total - maxResultsShown));
g.setColor(BG_NORMAL);
g.fillRect(buttonBaseX + buttonWidth * 1.005f, buttonBaseY, scrollbarWidth, buttonOffset * DownloadsMenu.MAX_RESULT_BUTTONS);
g.fillRect(buttonBaseX + buttonWidth * 1.005f, buttonBaseY, scrollbarWidth, buttonOffset * maxResultsShown);
g.setColor(Color.white);
g.fillRect(buttonBaseX + buttonWidth * 1.005f, buttonBaseY + offsetY, scrollbarWidth, scrollbarHeight);
}
@@ -183,10 +200,10 @@ public class DownloadNode {
float scrollbarWidth = containerWidth * 0.00347f;
float heightRatio = 0.0016f * (total * total) - 0.0705f * total + 0.9965f;
float scrollbarHeight = containerHeight * heightRatio;
float heightDiff = infoHeight + infoHeight * (DownloadsMenu.MAX_DOWNLOADS_SHOWN - 1) - scrollbarHeight;
float offsetY = heightDiff * ((float) index / (total - DownloadsMenu.MAX_DOWNLOADS_SHOWN));
float heightDiff = infoHeight + infoHeight * (maxDownloadsShown - 1) - scrollbarHeight;
float offsetY = heightDiff * ((float) index / (total - maxDownloadsShown));
g.setColor(BG_NORMAL);
g.fillRect(infoBaseX + infoWidth - scrollbarWidth, infoBaseY, scrollbarWidth, infoHeight * DownloadsMenu.MAX_DOWNLOADS_SHOWN);
g.fillRect(infoBaseX + infoWidth - scrollbarWidth, infoBaseY, scrollbarWidth, infoHeight * maxDownloadsShown);
g.setColor(Color.white);
g.fillRect(infoBaseX + infoWidth - scrollbarWidth, infoBaseY + offsetY, scrollbarWidth, scrollbarHeight);
}