diff --git a/frontend/android/assets/tableBG.png b/frontend/android/assets/tableBG.png index c63788c6cb611357c7f0663c0609b604ebcd3d05..16dc751219abc736d77c87a48ed7882c5d057f4b 100644 Binary files a/frontend/android/assets/tableBG.png and b/frontend/android/assets/tableBG.png differ diff --git a/frontend/android/assets/tableBGRounded.png b/frontend/android/assets/tableBGRounded.png index f5076b1bb74e656a662e49c83acda133d18808dd..28c3d6280b6a382d0dfb4af1ecac9c0a82805609 100644 Binary files a/frontend/android/assets/tableBGRounded.png and b/frontend/android/assets/tableBGRounded.png differ diff --git a/frontend/core/src/com/gameware/game/states/CreateNewTournamentState.java b/frontend/core/src/com/gameware/game/states/CreateNewTournamentState.java index 4b5df66c1a45f02b8d6807e255a5e28707286a19..cb40661bbb5f36a4dd84e83a82e19e5edadc1457 100644 --- a/frontend/core/src/com/gameware/game/states/CreateNewTournamentState.java +++ b/frontend/core/src/com/gameware/game/states/CreateNewTournamentState.java @@ -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(){ diff --git a/frontend/core/src/com/gameware/game/states/LoginState.java b/frontend/core/src/com/gameware/game/states/LoginState.java index 54339aa120e9e6459ea296f7a1b1d98904b3391b..69b20b5d56c2ecf20b8a253165bd67cfb3136640 100644 --- a/frontend/core/src/com/gameware/game/states/LoginState.java +++ b/frontend/core/src/com/gameware/game/states/LoginState.java @@ -23,7 +23,8 @@ public class LoginState extends State { // Labels private final Label titleLabel = new Label("GameWare", skin, "big"); - private final Label subHeadLabel = new Label("Log in / Create User", skin, "big"); + private final Label subHeadLabelLogIn = new Label("Log in", skin, "big"); + private final Label subHeadLabelCreateUser = new Label("Create User", skin, "big"); private Label errorLabel = new Label("", skin, "error"); // Input fields @@ -31,22 +32,23 @@ public class LoginState extends State { private TextField usernameInputField; private String passwordInputText = "Password"; private TextField passwordInputField; + private String confirmPasswordInputText = "Confirm password"; + private TextField confirmPasswordInputField; private final char passwordCharacter = '*'; private final int inputFieldWidth = Gdx.graphics.getWidth()/2; private final int inputFieldHeight = Gdx.graphics.getHeight()/15; // Button texts private final String loginBtnText = "Log in"; + private final String createUserText = "Create User"; private final String signUpBtnText = "Sign Up"; + private final String backText = "Back"; // Feedback texts private final String wrongLoginText = "User not found"; private final String takenUsernameText = "Username already taken"; private final String ioExceptionText = "Something went wrong with query"; - -// Feedback label animation - private final int animationDelay = 2; - private final int animationDuration = 1; + private final String passwordNotMatchingText = "Passwords do not match"; // Loading text private LoadingText loadingText = new LoadingText(); @@ -54,6 +56,10 @@ public class LoginState extends State { private boolean signUpBtnClicked = false; +// Variables + private int page = 0; + + public LoginState(GameStateManager gsm) { super(gsm); makeStage(); @@ -64,19 +70,36 @@ public class LoginState extends State { // Add widgets titleLabel.setFontScale(titleFontBigScale); - rootTable.add(titleLabel).expandY(); - rootTable.row(); - rootTable.add(subHeadLabel).expandY(); - rootTable.row(); - rootTable.add(makeUserInputField()).size(inputFieldWidth, inputFieldHeight); + rootTable.add(titleLabel).expandY().top(); rootTable.row(); - rootTable.add(makePasswordInputField()).size(inputFieldWidth, inputFieldHeight); - rootTable.row(); - rootTable.add(errorLabel); - rootTable.row(); - rootTable.add(makeLoginBtn()).size(buttonWidth, buttonHeight); - rootTable.row(); - rootTable.add(makeSignUpBtn()).size(buttonWidth, buttonHeight).padBottom(spacingLarge); + + if (page == 0) { + rootTable.add(subHeadLabelLogIn).expandY(); + rootTable.row(); + rootTable.add(makeUserInputField()).size(inputFieldWidth, inputFieldHeight); + rootTable.row(); + rootTable.add(makePasswordInputField()).size(inputFieldWidth, inputFieldHeight); + rootTable.row(); + rootTable.add(errorLabel); + rootTable.row(); + rootTable.add(makeLoginBtn()).size(buttonWidth, buttonHeight); + rootTable.row(); + rootTable.add(makeCreateUserBtn()).size(buttonWidth, buttonHeight).padBottom(spacingMedium).expandY().top(); + } else if (page == 1){ + rootTable.add(subHeadLabelCreateUser).expandY().spaceBottom(spacingMedium); + rootTable.row(); + rootTable.add(makeUserInputField()).size(inputFieldWidth, inputFieldHeight); + rootTable.row(); + rootTable.add(makePasswordInputField()).size(inputFieldWidth, inputFieldHeight); + rootTable.row(); + rootTable.add(makeConfirmPasswordInputField()).size(inputFieldWidth, inputFieldHeight); + rootTable.row(); + rootTable.add(errorLabel); + rootTable.row(); + rootTable.add(makeSignUpBtn()).size(buttonWidth, buttonHeight); + rootTable.row(); + rootTable.add(makeBackBtn()).expand().bottom().left(); + } removeKeyPadAtTouch(); @@ -116,6 +139,22 @@ public class LoginState extends State { return passwordInputField; } + private TextField makeConfirmPasswordInputField( ){ + confirmPasswordInputField = new TextField(confirmPasswordInputText, skin); + confirmPasswordInputField.setPasswordCharacter(passwordCharacter); + confirmPasswordInputField.addListener(new ClickListener() { + @Override + public void clicked(InputEvent event, float x, float y) { + super.clicked(event, x, y); + if(confirmPasswordInputField.getText().equals(confirmPasswordInputText)){ + confirmPasswordInputField.setText(""); + confirmPasswordInputField.setPasswordMode(true); + } + } + }); + return confirmPasswordInputField; + } + private TextButton makeLoginBtn( ){ TextButton loginBtn = new TextButton(loginBtnText, skin); loginBtn.addListener(new ClickListener() { @@ -127,17 +166,51 @@ public class LoginState extends State { return loginBtn; } + private TextButton makeCreateUserBtn( ){ + TextButton createUserBtn = new TextButton(createUserText, skin); + createUserBtn.addListener(new ClickListener() { + @Override + public void clicked(InputEvent e, float x, float y){ + page ++; + errorLabel.setText(""); + stage.clear(); + makeStage(); + } + }); + return createUserBtn; + } + private TextButton makeSignUpBtn( ){ TextButton signUpBtn = new TextButton(signUpBtnText, skin); signUpBtn.addListener(new ClickListener() { @Override public void clicked(InputEvent e, float x, float y){ - setSignUpBtnClicked(); + try{ + isValidPassword(); + setSignUpBtnClicked(); + }catch(IllegalArgumentException exception){ + errorLabel.setText(passwordNotMatchingText); + } + } }); return signUpBtn; } + private TextButton makeBackBtn(){ + TextButton backBtn = new TextButton(backText, skin); + backBtn.addListener(new ClickListener() { + @Override + public void clicked(InputEvent e, float x, float y){ + page --; + errorLabel.setText(""); + stage.clear(); + makeStage(); + } + }); + return backBtn; + } + // Handle click methods private void handleLoginBtnClick(){ @@ -157,12 +230,6 @@ public class LoginState extends State { }catch(Exception e) { e.printStackTrace(); -// Add animation - errorLabel.getColor().a = 1; - errorLabel.addAction(Actions.sequence( - new DelayAction(animationDelay), - Actions.fadeOut(animationDuration))); - // Different feedback text depending on which exception if (e instanceof NoSuchElementException) { errorLabel.setText(wrongLoginText); @@ -191,12 +258,6 @@ public class LoginState extends State { } catch (Exception e) { e.printStackTrace(); -// Add animation - errorLabel.getColor().a = 1; - errorLabel.addAction(Actions.sequence( - new DelayAction(animationDelay), - Actions.fadeOut(animationDuration))); - // Different feedback text depending on which exception if (e instanceof NoSuchElementException) { errorLabel.setText(takenUsernameText); @@ -221,6 +282,12 @@ public class LoginState extends State { } + private void isValidPassword() throws IllegalArgumentException { + if(!passwordInputField.getText().equals(confirmPasswordInputField.getText())){ + throw new IllegalArgumentException(); + } + } + @Override public void update(float dt) { super.update(dt); @@ -264,5 +331,7 @@ public class LoginState extends State { public void reset() { usernameInputField.setText(usernameInputText); passwordInputField.setText(passwordInputText); + confirmPasswordInputField.setText(confirmPasswordInputText); + errorLabel.setText(""); } } diff --git a/frontend/core/src/com/gameware/game/states/OptionsState.java b/frontend/core/src/com/gameware/game/states/OptionsState.java index ddde864646da94b075201f3d1ea64efc47bf791f..50e1f3d8c71511bf113a98ea382671fc88cd109d 100644 --- a/frontend/core/src/com/gameware/game/states/OptionsState.java +++ b/frontend/core/src/com/gameware/game/states/OptionsState.java @@ -41,6 +41,8 @@ public class OptionsState extends State { // Make inner Table + adds labels and checkboxes Table innerTable = new Table(); + innerTable.pad(padding); + innerTable.setBackground(backgroundTableBlueRounded); innerTable.defaults().spaceBottom(spacingMedium); innerTable.columnDefaults(0).spaceRight(spacingMedium); diff --git a/frontend/core/src/com/gameware/game/states/ScoreState.java b/frontend/core/src/com/gameware/game/states/ScoreState.java index bd1ccfa84f8f1dfe8fa349c62bbeb89f4c9ccd1c..176f2be49f713346126dc9513d756310855da7e3 100644 --- a/frontend/core/src/com/gameware/game/states/ScoreState.java +++ b/frontend/core/src/com/gameware/game/states/ScoreState.java @@ -1,6 +1,7 @@ package com.gameware.game.states; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.g2d.GlyphLayout; import com.badlogic.gdx.scenes.scene2d.actions.Actions; import com.badlogic.gdx.scenes.scene2d.actions.DelayAction; import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction; @@ -22,6 +23,7 @@ public class ScoreState extends State { // Variables private float currentTime = 0f; + private float scoreLabelDifferance = 0f; public ScoreState(GameStateManager gsm, int score, State nextState){ @@ -31,6 +33,10 @@ public class ScoreState extends State { scoreLabel.setText(score+""); continueLabel.getColor().a = 0; + GlyphLayout g = new GlyphLayout(); + g.setText(skin.getFont("font-big"), score+""); + scoreLabelDifferance = (g.width - (g.width*titleFontBigScale*2))/2; + makeStage(); } @@ -54,7 +60,7 @@ public class ScoreState extends State { scoreContainer.addAction(Actions.sequence( new DelayAction(1f), Actions.parallel( - Actions.moveBy(-(titleFontBigScale*35), -(titleFontBigScale*50),2), + Actions.moveBy(scoreLabelDifferance, -(titleFontBigScale*50),2), Actions.scaleTo(titleFontBigScale*2, titleFontBigScale*2, 2)))); continueLabel.addAction(Actions.sequence( diff --git a/frontend/core/src/com/gameware/game/states/TournamentHighScoreState.java b/frontend/core/src/com/gameware/game/states/TournamentHighScoreState.java index 6a3c2a5b7d1dcefc8d7475626be84ca956f74ec3..a16b98bc1d45a3be1528727c6a0b4f23d4e6ecc9 100644 --- a/frontend/core/src/com/gameware/game/states/TournamentHighScoreState.java +++ b/frontend/core/src/com/gameware/game/states/TournamentHighScoreState.java @@ -4,10 +4,13 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.scenes.scene2d.InputEvent; +import com.badlogic.gdx.scenes.scene2d.ui.Dialog; +import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.scenes.scene2d.ui.TextButton; import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; +import com.badlogic.gdx.utils.Align; import com.gameware.game.GameWare; import com.gameware.game.QueryIntermediate; import com.gameware.game.models.Point; @@ -32,10 +35,17 @@ public class TournamentHighScoreState extends State{ private final Label colTwoLabel = new Label("Total", skin, "big"); private final Label colThreeLabel = new Label("Last Round", skin, "big"); private final Label yourScoreThisRoundLabel = new Label("Your score this round: ", skin); + private final Label totalDialogLabel = new Label("Total number of tournament points (TP). The number of TP you get, depends on how many players there are in the tournament. Therefore no TP will be given until all players are finished with their round.\n\nFor example if there are 3 players in a tournament, then the one with the highest score would get 30 TP and the player with the lowest score would get 10 TP. ", skin); + private final Label lastRoundLabel = new Label("Tournament points (TP) recieved in the last round of the tournament. TP depends on every players score, so no TP will be given until all players are finished with their round.", skin); // Texts private final String backBtnText = "Back"; + +// Dialogs + private Dialog totalDialog; + private Dialog lastRoundDialog; + // Variables private final Color scrollPaneBGColor = Color.SKY; private final int padding = 50; @@ -51,6 +61,10 @@ public class TournamentHighScoreState extends State{ }catch(Exception e){ e.printStackTrace(); } + + totalDialog = makeDialog(totalDialogLabel); + lastRoundDialog = makeDialog(lastRoundLabel); + makeStage(); } @@ -66,7 +80,7 @@ public class TournamentHighScoreState extends State{ rootTable.add(subHeadLabel).expandY().top(); rootTable.row(); - rootTable.add(makeHighScoreTable()); + rootTable.add(makeHighScoreTable()).maxHeight(Gdx.graphics.getHeight()/1.75f); rootTable.row(); Table yourScoreTable = new Table(); @@ -74,7 +88,7 @@ public class TournamentHighScoreState extends State{ yourScoreTable.setBackground(backgroundTableBlueRounded); yourScoreTable.add(yourScoreThisRoundLabel); yourScoreTable.add(new Label(((int)round.getScoreValue())+"", skin)); - rootTable.add(yourScoreTable); + rootTable.add(yourScoreTable).height(Gdx.graphics.getHeight()/10); rootTable.row(); rootTable.add(makeBackBtn()).expand().bottom().left(); @@ -86,12 +100,12 @@ public class TournamentHighScoreState extends State{ private Table makeHighScoreTable(){ Table innerTable = new Table(); innerTable.pad(padding); - innerTable.defaults().space(spacingLittle); + innerTable.defaults().space(spacingLittle).expand(); innerTable.setBackground(backgroundTableBlueRounded); - innerTable.add(colOneLabel).expandX(); - innerTable.add(colTwoLabel).expandX(); - innerTable.add(colThreeLabel).expandX(); + innerTable.add(colOneLabel).top(); + innerTable.add(makeRow(colTwoLabel,totalDialog)).top(); + innerTable.add(makeRow(colThreeLabel,lastRoundDialog)).top(); innerTable.row(); for(Point point : points){ @@ -103,6 +117,36 @@ public class TournamentHighScoreState extends State{ return innerTable; } + private Table makeRow(Label label, final Dialog dialog){ + Table table = new Table(); + table.add(label).spaceRight(spacingLittle/2); + Image questionMarkImage = new Image(questionMark); + questionMarkImage.addListener(new ClickListener(){ + @Override + public void clicked(InputEvent e, float x, float y){ + if(GameWare.getInstance().isSoundEffectsOn()){ checkBoxSound.play(); } + dialog.show(stage); + } + }); + table.add(questionMarkImage).width(questionMarkWidthAndHeight).height(questionMarkWidthAndHeight).top(); + return table; + } + + private Dialog makeDialog(Label label){ + Dialog dialog = new Dialog("", skin, "dialog") { + public void result(Object obj) { } + }; + + label.setAlignment(Align.center); + label.setWrap(true); + 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()/2f); + + return dialog; + } + private TextButton makeBackBtn(){ TextButton backBtn = new TextButton(backBtnText, skin); backBtn.addListener(new ClickListener() { diff --git a/frontend/core/src/com/gameware/game/states/ViewTournamentState.java b/frontend/core/src/com/gameware/game/states/ViewTournamentState.java index 50983619b67cffeabe7c25563a0682018d27d250..70da5d3c40479e0c4620217158853ef4809f1f0e 100644 --- a/frontend/core/src/com/gameware/game/states/ViewTournamentState.java +++ b/frontend/core/src/com/gameware/game/states/ViewTournamentState.java @@ -16,10 +16,13 @@ import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; import com.badlogic.gdx.utils.Align; import com.gameware.game.GameWare; import com.gameware.game.QueryIntermediate; +import com.gameware.game.models.Game; import com.gameware.game.models.Round; import com.gameware.game.models.Tournament; import com.gameware.game.sprites.LoadingText; +import java.util.List; + public class ViewTournamentState extends State { // Data @@ -40,6 +43,8 @@ public class ViewTournamentState extends State { private final String roundsLeftText = "Rounds left:"; private final String leaveDialogText = "Are you sure want to\nleave "; + private String gameName = ""; + // Variables private final float playBtnWidth = buttonWidth*1.4f; private final float playBtnHeight = buttonHeight*1.2f; @@ -60,6 +65,18 @@ public class ViewTournamentState extends State { this.round = r; titleLabel.setText(tournament.getName()); roundDeadline.setText("Round deadline\n"+round.getDeadlineDate().toLocaleString()); + + try{ + List<Game> games = GameWare.getInstance().getGames(); + for (Game g : games){ + if(g.getId().equals(r.getGameId())){ + gameName = g.getName(); + } + } + }catch(Exception e){ + e.printStackTrace(); + } + makeStage(); } @@ -78,8 +95,15 @@ public class ViewTournamentState extends State { rootTable.add(makePlayBtn()).size(playBtnWidth, playBtnHeight).colspan(2); rootTable.row(); + Table currentRoundTable = new Table(); + currentRoundTable.pad(padding); + currentRoundTable.setBackground(backgroundTableBlueRounded); + + currentRoundTable.add(new Label("This round:\n\n"+gameName,skin)).space(spacingLittle); + PlayStateTemplate state = GameWare.getInstance().getGameIdToPlayState().get(round.getGameId()); - rootTable.add(new Image(state.screenshot)).width(imageWidthAndHeigh).height(imageWidthAndHeigh).spaceBottom(spacingMedium).colspan(2); + currentRoundTable.add(new Image(state.screenshot)).width(imageWidthAndHeigh).height(imageWidthAndHeigh).spaceBottom(spacingMedium).colspan(2); + rootTable.add(currentRoundTable).maxHeight(Gdx.graphics.getHeight()/5).colspan(2); rootTable.row(); rootTable.add(new Label(nrPlayersText+" "+tournament.getCurrentPlayers(), skin)).colspan(2); @@ -102,17 +126,17 @@ public class ViewTournamentState extends State { rootTable.add(roundDeadline).expand().bottom().right(); stage.addActor(rootTable); - makeDialog(); + makeLeaveDialog(); } // Make widgets methods - private void makeDialog(){ + private void makeLeaveDialog(){ dialog = new Dialog("", skin, "dialog") { public void result(Object obj) { if(obj.equals(true)){ setLeaveConfirmed(); } else{ - makeDialog(); + makeLeaveDialog(); } }