Skip to content
Snippets Groups Projects
Commit 36c784da authored by Turid Cecilie Dahl's avatar Turid Cecilie Dahl
Browse files

#90 game can't crash when something goes wrong with creating a tournament

parent 0825d354
No related branches found
No related tags found
1 merge request!89Resolve "Small frontend stuff"
......@@ -60,6 +60,10 @@ public class CreateNewTournamentState extends State {
private final String createBtnText = "Create";
private final String nextBtnText = "Next";
private final String noNameText = "No name given";
private final String noGamesSelectedText = "No games selected";
private final String IOExceptionText = "Something went wrong when\ncreating the tournament";
// Input fields
private TextField nameInputField = new TextField("",skin);
......@@ -80,7 +84,7 @@ public class CreateNewTournamentState extends State {
private final int inputFieldHeight = Gdx.graphics.getHeight()/15;
private final int nameFieldWidth = Gdx.graphics.getWidth()/3;
private final float checkBoxSize = Gdx.graphics.getWidth()/15;
private final float scrollPaneWidth = Gdx.graphics.getWidth()/1.13f;
private final float scrollPaneWidth = Gdx.graphics.getWidth()/1.14f;
private final float scrollPaneHeight = Gdx.graphics.getHeight()/2.3f;
private Table rootTable;
......@@ -263,7 +267,7 @@ public class CreateNewTournamentState extends State {
dialog.getContentTable().add(label).width(Gdx.graphics.getWidth()/1.5f).pad(dialog.getHeight()/5f).padBottom(0);
dialog.button("Okay", true); //sends "true" as the result
dialog.getButtonTable().pad(dialog.getHeight()/5f);
dialog.getButtonTable().pad(dialog.getHeight()/2f);
return dialog;
}
......@@ -287,8 +291,14 @@ public class CreateNewTournamentState extends State {
public void clicked(InputEvent e, float x, float y){
if(GameWare.getInstance().isSoundEffectsOn()){ buttonPressSound.play(); }
if(getTournamentName().equals("")){
errorLabel.setText(noNameText);
return;
}
page ++;
errorLabel.setText("");
nameUserInput = getTournamentName();
timePerRoundUserInput = getTimePerRound();
maxPlayersUserInput = getMaxPlayers();
......@@ -363,6 +373,7 @@ public class CreateNewTournamentState extends State {
stage.clear();
makeStage();
errorLabel.setText("");
nameInputField.setText(nameUserInput);
timePerRoundSelectBox.setSelected(timePerRoundUserInput);
maxPlayersSelectBox.setSelected(maxPlayersUserInput);
......@@ -374,21 +385,18 @@ public class CreateNewTournamentState extends State {
private void handleCreateBtnClick(){
if(GameWare.getInstance().isSoundEffectsOn()){ buttonPressSound.play(); }
if(chosenGames.isEmpty()){
errorLabel.setText("No games chosen.");
return;
}
if(getTournamentName().equals("")){
errorLabel.setText("No name given.");
errorLabel.setText(noGamesSelectedText);
return;
}
try {
tournament = new Tournament(GameWare.getInstance().getPlayer().getId(),chosenGames,nameUserInput, timePerRoundUserInput, maxPlayersUserInput, roundsPerGameUserInput,1,chosenGames.size(),startDelayUserInput);
tournamentFromDB = QueryIntermediate.createNewTournament(tournament);
round = QueryIntermediate.getRoundFromTournament(tournamentFromDB.get_id(), GameWare.getInstance().getPlayer().getId(), tournamentFromDB.getCurrentRound());
gsm.set(new ViewTournamentState(gsm,tournamentFromDB,round));
} catch (IOException e) {
e.printStackTrace();
errorLabel.setText(IOExceptionText);
}
gsm.set(new ViewTournamentState(gsm,tournamentFromDB,round));
}
private String getTournamentName(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment