Search in sources :

Example 1 with GameSessionSetup

use of de.gg.game.session.GameSessionSetup in project ProjektGG by eskalon.

the class LobbyScreen method setUIValues.

@Override
protected void setUIValues() {
    GameSessionSetup sessionSetup = application.getClient().getLobbyData().getSessionSetup();
    gameStarted = false;
    if (application.isHost()) {
        readyUpLobbyButton.setText(Lang.get("screen.lobby.start_game"));
    } else {
        readyUpLobbyButton.setDisabled(false);
        readyUpLobbyButton.setTouchable(Touchable.enabled);
    }
    settingsArea.setText(Lang.get("screen.lobby.map", sessionSetup.getMap()) + " \n" + Lang.get("screen.lobby.difficulty", sessionSetup.getDifficulty()));
    chatInputField.setText("");
    updateLobbyUI();
}
Also used : GameSessionSetup(de.gg.game.session.GameSessionSetup)

Example 2 with GameSessionSetup

use of de.gg.game.session.GameSessionSetup 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 GameSessionSetup

use of de.gg.game.session.GameSessionSetup in project ProjektGG by eskalon.

the class GameServerDiscoveryTest method testServer.

@Test
public void testServer() throws TimeoutException, InterruptedException {
    com.esotericsoftware.minlog.Log.INFO();
    waiter = new Waiter();
    sdh = new ServerDiscoveryHandler<>(DiscoveryResponsePacket.class, 2500);
    assertThrows(IllegalArgumentException.class, () -> {
        sdh.discoverHosts(-563, new HostDiscoveryListener<>() {

            @Override
            public void onHostDiscovered(String address, DiscoveryResponsePacket datagramPacket) {
            }
        });
    });
    assertThrows(NullPointerException.class, () -> {
        sdh.discoverHosts(123, null);
    });
    ServerSetup serverSetup = new ServerSetup(gameName, maxPlayerCount, port, true, serverVersion, true);
    GameSessionSetup sessionSetup = new GameSessionSetup(GameDifficulty.EASY, GameMap.BAMBERG, 25);
    server = new GameServer(serverSetup, sessionSetup, null, Arrays.asList(stub, stub, stub));
    server.start(new ISuccessCallback() {

        @Override
        public void onSuccess(Object param) {
            waiter.resume();
        }

        @Override
        public void onFailure(Object param) {
            waiter.fail((String) param);
        }
    });
    // Wait for resume() to be called
    waiter.await(8000);
    testServerDiscovery(waiter);
    server.stop();
}
Also used : DiscoveryResponsePacket(de.gg.engine.network.message.DiscoveryResponsePacket) GameSessionSetup(de.gg.game.session.GameSessionSetup) ServerSetup(de.gg.engine.network.ServerSetup) ISuccessCallback(de.damios.guacamole.ISuccessCallback) Waiter(net.jodah.concurrentunit.Waiter) BaseGameServer(de.gg.engine.network.BaseGameServer) Test(org.junit.jupiter.api.Test) LibgdxUnitTest(de.gg.game.LibgdxUnitTest)

Aggregations

GameSessionSetup (de.gg.game.session.GameSessionSetup)3 ISuccessCallback (de.damios.guacamole.ISuccessCallback)2 BaseGameServer (de.gg.engine.network.BaseGameServer)2 ServerSetup (de.gg.engine.network.ServerSetup)2 ButtonGroup (com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup)1 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)1 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)1 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 DiscoveryResponsePacket (de.gg.engine.network.message.DiscoveryResponsePacket)1 OffsettableTextField (de.gg.engine.ui.components.OffsettableTextField)1 LibgdxUnitTest (de.gg.game.LibgdxUnitTest)1 BackInputProcessor (de.gg.game.input.BackInputProcessor)1 BackInputActorListener (de.gg.game.input.BackInputProcessor.BackInputActorListener)1 ButtonClickListener (de.gg.game.input.ButtonClickListener)1 GameDifficulty (de.gg.game.model.types.GameDifficulty)1 GameClient (de.gg.game.network.GameClient)1 GameServer (de.gg.game.network.GameServer)1 ArrayList (java.util.ArrayList)1 Waiter (net.jodah.concurrentunit.Waiter)1