private int getIntFromColor(final Color COLOR) {
   String hex = COLOR.toString();
   StringBuilder intValue = new StringBuilder(10);
   intValue.append(hex.substring(8, 10));
   intValue.append(hex.substring(2, 8));
   // System.out.println((int) (Long.parseLong(intValue.toString(), 16) - 0x100000000l));
   return (int) Long.parseLong(intValue.toString(), 16);
 }
예제 #2
0
  @FXML
  private void playerSetup(ActionEvent e) throws NullPointerException {
    Stage newStage = new Stage();
    // try {
    if (e.getSource() == nextButton2) {

      String name = playerName.getText();
      String race = raceChoice.getSelectionModel().getSelectedItem().toString();
      if (race.length() > 8) {
        race = race.toUpperCase().substring(0, race.indexOf(" "));
      } else {
        race = race.toUpperCase();
      }
      Player.Race r = Player.Race.valueOf(race);

      Color color = colorPick.getValue();

      // creating Player
      Player p = new Player(name, r, color.toString());
      players[count - 1] = p;
      if (players[players.length - 1] != null) {
        // when players array is full, begins game turns
        Turns gameTurns = new Turns(players);
      }

      if (name.equals("")) { // check if player entered a name
        Launcher.primaryStage.setScene(Launcher.errorMessage);
        Launcher.primaryStage.setTitle("Enter name!");
      } else if (playerColors.contains(color)) {
        Launcher.primaryStage.setScene(Launcher.errorMessage);
        Launcher.primaryStage.setTitle("Choose new color!");
      } else {
        playerColors.add(color);
        if (count == 1) { // if only one player config screen has been shown go to player 2
          Launcher.primaryStage.setTitle("Player 2 Configuration");
          Launcher.primaryStage.toFront();
          playerName.clear();
          raceChoice.getSelectionModel().clearSelection();
          colorPick.setValue(Color.WHITE);
          count += 1;
        } else if (count == 2) {
          if (count == numPlayer) { // if user selected only 2 players then show game screen
            Launcher.primaryStage.hide();
            try {
              gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml"));
              gameScene = new Scene(gameRoot);
              Parent startWindow =
                  FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml"));
              startScene = new Scene(startWindow);
            } catch (Exception e1) {
              e1.printStackTrace();
            }
            newStage.setScene(gameScene);
            newStage.setTitle("Game Screen");
            newStage.show();
            GameController.beginTurn();
            // creates land array
            landPlots = new Land[9][5]; // 5 rows, 9 columns, col = i, row = j
            int count = 0;
            for (int i = 0; i < landPlots.length; i++) {
              for (int j = 0; j < landPlots[0].length; j++) {
                Land newLand = new Land(i, j);
                newLand.setType(landTypes[count]);
                landPlots[i][j] = newLand;
                count++;
              }
            }
          } else { // if user selected more than 2 players, go on to player 3 config
            Launcher.primaryStage.setTitle("Player 3 Configuration");
            Launcher.primaryStage.toFront();
            playerName.clear();
            raceChoice.getSelectionModel().clearSelection();
            colorPick.setValue(Color.WHITE);
            count += 1;
          }

        } else if (count == 3) {
          if (count == numPlayer) {
            Launcher.primaryStage.hide();
            try {
              gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml"));
              gameScene = new Scene(gameRoot);
              Parent startWindow =
                  FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml"));
              startScene = new Scene(startWindow);
            } catch (Exception e1) {
              e1.printStackTrace();
            }
            newStage.setScene(gameScene);
            newStage.setTitle("Game Screen");
            newStage.show();
            GameController.beginTurn();
            // creates land array
            landPlots = new Land[9][5]; // 5 rows, 9 columns, col = i, row = j
            int count = 0;
            for (int i = 0; i < landPlots.length; i++) {
              for (int j = 0; j < landPlots[0].length; j++) {
                Land newLand = new Land(i, j);
                newLand.setType(landTypes[count]);
                landPlots[i][j] = newLand;
                count++;
              }
            }
          } else {
            Launcher.primaryStage.setTitle("Player 4 Configuration");
            Launcher.primaryStage.toFront();
            playerName.clear();
            raceChoice.getSelectionModel().clearSelection();
            colorPick.setValue(Color.WHITE);
            count += 1;
          }

        } else if (count == 4) {
          Launcher.primaryStage.hide();
          try {
            gameRoot = FXMLLoader.load(getClass().getResource("UIFiles/MainMap.fxml"));
            gameScene = new Scene(gameRoot);
            Parent startWindow =
                FXMLLoader.load(getClass().getResource("UIFiles/playerStart.fxml"));
            startScene = new Scene(startWindow);
          } catch (Exception e1) {
            e1.printStackTrace();
          }

          newStage.setScene(gameScene);
          newStage.setTitle("Game Screen");
          newStage.show();
          GameController.beginTurn();
          // creates land array
          landPlots = new Land[9][5]; // 5 rows, 9 columns, col = i, row = j
          int count = 0;
          for (int i = 0; i < landPlots.length; i++) {
            for (int j = 0; j < landPlots[0].length; j++) {
              Land newLand = new Land(i, j);
              newLand.setType(landTypes[count]);
              landPlots[i][j] = newLand;
              count++;
            }
          }
        }
      }
    } else if (e.getSource() == backButton) {
      playerName.clear();
      raceChoice.getSelectionModel().clearSelection();
      colorPick.setValue(Color.WHITE);
      Launcher.primaryStage.setScene(Launcher.rootScene);
      Launcher.primaryStage.setTitle("M.U.L.E. Game Setup");
    }
    /*} catch (NullPointerException error) {
    	Launcher.primaryStage.setScene(Launcher.errorMessage);
    	Launcher.primaryStage.setTitle("Error!");
    }*/
  }
