diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java index e93f779..f7876a5 100644 --- a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/Main.java @@ -3,11 +3,21 @@ import edu.ntnu.idi.idatt2003.g40.mappe.model.Stock; import edu.ntnu.idi.idatt2003.g40.mappe.service.FileConverter; import edu.ntnu.idi.idatt2003.g40.mappe.service.FileParser; +import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; +import edu.ntnu.idi.idatt2003.g40.mappe.utils.ConfigValues; +import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewManager; +import edu.ntnu.idi.idatt2003.g40.mappe.view.ingame.InGameView; +import edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu.MainMenuController; +import edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu.MainMenuView; import javafx.application.Application; +import javafx.scene.Node; +import javafx.scene.Scene; +import javafx.scene.layout.Pane; import javafx.stage.Stage; import java.io.IOException; import java.util.List; +import java.util.Objects; public class Main extends Application { static void main() { @@ -24,6 +34,24 @@ static void main() { @Override public void start(final Stage stage) throws Exception { + Scene scene = new Scene(new Pane()); + scene.getStylesheets() + .add(Objects.requireNonNull(getClass().getResource("/styles.css")).toExternalForm()); + stage.setScene(scene); + stage.setWidth(ConfigValues.VIEWPORT_WIDTH.getValue()); + stage.setHeight(ConfigValues.VIEWPORT_HEIGHT.getValue()); + EventManager eventManager = new EventManager(); + ViewManager viewManager = new ViewManager(stage, eventManager); + MainMenuView mainMenuView = new MainMenuView(); + new MainMenuController(mainMenuView, eventManager); + + InGameView inGameView = new InGameView(); + + + viewManager.addView(mainMenuView); + viewManager.addView(inGameView); + viewManager.setScene(mainMenuView); + stage.show(); } } diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameView.java new file mode 100644 index 0000000..9c132de --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ingame/InGameView.java @@ -0,0 +1,27 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.view.ingame; + +import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; + +public class InGameView extends ViewElement { + + public InGameView() { + super(new VBox(), "InGameView"); + } + + @Override + protected void initLayout() { + getRootPane().getChildren().add(new Text("This is the game view!")); + } + + @Override + protected void initStyling() { + + } + + @Override + public void onUpdate() { + + } +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuController.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuController.java new file mode 100644 index 0000000..a1c0dff --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuController.java @@ -0,0 +1,41 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu; + +import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventData; +import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; +import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventType; +import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewController; +import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewData; + +/** + * Controller for the {@link MainMenuView}. + * + *

Extends {@link ViewController}

+ * */ +public class MainMenuController extends ViewController { + + /** + * Constructor. + * + * @param view The {@link MainMenuView} object to attach this controller to. + * @param eventManager the active {@link EventManager}. + * */ + public MainMenuController(final MainMenuView view, + final EventManager eventManager) { + super(view, eventManager); + } + + /** + * {@inheritDoc} + * + *

Sets play game button functionality

+ * */ + @Override + protected void initInteractions() { + getViewElement().getToGameButton().setOnAction(e -> { + ViewData viewData = new ViewData("InGameView"); + EventData eventData = + new EventData<>(EventType.SCENE_CHANGE, viewData); + getEventManager().invokeEvent(eventData); + }); + } +} diff --git a/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuView.java b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuView.java new file mode 100644 index 0000000..7b09c70 --- /dev/null +++ b/src/main/java/edu/ntnu/idi/idatt2003/g40/mappe/view/mainmenu/MainMenuView.java @@ -0,0 +1,121 @@ +package edu.ntnu.idi.idatt2003.g40.mappe.view.mainmenu; + +import edu.ntnu.idi.idatt2003.g40.mappe.view.ViewElement; +import javafx.geometry.Pos; +import javafx.scene.control.Button; +import javafx.scene.layout.StackPane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; + +/** + * The main menu UI. + * + *

Extends {@link ViewElement}, + * with a root pane of {@link StackPane}

+ * */ +public class MainMenuView extends ViewElement { + + /** + * "Play Game" Button. + * */ + private Button toGameButton; + + /** + * "Settings" Button. + * */ + private Button settingsButton; + + /** + * "Exit" Button. + * */ + private Button exitButton; + + /** + * Container for button elements. + * */ + private VBox buttonContainer; + + /** + * Constructor. + * + *

Constructs with name "MainMenu"

+ * */ + public MainMenuView() { + super(new StackPane(), "MainMenu"); + } + + /** + * Getter method for "Play" button. + * + * @return Play game button. + * */ + public Button getToGameButton() { + return toGameButton; + } + + /** + * Getter method for "Settings" button. + * + * @return Settings button. + * */ + public Button getSettingsButton() { + return settingsButton; + } + + /** + * Getter method for "Exit" button. + * + * @return Exit button. + * */ + public Button getExitButton() { + return exitButton; + } + + /** + * {@inheritDoc} + * + *

Displays three buttons:

+ *
    + *
  • "Play"
  • + *
  • "Settings"
  • + *
  • "Exit"
  • + *
+ * */ + @Override + protected void initLayout() { + toGameButton = new Button("Play"); + settingsButton = new Button("Settings"); + exitButton = new Button("Exit"); + buttonContainer = new VBox(); + buttonContainer.getChildren().addAll( + new Text("This is the main menu!"), + toGameButton, + settingsButton, + exitButton + ); + getRootPane().getChildren().add(buttonContainer); + StackPane.setAlignment(buttonContainer, Pos.CENTER); + } + + /** + * {@inheritDoc} + * */ + @Override + protected void initStyling() { + getRootPane().getStyleClass().add("main-menu-bg"); + + buttonContainer.getStyleClass().add("button-container"); + + toGameButton.getStyleClass().add("menu-button"); + settingsButton.getStyleClass().add("menu-button"); + exitButton.getStyleClass().add("menu-button"); + } + + /** + * {@inheritDoc} + * */ + @Override + public void onUpdate() { + + } +} diff --git a/src/main/resources/millionsbackground.png b/src/main/resources/millionsbackground.png new file mode 100644 index 0000000..bbbc4a9 Binary files /dev/null and b/src/main/resources/millionsbackground.png differ diff --git a/src/main/resources/styles.css b/src/main/resources/styles.css new file mode 100644 index 0000000..85ab14b --- /dev/null +++ b/src/main/resources/styles.css @@ -0,0 +1,33 @@ +/* Container for the buttons */ +.button-container { + -fx-spacing: 20; + -fx-alignment: center; +} + +/* Base button styling */ +.menu-button { + -fx-background-color: rgba(255, 255, 255, 0.7); /* Translucent white */ + -fx-background-radius: 15; + -fx-min-width: 350; + -fx-min-height: 60; + -fx-font-family: "System"; + -fx-font-weight: bold; + -fx-font-style: italic; + -fx-font-size: 24px; + -fx-text-fill: black; + -fx-cursor: hand; +} + +/* Hover effect for interactivity */ +.menu-button:hover { + -fx-background-color: rgba(255, 255, 255, 0.9); + -fx-scale-x: 1.05; + -fx-scale-y: 1.05; +} + +/* Background image styling */ +.main-menu-bg { + -fx-background-image: url("millionsbackground.png"); /* Replace with your image path */ + -fx-background-size: cover; + -fx-background-position: center; +} \ No newline at end of file