From 782f32be8f602f51b5426fff937535722400c9d9 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Sun, 7 Aug 2022 15:35:35 +0200 Subject: [PATCH 1/3] Added windows package command. --- launcher/package_windows.ps1 | 41 ++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 launcher/package_windows.ps1 diff --git a/launcher/package_windows.ps1 b/launcher/package_windows.ps1 new file mode 100644 index 0000000..26f8714 --- /dev/null +++ b/launcher/package_windows.ps1 @@ -0,0 +1,41 @@ +# 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 exe ` + --name "Ace-of-Shades" ` + --app-version "1.0.0" ` + --description "Top-down 2D shooter game inspired by Ace of Spades." ` + --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 From 38b01f0531e23b818439ccb373c71ce90c103ba7 Mon Sep 17 00:00:00 2001 From: Andrew Lalis Date: Sun, 7 Aug 2022 15:53:21 +0200 Subject: [PATCH 2/3] Added more popups and customizable registry URL. --- .../aos2_launcher/MainViewController.java | 23 +++++++++++------ .../andrewl/aos2_launcher/ServersFetcher.java | 25 +++++++++++++++---- launcher/src/main/resources/main_view.fxml | 25 ++++++++----------- 3 files changed, 46 insertions(+), 27 deletions(-) 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 @@