Launcher overhaul. Now capable of setting resolution and fullscreen set.

This commit is contained in:
François Autin 2021-06-10 15:20:26 +02:00
parent fba6c50de0
commit 76bfe1d56e
No known key found for this signature in database
GPG Key ID: 24025429AC559B7C
4 changed files with 87 additions and 14 deletions

View File

@ -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<String, Object> arraysettings;
private static Map<String, Object> 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<String> cb = (ChoiceBox<String>) main.lookup("#resolution");
namespace = loader.getNamespace();
ChoiceBox<String> cb = (ChoiceBox<String>) namespace.get("resolution");
ObservableList<String> 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<String> cb = (ChoiceBox<String>) 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

View File

@ -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;
}
}

View File

@ -2,6 +2,7 @@
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.CheckBox?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.layout.HBox?>
@ -36,7 +37,13 @@
<Button text="Play" fx:id="btn_launch" onAction="#launch"
prefWidth="110" prefHeight="15"/>
<Label text="Resolution"/>
<ChoiceBox fx:id="resolution"/>
<ChoiceBox fx:id="resolution" styleClass="res_box"/>
<HBox fx:id="fs_box" styleClass="fs_box">
<children>
<Label text="Fullscreen"/>
<CheckBox fx:id="fullscreen"/>
</children>
</HBox>
<Button text="Quit" fx:id="btn_quit" onAction="#quit"
prefWidth="110" prefHeight="15"/>
</children>

View File

@ -8,7 +8,7 @@
#sidepanel {
-fx-background-color: #303050;
-fx-aligment: center;
-fx-alignment: center;
}
/* Logo */
@ -54,7 +54,11 @@ Hyperlink:visited {
-fx-text-fill: #0095c8;
}
.contr_box {
.res_box Label {
-fx-fill: #000000 !important;
-fx-text-fill: #000000 !important;
}
.fs_box {
-fx-alignment: center;
}