Search in sources :

Example 1 with OffsettableTextField

use of de.gg.engine.ui.components.OffsettableTextField in project ProjektGG by eskalon.

the class ServerBrowserScreen method create.

@Override
protected void create() {
    super.create();
    setImage(backgroundTexture);
    BackInputProcessor backInput = new BackInputProcessor() {

        @Override
        public void onBackAction() {
            application.getScreenManager().pushScreen("main_menu", "blendingTransition");
        }
    };
    addInputProcessor(backInput);
    mainTable.addListener(new BackInputActorListener() {

        @Override
        public void onBackAction() {
            backInput.onBackAction();
        }
    });
    this.connectionCallback = new ISuccessCallback() {

        @Override
        public void onSuccess(Object param) {
        }

        @Override
        public void onFailure(Object param) {
            connectingDialog.setVisible(false);
            application.setClient(null);
            SimpleTextDialog.createAndShow(stage, skin, Lang.get("ui.generic.error"), (String) param);
        }
    };
    ImageTextButton backButton = new ImageTextButton(Lang.get("ui.generic.back"), skin);
    backButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            application.getScreenManager().pushScreen("main_menu", "blendingTransition");
        }
    });
    ImageTextButton createLobbyButton = new ImageTextButton(Lang.get("screen.server_browser.create_game"), skin);
    createLobbyButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            application.getScreenManager().pushScreen("lobby_creation", "shortBlendingTransition");
        }
    });
    ImageTextButton directConnectButton = new ImageTextButton(Lang.get("screen.server_browser.connect_directly"), skin);
    directConnectButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            OffsettableTextField portInputField = new OffsettableTextField(String.valueOf(BaseGameServer.DEFAULT_PORT), skin, 5);
            portInputField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
            OffsettableTextField ipInputField = new OffsettableTextField("127.0.0.1", skin, 5);
            BasicDialog dialog = new BasicDialog(Lang.get("screen.server_browser.connect_directly"), skin) {

                @Override
                public void result(Object obj) {
                    if ((Boolean) obj) {
                        // Connect to client
                        application.setClient(new GameClient(application.getEventBus()));
                        application.getClient().connect(connectionCallback, application.VERSION, ipInputField.getText(), Integer.valueOf(portInputField.getText()));
                        connectingDialog = SimpleTextDialog.createAndShow(stage, skin, Lang.get("ui.generic.connecting"), Lang.get("screen.server_browser.joining"), false, null);
                    }
                }
            };
            dialog.text(Lang.get("screen.server_browser.ip")).button(Lang.get("ui.generic.back"), false).button(Lang.get("ui.generic.connect"), true).key(Keys.ENTER, true).key(Keys.ESCAPE, false);
            dialog.getContentTable().add(ipInputField).width(170).row();
            dialog.getContentTable().add(new Label(Lang.get("screen.server_browser.port"), skin, "dark_text"));
            dialog.getContentTable().add(portInputField).width(150).left();
            dialog.show(stage);
        }
    });
    ImageButton refreshButton = new ImageButton(skin, "refresh");
    refreshButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            discoverServers();
        }
    });
    Table titleTable = new Table();
    titleTable.add(new Label(Lang.get("screen.server_browser.title"), skin, "title")).padTop(25);
    Table serverHeaderTable = new Table();
    serverHeaderTable.add(new Label(Lang.get("screen.server_browser.header_status"), skin)).left().padLeft(10).padRight(158);
    serverHeaderTable.add(new Label(Lang.get("screen.server_browser.header_name"), skin)).left().expandX();
    serverHeaderTable.add(refreshButton).padLeft(15).padRight(10).row();
    serverTable = new Table();
    ScrollPane pane = new ScrollPane(serverTable);
    Table buttonTable = new Table();
    buttonTable.add(backButton);
    buttonTable.add(directConnectButton).width(158).padLeft(45);
    buttonTable.add(createLobbyButton).width(136).padLeft(45);
    Table mTable = new Table();
    mTable.setWidth(615);
    mTable.setHeight(475);
    mTable.setBackground(skin.getDrawable("parchment2"));
    mTable.add(titleTable).row();
    mTable.add(serverHeaderTable).width(580).padTop(25).row();
    mTable.add(new Image(skin.getDrawable("white_bar"))).padTop(2).center().expandX().row();
    mTable.add(pane).width(580).height(265).padTop(10).row();
    mTable.add(buttonTable).height(50).bottom();
    mainTable.add(mTable);
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) GameClient(de.gg.game.network.GameClient) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) BackInputActorListener(de.gg.game.input.BackInputProcessor.BackInputActorListener) ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) BackInputProcessor(de.gg.game.input.BackInputProcessor) ButtonClickListener(de.gg.game.input.ButtonClickListener) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) OffsettableTextField(de.gg.engine.ui.components.OffsettableTextField) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) OffsettableTextField(de.gg.engine.ui.components.OffsettableTextField) ISuccessCallback(de.damios.guacamole.ISuccessCallback) BasicDialog(de.gg.game.ui.components.BasicDialog)

