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 {
// 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,9 +70,11 @@ public class LoginState extends State {
// Add widgets
titleLabel.setFontScale(titleFontBigScale);
rootTable.add(titleLabel).expandY();
rootTable.add(titleLabel).expandY().top();
rootTable.row();
rootTable.add(subHeadLabel).expandY();
if (page == 0) {
rootTable.add(subHeadLabelLogIn).expandY();
rootTable.row();
rootTable.add(makeUserInputField()).size(inputFieldWidth, inputFieldHeight);
rootTable.row();
......@@ -76,7 +84,22 @@ public class LoginState extends State {
rootTable.row();
rootTable.add(makeLoginBtn()).size(buttonWidth, buttonHeight);
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();
......@@ -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){
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("");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment