content: package com.almasb.tutorial10;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.nio.file.Files;
  import java.nio.file.Paths;
  
  import javafx.animation.TranslateTransition;
  import javafx.application.Application;
  import javafx.geometry.*;
  import javafx.scene.*;
  import javafx.scene.image.*;
  import javafx.scene.layout.*;
  import javafx.scene.paint.*;
  import javafx.scene.shape.*;
  import javafx.scene.text.*;
  import javafx.scene.input.KeyCode;
  import javafx.scene.effect.DropShadow;
  import javafx.stage.Stage;
  import javafx.util.Duration;
  
  public class Main extends Application {
  
      private static Font font;
      private MenuBox menu;
  
      private Parent createContent() {
          Pane root = new Pane();
          root.setPrefSize(800, 600);
  
          try (InputStream is = Files.newInputStream(Paths.get("res/images/cod_bg.jpg"));
                  InputStream fontStream = Files.newInputStream(Paths.get("res/fonts/cod_font.ttf"))) {
              ImageView img = new ImageView(new Image(is));
              img.setFitWidth(1066);
              img.setFitHeight(600);
  
              root.getChildren().add(img);
  
              font = Font.loadFont(fontStream, 30);
          }
          catch (IOException e) {
              System.out.println("Couldn't load image or font");
          }
  
          MenuItem itemQuit = new MenuItem("QUIT");
          itemQuit.setOnMouseClicked(event -> System.exit(0));
  
          menu = new MenuBox("CAMPAIGN",
                  new MenuItem("RESUME GAME"),
                  new MenuItem("NEW GAME"),
                  new MenuItem("MISSION SELECT"),
                  new MenuItem("OPTIONS"),
                  new MenuItem("CREDITS"),
                  new MenuItem("MAIN MENU"),
                  itemQuit);
  
          root.getChildren().add(menu);
          return root;
      }
  
      @Override
      public void start(Stage primaryStage) throws Exception {
          Scene scene = new Scene(createContent());
          scene.setOnKeyPressed(event -> {
              if (event.getCode() == KeyCode.ESCAPE) {
                  if (menu.isVisible()) {
                      menu.hide();
                  }
                  else {
                      menu.show();
                  }
              }
          });
          primaryStage.setTitle("Tutorial");
          primaryStage.setScene(scene);
          primaryStage.show();
      }
  
      private static class MenuBox extends StackPane {
          public MenuBox(String title, MenuItem... items) {
              Rectangle bg = new Rectangle(300, 600);
              bg.setOpacity(0.2);
  
              DropShadow shadow = new DropShadow(7, 5, 0, Color.BLACK);
              shadow.setSpread(0.8);
  
              bg.setEffect(shadow);
  
              Text text = new Text(title + "   ");
              text.setFont(font);
              text.setFill(Color.WHITE);
  
              Line hSep = new Line();
              hSep.setEndX(250);
              hSep.setStroke(Color.DARKGREEN);
              hSep.setOpacity(0.4);
  
              Line vSep = new Line();
              vSep.setStartX(300);
              vSep.setEndX(300);
              vSep.setEndY(600);
              vSep.setStroke(Color.DARKGREEN);
              vSep.setOpacity(0.4);
  
              VBox vbox = new VBox();
              vbox.setAlignment(Pos.TOP_RIGHT);
              vbox.setPadding(new Insets(60, 0, 0, 0));
              vbox.getChildren().addAll(text, hSep);
              vbox.getChildren().addAll(items);
  
              setAlignment(Pos.TOP_RIGHT);
              getChildren().addAll(bg, vSep, vbox);
          }
  
          public void show() {
              setVisible(true);
              TranslateTransition tt = new TranslateTransition(Duration.seconds(0.5), this);
              tt.setToX(0);
              tt.play();
          }
  
          public void hide() {
              TranslateTransition tt = new TranslateTransition(Duration.seconds(0.5), this);
              tt.setToX(-300);
              tt.setOnFinished(event -> setVisible(false));
              tt.play();
          }
      }
  
      private static class MenuItem extends StackPane {
          public MenuItem(String name) {
              Rectangle bg = new Rectangle(300, 24);
  
              LinearGradient gradient = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, new Stop[] {
                      new Stop(0, Color.BLACK),
                      new Stop(0.2, Color.DARKGREY)
              });
  
              bg.setFill(gradient);
              bg.setVisible(false);
              bg.setEffect(new DropShadow(5, 0, 5, Color.BLACK));
  
              Text text = new Text(name + "      ");
              text.setFill(Color.LIGHTGREY);
              text.setFont(Font.font(20));
  
              setAlignment(Pos.CENTER_RIGHT);
              getChildren().addAll(bg, text);
  
              setOnMouseEntered(event -> {
                  bg.setVisible(true);
                  text.setFill(Color.WHITE);
              });
  
              setOnMouseExited(event -> {
                  bg.setVisible(false);
                  text.setFill(Color.LIGHTGREY);
              });
  
              setOnMousePressed(event -> {
                  bg.setFill(Color.WHITE);
                  text.setFill(Color.BLACK);
              });
  
              setOnMouseReleased(event -> {
                  bg.setFill(gradient);
                  text.setFill(Color.WHITE);
              });
          }
      }
  
      public static void main(String[] args) {
          launch(args);
      }
  }
  