From 76bfe1d56ef396d279544e9a3da64fbfee468bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Autin?= Date: Thu, 10 Jun 2021 15:20:26 +0200 Subject: [PATCH] Launcher overhaul. Now capable of setting resolution and fullscreen set. --- src/launcher/Launcher.java | 79 ++++++++++++++++++++++++++++++++------ src/launcher/Settings.java | 5 +++ src/launcher/launcher.fxml | 9 ++++- src/launcher/style.css | 8 +++- 4 files changed, 87 insertions(+), 14 deletions(-) diff --git a/src/launcher/Launcher.java b/src/launcher/Launcher.java index bffe9bd..2f1f61c 100644 --- a/src/launcher/Launcher.java +++ b/src/launcher/Launcher.java @@ -16,17 +16,20 @@ import javafx.collections.ObservableList; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.ChoiceBox; +import javafx.scene.control.CheckBox; import javafx.stage.Stage; import javafx.stage.StageStyle; import javafx.fxml.*; import java.util.HashMap; +import java.util.Map; public class Launcher extends Application { public static Launcher pointer; private static Settings setter; private HashMap arraysettings; - + private static Map namespace; + public Launcher() { pointer = this; try { @@ -41,15 +44,18 @@ public class Launcher extends Application { /* * Start method is used by Launcher as an implementation of the Application class to create a JavaFX thread to display the GUI window */ + public void start(Stage primaryStage) throws Exception { - Parent root = FXMLLoader.load(getClass().getResource("launcher.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("launcher.fxml")); + + Parent root = loader.load(); Scene main = new Scene(root); - @SuppressWarnings("unchecked") - ChoiceBox cb = (ChoiceBox) main.lookup("#resolution"); + namespace = loader.getNamespace(); + ChoiceBox cb = (ChoiceBox) namespace.get("resolution"); ObservableList availableres = FXCollections.observableArrayList("640x480", "800x600", "1024x768", "1280x720", "1366x768", "1600x900", "1920x1080"); cb.setItems(availableres); if (!availableres.contains(setter.getResolution())) { @@ -58,6 +64,15 @@ public class Launcher extends Application { cb.setValue(setter.getResolution()); } + CheckBox fs = (CheckBox) namespace.get("fullscreen"); + if(setter.getFullscreen()) { + fs.setSelected(true); + } else { + fs.setSelected(false); + } + + + primaryStage.initStyle(StageStyle.UNDECORATED); primaryStage.setTitle("Boulevard Combattant"); primaryStage.setScene(main); @@ -65,10 +80,57 @@ public class Launcher extends Application { } - public static void runGame() { + @FXML + public void runGame() { try { + int width, height; + System.out.println(namespace.size()); + ChoiceBox cb = (ChoiceBox) namespace.get("resolution"); + switch (cb.getValue()) { + case "640x480": + width = 640; + height = 480; + break; + case "800x600": + width = 800; + height = 600; + break; + case "1024x768": + width = 1024; + height = 768; + break; + case "1280x720": + width = 1280; + height = 720; + break; + case "1366x768": + width = 1366; + height = 768; + break; + case "1600x900": + width = 1600; + height = 900; + break; + case "1920x1080": + width = 1920; + height = 1080; + break; + default: + width = 640; + height = 480; + break; + } + pointer.arraysettings.put("width", width); + pointer.arraysettings.put("height", height); + CheckBox fs = (CheckBox) namespace.get("fullscreen"); + pointer.arraysettings.put("fullscreen", fs.isSelected()); + pointer.arraysettings.put("rounds", 3); + pointer.arraysettings.put("character1", "default"); + pointer.arraysettings.put("character2", "default"); + pointer.arraysettings.put("stage", "default"); setter.setSettings(); match.main(null); + } catch (Exception e) { e.printStackTrace(); System.exit(1); @@ -77,12 +139,7 @@ public class Launcher extends Application { @FXML public void launch() { - Launcher.runGame(); - } - - @FXML - public void settings() { - + this.runGame(); } @FXML diff --git a/src/launcher/Settings.java b/src/launcher/Settings.java index 7ff6a2a..f919f35 100644 --- a/src/launcher/Settings.java +++ b/src/launcher/Settings.java @@ -40,4 +40,9 @@ public class Settings { public String getResolution() { return "" + Integer.toString(config.width) + "x" + Integer.toString(config.height); } + + public boolean getFullscreen() { + return config.fullscreen; + } + } diff --git a/src/launcher/launcher.fxml b/src/launcher/launcher.fxml index 369b2a5..41b15ca 100644 --- a/src/launcher/launcher.fxml +++ b/src/launcher/launcher.fxml @@ -2,6 +2,7 @@ + @@ -36,7 +37,13 @@