Skip to content

Commit

Permalink
Auto import beatmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
ringosham committed Mar 18, 2019
1 parent 0f59cd9 commit c02085c
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/com/ringosham/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

package com.ringosham;

import com.ringosham.locale.Localizer;
import com.ringosham.objects.Beatmap;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonType;
import javafx.scene.image.Image;

import java.awt.*;
Expand Down Expand Up @@ -76,6 +79,7 @@ private void initConfig() throws IOException {
config.setProperty("lazerDirectory", Defaults.getDefaultDirectory());
config.setProperty("locale", Defaults.locale.toString());
config.setProperty("settings.videoDownload", String.valueOf(Defaults.videoDownload));
config.setProperty("settings.gameExecutable", Defaults.getDefaultGameExecutable());
config.store(out, "Lazer exporter config");
out.close();
}
Expand Down Expand Up @@ -210,6 +214,7 @@ private void invokeAlertBox(Alert.AlertType alertType, String title, String head
alert.setTitle(title);
alert.setHeaderText(headerText);
alert.setContentText(content);
((Button) (alert.getDialogPane().lookupButton(ButtonType.OK))).setText(Localizer.getLocalizedText("dialog.common.ok"));
alert.showAndWait();
}

Expand Down
2 changes: 1 addition & 1 deletion src/com/ringosham/fxml/about.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<Font name="Verdana" size="22.0"/>
</font>
</Label>
<Label text="1.3" GridPane.rowIndex="2"/>
<Label text="1.4" GridPane.rowIndex="2"/>
<Label alignment="CENTER" text="Copyright © 2019 - Ringosham" GridPane.rowIndex="3"/>
<Hyperlink fx:id="github" contentDisplay="GRAPHIC_ONLY" GridPane.rowIndex="4">
<graphic>
Expand Down
2 changes: 1 addition & 1 deletion src/com/ringosham/fxml/settings.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<HBox alignment="TOP_RIGHT" layoutX="384.0" layoutY="362.0" prefHeight="20.0" prefWidth="200.0" spacing="10.0"
AnchorPane.bottomAnchor="14.0" AnchorPane.rightAnchor="16.0">
<Button mnemonicParsing="false" onAction="#apply" text="%settings.apply"/>
<Button mnemonicParsing="false" onAction="#close" text="%settings.cancel"/>
<Button mnemonicParsing="false" onAction="#close" text="%dialog.common.cancel"/>
</HBox>
<TextField fx:id="gameDirectory" layoutX="14.0" layoutY="37.0" minHeight="-Infinity" prefHeight="25.0"
prefWidth="572.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0"
Expand Down
12 changes: 10 additions & 2 deletions src/com/ringosham/lang/lang_en_US.properties
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dialog.error.failLaunchGameDesc=Cannot launch game. This normally should not hap
#--------------------------------
settings.title=Settings
settings.apply=Apply and close
settings.cancel=Cancel
dialog.common.cancel=Cancel
settings.gameDirectory=Game directory
settings.browse=Browse
settings.language=Language
Expand Down Expand Up @@ -163,4 +163,12 @@ dialog.warn.nullIDDesc=There are a few causes for this.\n1. The database is upgr
#Invalid executable
dialog.error.invalidExec=Invalid executable
dialog.error.invalidExecDesc=Invalid executable. Please try again.
download.notFound=Beatmap has been removed from osu! repository
download.notFound=Beatmap has been removed from osu! repository
dialog.common.ok=OK
dialog.common.yes=Yes
dialog.common.no=No
dialog.import.beatmapTitle=Download complete
dialog.import.beatmapHeader=Do you want to import the beatmaps now?
dialog.import.beatmapText=Requires launching the game. If you choose not to do so, you must import them manually.
dialog.import.saveTitle=Saved location
dialog.import.saveText=You can find your downloaded beatmaps in the following location
12 changes: 10 additions & 2 deletions src/com/ringosham/lang/lang_zh_TW.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dialog.error.failLaunchGame=\u7121\u6CD5\u555F\u52D5\u7A0B\u5F0F
dialog.error.failLaunchGameDesc=\u7121\u6CD5\u555F\u52D5\u904A\u6232\uFF0C\u5982\u679C\u4F60\u8A8D\u70BA\u6709\u6F0F\u6D1E\u7684\u8A71\uFF0C\u8ACB\u5728GitHub\u5831\u544A
settings.title=\u8A2D\u5B9A
settings.apply=\u5957\u7528\u4E26\u95DC\u9589
settings.cancel=\u53D6\u6D88
dialog.common.cancel=\u53D6\u6D88
settings.gameDirectory=\u904A\u6232\u76EE\u9304
settings.browse=\u700F\u89BD
settings.language=\u8A9E\u8A00
Expand Down Expand Up @@ -122,4 +122,12 @@ dialog.warn.nullIDHead="Online beatmap ID"\u7684\u6578\u503C\u70BA<null>\uFF0C\u
dialog.warn.nullIDDesc=\u9019\u6709\u53EF\u80FD\u662F\u4EE5\u4E0B\u539F\u56E0\n1. \u4F60\u7684\u6578\u64DA\u5EAB\u662F\u5F9E\u820A\u7248\u672C\u66F4\u65B0\uFF0C\u5982\u679C\u662F\u9019\u6A23\u7684\u8A71\uFF0C\u8ACB\u91CD\u65B0\u532F\u5165\u5716\u8B5C\n2. \u5716\u8B5CID\u53EF\u80FD\u6709\u885D\u7A81\n3. \u5716\u8B5C\u4E26\u672A\u4E0A\u8F09\u81F3\u5B98\u65B9\u7DB2\u7AD9\u6216\u88AB\u79FB\u9664
dialog.error.invalidExec=\u7121\u6548\u7684\u6A94\u6848
dialog.error.invalidExecDesc=\u7121\u6548\u7684\u6A94\u6848\uFF0C\u8ACB\u91CD\u8A66
download.notFound=\u8A72\u5716\u8B5C\u5DF2\u5F9Eosu!\u9801\u9762\u4E2D\u79FB\u9664
download.notFound=\u8A72\u5716\u8B5C\u5DF2\u5F9Eosu!\u9801\u9762\u4E2D\u79FB\u9664
dialog.common.ok=\u78BA\u5B9A
dialog.common.yes=\u662F
dialog.common.no=\u5426
dialog.import.beatmapTitle=\u4E0B\u8F09\u5B8C\u6210
dialog.import.beatmapHeader=\u4F60\u60F3\u73FE\u5728\u532F\u5165\u5716\u8B5C\u55CE?
dialog.import.beatmapText=\u9700\u8981\u555F\u52D5\u904A\u6232\uFF0C\u5426\u5247\u9700\u8981\u81EA\u884C\u532F\u5165
dialog.import.saveTitle=\u5132\u5B58\u4F4D\u7F6E
dialog.import.saveText=\u4F60\u53EF\u4EE5\u5728\u4EE5\u4E0B\u627E\u5230\u4F60\u4E0B\u8F09\u7684\u5716\u8B5C
33 changes: 33 additions & 0 deletions src/com/ringosham/threads/imports/download/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,20 @@
import com.ringosham.locale.Localizer;
import com.ringosham.objects.xml.BeatmapXML;
import javafx.application.Platform;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;

