jeu-de-combat/src/launcher/Launcher.java

161 lines
3.7 KiB
Java
Raw Normal View History

2021-05-03 02:29:11 +02:00
/**
* CLASS LAUNCHER
*
* Fenêtre de configuration du jeu préalablement au lancement d'une partie
*
* @author François Autin
*
*/
package launcher;
import gameplay.match.*;
import javafx.application.Application;
import javafx.collections.FXCollections;
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 {
setter = new Settings();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
arraysettings = new HashMap<String, Object>();
}
/*
* Start method is used by Launcher as an implementation of the Application class to create a JavaFX thread to display the GUI window
*/
@SuppressWarnings("unchecked")
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(getClass().getResource("launcher.fxml"));
Parent root = loader.load();
Scene main = new Scene(root);
2021-05-03 02:29:11 +02:00
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())) {
cb.setValue("640x480");
} else {
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);
primaryStage.show();
2021-05-03 02:29:11 +02:00
}
@SuppressWarnings("unchecked")
@FXML
public void runGame() {
try {
int width, height;
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);
}
}
@FXML
public void launch() {
this.runGame();
}
@FXML
public void quit() {
System.exit(0);
}
@FXML
public void website() {
getHostServices().showDocument("https://gitlab.istic.univ-rennes1.fr/fautin/jeu-de-combat");
}
public HashMap<String, Object> getArraysettings() {
return arraysettings;
}
2021-05-03 02:29:11 +02:00
}