Skip to content

implement desktop view and fix swithing of views #68

Merged
merged 1 commit into from
Apr 10, 2026
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
package edu.ntnu.idi.idatt2003.gruppe42.Controller;

import edu.ntnu.idi.idatt2003.gruppe42.Model.Player;
import edu.ntnu.idi.idatt2003.gruppe42.View.StartScreen;
import edu.ntnu.idi.idatt2003.gruppe42.View.StartView;
import java.math.BigDecimal;
import javafx.scene.control.RadioButton;

public class StartScreenController {
public class StartViewController {

private String username = "";
private final StartScreen startScreen;
private final StartView startView;

public StartScreenController(StartScreen startScreen) {
public StartViewController(StartView startView) {

this.startScreen = startScreen;
this.startView = startView;

startScreen.getUsernameField().textProperty().addListener((obs, old, newValue) -> {
startView.getUsernameField().textProperty().addListener((obs, old, newValue) -> {
if (isValidName(newValue)) {
username = newValue;
}
});

startScreen.getLoginButton().setOnAction(e -> handleStart());
startView.getLoginButton().setOnAction(e -> handleStart());
}

private void handleStart() {
Expand All @@ -35,7 +34,7 @@ private boolean isValidName(String value) {
}

private BigDecimal getStartingMoney() {
String selected = startScreen.getSelectedMode();
String selected = startView.getSelectedMode();

return switch (selected.charAt(0)) {
case 'E' -> new BigDecimal("1000");
Expand Down
31 changes: 25 additions & 6 deletions src/main/java/edu/ntnu/idi/idatt2003/gruppe42/Millions.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
package edu.ntnu.idi.idatt2003.gruppe42;

import edu.ntnu.idi.idatt2003.gruppe42.Controller.StartScreenController;
import edu.ntnu.idi.idatt2003.gruppe42.View.StartScreen;
import edu.ntnu.idi.idatt2003.gruppe42.Controller.StartViewController;
import edu.ntnu.idi.idatt2003.gruppe42.View.DesktopView;
import edu.ntnu.idi.idatt2003.gruppe42.View.StartView;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Millions extends Application {

private Scene scene;
private Stage stage;

@Override
public void start(Stage stage) throws Exception {
StartScreen startScreen = new StartScreen();
this.stage = stage;

StartView startView = new StartView();
new StartViewController(startView);

StartScreenController controller = new StartScreenController(startScreen);
Scene scene = new Scene(startScreen.getRoot(), 900, 700);
scene = new Scene(startView.getRoot(), 900, 700);

stage.setTitle("Millions");
stage.setScene(scene);
stage.setFullScreen(true);
stage.show();

switchToDesktopView();
}

public void switchToStartView() {
StartView startView = new StartView();
scene.setRoot(startView.getRoot());
stage.setScene(scene);
}

public void switchToDesktopView() {
DesktopView desktopView = new DesktopView();
scene.setRoot(desktopView.getRoot());
stage.setScene(scene);
}

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package edu.ntnu.idi.idatt2003.gruppe42.View;

import javafx.scene.layout.BorderPane;

public class DesktopView {

public BorderPane getRoot() {

BorderPane root = new BorderPane();

return root;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@

import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

import java.util.Objects;

public class StartScreen {
public class StartView {

private final TextField usernameField = new TextField();
private final Button loginButton = new Button("Login");
Expand Down