import javax.net.ssl.HttpsURLConnection;
import java.io.*;
import java.net.URL;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

class Downloader {
private static final String downloadUrlPrefix = "https://osu.ppy.sh/beatmapsets/";
Expand Down Expand Up @@ -64,6 +72,31 @@ void downloadTask() {
.replace("%FAILCOUNT%", Integer.toString(failCount)));
mainScreen.mainProgress.setProgress(0);
mainScreen.subProgress.setProgress(0);
ButtonType ok = new ButtonType(Localizer.getLocalizedText("dialog.common.yes"), ButtonBar.ButtonData.OK_DONE);
ButtonType cancel = new ButtonType(Localizer.getLocalizedText("dialog.common.no"), ButtonBar.ButtonData.CANCEL_CLOSE);
Alert alert = new Alert(Alert.AlertType.CONFIRMATION, Localizer.getLocalizedText("dialog.import.beatmapText"), ok, cancel);
alert.setTitle(Localizer.getLocalizedText("dialog.import.beatmapTitle"));
alert.setHeaderText(Localizer.getLocalizedText("dialog.import.beatmapHeader"));
Optional<ButtonType> result = alert.showAndWait();
if (result.orElse(cancel) == ok) {
File[] beatmaps = new File(Global.INSTANCE.getLazerDirectory(), "files").listFiles((dir, name) -> name.endsWith(".osz"));
List<String> command = new ArrayList<>();
command.add(Global.INSTANCE.getGameExecutable().getAbsolutePath());
List<String> paths = beatmaps == null ? new ArrayList<>() : Arrays.stream(beatmaps).map(File::getAbsolutePath).collect(Collectors.toList());
command.addAll(paths);
ProcessBuilder builder = new ProcessBuilder(command);
try {
builder.start();
} catch (IOException ignored) {
}
} else {
Alert saveAlert = new Alert(Alert.AlertType.INFORMATION);
saveAlert.setTitle(Localizer.getLocalizedText("dialog.import.saveTitle"));
saveAlert.setHeaderText(Localizer.getLocalizedText("dialog.import.saveText"));
saveAlert.setContentText(new File(Global.INSTANCE.getLazerDirectory(), "files").getAbsolutePath());
((Button) (saveAlert.getDialogPane().lookupButton(ButtonType.OK))).setText(Localizer.getLocalizedText("dialog.common.ok"));
saveAlert.showAndWait();
}
});
}

Expand Down

0 comments on commit c02085c

Please sign in to comment.