예제 #3
0
 public static String colorToHex(Color color) {
   String hex = color.toString();
   return "#" + hex.substring(2, hex.length() - 2);
 }
  /**
   * @param axis Axis name to wich the new series belongs
   * @param cs Series Coinfiguration
   */
  @Override
  public final void addSeries(String axis, SimpleSeriesConfiguration cs) {
    for (int i = 0; i < axes.size(); i++) {
      if (axes.get(i).getName().equals(axis)) {
        String strColor;
        javafx.scene.paint.Color color;
        int indice = seriesList.size();
        if (cs.getColor() == null) {
          color = getColor(indice);
        } else {
          color = cs.getColor();
        }
        strColor = color.toString();

        XYSeriesCollection dataset = datasetList.get(i);
        Series series =
            new Series(
                cs.getName(),
                "color: "
                    + strColor
                    + ";width: "
                    + String.valueOf(cs.getLineWidth())
                    + ";shape: "
                    + cs.getShapeName()
                    + ";",
                i,
                dataset.getSeriesCount());
        dataset.addSeries(series);

        XYItemRenderer renderer = plot.getRenderer(i);
        renderer.setSeriesPaint(dataset.getSeriesCount() - 1, scene2awtColor(color));

        SeriesShape simb =
            new SeriesShape(
                cs.getShapeName(), javafx.scene.paint.Color.web(strColor.replace("#", "0x")));

        if (cs.getLineWidth() > 0) {
          ((XYLineAndShapeRenderer) renderer)
              .setSeriesLinesVisible(dataset.getSeriesCount() - 1, true);
          renderer.setSeriesStroke(
              dataset.getSeriesCount() - 1, new BasicStroke(cs.getLineWidth()));
        } else {
          ((XYLineAndShapeRenderer) renderer)
              .setSeriesLinesVisible(dataset.getSeriesCount() - 1, false);
        }

        if (cs.getShapeName().equals("null")) {
          renderer.setSeriesShape(dataset.getSeriesCount() - 1, null);
          ((XYLineAndShapeRenderer) renderer)
              .setSeriesShapesVisible(dataset.getSeriesCount() - 1, false);
        } else {
          renderer.setSeriesShape(dataset.getSeriesCount() - 1, simb.getShapeAWT());
          ((XYLineAndShapeRenderer) renderer)
              .setSeriesShapesVisible(dataset.getSeriesCount() - 1, true);
          if (cs.getShapeName().contains("empty")) {
            ((XYLineAndShapeRenderer) renderer)
                .setSeriesShapesFilled(dataset.getSeriesCount() - 1, false);
          } else {
            ((XYLineAndShapeRenderer) renderer)
                .setSeriesShapesFilled(dataset.getSeriesCount() - 1, true);
          }
        }

        if (i == 0) {
          plot.setRenderer(renderer);
        } else {
          plot.setRenderer(i, renderer);
        }

        seriesList.add(series);

        final LegendAxis le = getLegendAxis(axis);
        final Label label = new Label(cs.toString());
        Platform.runLater(
            () -> {
              label.setStyle(
                  "fondo: "
                      + strChartBackgroundColor
                      + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                      + String.valueOf(fontSize)
                      + "px");
            });

        label.setOnMouseClicked(
            (MouseEvent t) -> {
              if (t.getClickCount() == 2) {
                for (int i1 = 0; i1 < seriesList.size(); i1++) {
                  if (seriesList.get(i1).getKey().toString().equals(label.getText())) {
                    editSeries(seriesList.get(i1));
                    break;
                  }
                }
              }
            });
        label.setOnMouseExited(
            (MouseEvent t) -> {
              label.setStyle(
                  label
                      .getStyle()
                      .replace("-fx-background-color: blue", "-fx-background-color: fondo"));
            });
        label.setOnMouseEntered(
            (MouseEvent t) -> {
              label.setStyle(
                  label
                      .getStyle()
                      .replace("-fx-background-color: fondo", "-fx-background-color: blue"));
              for (Node le1 : legendFrame.getChildren()) {
                if (le1 instanceof LegendAxis) {
                  le1.setStyle("-fx-background-color:" + strBackgroundColor);
                  ((LegendAxis) le1).selected = false;
                }
              }
            });
        label.setStyle(
            "fondo: "
                + strChartBackgroundColor
                + ";-fx-text-fill: white;-fx-background-color: fondo;-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                + String.valueOf(fontSize)
                + "px");

        le.getChildren().add(label);
        label.setGraphic(simb.getShapeGraphic());

        break;
      }
    }
  }
예제 #5
0
 public static final String toCSSColorString(final Color color) {
   return "#" + color.toString().substring(2, 8);
 }