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