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;
|
|
|
|
|
2021-06-10 14:07:06 +02:00
|
|
|
import gameplay.match.*;
|
2021-05-27 03:02:36 +02:00
|
|
|
import javafx.application.Application;
|
2021-06-10 14:07:06 +02:00
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.ObservableList;
|
2021-05-27 03:02:36 +02:00
|
|
|
import javafx.scene.Parent;
|
|
|
|
import javafx.scene.Scene;
|
2021-06-10 14:07:06 +02:00
|
|
|
import javafx.scene.control.ChoiceBox;
|
2021-06-23 16:12:09 +02:00
|
|
|
import javafx.scene.image.Image;
|
|
|
|
import javafx.scene.image.ImageView;
|
|
|
|
import javafx.scene.layout.VBox;
|
2021-06-10 15:20:26 +02:00
|
|
|
import javafx.scene.control.CheckBox;
|
2021-05-27 03:02:36 +02:00
|
|
|
import javafx.stage.Stage;
|
2021-06-03 03:46:38 +02:00
|
|
|
import javafx.stage.StageStyle;
|
2021-05-27 03:02:36 +02:00
|
|
|
import javafx.fxml.*;
|
2021-06-10 14:07:06 +02:00
|
|
|
import java.util.HashMap;
|
2021-06-10 15:20:26 +02:00
|
|
|
import java.util.Map;
|
2021-06-03 00:47:49 +02:00
|
|
|
|
2021-06-23 16:12:09 +02:00
|
|
|
@SuppressWarnings("unchecked")
|
2021-05-27 03:02:36 +02:00
|
|
|
public class Launcher extends Application {
|
|
|
|
|
2021-06-03 00:47:49 +02:00
|
|
|
public static Launcher pointer;
|
|
|
|
private static Settings setter;
|
2021-06-10 14:07:06 +02:00
|
|
|
private HashMap<String, Object> arraysettings;
|
2021-06-10 15:20:26 +02:00
|
|
|
private static Map<String, Object> namespace;
|
|
|
|
|
2021-06-03 00:47:49 +02:00
|
|
|
public Launcher() {
|
|
|
|
pointer = this;
|
|
|
|
try {
|
|
|
|
setter = new Settings();
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
2021-06-10 14:07:06 +02:00
|
|
|
arraysettings = new HashMap<String, Object>();
|
2021-06-03 00:47:49 +02:00
|
|
|
}
|
|
|
|
|
2021-05-28 01:15:50 +02:00
|
|
|
/*
|
|
|
|
* Start method is used by Launcher as an implementation of the Application class to create a JavaFX thread to display the GUI window
|
|
|
|
*/
|
2021-06-10 15:20:26 +02:00
|
|
|
|
2021-05-27 03:02:36 +02:00
|
|
|
public void start(Stage primaryStage) throws Exception {
|
2021-05-27 03:14:20 +02:00
|
|
|
|
2021-06-10 15:20:26 +02:00
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("launcher.fxml"));
|
|
|
|
|
|
|
|
Parent root = loader.load();
|
2021-05-28 01:15:50 +02:00
|
|
|
|
|
|
|
Scene main = new Scene(root);
|
2021-05-03 02:29:11 +02:00
|
|
|
|
2021-06-10 15:20:26 +02:00
|
|
|
namespace = loader.getNamespace();
|
2021-06-10 14:07:06 +02:00
|
|
|
|
2021-06-10 15:20:26 +02:00
|
|
|
ChoiceBox<String> cb = (ChoiceBox<String>) namespace.get("resolution");
|
2021-06-10 14:07:06 +02:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2021-06-10 15:20:26 +02:00
|
|
|
CheckBox fs = (CheckBox) namespace.get("fullscreen");
|
|
|
|
if(setter.getFullscreen()) {
|
|
|
|
fs.setSelected(true);
|
|
|
|
} else {
|
|
|
|
fs.setSelected(false);
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:12:09 +02:00
|
|
|
VBox v1 = (VBox) namespace.get("p1");
|
|
|
|
ChoiceBox<String> b1 = (ChoiceBox<String>) v1.getChildren().get(1);
|
|
|
|
VBox v2 = (VBox) namespace.get("p2");
|
|
|
|
ChoiceBox<String> b2 = (ChoiceBox<String>) v2.getChildren().get(1);
|
|
|
|
ObservableList<String> availablechar = FXCollections.observableArrayList("Blue");
|
|
|
|
b1.setItems(availablechar);
|
|
|
|
b2.setItems(availablechar);
|
2021-06-10 15:20:26 +02:00
|
|
|
|
2021-06-23 16:12:09 +02:00
|
|
|
if(setter.getChar1().equals("blue")) {
|
|
|
|
b1.setValue("Blue");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(setter.getChar2().equals("blue")) {
|
|
|
|
b2.setValue("Blue");
|
|
|
|
}
|
2021-06-10 15:20:26 +02:00
|
|
|
|
2021-06-03 03:46:38 +02:00
|
|
|
primaryStage.initStyle(StageStyle.UNDECORATED);
|
2021-05-28 01:15:50 +02:00
|
|
|
primaryStage.setTitle("Boulevard Combattant");
|
2021-05-27 03:14:20 +02:00
|
|
|
primaryStage.setScene(main);
|
|
|
|
primaryStage.show();
|
2021-06-03 00:47:49 +02:00
|
|
|
|
2021-05-03 02:29:11 +02:00
|
|
|
}
|
|
|
|
|
2021-06-10 15:20:26 +02:00
|
|
|
@FXML
|
|
|
|
public void runGame() {
|
2021-06-03 00:47:49 +02:00
|
|
|
try {
|
2021-06-10 15:20:26 +02:00
|
|
|
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);
|
2021-06-23 16:12:09 +02:00
|
|
|
|
|
|
|
VBox vp1 = (VBox) namespace.get("p1");
|
|
|
|
ChoiceBox<String> p1 = (ChoiceBox<String>) vp1.getChildren().get(1);
|
|
|
|
pointer.arraysettings.put("character1", p1.getValue().toLowerCase());
|
|
|
|
|
|
|
|
VBox vp2 = (VBox) namespace.get("p2");
|
|
|
|
ChoiceBox<String> p2 = (ChoiceBox<String>) vp2.getChildren().get(1);
|
|
|
|
pointer.arraysettings.put("character2", p2.getValue().toLowerCase());
|
|
|
|
|
2021-06-10 15:20:26 +02:00
|
|
|
pointer.arraysettings.put("stage", "default");
|
2021-06-03 00:47:49 +02:00
|
|
|
setter.setSettings();
|
2021-06-10 14:07:06 +02:00
|
|
|
match.main(null);
|
2021-06-10 15:20:26 +02:00
|
|
|
|
2021-06-03 00:47:49 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 03:46:38 +02:00
|
|
|
@FXML
|
|
|
|
public void launch() {
|
2021-06-10 15:20:26 +02:00
|
|
|
this.runGame();
|
2021-06-03 00:47:49 +02:00
|
|
|
}
|
2021-06-03 03:46:38 +02:00
|
|
|
|
|
|
|
@FXML
|
|
|
|
public void quit() {
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public void website() {
|
|
|
|
getHostServices().showDocument("https://gitlab.istic.univ-rennes1.fr/fautin/jeu-de-combat");
|
|
|
|
}
|
2021-06-23 16:12:09 +02:00
|
|
|
|
|
|
|
@FXML
|
|
|
|
public void chp1() {
|
|
|
|
VBox v1 = (VBox) namespace.get("p1");
|
|
|
|
ImageView iv1 = (ImageView) v1.getChildren().get(0);
|
|
|
|
ChoiceBox<String> b1 = (ChoiceBox<String>) v1.getChildren().get(1);
|
|
|
|
switch (b1.getValue()) {
|
|
|
|
case "Blue":
|
|
|
|
iv1.setImage(new Image("/launcher/charfaces/blue.png"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
iv1.setImage(new Image("/launcher/default.png"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
public void chp2() {
|
|
|
|
VBox v1 = (VBox) namespace.get("p2");
|
|
|
|
ImageView iv1 = (ImageView) v1.getChildren().get(0);
|
|
|
|
ChoiceBox<String> b1 = (ChoiceBox<String>) v1.getChildren().get(1);
|
|
|
|
switch (b1.getValue()) {
|
|
|
|
case "Blue":
|
|
|
|
iv1.setImage(new Image("/launcher/charfaces/blue.png"));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
iv1.setImage(new Image("/launcher/default.png"));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-06-03 00:47:49 +02:00
|
|
|
|
2021-06-10 14:07:06 +02:00
|
|
|
public HashMap<String, Object> getArraysettings() {
|
|
|
|
return arraysettings;
|
|
|
|
}
|
|
|
|
|
2021-05-03 02:29:11 +02:00
|
|
|
}
|