Search in sources :

Example 1 with NetworkHandler

use of de.gg.network.NetworkHandler in project ProjektGG by eskalon.

the class LobbyScreen method initUI.

@Override
protected void initUI() {
    // backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
    Sound clickSound = assetManager.get(BUTTON_SOUND);
    // mainTable.setBackground(skin.getDrawable("parchment-small"));
    ImageTextButton leaveButton = new ImageTextButton("Verlassen", skin);
    leaveButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            game.getNetworkHandler().disconnect();
            game.pushScreen("mainMenu");
            return true;
        }
    });
    NetworkHandler netHandler = game.getNetworkHandler();
    readyUpLobbyButton = new ImageTextButton("Bereit", skin);
    if (netHandler.isHost()) {
        readyUpLobbyButton.setDisabled(true);
        readyUpLobbyButton.setText("Spiel starten");
    }
    readyUpLobbyButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            getLocalPlayer().toggleReady();
            netHandler.onLocalPlayerChange(getLocalPlayer());
            updateLobbyUI();
            return true;
        }
    });
    Table playerTable = new Table();
    Table settingsTable = new Table();
    Table buttonTable = new Table();
    Table chatTable = new Table();
    // settings table + player table
    buttonTable.add(readyUpLobbyButton).bottom().padBottom(20).row();
    buttonTable.add(leaveButton);
    Table chatInputTable = new Table();
    ImageTextButton sendButton = new ImageTextButton("Senden", skin);
    TextField chatInputField = new TextField("", skin);
    chatInputField.setTextFieldListener(new TextFieldListener() {

        @Override
        public void keyTyped(TextField textField, char key) {
            if (!textField.getText().isEmpty() && (key == (char) 13)) {
                // Enter
                clickSound.play(1F);
                netHandler.sendChatMessage(chatInputField.getText());
                onNewChatMessage(new NewChatMessagEvent(localNetworkId, chatInputField.getText()));
                chatInputField.setText("");
            }
        }
    });
    sendButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            if (!chatInputField.getText().isEmpty()) {
                clickSound.play(1F);
                netHandler.sendChatMessage(chatInputField.getText());
                onNewChatMessage(new NewChatMessagEvent(localNetworkId, chatInputField.getText()));
                chatInputField.setText("");
            }
            return true;
        }
    });
    messagesArea = new TextArea("", skin);
    messagesArea.setDisabled(true);
    ScrollPane messagesPane = new ScrollPane(messagesArea);
    chatInputTable.add(chatInputField).left().width(325).padRight(15);
    chatInputTable.add(sendButton);
    chatTable.debug();
    chatTable.add(messagesPane).height(125).width(425).top().row();
    chatTable.add(chatInputTable).left().padTop(10).width(425).bottom();
    playerSlots = new Table[6];
    playerSlots[0] = new Table();
    playerSlots[1] = new Table();
    playerSlots[2] = new Table();
    playerSlots[3] = new Table();
    playerSlots[4] = new Table();
    playerSlots[5] = new Table();
    playerTable.add(playerSlots[0]).height(25).width(425).row();
    playerTable.add(playerSlots[1]).height(25).width(425).row();
    playerTable.add(playerSlots[2]).height(25).width(425).row();
    playerTable.add(playerSlots[3]).height(25).width(425).row();
    playerTable.add(playerSlots[4]).height(25).width(425).row();
    playerTable.add(playerSlots[5]).height(25).width(425).row();
    mainTable.add(playerTable).width(425).height(155);
    mainTable.add(settingsTable).width(155).row();
    mainTable.add(chatTable).height(165).bottom();
    mainTable.add(buttonTable).height(165);
    mainTable.setDebug(true);
// updateLobbyUI();
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Table(com.badlogic.gdx.scenes.scene2d.ui.Table) TextArea(com.badlogic.gdx.scenes.scene2d.ui.TextArea) Sound(com.badlogic.gdx.audio.Sound) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) NewChatMessagEvent(de.gg.event.NewChatMessagEvent) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) NetworkHandler(de.gg.network.NetworkHandler) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 2 with NetworkHandler

use of de.gg.network.NetworkHandler in project ProjektGG by eskalon.

the class ProjektGG method create.

