Search in sources :

Example 6 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project commons-gdx by gemserk.

the class Actors method threeOptionsDialog.

public static Actor threeOptionsDialog(String[] texts, final DialogListener dialogListener, String titleText, String firstOption, String secondOption, String thirdOption, Skin skin) {
    Window window = new Window(titleText, skin);
    window.setMovable(false);
    TextButton firstOptionButton = new TextButton(firstOption, skin);
    TextButton secondOptionButton = new TextButton(secondOption, skin);
    TextButton thirdOptionButton = new TextButton(thirdOption, skin);
    firstOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(0);
        }
    });
    secondOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(1);
        }
    });
    thirdOptionButton.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            dialogListener.optionSelected(2);
        }
    });
    window.defaults().spaceBottom(10);
    window.row().fill().expandX();
    for (int i = 0; i < texts.length; i++) {
        window.row().padLeft(20);
        Label label = new Label(texts[i], skin);
        label.setWrap(true);
        window.add(label).align(Align.left).colspan(2).fillX();
    }
    window.row().fill().expandX().padTop(10);
    window.add(firstOptionButton).align(Align.center).padLeft(30).padRight(30);
    window.row().fill().expandX();
    window.add(secondOptionButton).align(Align.center).padLeft(30).padRight(30);
    window.row().fill().expandX();
    window.add(thirdOptionButton).align(Align.center).padLeft(30).padRight(30);
    ScrollPane scrollPane = new ScrollPane(window);
    scrollPane.setWidth(Gdx.graphics.getWidth() * 0.95f);
    scrollPane.setHeight(Gdx.graphics.getHeight() * 0.95f);
    scrollPane.setX(Gdx.graphics.getWidth() * 0.5f - scrollPane.getWidth() * 0.5f);
    scrollPane.setY(Gdx.graphics.getHeight() * 0.5f - scrollPane.getHeight() * 0.5f);
    return scrollPane;
}
Also used : Window(com.badlogic.gdx.scenes.scene2d.ui.Window) TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) ScrollPane(com.badlogic.gdx.scenes.scene2d.ui.ScrollPane) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 7 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project AmazingMaze by TheVirtualMachine.

the class FishMiniGame method dialog.

/**
	 * Displays the results dialog.
	 */
public void dialog() {
    message = formatString(answerField.getText());
    Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
    final Dialog dialog = new Dialog("Results", game.assets.skin);
    final TextButton okButton = new TextButton("OK", game.assets.skin);
    dialog.getButtonTable().bottom();
    if (checkAnswer() == -1) {
        Label label = new Label("Invalid answer. Please try again.", labelStyle);
        label.setScale(.5f);
        label.setWrap(true);
        label.setAlignment(Align.center);
        dialog.add(label).width(500).pad(50);
        dialog.add(okButton).bottom();
        okButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (okButton.isPressed()) {
                    dialog.hide();
                    canvas.setColor(drawColor);
                }
            }
        });
        dialog.addListener(new InputListener() {

            @Override
            public boolean keyDown(InputEvent event, int keycode) {
                if (keycode == Keys.ENTER) {
                    dialog.hide();
                    return true;
                }
                return false;
            }
        });
    } else {
        Label label = new Label("Your answer was: " + message + ". " + "The correct answer was: " + answer + ". " + "You get " + checkAnswer() + " back!", labelStyle);
        game.save.addScore(checkAnswer());
        game.save.setLives(player.getLives());
        label.setScale(.5f);
        label.setWrap(true);
        label.setAlignment(Align.center);
        dialog.add(label).width(500).pad(50);
        dialog.add(okButton).bottom();
        okButton.addListener(new ChangeListener() {

            @Override
            public void changed(ChangeEvent event, Actor actor) {
                if (okButton.isPressed()) {
                    dialog.cancel();
                    if ((game.save.getLevel() - 1) % 5 == 0) {
                        game.setScreen(new ContinueScreen(game, true));
                    } else {
                        game.setScreen(new MazeScreen(game, false));
                    }
                }
            }
        });
        dialog.addListener(new InputListener() {

            @Override
            public boolean keyDown(InputEvent event, int keycode) {
                if (keycode == Keys.ENTER) {
                    if ((game.save.getLevel() - 1) % 5 == 0) {
                        game.setScreen(new ContinueScreen(game, true));
                    } else {
                        game.setScreen(new MazeScreen(game, false));
                    }
                    return true;
                }
                return false;
            }
        });
    }
    dialog.show(stage);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 8 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project AmazingMaze by TheVirtualMachine.

the class ContinueScreen method highScoreDialog.

/**
	 * Displays the high score dialog.
	 */
