Search in sources :

Example 6 with Message

use of com.janfic.games.computercombat.network.Message 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)

Example 7 with Message

use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.

the class Server method accept.

/**
 * Accepts a connection to a client
 *
 * @param s
 */
public void accept(Socket s) {
    InputStream is = s.getInputStream();
    try {
        while (is.available() == 0 && s.isConnected()) {
        }
    } catch (Exception e) {
    }
    Message m = readMessage(is);
    if (m != null) {
        if (m.type == Type.CONNECTION_REQUEST) {
            Client client = new Client(s);
            while (clients.containsKey(client.getClientUID())) {
                if (client.getIP().equals(clients.get(client.getClientUID()).getIP())) {
                    break;
                } else {
                    client.setClientUID(client.getClientUID() + 1);
                }
            }
            clients.put(client.getClientUID(), client);
            Message r = new Message(Type.CONNECTION_ACCEPT, "SERVER UID:" + client.getClientUID());
            try {
                client.sendMessage(r);
            } catch (IOException e) {
            }
        }
    }
}
Also used : Message(com.janfic.games.computercombat.network.Message) Client(com.janfic.games.computercombat.network.server.Client) MatchClient(com.janfic.games.computercombat.network.server.MatchClient) UsernameExistsException(software.amazon.awssdk.services.cognitoidentityprovider.model.UsernameExistsException)

Example 8 with Message

use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.

the class Client method readMessage.

public Message readMessage() {
    try {
        Json json = new Json();
        InputStream is = socket.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String content = "";
        String line;
        while (is.available() > 0 && (line = reader.readLine()) != null) {
            if (line.equals("END")) {
                break;
            }
            content += line + "\n";
        }
        Message m = json.fromJson(Message.class, content);
        return m;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) Message(com.janfic.games.computercombat.network.Message) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) Json(com.badlogic.gdx.utils.Json) SocketException(java.net.SocketException) IOException(java.io.IOException)

Example 9 with Message

use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.

the class LoadingScreen method render.

@Override
public void render(float f) {
    stage.act(f);
    stage.draw();
    assetManager.update();
    progressBar.setValue(assetManager.getProgress());
    if (progressBar.getValue() >= 1) {
        if (game.getServerAPI() != null && game.getServerAPI().hasMessage()) {
            Message m = game.getServerAPI().readMessage();
            if (m.type == Type.CONNECTION_ACCEPT) {
                game.popScreen();
                game.pushScreen(new MainMenuScreen(game));
            }
        }
    }
}
Also used : Message(com.janfic.games.computercombat.network.Message)

Example 10 with Message

use of com.janfic.games.computercombat.network.Message in project computercombat by janfic.

the class LoginScreen method render.

@Override
public void render(float f) {
    stage.act(f);
    stage.draw();
    if (game.getServerAPI().hasMessage()) {
        Message m = game.getServerAPI().readMessage();
        showWindow(m);
    }
}
Also used : Message(com.janfic.games.computercombat.network.Message)

Aggregations

Message (com.janfic.games.computercombat.network.Message)19 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)6 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)6 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)5 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)4 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)4 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)4 Json (com.badlogic.gdx.utils.Json)4 TextFieldFilter (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldFilter)3 BorderedGrid (com.janfic.games.computercombat.actors.BorderedGrid)3 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)2 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)2 Move (com.janfic.games.computercombat.model.moves.Move)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 UsernameExistsException (software.amazon.awssdk.services.cognitoidentityprovider.model.UsernameExistsException)2 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 SocketHints (com.badlogic.gdx.net.SocketHints)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1