Просмотр исходного кода

Added deciding between CLI and GUI

Ondřej Schlaichert 8 месяцев назад
Родитель
Сommit
eb90c21851

+ 1 - 1
pom.xml

@@ -60,7 +60,7 @@
                         <!-- Default configuration for running with: mvn clean javafx:run -->
                         <!-- Default configuration for running with: mvn clean javafx:run -->
                         <id>default-cli</id>
                         <id>default-cli</id>
                         <configuration>
                         <configuration>
-                            <mainClass>eu.oschl.schmorngui/eu.oschl.gui.HelloApplication</mainClass>
+                            <mainClass>eu.oschl.schmorngui/eu.oschl.gui.Session</mainClass>
                             <launcher>app</launcher>
                             <launcher>app</launcher>
                             <jlinkZipName>app</jlinkZipName>
                             <jlinkZipName>app</jlinkZipName>
                             <jlinkImageName>app</jlinkImageName>
                             <jlinkImageName>app</jlinkImageName>

+ 1 - 1
src/main/java/eu/oschl/gui/HelloController.java → src/main/java/eu/oschl/gui/GameController.java

@@ -3,7 +3,7 @@ package eu.oschl.gui;
 import javafx.fxml.FXML;
 import javafx.fxml.FXML;
 import javafx.scene.control.Label;
 import javafx.scene.control.Label;
 
 
-public class HelloController {
+public class GameController {
     @FXML
     @FXML
     private Label welcomeText;
     private Label welcomeText;
 
 

+ 0 - 9
src/main/java/eu/oschl/gui/Launcher.java

@@ -1,9 +0,0 @@
-package eu.oschl.gui;
-
-import javafx.application.Application;
-
-public class Launcher {
-    public static void main(String[] args) {
-        Application.launch(HelloApplication.class, args);
-    }
-}

+ 8 - 3
src/main/java/eu/oschl/gui/HelloApplication.java → src/main/java/eu/oschl/gui/Session.java

@@ -7,12 +7,17 @@ import javafx.stage.Stage;
 
 
 import java.io.IOException;
 import java.io.IOException;
 
 
-public class HelloApplication extends Application {
+public class Session extends Application {
+    public static void launchGui(String[] args)
+    {
+        Application.launch(Session.class, args);
+    }
+
     @Override
     @Override
     public void start(Stage stage) throws IOException {
     public void start(Stage stage) throws IOException {
-        FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));
+        FXMLLoader fxmlLoader = new FXMLLoader(Session.class.getResource("game.fxml"));
         Scene scene = new Scene(fxmlLoader.load(), 320, 240);
         Scene scene = new Scene(fxmlLoader.load(), 320, 240);
-        stage.setTitle("Hello!");
+        stage.setTitle("Schmorn");
         stage.setScene(scene);
         stage.setScene(scene);
         stage.show();
         stage.show();
     }
     }

+ 17 - 4
src/main/java/eu/oschl/schmorn/Main.java

@@ -1,15 +1,28 @@
 package eu.oschl.schmorn;
 package eu.oschl.schmorn;
-import eu.oschl.cli.Session;
 
 
 /**
 /**
- * This class serves as the entry point for the game.
+ * Serves as an entry point, handles starting either CLI or GUI version of the game.
  *
  *
  * @author Ondřej Schlaichert
  * @author Ondřej Schlaichert
  */
  */
 class Main {
 class Main {
-    static void main() {
+    static void main(String[] args) {
+        var useCli = args.length > 0 && args[0].equalsIgnoreCase("--cli");
+
+        if (useCli) {
+            startCli();
+        } else {
+            startGui(args);
+        }
+    }
+
+    private static void startCli() {
         var game = Setup.createGame();
         var game = Setup.createGame();
-        var session = new Session(game);
+        var session = new eu.oschl.cli.Session(game);
         session.start();
         session.start();
     }
     }
+
+    private static void startGui(String[] args) {
+        eu.oschl.gui.Session.launchGui(args);
+    }
 }
 }

+ 38 - 0
src/main/resources/eu/oschl/gui/game.fxml

@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<?import javafx.scene.control.Button?>
+<?import javafx.scene.control.ScrollPane?>
+<?import javafx.scene.image.ImageView?>
+<?import javafx.scene.layout.ColumnConstraints?>
+<?import javafx.scene.layout.GridPane?>
+<?import javafx.scene.layout.RowConstraints?>
+<?import javafx.scene.layout.VBox?>
+<?import javafx.scene.text.TextFlow?>
+
+<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/25">
+  <columnConstraints>
+    <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
+  </columnConstraints>
+  <rowConstraints>
+    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
+    <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
+      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
+  </rowConstraints>
+   <children>
+      <ScrollPane>
+         <content>
+            <TextFlow />
+         </content>
+      </ScrollPane>
+      <ImageView fitHeight="150.0" fitWidth="200.0" pickOnBounds="true" preserveRatio="true" GridPane.halignment="CENTER" GridPane.rowIndex="1" GridPane.valignment="CENTER" />
+      <ScrollPane fitToWidth="true" GridPane.rowIndex="2">
+         <content>
+            <VBox>
+               <children>
+                  <Button maxWidth="1.7976931348623157E308" mnemonicParsing="false" text="Button" />
+               </children>
+            </VBox>
+         </content>
+      </ScrollPane>
+   </children>
+</GridPane>

+ 1 - 1
src/main/resources/eu/oschl/gui/hello-view.fxml

@@ -6,7 +6,7 @@
 
 
 <?import javafx.scene.control.Button?>
 <?import javafx.scene.control.Button?>
 <VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml"
 <VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml"
-      fx:controller="eu.oschl.gui.HelloController">
+      fx:controller="eu.oschl.gui.GameController">
     <padding>
     <padding>
         <Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
         <Insets bottom="20.0" left="20.0" right="20.0" top="20.0"/>
     </padding>
     </padding>