diff --git a/src/main/java/edu/ntnu/idi/idatt/Launcher.java b/src/main/java/edu/ntnu/idi/idatt/Launcher.java index 601d11e..c390dbd 100644 --- a/src/main/java/edu/ntnu/idi/idatt/Launcher.java +++ b/src/main/java/edu/ntnu/idi/idatt/Launcher.java @@ -1,8 +1,8 @@ package edu.ntnu.idi.idatt; +import edu.ntnu.idi.idatt.view.SceneManager; +import edu.ntnu.idi.idatt.view.primary.PrimaryView; import javafx.application.Application; -import javafx.scene.Scene; -import javafx.scene.layout.VBox; import javafx.stage.Stage; public final class Launcher { @@ -21,7 +21,7 @@ public void start(Stage stage) { stage.setWidth(1200); stage.setHeight(700); stage.setTitle("Stock Game"); - stage.setScene(new Scene(new VBox())); + SceneManager.init(stage, new PrimaryView().getInstance()); stage.show(); } diff --git a/src/main/java/edu/ntnu/idi/idatt/view/SceneManager.java b/src/main/java/edu/ntnu/idi/idatt/view/SceneManager.java new file mode 100644 index 0000000..be87d13 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt/view/SceneManager.java @@ -0,0 +1,55 @@ +package edu.ntnu.idi.idatt.view; + +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +/** + * SceneManager class for managing objects to the stage. + * + *

+ * This class provides methods for changing the root object to + * the scene, providing simple use of components to change between the + * pages + *

+ * + * @author Pawel Sapula + */ +public final class SceneManager { + + // Store scene reference. + private static Scene scene; + + // Disable initialization. + private SceneManager() { + } + + /** + * Method for intialization of the Scene Manager. + * + *

+ * This method enables initialization of the primary scene, + * based on the stage from the program entry point, and a + * page based on the page's root object. + *

+ * + * @param stage - Application's stage + * @param root - The root object / fundamental object of a page + */ + public static void init(Stage stage, Parent root) { + scene = new Scene(root); + // Add styling sheet permamently for the scene. + scene.getStylesheets().add(SceneManager.class.getResource("/themes/default.css").toExternalForm()); + stage.setScene(scene); + } + + /** + * Method for switching the scene's root variable. + * + * @param root - Parent JavaFX object. + */ + public static void switchTo(Parent root) { + scene.setRoot(root); + } + +} diff --git a/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java new file mode 100644 index 0000000..18d51a2 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt/view/components/AbstractView.java @@ -0,0 +1,58 @@ +package edu.ntnu.idi.idatt.view.components; + +import javafx.scene.Parent; +import javafx.scene.layout.Pane; + +/** + * INFO! + * + *

+ * This class is based on the generic Type parameter - T. It's experimental + * for the time of creating the class (24.04.26), since parent don't have access + * to the + * getChildren() method which could provide usefuleness in creating a standalone + * abstract class. + * + * Since most views will be based on the Pane subclasses, it is fully + * functional, but + * may throw errors if the typeparameter isn't of this type. + *

+ * + * Reference: https://docs.oracle.com/javase/8/javafx/api/overview-tree.html + */ + +/** + * AbstractView class + * + *

+ * Provides a simple abstraction of the Pane subclasses, + * making it a useful framework for creating different views. + *

+ */ +public abstract class AbstractView { + + private T instance; + + /** + * Constructor for AbstractView. + */ + public AbstractView(T type) { + instance = type; + instance.getChildren().add(this.createContent()); + } + + /** + * Getter for current view instance. + * + * @return Instance of current view. + */ + public T getInstance() { + return instance; + } + + /** + * Abstract method for creating view content. + */ + public abstract Parent createContent(); + +} diff --git a/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java b/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java new file mode 100644 index 0000000..7e94df1 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt/view/primary/PrimaryView.java @@ -0,0 +1,45 @@ +package edu.ntnu.idi.idatt.view.primary; + +import java.util.List; + +import edu.ntnu.idi.idatt.view.components.AbstractView; +import javafx.geometry.Insets; +import javafx.geometry.Pos; +import javafx.scene.Parent; +import javafx.scene.control.Label; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; + +public class PrimaryView extends AbstractView { + + public PrimaryView() { + super(new StackPane()); + this.getInstance().getStyleClass().add("dark"); + } + + @Override + public Parent createContent() { + StackPane root = new StackPane(); + root.getStyleClass().add("light"); + StackPane.setAlignment(root, Pos.CENTER); + StackPane.setMargin(root, new Insets(40.0)); + + Label title = new Label("Millions"); + title.getStyleClass().add("title"); + StackPane.setAlignment(title, Pos.TOP_CENTER); + + VBox wrapper = new VBox(); + + Label playerName = new Label("Player name:"); + playerName.getStyleClass().add("big-text-32"); + + Label startBalance = new Label("Start balance:"); + startBalance.getStyleClass().add("big-text-32"); + + wrapper.getChildren().addAll(List.of(playerName, startBalance)); + + root.getChildren().addAll(List.of(title, wrapper)); + return root; + } + +} diff --git a/src/main/resources/themes/default.css b/src/main/resources/themes/default.css new file mode 100644 index 0000000..29bcf92 --- /dev/null +++ b/src/main/resources/themes/default.css @@ -0,0 +1,27 @@ +.dark { + -fx-background-color: #0B2B40; +} + +.light { + -fx-background-color: #1E5959; +} + +.primary { + -fx-background-color: #3B8C6E; +} + +.title { + -fx-font-size: 56px; + -fx-font-weight: 700; + -fx-text-fill: #EEEEEE; + -fx-padding: 30px; + -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.5, 0, 5); +} + +.big-text-32{ + -fx-font-size: 32px; + -fx-font-weight: 700; + -fx-text-fill: #EEEEEE; + -fx-padding: 30px; + -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.5, 0, 5); +}