diff --git a/launcher/icon.ico b/launcher/icon.ico new file mode 100644 index 0000000..54fd966 Binary files /dev/null and b/launcher/icon.ico differ diff --git a/launcher/icon.png b/launcher/icon.png new file mode 100644 index 0000000..b8688f1 Binary files /dev/null and b/launcher/icon.png differ diff --git a/launcher/package_linux.sh b/launcher/package_linux.sh index e253786..35d1cc7 100755 --- a/launcher/package_linux.sh +++ b/launcher/package_linux.sh @@ -19,6 +19,7 @@ jpackage \ --name "Ace of Shades Launcher" \ --app-version "1.0.0" \ --description "Launcher app for Ace of Shades, a voxel-based first-person shooter." \ + --icon ../icon.ico \ --linux-shortcut \ --linux-deb-maintainer "andrewlalisofficial@gmail.com" \ --linux-menu-group "Game" \ diff --git a/launcher/package_windows.ps1 b/launcher/package_windows.ps1 new file mode 100644 index 0000000..958f9d8 --- /dev/null +++ b/launcher/package_windows.ps1 @@ -0,0 +1,42 @@ +# This script prepares and runs the jpackage command to generate a Windows AOS Client installer. + +$projectDir = $PSScriptRoot +Push-Location $projectDir\target + +# Remove existing file if it exists. +Write-Output "Removing existing exe file." +Get-ChildItem *.exe | ForEach-Object { Remove-Item -Path $_.FullName -Force } +Write-Output "Done." + +# Run the build +Write-Output "Building the project." +Push-Location $projectDir +mvn clean package + +# Get list of dependency modules that maven copied into the lib directory. +Push-Location $projectDir\target +$modules = Get-ChildItem -Path lib -Name | ForEach-Object { "lib\$_" } +# Add our own main module. +$mainModuleJar = Get-ChildItem -Name -Include "aos2-launcher-*.jar" -Exclude "*-jar-with-dependencies.jar" +$modules += $mainModuleJar +Write-Output "Found modules: $modules" +$modulePath = $modules -join ';' + +Write-Output "Running jpackage..." +jpackage ` + --type msi ` + --name "Ace-of-Shades" ` + --app-version "1.0.0" ` + --description "Top-down 2D shooter game inspired by Ace of Spades." ` + --icon ..\icon.ico ` + --win-shortcut ` + --win-dir-chooser ` + --win-per-user-install ` + --win-menu ` + --win-shortcut ` + --win-menu-group "Game" ` + --module-path "$modulePath" ` + --module aos2_launcher/nl.andrewl.aos2_launcher.Launcher ` + --add-modules jdk.crypto.cryptoki + +Write-Output "Done!" \ No newline at end of file diff --git a/launcher/src/main/java/nl/andrewl/aos2_launcher/MainViewController.java b/launcher/src/main/java/nl/andrewl/aos2_launcher/MainViewController.java index d7ba0e4..5bc6545 100644 --- a/launcher/src/main/java/nl/andrewl/aos2_launcher/MainViewController.java +++ b/launcher/src/main/java/nl/andrewl/aos2_launcher/MainViewController.java @@ -4,11 +4,9 @@ import javafx.application.Platform; import javafx.beans.binding.BooleanBinding; import javafx.collections.ListChangeListener; import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.Label; -import javafx.scene.control.ProgressBar; -import javafx.scene.control.ProgressIndicator; +import javafx.scene.control.*; import javafx.scene.layout.VBox; +import javafx.stage.Window; import nl.andrewl.aos2_launcher.model.Profile; import nl.andrewl.aos2_launcher.model.ProfileSet; import nl.andrewl.aos2_launcher.model.ProgressReporter; @@ -32,10 +30,11 @@ public class MainViewController implements ProgressReporter { @FXML public VBox progressVBox; @FXML public Label progressLabel; @FXML public ProgressBar progressBar; + @FXML public TextField registryUrlField; private final ProfileSet profileSet = new ProfileSet(); - private final ServersFetcher serversFetcher = new ServersFetcher(); + private ServersFetcher serversFetcher; @FXML public void initialize() { @@ -61,14 +60,24 @@ public class MainViewController implements ProgressReporter { progressVBox.managedProperty().bind(progressVBox.visibleProperty()); progressVBox.setVisible(false); - refreshServers(); + + serversFetcher = new ServersFetcher(registryUrlField.textProperty()); + Platform.runLater(this::refreshServers); } @FXML public void refreshServers() { - serversFetcher.fetchServers() + Window owner = this.profilesVBox.getScene().getWindow(); + serversFetcher.fetchServers(owner) .exceptionally(throwable -> { throwable.printStackTrace(); + Platform.runLater(() -> { + Alert alert = new Alert(Alert.AlertType.ERROR); + alert.setHeaderText("Couldn't fetch servers."); + alert.setContentText("An error occurred, and the list of servers couldn't be fetched: " + throwable.getMessage() + ". Are you sure that you have the correct registry URL? Check the \"Servers\" tab."); + alert.initOwner(owner); + alert.show(); + }); return new ArrayList<>(); }) .thenAccept(newServers -> Platform.runLater(() -> { diff --git a/launcher/src/main/java/nl/andrewl/aos2_launcher/ServersFetcher.java b/launcher/src/main/java/nl/andrewl/aos2_launcher/ServersFetcher.java index b32e641..4917af1 100644 --- a/launcher/src/main/java/nl/andrewl/aos2_launcher/ServersFetcher.java +++ b/launcher/src/main/java/nl/andrewl/aos2_launcher/ServersFetcher.java @@ -4,6 +4,11 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import javafx.application.Platform; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; +import javafx.scene.control.Alert; +import javafx.stage.Window; import nl.andrewl.aos2_launcher.model.Server; import java.net.URI; @@ -16,18 +21,28 @@ import java.util.List; import java.util.concurrent.CompletableFuture; class ServersFetcher { - private static final String registryURL = "http://localhost:8080"; - private final HttpClient httpClient; private final Gson gson; + private final StringProperty registryUrl; - public ServersFetcher() { + public ServersFetcher(StringProperty registryUrlProperty) { httpClient = HttpClient.newBuilder().build(); gson = new Gson(); + this.registryUrl = new SimpleStringProperty("http://localhost:8080"); + registryUrl.bind(registryUrlProperty); } - public CompletableFuture> fetchServers() { - HttpRequest req = HttpRequest.newBuilder(URI.create(registryURL + "/servers")) + public CompletableFuture> fetchServers(Window owner) { + if (registryUrl.get() == null || registryUrl.get().isBlank()) { + Platform.runLater(() -> { + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.setContentText("Invalid or missing registry URL. Can't fetch the list of servers."); + alert.initOwner(owner); + alert.show(); + }); + return CompletableFuture.completedFuture(new ArrayList<>()); + } + HttpRequest req = HttpRequest.newBuilder(URI.create(registryUrl.get() + "/servers")) .GET() .timeout(Duration.ofSeconds(3)) .header("Accept", "application/json") diff --git a/launcher/src/main/resources/main_view.fxml b/launcher/src/main/resources/main_view.fxml index 8281c94..4e30590 100644 --- a/launcher/src/main/resources/main_view.fxml +++ b/launcher/src/main/resources/main_view.fxml @@ -1,10 +1,11 @@ - + - - + + + @@ -22,6 +23,7 @@