@Override
public final void create() {
    if (debug)
        Gdx.app.setLogLevel(Gdx.app.LOG_DEBUG);
    else
        Gdx.app.setLogLevel(Gdx.app.LOG_INFO);
    // Initialize sprite batch
    this.batch = new SpriteBatch();
    // Initialize asset manager
    FileHandleResolver resolver = new InternalFileHandleResolver();
    this.assetManager.setLoader(FreeTypeFontGenerator.class, new FreeTypeFontGeneratorLoader(resolver));
    this.assetManager.setLoader(BitmapFont.class, ".ttf", new FreetypeFontLoader(resolver));
    this.assetManager.setLoader(Text.class, new TextLoader(new InternalFileHandleResolver()));
    this.viewportWidth = Gdx.graphics.getWidth();
    this.viewportHeight = Gdx.graphics.getHeight();
    // Initialize cameras
    this.uiCamera = new OrthographicCamera(viewportWidth, viewportHeight);
    this.uiCamera.translate(viewportWidth / 2, viewportHeight / 2, 0);
    this.uiCamera.update();
    this.gameCamera = new CameraWrapper(new PerspectiveCamera(67, viewportWidth, viewportHeight));
    this.gameCamera.getCamera().translate(viewportWidth / 2, viewportHeight / 2, 0);
    // this.camera.update();
    this.batch.setProjectionMatrix(this.gameCamera.getCamera().combined);
    // Load game settings
    this.settings = new GameSettings("projekt-gg");
    // Create the event bus
    this.eventBus = new EventQueueBus();
    // Create the network handler
    this.networkHandler = new NetworkHandler(eventBus);
    // Set input processor
    Gdx.input.setInputProcessor(inputProcessor);
    // Add screens
    addScreen("splash", new SplashScreen());
    addScreen("mainMenu", new MainMenuScreen());
    addScreen("loading", new LoadingScreen());
    addScreen("gameLoading", new GameLoadingScreen());
    addScreen("serverBrowser", new ServerBrowserScreen());
    addScreen("lobby", new LobbyScreen());
    addScreen("lobbyCreation", new LobbyCreationScreen());
    addScreen("map", new GameMapScreen());
    addScreen("house", new GameInHouseScreen());
    addScreen("roundEnd", new GameRoundendScreen());
    // Push screen
    if (showSplashscreen)
        pushScreen("splash");
    else
        pushScreen("loading");
}
Also used : GameLoadingScreen(de.gg.screen.GameLoadingScreen) EventQueueBus(de.gg.util.EventQueueBus) ServerBrowserScreen(de.gg.screen.ServerBrowserScreen) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) FreeTypeFontGeneratorLoader(com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) GameLoadingScreen(de.gg.screen.GameLoadingScreen) LoadingScreen(de.gg.screen.LoadingScreen) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) GameInHouseScreen(de.gg.screen.GameInHouseScreen) GameRoundendScreen(de.gg.screen.GameRoundendScreen) TextLoader(de.gg.util.asset.TextLoader) FileHandleResolver(com.badlogic.gdx.assets.loaders.FileHandleResolver) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) SplashScreen(de.gg.screen.SplashScreen) NetworkHandler(de.gg.network.NetworkHandler) GameMapScreen(de.gg.screen.GameMapScreen) GameSettings(de.gg.setting.GameSettings) MainMenuScreen(de.gg.screen.MainMenuScreen) FreetypeFontLoader(com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader) LobbyScreen(de.gg.screen.LobbyScreen) LobbyCreationScreen(de.gg.screen.LobbyCreationScreen) CameraWrapper(de.gg.camera.CameraWrapper)

Aggregations

NetworkHandler (de.gg.network.NetworkHandler)2 FileHandleResolver (com.badlogic.gdx.assets.loaders.FileHandleResolver)1 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)1 Sound (com.badlogic.gdx.audio.Sound)1 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)1 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)1 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)1 FreeTypeFontGeneratorLoader (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader)1 FreetypeFontLoader (com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader)1 InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)1 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)1 ImageTextButton (com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton)1 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)1 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)1 TextArea (com.badlogic.gdx.scenes.scene2d.ui.TextArea)1 TextField (com.badlogic.gdx.scenes.scene2d.ui.TextField)1 TextFieldListener (com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener)1 CameraWrapper (de.gg.camera.CameraWrapper)1 NewChatMessagEvent (de.gg.event.NewChatMessagEvent)1 GameInHouseScreen (de.gg.screen.GameInHouseScreen)1