|
@@ -1,13 +1,22 @@
|
|
|
package eu.oschl.gui;
|
|
package eu.oschl.gui;
|
|
|
|
|
|
|
|
|
|
+import eu.oschl.schmorn.Setup;
|
|
|
import eu.oschl.textadventure.Game;
|
|
import eu.oschl.textadventure.Game;
|
|
|
import javafx.application.Application;
|
|
import javafx.application.Application;
|
|
|
|
|
+import javafx.application.Platform;
|
|
|
|
|
+import javafx.event.Event;
|
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.fxml.FXMLLoader;
|
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.Scene;
|
|
|
|
|
+import javafx.scene.control.Alert;
|
|
|
|
|
+import javafx.scene.control.ButtonType;
|
|
|
|
|
+import javafx.scene.input.KeyCode;
|
|
|
|
|
+import javafx.scene.input.KeyCodeCombination;
|
|
|
|
|
+import javafx.scene.input.KeyCombination;
|
|
|
import javafx.stage.Stage;
|
|
import javafx.stage.Stage;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
|
|
public class Session extends Application {
|
|
public class Session extends Application {
|
|
|
private static Game game;
|
|
private static Game game;
|
|
@@ -21,14 +30,27 @@ public class Session extends Application {
|
|
|
return actionProcessor;
|
|
return actionProcessor;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public static void launchGui(Game game, String[] args)
|
|
|
|
|
|
|
+ public static void launchGui(String[] args)
|
|
|
{
|
|
{
|
|
|
- Session.game = game;
|
|
|
|
|
|
|
+ createNewGame();
|
|
|
|
|
+
|
|
|
Session.actionProcessor = ActionProcessor.create(game);
|
|
Session.actionProcessor = ActionProcessor.create(game);
|
|
|
|
|
|
|
|
Application.launch(Session.class, args);
|
|
Application.launch(Session.class, args);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private static void createNewGame() {
|
|
|
|
|
+ Session.game = Setup.createGame();
|
|
|
|
|
+
|
|
|
|
|
+ if (Session.actionProcessor != null) {
|
|
|
|
|
+ Session.actionProcessor.changeGame(Session.game);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Session.actionProcessor = ActionProcessor.create(Session.game);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Session.actionProcessor.sendEvent();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public void start(Stage stage) throws IOException {
|
|
public void start(Stage stage) throws IOException {
|
|
|
FXMLLoader fxmlLoader = new FXMLLoader(Session.class.getResource("game.fxml"));
|
|
FXMLLoader fxmlLoader = new FXMLLoader(Session.class.getResource("game.fxml"));
|
|
@@ -39,6 +61,45 @@ public class Session extends Application {
|
|
|
|
|
|
|
|
stage.setTitle("Schmorn");
|
|
stage.setTitle("Schmorn");
|
|
|
stage.setScene(scene);
|
|
stage.setScene(scene);
|
|
|
|
|
+
|
|
|
|
|
+ stage.setOnCloseRequest(event -> handleCloseRequest(stage, event));
|
|
|
|
|
+
|
|
|
|
|
+ KeyCombination restartKeyCombination = new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN);
|
|
|
|
|
+ scene.getAccelerators().put(restartKeyCombination, () -> handleRestartRequest(stage));
|
|
|
|
|
+
|
|
|
stage.show();
|
|
stage.show();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void handleCloseRequest(Stage stage, Event event) {
|
|
|
|
|
+ Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
|
|
|
|
+ alert.initOwner(stage);
|
|
|
|
|
+ alert.setTitle("Quit Game");
|
|
|
|
|
+ alert.setHeaderText("You are about to quit playing.");
|
|
|
|
|
+ alert.setContentText("Are you sure you want to quit?");
|
|
|
|
|
+
|
|
|
|
|
+ Optional<ButtonType> result = alert.showAndWait();
|
|
|
|
|
+
|
|
|
|
|
+ if (result.isPresent() && result.get() == ButtonType.OK) {
|
|
|
|
|
+ Platform.exit();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ event.consume();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void handleRestartRequest(Stage stage) {
|
|
|
|
|
+ Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
|
|
|
|
|
+ alert.initOwner(stage);
|
|
|
|
|
+ alert.setTitle("Restart Game");
|
|
|
|
|
+ alert.setHeaderText("You are about to restart the game.");
|
|
|
|
|
+ alert.setContentText("Are you sure you want to restart?");
|
|
|
|
|
+
|
|
|
|
|
+ Optional<ButtonType> result = alert.showAndWait();
|
|
|
|
|
+
|
|
|
|
|
+ if (result.isPresent() && result.get() == ButtonType.OK) {
|
|
|
|
|
+ createNewGame();
|
|
|
|
|
+
|
|
|
|
|
+ Output.clear();
|
|
|
|
|
+ Output.print(game.getPrologue());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|