Example 2 with OffsettableTextField

use of de.gg.engine.ui.components.OffsettableTextField in project ProjektGG by eskalon.

the class LobbyCreationScreen method create.

@Override
protected void create() {
    super.create();
    setImage(backgroundTexture);
    BackInputProcessor backInput = new BackInputProcessor() {

        @Override
        public void onBackAction() {
            application.getScreenManager().pushScreen("server_browser", "shortBlendingTransition");
        }
    };
    addInputProcessor(backInput);
    mainTable.addListener(new BackInputActorListener() {

        @Override
        public void onBackAction() {
            backInput.onBackAction();
        }
    });
    this.playerStubs = playerStubsJson.getData(new TypeToken<ArrayList<PlayerStub>>() {
    }.getType());
    Label nameLabel = new Label(Lang.get("screen.lobby_creation.name"), skin);
    Label portLabel = new Label(Lang.get("screen.lobby_creation.port"), skin);
    nameField = new OffsettableTextField("", skin, 6);
    portField = new OffsettableTextField(String.valueOf(BaseGameServer.DEFAULT_PORT), skin, 6);
    portField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
    Label difficultyLabel = new Label(Lang.get("screen.lobby_creation.difficulty"), skin);
    CheckBox easyDifficultyCheckbox = new CheckBox(Lang.get(GameDifficulty.EASY), skin);
    normalDifficultyCheckbox = new CheckBox(Lang.get(GameDifficulty.NORMAL), skin);
    CheckBox hardDifficultyCheckbox = new CheckBox(Lang.get(GameDifficulty.HARD), skin);
    ButtonGroup<CheckBox> speedGroup = new ButtonGroup<>();
    speedGroup.add(easyDifficultyCheckbox);
    speedGroup.add(normalDifficultyCheckbox);
    speedGroup.add(hardDifficultyCheckbox);
    ImageTextButton backButton = new ImageTextButton(Lang.get("ui.generic.back"), skin);
    backButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            application.getScreenManager().pushScreen("server_browser", "shortBlendingTransition");
        }
    });
    ImageTextButton createButton = new ImageTextButton(Lang.get("screen.lobby_creation.create"), skin);
    createButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            if (!nameField.getText().isEmpty() && !portField.getText().isEmpty()) {
                GameDifficulty difficulty = GameDifficulty.NORMAL;
                if (speedGroup.getChecked().equals(easyDifficultyCheckbox)) {
                    difficulty = GameDifficulty.EASY;
                } else if (speedGroup.getChecked().equals(normalDifficultyCheckbox)) {
                    difficulty = GameDifficulty.NORMAL;
                } else if (speedGroup.getChecked().equals(hardDifficultyCheckbox)) {
                    difficulty = GameDifficulty.HARD;
                }
                // Start Sever & Client
                ServerSetup serverSetup = new ServerSetup(nameField.getText(), 7, Integer.valueOf(portField.getText()), true, application.VERSION, true);
                GameSessionSetup sessionSetup = new GameSessionSetup(difficulty, GameMap.BAMBERG, System.currentTimeMillis());
                application.setServer(new GameServer(serverSetup, sessionSetup, null, playerStubs));
                application.getServer().start(new ISuccessCallback() {

                    @Override
                    public void onSuccess(Object param) {
                        // Connect client to server
                        application.setClient(new GameClient(application.getEventBus()));
                        application.getClient().connect(new ISuccessCallback() {

                            public void onSuccess(Object param) {
                            // wait for
                            // LobbyDataReceivedEvent
                            }

                            public void onFailure(Object param) {
                                onHostStartingFailed(((Exception) param).getMessage());
                            }
                        }, application.VERSION, "localhost", serverSetup.getPort());
                    }

                    public void onFailure(Object param) {
                        onHostStartingFailed(((Exception) param).getMessage());
                    }
                });
                connectingDialog = SimpleTextDialog.createAndShow(stage, skin, Lang.get("screen.lobby_creation.starting_server.title"), Lang.get("screen.lobby_creation.starting_server.text"), false, null);
                connectingDialog.show(stage);
            } else {
                SimpleTextDialog.createAndShow(stage, skin, Lang.get("screen.lobby_creation.fields_empty.title"), Lang.get("screen.lobby_creation.fields_empty.text"));
            }
        }
    });
    Table titleTable = new Table();
    Table settingsTable = new Table();
    Table settings2ColTable = new Table();
    Table settings3ColTable = new Table();
    Table buttonTable = new Table();
    titleTable.add(new Label(Lang.get("screen.lobby_creation.title"), skin, "title")).padTop(25);
    settings2ColTable.add(nameLabel).padLeft(100).padBottom(20).padRight(10).padTop(30);
    settings2ColTable.add(nameField).row();
    settings2ColTable.add(portLabel).padLeft(100).padRight(10);
    settings2ColTable.add(portField).row();
    settings3ColTable.add(difficultyLabel).colspan(3).padLeft(150).row();
    settings3ColTable.add(easyDifficultyCheckbox).padLeft(150).padRight(12);
    settings3ColTable.add(normalDifficultyCheckbox).padRight(12);
    settings3ColTable.add(hardDifficultyCheckbox);
    settingsTable.left().top().add(settings2ColTable).padBottom(27).row();
    settingsTable.add(settings3ColTable).row();
    buttonTable.add(backButton);
    buttonTable.add(createButton).padLeft(65);
    Table mTable = new Table();
    mTable.setWidth(615);
    mTable.setHeight(475);
    mTable.setBackground(skin.getDrawable("parchment2"));
    mTable.add(titleTable).row();
    mTable.add(settingsTable).width(580).height(215).row();
    mTable.add(buttonTable).height(50).bottom().padBottom(50);
    mainTable.add(mTable);
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) GameClient(de.gg.game.network.GameClient) ArrayList(java.util.ArrayList) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) GameDifficulty(de.gg.game.model.types.GameDifficulty) BackInputActorListener(de.gg.game.input.BackInputProcessor.BackInputActorListener) ButtonGroup(com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup) GameSessionSetup(de.gg.game.session.GameSessionSetup) BackInputProcessor(de.gg.game.input.BackInputProcessor) CheckBox(com.badlogic.gdx.scenes.scene2d.ui.CheckBox) ButtonClickListener(de.gg.game.input.ButtonClickListener) ServerSetup(de.gg.engine.network.ServerSetup) OffsettableTextField(de.gg.engine.ui.components.OffsettableTextField) ISuccessCallback(de.damios.guacamole.ISuccessCallback) BaseGameServer(de.gg.engine.network.BaseGameServer) GameServer(de.gg.game.network.GameServer)