public void highScoreDialog() {
    Label.LabelStyle labelStyle = new Label.LabelStyle(game.assets.getFont(Assets.MONO_REGULAR, Assets.SMALL_FONT_SIZE), Color.WHITE);
    final Dialog dialog = new Dialog("High Score", game.assets.skin);
    final TextButton okButton = new TextButton("OK", game.assets.skin);
    dialog.getButtonTable().bottom();
    Label label = new Label("Enter your name:", labelStyle);
    label.setScale(.5f);
    label.setWrap(true);
    label.setAlignment(Align.center);
    final TextField nameField = new TextField("", game.assets.skin);
    dialog.add(label).width(500).pad(50);
    dialog.add(nameField);
    dialog.add(okButton).bottom();
    nameField.setTextFieldListener(new TextFieldListener() {

        @Override
        public void keyTyped(TextField textField, char key) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (key == (char) 13) {
                    displayHighScores(name);
                }
            }
        }
    });
    okButton.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (okButton.isPressed()) {
                    dialog.hide();
                    displayHighScores(name);
                }
            }
        }
    });
    dialog.addListener(new InputListener() {

        @Override
        public boolean keyDown(InputEvent event, int keycode) {
            name = formatString(nameField.getText());
            if (!name.equals("")) {
                if (keycode == Keys.ENTER) {
                    displayHighScores(name);
                    return true;
                }
            }
            return false;
        }
    });
    dialog.show(stage);
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) Label(com.badlogic.gdx.scenes.scene2d.ui.Label) InputListener(com.badlogic.gdx.scenes.scene2d.InputListener) Dialog(com.badlogic.gdx.scenes.scene2d.ui.Dialog) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextField(com.badlogic.gdx.scenes.scene2d.ui.TextField) TextFieldListener(com.badlogic.gdx.scenes.scene2d.ui.TextField.TextFieldListener) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent)

Example 9 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project Catacomb-Snatch by Catacomb-Snatch.

the class Scene method addTextButton.

/**
     * Adds a new text button
     *
     * @param text The text it contains
     * @param x    The x-position
     * @param y    The y-position
     * @return The created {@link TextButton}
     */
public TextButton addTextButton(String text, int x, int y) {
    final TextButton button = new TextButton(text, Art.skin);
    button.setPosition(x, y);
    button.addListener(new ClickListener() {

        @Override
        public void clicked(InputEvent event, float x, float y) {
            button.act(Gdx.graphics.getDeltaTime());
        }
    });
    addActor(button);
    return button;
}
Also used : TextButton(com.badlogic.gdx.scenes.scene2d.ui.TextButton) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Example 10 with InputEvent

use of com.badlogic.gdx.scenes.scene2d.InputEvent in project gdx-skineditor by cobolfoo.

the class WidgetsBar method initializeButtons.

/**
	 * 
	 */
public void initializeButtons() {
    group = new ButtonGroup();
    Tooltips.TooltipStyle styleTooltip = new Tooltips.TooltipStyle(game.skin.getFont("default-font"), game.skin.getDrawable("default-round"), game.skin.getColor("white"));
    String[] widgets = SkinEditorGame.widgets;
    for (String widget : widgets) {
        ImageButtonStyle style = new ImageButtonStyle();
        style.checked = game.skin.getDrawable("default-round-down");
        style.down = game.skin.getDrawable("default-round-down");
        style.up = game.skin.getDrawable("default-round");
        style.imageUp = game.skin.getDrawable("widgets/" + widget);
        ImageButton button = new ImageButton(style);
        button.setUserObject(widget);
        Tooltips tooltip = new Tooltips(styleTooltip, getStage());
        tooltip.registerTooltip(button, (String) button.getUserObject());
        button.addListener(new ClickListener() {

            @Override
            public void clicked(InputEvent event, float x, float y) {
                game.screenMain.panePreview.refresh();
                game.screenMain.paneOptions.refresh();
            }
        });
        group.add(button);
        add(button).pad(5);
    }
}
Also used : ImageButton(com.badlogic.gdx.scenes.scene2d.ui.ImageButton) ButtonGroup(com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup) Tooltips(com.mobidevelop.maps.editor.ui.utils.Tooltips) ImageButtonStyle(com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle) InputEvent(com.badlogic.gdx.scenes.scene2d.InputEvent) ClickListener(com.badlogic.gdx.scenes.scene2d.utils.ClickListener)

Aggregations

InputEvent (com.badlogic.gdx.scenes.scene2d.InputEvent)26 ClickListener (com.badlogic.gdx.scenes.scene2d.utils.ClickListener)17 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)16 TextButton (com.badlogic.gdx.scenes.scene2d.ui.TextButton)16 Stage (com.badlogic.gdx.scenes.scene2d.Stage)15 Skin (com.badlogic.gdx.scenes.scene2d.ui.Skin)13 Table (com.badlogic.gdx.scenes.scene2d.ui.Table)10 Actor (com.badlogic.gdx.scenes.scene2d.Actor)9 InputListener (com.badlogic.gdx.scenes.scene2d.InputListener)7 ScrollPane (com.badlogic.gdx.scenes.scene2d.ui.ScrollPane)6 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)6 Texture (com.badlogic.gdx.graphics.Texture)5 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)5 TextureRegion (com.badlogic.gdx.graphics.g2d.TextureRegion)4 CheckBox (com.badlogic.gdx.scenes.scene2d.ui.CheckBox)3 Image (com.badlogic.gdx.scenes.scene2d.ui.Image)3 List (com.badlogic.gdx.scenes.scene2d.ui.List)3 TextButtonStyle (com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle)3 Window (com.badlogic.gdx.scenes.scene2d.ui.Window)3 Batch (com.badlogic.gdx.graphics.g2d.Batch)2