Skip to content

Commit

Permalink
Gui/Backend: Store game info as Game object (#45)
Browse files Browse the repository at this point in the history
Create a Game object when a user clicks "Add" in the new game window.
Currently does not do any permanent storage of Game object.
  • Loading branch information
Stevoisiak authored Mar 6, 2017
1 parent 8c1c6b1 commit 1360dff
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions src/virtualgameshelf/gui/NewGameWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javafx.scene.layout.*;
import javafx.scene.*;
import javafx.stage.*;
import virtualgameshelf.backend.domain.Game;

public class NewGameWindow extends Stage {
private TextField systemField;
Expand Down Expand Up @@ -44,7 +45,7 @@ public NewGameWindow() {
TextField nameField = new TextField("");

Label systemLabel = new Label("Game System:");
ComboBox<String> systemChooser = new ComboBox<String>();
ComboBox<String> systemChooser = new ComboBox<>();
systemChooser.getItems().addAll(systemList);

systemChooser.setPromptText("Choose a System");
Expand All @@ -63,7 +64,7 @@ public void changed(ObservableValue<? extends String> ov, String oldValue, Strin
});

Label completionLabel = new Label("Game Completion:");
ComboBox<String> completionChooser = new ComboBox<String>();
ComboBox<String> completionChooser = new ComboBox<>();
completionChooser.getItems().addAll("Unfinished", "Beaten", "Completed", "Null", "Mastered", "Unplayed");

completionChooser.setPromptText("Choose a Level of Completion");
Expand Down Expand Up @@ -101,25 +102,44 @@ public void changed(ObservableValue<? extends String> observable, String oldValu
starRow.getChildren().add(starButtons[i]);
}

// Create entry with entered game data
Button addButton = new Button("Add");
addButton.setOnAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent e) {
System.out.println("Game Name: " + nameField.getText());
Game newGame = new Game();
boolean customConsole = false;

// Retrieve and set game info
newGame.setName(nameField.getText());

if (systemChooser.getValue() == "Add New System") {
System.out.println("Game System: <Choice>" + systemChooser.getValue() + "<Choice> " + "<Adding>"
+ systemField.getText() + "<Adding>");
customConsole = true;
newGame.setSystem(systemField.getText());
} else {
System.out.println("Game System: " + systemChooser.getValue());
newGame.setSystem(systemChooser.getValue());
}

System.out.println("Game Completion: " + completionChooser.getValue());

System.out.println("Hours Played: " + hoursField.getText());

if (starGroup.getSelectedToggle() != null) {
int starRating = (int) starGroup.getSelectedToggle().getUserData();
System.out.println("Rating: " + starRating + " Star");
newGame.setCompletion(completionChooser.getValue());

if (hoursField.getText() != null || hoursField.getText().trim().isEmpty())
newGame.setHours(0);
else
newGame.setHours(Integer.parseInt(hoursField.getText()));

if (starGroup.getSelectedToggle() != null)
newGame.setRating((int) starGroup.getSelectedToggle().getUserData());
else
newGame.setRating(0);

// Print game info
System.out.println("Game Name: " + newGame.getName());
System.out.println("Game System: " + newGame.getSystem());
System.out.println("Game Completion: " + newGame.getCompletion());
System.out.println("Hours Played: " + newGame.getHours());
if (newGame.getRating() == 1) {
System.out.println("Rating: " + newGame.getRating() + " star");
} else {
System.out.println("Rating: " + newGame.getRating() + " stars");
}
}
});
Expand Down

0 comments on commit 1360dff

Please sign in to comment.