Example 3 with OffsettableTextField

use of de.gg.engine.ui.components.OffsettableTextField in project ProjektGG by eskalon.

the class LobbyScreen method create.

@Override
protected void create() {
    super.create();
    setImage(backgroundTexture);
    PlayerLobbyConfigDialog playerConfigDialog = new PlayerLobbyConfigDialog(application, skin);
    ImageTextButton playerSettingsButton = new ImageTextButton(Lang.get("screen.lobby.configure"), skin);
    playerSettingsButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            playerConfigDialog.initUIValues(application.getClient().getLobbyPlayers(), application.getClient().getLocalLobbyPlayer());
            playerConfigDialog.show(stage);
        }
    });
    ImageTextButton leaveButton = new ImageTextButton(Lang.get("screen.lobby.disconnect"), skin);
    leaveButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            Log.info("Client", "Disconnecting from Lobby");
            final GameClient client = application.getClient();
            final GameServer server = application.getServer();
            application.setClient(null);
            application.setServer(null);
            ThreadHandler.getInstance().executeRunnable(() -> {
                client.disconnect();
                Log.info("Client", "Client disconnected");
                if (server != null) {
                    server.stop();
                }
                Log.info("Server", "Server stopped");
            });
            application.getScreenManager().pushScreen("server_browser", null);
        }
    });
    readyUpLobbyButton = new ImageTextButton(Lang.get("screen.lobby.ready"), skin);
    readyUpLobbyButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            // TODO warum nicht readyUp(); ?
            application.getClient().getLocalLobbyPlayer().toggleReady();
            application.getClient().getActionHandler().changeLocalPlayer(application.getClient().getLocalLobbyPlayer());
            updateLobbyUI();
        }
    });
    settingsArea = new Label("", skin);
    settingsArea.setAlignment(Align.topLeft);
    settingsArea.setWrap(true);
    Table playerTable = new Table();
    Table buttonTable = new Table();
    Table chatTable = new Table();
    buttonTable.add(playerSettingsButton).bottom().padBottom(18).row();
    buttonTable.add(readyUpLobbyButton).padBottom(18).row();
    buttonTable.add(leaveButton).padBottom(50);
    Table chatInputTable = new Table();
    ImageTextButton sendButton = new ImageTextButton(Lang.get("screen.lobby.send"), skin);
    chatInputField = new OffsettableTextField("", skin, "large", 8);
    chatInputField.setTextFieldListener(new TextFieldListener() {

        @Override
        public void keyTyped(TextField textField, char key) {
            if (!textField.getText().isEmpty() && key == '\n') {
                // Enter
                application.getSoundManager().playSoundEffect("button_click");
                application.getClient().getActionHandler().sendChatmessage(chatInputField.getText());
                application.getClient().getChatMessages().add(new ChatMessage(application.getClient().getLocalLobbyPlayer(), chatInputField.getText()));
                setUIValues();
                chatInputField.setText("");
            }
        }
    });
    sendButton.addListener(new ButtonClickListener(application.getSoundManager()) {

        @Override
        protected void onClick() {
            application.getClient().getActionHandler().sendChatmessage(chatInputField.getText());
            application.getClient().getChatMessages().add(new ChatMessage(application.getClient().getLocalLobbyPlayer(), chatInputField.getText()));
            setUIValues();
            chatInputField.setText("");
        }

        @Override
        protected boolean arePreconditionsMet() {
            return !chatInputField.getText().isEmpty();
        }
    });
    messagesArea = new Label("", skin, "text");
    messagesArea.setWidth(425);
    messagesArea.setWrap(true);
    Table messagesTable = new Table();
    messagesTable.add(messagesArea).padLeft(10).left().top().expand();
    messagesPane = new ScrollPane(messagesTable, skin, "with-background");
    messagesPane.setForceScroll(false, true);
    chatInputTable.add(chatInputField).left().width(325).padRight(15);
    chatInputTable.add(sendButton);
    chatTable.add(messagesPane).height(135).width(465).top().row();
    chatTable.add(chatInputTable).left().padTop(10).width(465).bottom();
    playerSlots = new Table[maxPlayerCount];
    for (int i = 0; i < playerSlots.length; i++) {
        playerSlots[i] = new Table();
        playerTable.add(playerSlots[i]).height(29).width(465).row();
    }
    Table mTable = new Table();
    mTable.setWidth(615);
    mTable.setHeight(475);
    mTable.setBackground(skin.getDrawable("parchment1"));
    mTable.add(playerTable).width(465).height(185).padBottom(15);
    mTable.add(settingsArea).width(155).height(185).row();
    mTable.add(chatTable).height(185).bottom();
    mTable.add(buttonTable).height(185);
    mainTable.add(mTable);
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) GameClient(de.gg.game.network.GameClient) ChatMessage(de.gg.game.ui.data.ChatMessage) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) ButtonClickListener(de.gg.game.input.ButtonClickListener) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) OffsettableTextField(de.gg.engine.ui.components.OffsettableTextField) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) OffsettableTextField(de.gg.engine.ui.components.OffsettableTextField) PlayerLobbyConfigDialog(de.gg.game.ui.dialogs.PlayerLobbyConfigDialog) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) GameServer(de.gg.game.network.GameServer)

Aggregations

ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)3 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)3 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)3 OffsettableTextField (de.gg.engine.ui.components.OffsettableTextField)3 ButtonClickListener (de.gg.game.input.ButtonClickListener)3 GameClient (de.gg.game.network.GameClient)3 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)2 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)2 ISuccessCallback (de.damios.guacamole.ISuccessCallback)2 BackInputProcessor (de.gg.game.input.BackInputProcessor)2 BackInputActorListener (de.gg.game.input.BackInputProcessor.BackInputActorListener)2 GameServer (de.gg.game.network.GameServer)2 ButtonGroup (com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup)1 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)1 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)1 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)1 TextFieldListener (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener)1 BaseGameServer (de.gg.engine.network.BaseGameServer)1 ServerSetup (de.gg.engine.network.ServerSetup)1 GameDifficulty (de.gg.game.model.types.GameDifficulty)1