Skip to content

Commit

Permalink
added rps button, not in correct place though...
Browse files Browse the repository at this point in the history
  • Loading branch information
KelBell1009 committed Sep 30, 2017
1 parent 4cd5422 commit 9cd8db4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 21 deletions.
Binary file added images/rps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 29 additions & 21 deletions src/cellsociety_UIUX/MenuWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ public class MenuWindow extends Window {
private static final String FIRE_TAG = "Fire";
private static final String PREDATORPREY_TAG = "PredatorPrey";
private static final String SEGREGATION_TAG = "Segregation";
private static final String RPS_TAG = "RockPaperScissors";

private static final String GAMEOFLIFE_PNG = "gameoflife.png";
private static final String FIRE_PNG = "fire.png";
private static final String WATOR_PNG = "wator.png";
private static final String SEGREGATION_PNG = "segregation.png";
private static final String RPS_PNG = "rps.png";
private static final double WIDTH = 1000;
private static final double HEIGHT = 500;

private static final int BUTTONOFFSET = 50;
private static final int BUTTONS_PER_LINE = 4;
private List<Button> buttons;
// private Button newSimButton;
private double buttonPadding;

// private Stage simStage = new Stage();
// private boolean newSim = true;
private CellManager simChoice;
private Driver simDriver;

public MenuWindow(Stage s) {
super(s);
simChoice = null;
Expand All @@ -52,7 +52,7 @@ public void setupScene() {
addButtons();
addTitle();
}

protected void setupSceneDimensions() {
myScene = new Scene(myRoot, WIDTH, HEIGHT);
}
Expand Down Expand Up @@ -81,14 +81,14 @@ public void chooseSim() { //http://www.java2s.com/Code/Java/JavaFX/AddClickactio
//System.out.println(file);
}
});

}
}

public void resetMenu() {
simChoice = null;
}

private CellManager getSimFromFile(Button buttonPressed) {
String simFileString = buttonPressed.getAccessibleText();
simFileString += ".xml";
Expand All @@ -98,35 +98,43 @@ private CellManager getSimFromFile(Button buttonPressed) {
parser.buttonChooseFile(simFile);
return parser.getSimulation();
}

private void addButtons() { //https://stackoverflow.com/questions/40883858/how-to-evenly-distribute-elements-of-a-javafx-vbox
//http://docs.oracle.com/javafx/2/ui_controls/button.htm
Button segregationButton = createMenuButton(SEGREGATION_PNG, SEGREGATION_TAG);
Button watorButton = createMenuButton(WATOR_PNG, PREDATORPREY_TAG);
Button fireButton = createMenuButton(FIRE_PNG, FIRE_TAG);
Button gameoflifeButton = createMenuButton(GAMEOFLIFE_PNG, GAMEOFLIFE_TAG);

buttons = new ArrayList<Button>(Arrays.asList(segregationButton, watorButton, fireButton, gameoflifeButton));
buttonPadding = (WIDTH - BUTTONOFFSET*2 - buttons.get(0).getWidth())/buttons.size();

for (int i = 0; i < buttons.size(); i++) {
Button button = buttons.get(i);
setMenuButtonLayout(button, BUTTONOFFSET + buttons.get(i).getMaxWidth() + i*buttonPadding, HEIGHT*2/3);
Button rpsButton = createMenuButton(RPS_PNG, RPS_TAG);

buttons = new ArrayList<Button>(Arrays.asList(segregationButton, watorButton, fireButton, gameoflifeButton, rpsButton));
double buttonXPadding = (WIDTH - BUTTONOFFSET*2 - buttons.get(0).getWidth())/BUTTONS_PER_LINE;
double buttonYPadding = (HEIGHT/2 - BUTTONOFFSET - buttons.get(0).getHeight()*2)/BUTTONS_PER_LINE;

int line = 0;
while (line <= Math.floor(buttons.size()/BUTTONS_PER_LINE)) {
for (int i = line; i < line + BUTTONS_PER_LINE; i++) {
if (line*BUTTONS_PER_LINE + i < buttons.size()) {
Button button = buttons.get(line*BUTTONS_PER_LINE + i);
setMenuButtonLayout(button, BUTTONOFFSET + button.getMaxWidth() + i*buttonXPadding, HEIGHT/2 + line*buttonYPadding);
}
}
line++;
}
myRoot.getChildren().addAll(buttons);
}

private void setMenuButtonLayout(Button button, Double x, Double y) {
button.setLayoutX(x);
button.setLayoutY(y);
}

private Button createMenuButton(String imageName, String buttonText) {
Image buttonImage = new Image(getClass().getClassLoader().getResourceAsStream(imageName));
Button simButton = new Button();
simButton.setGraphic(new ImageView(buttonImage));
simButton.setAccessibleText(buttonText);

return simButton;
}

Expand Down
1 change: 1 addition & 0 deletions src/main.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class main extends Application {
*/
@Override
public void start(Stage stage) {
//TODO move this stuff into MenuWindow?
menuStage = stage;
menuStage.setTitle(MENUTITLE);
menuWindow = new MenuWindow(menuStage);
Expand Down

0 comments on commit 9cd8db4

Please sign in to comment.