Search in sources :

Example 1 with TextFieldFilter

use of com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldFilter in project computercombat by janfic.

the class SignUpScreen method show.

@Override
public void show() {
    this.camera = new OrthographicCamera(1920 / 4, 1080 / 4);
    this.stage = ComputerCombatGame.makeNewStage(camera);
    this.toolTipManager = TooltipManager.getInstance();
    this.toolTipManager.instant();
    Gdx.input.setInputProcessor(stage);
    Table table = new Table();
    table.setFillParent(true);
    table.defaults().pad(5);
    Label title = new Label("New Account", skin, "title");
    title.setAlignment(Align.center);
    Table leftGroup = new Table();
    Table rightGroup = new Table();
    BorderedGrid grid = new BorderedGrid(skin);
    Table usernameTable = new Table(skin);
    usernameTable.background("border_filled");
    Label userNameFieldLabel = new Label(" Username: ", skin);
    Image usernameInfo = new Image(skin, "info_icon");
    usernameTable.add(usernameInfo).left();
    usernameTable.add(userNameFieldLabel).expand().right();
    Label emailFieldLabel = new Label("Email: ", skin, "filled");
    Table passwordTable = new Table(skin);
    passwordTable.background("border_filled");
    Label passwordFieldLabel = new Label(" Create Password: ", skin);
    Image passwordInfo = new Image(skin, "info_icon");
    passwordTable.add(passwordInfo).left();
    passwordTable.add(passwordFieldLabel).expand().right();
    Label confirmFieldLabel = new Label(" Confirm Password: ", skin, "filled");
    userNameField = new TextField("", skin);
    emailField = new TextField("", skin);
    passwordField = new TextField("", skin);
    confirmField = new TextField("", skin);
    TextButton createAccountButton = new TextButton("Create Account", skin);
    TextTooltip usernameToolTip = new TextTooltip("Only alphanumeric characters (A-Z,0-9)", toolTipManager, skin);
    usernameInfo.addListener(usernameToolTip);
    TextTooltip passwordToolTip = new TextTooltip("Minimum 8 alphanumeric characters (A-Z,0-9)", toolTipManager, skin);
    passwordInfo.addListener(passwordToolTip);
    TextFieldFilter alphaNumeric = new TextFieldFilter() {

        @Override
        public boolean acceptChar(TextField tf, char c) {
            return tf.getText().length() < 12 && (Character.isAlphabetic(c) || Character.isDigit(c));
        }
    };
    userNameField.setTextFieldFilter(alphaNumeric);
    passwordField.setTextFieldFilter(alphaNumeric);
    userNameFieldLabel.setAlignment(Align.right);
    emailFieldLabel.setAlignment(Align.right);
    passwordFieldLabel.setAlignment(Align.right);
    confirmFieldLabel.setAlignment(Align.right);
    passwordField.setPasswordMode(true);
    passwordField.setPasswordCharacter('*');
    confirmField.setPasswordMode(true);
    confirmField.setPasswordCharacter('*');
    grid.pad(10);
    grid.defaults().space(6);
    leftGroup.defaults().space(5);
    // leftGroup.debugAll();
    leftGroup.add(usernameTable).growX().minHeight(25);
    leftGroup.add(userNameField).minHeight(25).row();
    leftGroup.add(emailFieldLabel).growX().minHeight(25);
    leftGroup.add(emailField).minHeight(25).row();
    leftGroup.add(passwordTable).growX().minHeight(25);
    leftGroup.add(passwordField).minHeight(25).row();
    leftGroup.add(confirmFieldLabel).growX().minHeight(25);
    leftGroup.add(confirmField).minHeight(25).row();
    leftGroup.add(createAccountButton).colspan(2).row();
    createAccountButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailField.getText().trim());
            boolean validSignUp = true;
            if (!matcher.find()) {
                validSignUp = false;
                emailField.setColor(Color.RED);
            } else {
                emailField.setColor(Color.WHITE);
            }
            if (userNameField.getText().trim().length() <= 0 || userNameField.getText().trim().length() > 12) {
                validSignUp = false;
                userNameField.setColor(Color.RED);
            // stage.addActor(toolTip.getContainer());
            // stage.addActor(toolTip.getContainer().getActor());
            // toolTip.getContainer().setPosition(0, 0);
            // toolTip.getContainer().setSize(toolTip.getActor().getWidth(), toolTip.getActor().getHeight());
            } else {
                userNameField.setColor(Color.WHITE);
            }
            String password = passwordField.getText().trim();
            if (password.length() < 7) {
                validSignUp = false;
                passwordField.setColor(Color.RED);
            } else {
                passwordField.setColor(Color.WHITE);
            }
            if (!passwordField.getText().trim().equals(confirmField.getText().trim())) {
                validSignUp = false;
                confirmField.setColor(Color.RED);
            } else {
                confirmField.setColor(Color.WHITE);
            }
            if (validSignUp) {
                game.getServerAPI().sendMessage(new Message(Type.NEW_PROFILE_REQUEST, userNameField.getText().trim() + "," + emailField.getText().trim() + "," + passwordField.getText().trim()));
            }
        }
    });
    Panel divider = new Panel(skin);
    rightGroup.defaults().space(6);
    TextButton signUpWithGoogle = new TextButton("Sign Up With Google", skin);
    signUpWithGoogle.getLabel().setWrap(true);
    TextButton signUpWithFacebook = new TextButton("Sign Up With Facebook", skin);
    signUpWithFacebook.getLabel().setWrap(true);
    TextButton signUpWithApple = new TextButton("Sign Up With Apple", skin);
    signUpWithApple.getLabel().setWrap(true);
    rightGroup.add(signUpWithGoogle).width(100).row();
    rightGroup.add(signUpWithFacebook).width(100).row();
    rightGroup.add(signUpWithApple).width(100);
    grid.add(leftGroup).grow();
    grid.add(divider).growY();
    grid.add(rightGroup).grow();
    Table navGrid = new Table();
    TextButton backButton = new TextButton("Back", skin);
    backButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            game.popScreen();
        }
    });
    navGrid.add(backButton).expand().width(150).left();
    table.add(title).grow().row();
    table.add(grid).expand().grow().row();
    table.add(navGrid).growX();
    stage.addActor(table);
}
Also used : Message(com.janfic.games.computercombat.network.Message) Matcher(java.util.regex.Matcher) TextFieldFilter(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldFilter) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) BorderedGrid(com.janfic.games.computercombat.actors.BorderedGrid) Panel(com.janfic.games.computercombat.actors.Panel) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 TextFieldFilter (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldFilter)1 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)1 BorderedGrid (com.janfic.games.computercombat.actors.BorderedGrid)1 Panel (com.janfic.games.computercombat.actors.Panel)1 Message (com.janfic.games.computercombat.network.Message)1 Matcher (java.util.regex.Matcher)1