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

#90 Adds create user page + removes animation in loginstate

parent 76c5d7c7
No related branches found
No related tags found
1 merge request!89Resolve "Small frontend stuff"
...@@ -23,7 +23,8 @@ public class LoginState extends State { ...@@ -23,7 +23,8 @@ public class LoginState extends State {
// Labels // Labels
private final Label titleLabel = new Label("GameWare", skin, "big"); 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"); private Label errorLabel = new Label("", skin, "error");
// Input fields // Input fields
...@@ -31,22 +32,23 @@ public class LoginState extends State { ...@@ -31,22 +32,23 @@ public class LoginState extends State {
private TextField usernameInputField; private TextField usernameInputField;
private String passwordInputText = "Password"; private String passwordInputText = "Password";
private TextField passwordInputField; private TextField passwordInputField;
private String confirmPasswordInputText = "Confirm password";
private TextField confirmPasswordInputField;
private final char passwordCharacter = '*'; private final char passwordCharacter = '*';
private final int inputFieldWidth = Gdx.graphics.getWidth()/2; private final int inputFieldWidth = Gdx.graphics.getWidth()/2;
private final int inputFieldHeight = Gdx.graphics.getHeight()/15; private final int inputFieldHeight = Gdx.graphics.getHeight()/15;
// Button texts // Button texts
private final String loginBtnText = "Log in"; private final String loginBtnText = "Log in";
private final String createUserText = "Create User";
private final String signUpBtnText = "Sign Up"; private final String signUpBtnText = "Sign Up";
private final String backText = "Back";
// Feedback texts // Feedback texts
private final String wrongLoginText = "User not found"; private final String wrongLoginText = "User not found";
private final String takenUsernameText = "Username already taken"; private final String takenUsernameText = "Username already taken";
private final String ioExceptionText = "Something went wrong with query"; private final String ioExceptionText = "Something went wrong with query";
private final String passwordNotMatchingText = "Passwords do not match";
// Feedback label animation
private final int animationDelay = 2;
private final int animationDuration = 1;
// Loading text // Loading text
private LoadingText loadingText = new LoadingText(); private LoadingText loadingText = new LoadingText();
...@@ -54,6 +56,10 @@ public class LoginState extends State { ...@@ -54,6 +56,10 @@ public class LoginState extends State {
private boolean signUpBtnClicked = false; private boolean signUpBtnClicked = false;
// Variables
private int page = 0;
public LoginState(GameStateManager gsm) { public LoginState(GameStateManager gsm) {
super(gsm); super(gsm);
makeStage(); makeStage();
...@@ -64,9 +70,11 @@ public class LoginState extends State { ...@@ -64,9 +70,11 @@ public class LoginState extends State {
// Add widgets // Add widgets
titleLabel.setFontScale(titleFontBigScale); titleLabel.setFontScale(titleFontBigScale);
rootTable.add(titleLabel).expandY(); rootTable.add(titleLabel).expandY().top();
rootTable.row(); rootTable.row();
rootTable.add(subHeadLabel).expandY();
if (page == 0) {
rootTable.add(subHeadLabelLogIn).expandY();
rootTable.row(); rootTable.row();
rootTable.add(makeUserInputField()).size(inputFieldWidth, inputFieldHeight); rootTable.add(makeUserInputField()).size(inputFieldWidth, inputFieldHeight);
rootTable.row(); rootTable.row();
...@@ -76,7 +84,22 @@ public class LoginState extends State { ...@@ -76,7 +84,22 @@ public class LoginState extends State {
rootTable.row(); rootTable.row();
rootTable.add(makeLoginBtn()).size(buttonWidth, buttonHeight); rootTable.add(makeLoginBtn()).size(buttonWidth, buttonHeight);
rootTable.row(); rootTable.row();
rootTable.add(makeSignUpBtn()).size(buttonWidth, buttonHeight).padBottom(spacingLarge); 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(); removeKeyPadAtTouch();
...@@ -116,6 +139,22 @@ public class LoginState extends State { ...@@ -116,6 +139,22 @@ public class LoginState extends State {
return passwordInputField; 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( ){ private TextButton makeLoginBtn( ){
TextButton loginBtn = new TextButton(loginBtnText, skin); TextButton loginBtn = new TextButton(loginBtnText, skin);
loginBtn.addListener(new ClickListener() { loginBtn.addListener(new ClickListener() {
...@@ -127,17 +166,51 @@ public class LoginState extends State { ...@@ -127,17 +166,51 @@ public class LoginState extends State {
return loginBtn; 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( ){ private TextButton makeSignUpBtn( ){
TextButton signUpBtn = new TextButton(signUpBtnText, skin); TextButton signUpBtn = new TextButton(signUpBtnText, skin);
signUpBtn.addListener(new ClickListener() { signUpBtn.addListener(new ClickListener() {
@Override @Override
public void clicked(InputEvent e, float x, float y){ public void clicked(InputEvent e, float x, float y){
try{
isValidPassword();
setSignUpBtnClicked(); setSignUpBtnClicked();
}catch(IllegalArgumentException exception){
errorLabel.setText(passwordNotMatchingText);
}
} }
}); });
return signUpBtn; 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 // Handle click methods
private void handleLoginBtnClick(){ private void handleLoginBtnClick(){
...@@ -157,12 +230,6 @@ public class LoginState extends State { ...@@ -157,12 +230,6 @@ public class LoginState extends State {
}catch(Exception e) { }catch(Exception e) {
e.printStackTrace(); 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 // Different feedback text depending on which exception
if (e instanceof NoSuchElementException) { if (e instanceof NoSuchElementException) {
errorLabel.setText(wrongLoginText); errorLabel.setText(wrongLoginText);
...@@ -191,12 +258,6 @@ public class LoginState extends State { ...@@ -191,12 +258,6 @@ public class LoginState extends State {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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 // Different feedback text depending on which exception
if (e instanceof NoSuchElementException) { if (e instanceof NoSuchElementException) {
errorLabel.setText(takenUsernameText); errorLabel.setText(takenUsernameText);
...@@ -221,6 +282,12 @@ public class LoginState extends State { ...@@ -221,6 +282,12 @@ public class LoginState extends State {
} }
private void isValidPassword() throws IllegalArgumentException {
if(!passwordInputField.getText().equals(confirmPasswordInputField.getText())){
throw new IllegalArgumentException();
}
}
@Override @Override
public void update(float dt) { public void update(float dt) {
super.update(dt); super.update(dt);
...@@ -264,5 +331,7 @@ public class LoginState extends State { ...@@ -264,5 +331,7 @@ public class LoginState extends State {
public void reset() { public void reset() {
usernameInputField.setText(usernameInputText); usernameInputField.setText(usernameInputText);
passwordInputField.setText(passwordInputText); passwordInputField.setText(passwordInputText);
confirmPasswordInputField.setText(confirmPasswordInputText);
errorLabel.setText("");
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment