Search in sources :

Example 96 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent 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 97 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project ProjektGG by eskalon.

the class MainMenuScreen method initUI.

@Override
protected void initUI() {
    backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
    Sound clickSound = assetManager.get(BUTTON_SOUND);
    ImageTextButton multiplayerButton = new ImageTextButton("Multiplayer", skin);
    multiplayerButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            game.pushScreen("serverBrowser");
            return true;
        }
    });
    ImageTextButton settingsButton = new ImageTextButton("Einstellungen", skin);
    settingsButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            // Gdx.app.exit();
            return true;
        }
    });
    ImageTextButton exitButton = new ImageTextButton("Beenden", skin);
    exitButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            Gdx.app.exit();
            return true;
        }
    });
    Image logoImage = new Image((Texture) assetManager.get(LOGO_IMAGE_PATH));
    /*
		 * multiplayerButton .addListener(new TextTooltip("You can press this",
		 * skin));
		 */
    mainTable.add(logoImage).padBottom(25f).padTop(-120f);
    mainTable.row();
    mainTable.add(multiplayerButton).padBottom(11f);
    mainTable.row();
    mainTable.add(settingsButton).padBottom(11f);
    mainTable.row();
    mainTable.add(exitButton);
}
Also used : ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Sound(com.badlogic.gdx.audio.Sound) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Image(com.badlogic.gdx.scenes.scene2d.ui.Image)

Example 98 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project ProjektGG by eskalon.

the class ServerBrowserScreen method initUI.

@Override
protected void initUI() {
    backgroundTexture = assetManager.get(BACKGROUND_IMAGE_PATH);
    Sound clickSound = assetManager.get(BUTTON_SOUND);
    // mainTable.setBackground(skin.getDrawable("parchment-small"));
    Table serverTable = new Table();
    ScrollPane pane = new ScrollPane(serverTable);
    // TODO gegen echte Server-Daten austauschen
    String ip = "127.0.0.1";
    int port = 12345;
    ImageTextButton joinButton = new ImageTextButton("Beitreten", skin);
    joinButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            game.getNetworkHandler().setUpConnectionAsClient(ip, port);
            connectingDialog = new Dialog("Verbinden...", skin);
            connectingDialog.text("Spiel beitreten...");
            connectingDialog.show(stage);
            return true;
        }
    });
    ImageTextButton backButton = new ImageTextButton("Zur�ck", skin);
    backButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            game.pushScreen("mainMenu");
            return true;
        }
    });
    ImageTextButton createLobbyButton = new ImageTextButton("Spiel erstellen", skin);
    createLobbyButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            game.pushScreen("lobbyCreation");
            return true;
        }
    });
    ImageTextButton directConnectButton = new ImageTextButton("Direkt verbinden", skin);
    directConnectButton.addListener(new InputListener() {

        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            clickSound.play(1F);
            TextField portInputField = new TextField("55789", skin);
            portInputField.setTextFieldFilter(new TextField.TextFieldFilter.DigitsOnlyFilter());
            TextField ipInputField = new TextField("127.0.0.1", skin);
            Dialog dialog = new Dialog("Direkt verbinden", skin) {

                public void result(Object obj) {
                    if ((Boolean) obj) {
                        game.getNetworkHandler().setUpConnectionAsClient(ipInputField.getText(), Integer.valueOf(portInputField.getText()));
                        connectingDialog = new Dialog("Verbinden...", skin);
                        connectingDialog.text("Spiel beitreten...");
                        connectingDialog.show(stage);
                    }
                }
            };
            dialog.text("IP: ").button("Zur�ck", false).button("Verbinden", true).key(Keys.ENTER, true).key(Keys.ESCAPE, false);
            dialog.getContentTable().add(ipInputField).width(170).row();
            dialog.getContentTable().add(new Label("Port:", skin));
            dialog.getContentTable().add(portInputField).width(90).left();
            dialog.show(stage);
            return true;
        }
    });
    Table buttonTable = new Table();
    buttonTable.add(backButton);
    buttonTable.add(createLobbyButton).padLeft(55);
    buttonTable.add(directConnectButton).padLeft(55);
    serverTable.left().top().add(new Image((Texture) assetManager.get(TICK_IMAGE_PATH))).padRight(15).padLeft(12);
    serverTable.add(new Label("Spiel 2", skin)).expandX();
    serverTable.add(joinButton).padRight(12);
    serverTable.row().padTop(20);
    mainTable.add(serverTable).width(580).height(405).row();
    mainTable.add(buttonTable).height(50).bottom();
}
Also used : Table(com.badlogic.gdx.scenes.scene2d.ui.Table) ImageTextButton(com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) Sound(com.badlogic.gdx.audio.Sound) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) Texture(com.badlogic.gdx.graphics.Texture) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 99 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Rebleyama by dhbw-stginf16a.

the class ClientUI method createXButton.

/**
 * method to create X button for window
 *
 * @param window in which a X button shall be created
 */
private void createXButton(Window window) {
    // create button
    final TextButton buttonX = new TextButton("X", skin);
    // ad butto to top bar of window
    window.getTitleTable().add(buttonX).height(window.getPadTop());
    // setup event listener for X button
    buttonX.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            window.setVisible(false);
        }
    });
}
Also used : InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 100 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Rebleyama by dhbw-stginf16a.

the class ClientUI method createMinimap.

/**
 * Creates a windows with a minimap in it
 */
private void createMinimap() {
    // create window
    miniMapWindow = new Window("Minimap", skin);
    // set postion of window (-size)
    miniMapWindow.setPosition((float) (Gdx.graphics.getWidth() - 200), (float) (Gdx.graphics.getHeight() - 200));
    // set size of window
    miniMapWindow.setSize(256, 256);
    // create image
    minimap = new Image();
    // add Xbuton in top bar of minimap with extras
    final TextButton buttonX = new TextButton("X", skin);
    // ad butto to top bar of window
    miniMapWindow.getTitleTable().add(buttonX).height(miniMapWindow.getPadTop());
    // setup event listener for X button
    buttonX.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            miniMapWindow.setVisible(false);
            // close render
            endcalcThread();
        }
    });
    // aspect ratio button
    final TextButton buttonScale = new TextButton("+", skin);
    // listener with logic inside
    buttonScale.addListener(new DragListener() {

        float oldY;

        float oldX;

        float oldWidth;

        float newwidth;

        @Override
        public void drag(InputEvent event, float x, float y, int pointer) {
            oldY = miniMapWindow.getY();
            oldX = miniMapWindow.getX();
            oldWidth = miniMapWindow.getWidth();
            // logic for minimap resizing
            if ((x > 0) && (y > 0) && (oldWidth > 128)) {
                if (oldWidth - x < 128) {
                    newwidth = 128;
                } else {
                    newwidth = oldWidth - x;
                }
            } else if ((x < 0) && (y < 0) && (oldWidth < 512)) {
                if (oldWidth - x > 512) {
                    newwidth = 512;
                } else {
                    newwidth = oldWidth - x;
                }
            }
            miniMapWindow.setPosition(oldX + oldWidth - newwidth, oldY + oldWidth - newwidth);
            miniMapWindow.setSize(newwidth, newwidth);
        }
    });
    // stack actor over each other
    Stack stack = new Stack();
    Table overlay = new Table();
    stack.add(minimap);
    overlay.add(buttonScale).expand().bottom().left();
    stack.add(overlay);
    miniMapWindow.add(stack);
    // add minimap to ui stage
    stage.addActor(miniMapWindow);
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) DragListener(com.badlogic.gdx.scenes.scene2d.utils.DragListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) Image(com.badlogic.gdx.scenes.scene2d.ui.Image) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)358 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)183 Actor (com.badlogic.gdx.scenes.scene2d.Actor)174 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)144 PopTableClickListener (com.ray3k.stripe.PopTableClickListener)110 SimActor (com.ray3k.skincomposer.dialog.scenecomposer.DialogSceneComposerModel.SimActor)109 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)86 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)53 Stage (com.badlogic.gdx.scenes.scene2d.Stage)49 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)47 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)45 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)35 Texture (com.badlogic.gdx.graphics.Texture)34 Spinner (com.ray3k.stripe.Spinner)32 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)31 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)29 TextureRegionDrawable (com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable)26 ImageButton (com.badlogic.gdx.scenes.scene2d.ui.ImageButton)25 StyleSelectorPopTable (com.ray3k.skincomposer.dialog.scenecomposer.StyleSelectorPopTable)25 Sprite (com.badlogic.gdx.graphics.g2d.Sprite)22