@Override public void start(Stage theStage) { this.tStage = theStage; theStage.setTitle("Ball of Duty"); theStage.setHeight(WINDOW_START_HEIGHT); theStage.setWidth(WINDOW_START_WIDTH); theStage.centerOnScreen(); theStage.setResizable(false); theStage.setOnCloseRequest( new EventHandler<WindowEvent>() { public void handle(WindowEvent we) { gameManager.quitGame(); System.exit(0); } }); BorderPane startMenuRoot = new BorderPane(); startMenu = new Scene(startMenuRoot); gameBox = new BorderPane(); Scene gameScene = new Scene(gameBox); BorderPane createAccountRoot = new BorderPane(); BorderPane lohInRoot = new BorderPane(); theStage.setScene(startMenu); gameManager = new GameClient(getRelativeSceneLocation(theStage)); scale = new Scale(); scale.xProperty().bind(gameScene.widthProperty().divide(WINDOW_START_WIDTH)); scale.yProperty().bind(gameScene.heightProperty().divide(WINDOW_START_HEIGHT)); scale.setPivotX(0); scale.setPivotY(0); // gameBox.getTransforms().add(scale); // gameBox.setBackground(null); // TODO scaling theStage .heightProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); // This // only // happens // once // for // some // reason. }); theStage .widthProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); theStage .xProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); theStage .yProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); gameScene .xProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); gameScene .yProperty() .addListener( e -> { gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); }); Image image = new Image("images/frontpage.png"); BackgroundSize backgroundSize = new BackgroundSize(100, 100, true, true, true, false); // new BackgroundImage(image, repeatX, repeatY, position, size) BackgroundImage backgroundImage = new BackgroundImage( image, BackgroundRepeat.REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER, backgroundSize); // new Background(images...) Background background = new Background(backgroundImage); startMenuRoot.setBackground(background); RadioButton chooseBlaster = new RadioButton("Blaster"); RadioButton chooseRoller = new RadioButton("Roller"); RadioButton chooseHeavy = new RadioButton("Heavy"); final ToggleGroup specializationGroup = new ToggleGroup(); chooseBlaster.setToggleGroup(specializationGroup); chooseRoller.setToggleGroup(specializationGroup); chooseHeavy.setToggleGroup(specializationGroup); chooseBlaster.setSelected(true); HBox specializationBox = new HBox(); specializationBox.setSpacing(9); specializationBox.getChildren().add(chooseBlaster); specializationBox.getChildren().add(chooseRoller); specializationBox.getChildren().add(chooseHeavy); Label lblNickname = new Label("Nickname:"); TextField tfNickname = new TextField(); Button loginStart = new Button("Log in"); Button createStart = new Button("Create Account"); theStage.getIcons().add(new Image("images/ball_red.png")); VBox mainButtonBox = new VBox(); mainButtonBox.setSpacing(5); Button joinBtn = new Button("Join game"); Button viewLB = new Button("Leaderboard"); viewLB.setPrefSize(150, 50); viewLB.setId("viewLB"); viewLB.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); BorderPane lbBorder = new BorderPane(); VBox lbBox = new VBox(); Scene lbScene = new Scene(lbBorder); Button lbBack = new Button("Start menu"); lbBox.getChildren().add(lbBack); lbBorder.setLeft(lbBox); lbBack.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); Label topText = new Label("Only shows scores higher than 100!"); topText.setStyle("-fx-font-size: 20pt;-fx-font-family: Segoe UI Semibold;"); viewLB.setOnAction( ActionEvent -> { HighscoreLeaderboard hBoard = gameManager.getHighscoreLeaderboard(); hBoard.setFocusTraversable(false); lbBorder.setCenter(hBoard); if (gameManager.getPlayer() != null) { Player client = gameManager.getPlayer(); Label you = new Label( "YOU: " + client.getNickname() + " [" + client.getId() + "] | Score: " + client.getHighscore()); you.setStyle("-fx-font-size: 15pt;-fx-font-family: Segoe UI Semibold;"); lbBorder.setBottom(you); } BorderPane.setMargin(hBoard, new Insets(12, 12, 12, 12)); lbBorder.setTop(topText); theStage.setScene(lbScene); lbBack.setOnAction( ActionEvent1 -> { theStage.setScene(startMenu); startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); joinBtn.setPrefSize(150, 50); tfNickname.setPrefSize(150, 20); joinBtn.setId("joinBtn"); joinBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblNickname.setId("lblNickname"); lblNickname.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); createStart.setId("CreateStart"); createStart.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); loginStart.setId("loginStart"); loginStart.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); joinBtn.setOnAction( ActionEvent -> { Specializations spec; if (chooseRoller.isSelected()) { spec = Specializations.ROLLER; } else if (chooseHeavy.isSelected()) { spec = Specializations.HEAVY; } else // Blaster is default, if something goes wrong with radio // buttons { spec = Specializations.BLASTER; } theStage.setScene(gameScene); gameManager.joinAsGuest(gameBox, tfNickname.getText(), spec); gameManager.getMap().addObserver(this); gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); gameBox.requestFocus(); }); tfNickname.setOnAction( ActionEvent -> { Specializations spec; if (chooseRoller.isSelected()) { spec = Specializations.ROLLER; } else if (chooseHeavy.isSelected()) { spec = Specializations.HEAVY; } else // Blaster is default, if something goes wrong with radio // buttons { spec = Specializations.BLASTER; } theStage.setScene(gameScene); gameManager.joinAsGuest(gameBox, tfNickname.getText(), spec); gameManager.setSceneRelativeLocation(getRelativeSceneLocation(theStage)); gameBox.requestFocus(); }); mainButtonBox.getChildren().add(lblNickname); mainButtonBox.getChildren().add(tfNickname); mainButtonBox.getChildren().add(specializationBox); mainButtonBox.getChildren().add(joinBtn); mainButtonBox.getChildren().add(loginStart); mainButtonBox.getChildren().add(createStart); mainButtonBox.getChildren().add(viewLB); startMenuRoot.setLeft(mainButtonBox); createStart.setOnAction( ActionEvent -> { VBox createAccountButtonBox = new VBox(); Label lblNickname2 = new Label("Nickname:"); TextField tfNickname2 = new TextField(); Label lblUserName = new Label("Name:"); TextField tfUserName = new TextField(); Label lblPassword = new Label("Password:"******"Repeat password:"******"Create account"); Button back = new Button("Start menu"); createBtn.setId("join-yyyyy"); createBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblUserName.setId("join-game"); lblUserName.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblPassword.setId("join-game"); lblPassword.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); lblPassword2.setId("join-game"); lblPassword2.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); back.setId("join-game"); back.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); createAccountButtonBox.getChildren().add(lblNickname2); createAccountButtonBox.getChildren().add(tfNickname2); createAccountButtonBox.getChildren().add(lblUserName); createAccountButtonBox.getChildren().add(tfUserName); createAccountButtonBox.getChildren().add(lblPassword); createAccountButtonBox.getChildren().add(pf); createAccountButtonBox.getChildren().add(lblPassword2); createAccountButtonBox.getChildren().add(pf2); createAccountButtonBox.getChildren().add(createBtn); createAccountButtonBox.getChildren().add(back); startMenuRoot.setLeft(createAccountButtonBox); BorderPane.setMargin(createAccountButtonBox, new Insets(350, 0, 0, 150)); createBtn.setOnAction( ActionEvent1 -> { gameManager.createAccount( tfUserName.getText(), tfNickname2.getText(), pf.getText().toCharArray(), pf2.getText().toCharArray()); startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); back.setOnAction( ActionEvent1 -> { startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); loginStart.setOnAction( ActionEvent -> { VBox loginButtonBox = new VBox(); Button logInBtn = new Button("Log in"); Label lblUserName2 = new Label("Name:"); TextField tfUserName2 = new TextField(); Label lblPassword2 = new Label("Password:"******"Start Menu"); logInBtn.setId("join-game"); logInBtn.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); back2.setId("join-game"); back2.setStyle("-fx-font: 20 arial; -fx-base: #ff0717;"); loginButtonBox.getChildren().add(lblUserName2); loginButtonBox.getChildren().add(tfUserName2); loginButtonBox.getChildren().add(lblPassword2); loginButtonBox.getChildren().add(pf3); loginButtonBox.getChildren().add(logInBtn); loginButtonBox.getChildren().add(back2); startMenuRoot.setLeft(loginButtonBox); BorderPane.setMargin(loginButtonBox, new Insets(350, 0, 0, 150)); logInBtn.setOnAction( ActionEvent1 -> { // TODO login }); back2.setOnAction( ActionEvent1 -> { startMenuRoot.setLeft(mainButtonBox); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); }); }); BorderPane.setMargin(mainButtonBox, new Insets(350, 0, 0, 150)); Button quitBtn = new Button("Quit game"); quitBtn.setPrefSize(80, 40); quitBtn.setId("quit-game"); quitBtn.setOnAction( ActionEvent -> { gameManager.quitGame(); theStage.setScene(startMenu); }); canvas = new Canvas(CANVAS_START_WIDTH, CANVAS_START_HEIGHT); gameBox.setCenter(canvas); BorderPane.setAlignment(canvas, Pos.TOP_LEFT); gameBox.setBottom(quitBtn); BorderPane.setAlignment(quitBtn, Pos.TOP_LEFT); theStage.show(); }
@Override public void requestFocus() { super.requestFocus(); treeTableView.requestFocus(); }