Search in sources :

Example 1 with ChatMessage

use of de.gg.game.ui.data.ChatMessage in project ProjektGG by eskalon.

the class ClientsideResultListener method onChatMessage.

@Override
public void onChatMessage(short senderId, String message) {
    if (senderId != client.getLocalNetworkID()) {
        client.chatMessages.add(new ChatMessage(client.lobbyPlayers.get(senderId), message));
        eventBus.post(new UIRefreshEvent());
    }
}
Also used : ChatMessage(de.gg.game.ui.data.ChatMessage) UIRefreshEvent(de.gg.game.events.UIRefreshEvent)

Example 2 with ChatMessage

use of de.gg.game.ui.data.ChatMessage in project ProjektGG by eskalon.

the class LobbyScreen method startGameIfReady.

/**
 * Starts the game if all players are ready.
 */
private void startGameIfReady() {
    if (PlayerUtils.areAllPlayersReady(application.getClient().getLobbyPlayers().values()) && !gameStarted) {
        gameStarted = true;
        addChatMessageToUI(new ChatMessage(Lang.get("screen.lobby.game_starting")));
        application.getInputMultiplexer().removeProcessors(new Array<>(getInputProcessors()));
        // Set up the game on the client side
        application.getClient().initGameSession();
        Log.info("Client", "Loading game stuff...");
        application.getScreenManager().pushScreen("game_loading", "blendingTransition");
    } else {
        gameStarted = false;
    }
}
Also used : ChatMessage(de.gg.game.ui.data.ChatMessage)

Example 3 with ChatMessage

use of de.gg.game.ui.data.ChatMessage 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)

Example 4 with ChatMessage

use of de.gg.game.ui.data.ChatMessage in project ProjektGG by eskalon.

the class LobbyScreen method updateLobbyUI.

/**
 * Updates the lobby ui after player changes.
 */
private void updateLobbyUI() {
    Object[] playersArray = application.getClient().getLobbyPlayers().values().toArray();
    for (int i = 0; i < playerSlots.length; i++) {
        updatePlayerSlot(playerSlots[i], (playersArray.length >= (i + 1) ? (LobbyPlayer) playersArray[i] : null));
    }
    messagesArea.setText("");
    for (ChatMessage c : application.getClient().getChatMessages()) {
        addChatMessageToUI(c);
    }
    if (application.isHost()) {
        if (PlayerUtils.areAllPlayersReadyExcept(application.getClient().getLobbyPlayers().values(), application.getClient().getLocalLobbyPlayer())) {
            readyUpLobbyButton.setDisabled(false);
            readyUpLobbyButton.setTouchable(Touchable.enabled);
        } else {
            readyUpLobbyButton.setDisabled(true);
            readyUpLobbyButton.setTouchable(Touchable.disabled);
        }
    } else {
        if (application.getClient().getLocalLobbyPlayer().isReady()) {
            readyUpLobbyButton.setText(Lang.get("screen.lobby.not_ready"));
        } else {
            readyUpLobbyButton.setText(Lang.get("screen.lobby.ready"));
        }
    }
    startGameIfReady();
}
Also used : ChatMessage(de.gg.game.ui.data.ChatMessage)

Example 5 with ChatMessage

use of de.gg.game.ui.data.ChatMessage in project ProjektGG by eskalon.

the class ClientsideResultListener method onPlayerJoined.

@Override
public void onPlayerJoined(short id, LobbyPlayer player) {
    client.lobbyPlayers.put(id, player);
    client.chatMessages.add(new ChatMessage(Lang.get("screen.lobby.player_joined", player)));
    eventBus.post(new UIRefreshEvent());
}
Also used : ChatMessage(de.gg.game.ui.data.ChatMessage) UIRefreshEvent(de.gg.game.events.UIRefreshEvent)

Aggregations

ChatMessage (de.gg.game.ui.data.ChatMessage)6 UIRefreshEvent (de.gg.game.events.UIRefreshEvent)3 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 PlayerLobbyConfigDialog (de.gg.game.ui.dialogs.PlayerLobbyConfigDialog)1