Search in sources :

Example 1 with PlayerLobbyConfigDialog

use of de.gg.game.ui.dialogs.PlayerLobbyConfigDialog 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)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 TextFieldListener (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener)1 OffsettableTextField (de.gg.engine.ui.components.OffsettableTextField)1 ButtonClickListener (de.gg.game.input.ButtonClickListener)1 GameClient (de.gg.game.network.GameClient)1 GameServer (de.gg.game.network.GameServer)1 ChatMessage (de.gg.game.ui.data.ChatMessage)1 PlayerLobbyConfigDialog (de.gg.game.ui.dialogs.PlayerLobbyConfigDialog)1